Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: webrtc/video/vie_sync_module.cc

Issue 1905983002: Use vcm::VideoReceiver on the receive side. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/vie_sync_module.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/video/vie_sync_module.h" 11 #include "webrtc/video/vie_sync_module.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/base/trace_event.h" 15 #include "webrtc/base/trace_event.h"
16 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" 16 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
18 #include "webrtc/modules/video_coding/include/video_coding.h" 18 #include "webrtc/modules/video_coding/video_coding_impl.h"
19 #include "webrtc/system_wrappers/include/clock.h" 19 #include "webrtc/system_wrappers/include/clock.h"
20 #include "webrtc/video/stream_synchronization.h" 20 #include "webrtc/video/stream_synchronization.h"
21 #include "webrtc/video_frame.h" 21 #include "webrtc/video_frame.h"
22 #include "webrtc/voice_engine/include/voe_video_sync.h" 22 #include "webrtc/voice_engine/include/voe_video_sync.h"
23 23
24 namespace webrtc { 24 namespace webrtc {
25 namespace { 25 namespace {
26 int UpdateMeasurements(StreamSynchronization::Measurements* stream, 26 int UpdateMeasurements(StreamSynchronization::Measurements* stream,
27 const RtpRtcp& rtp_rtcp, const RtpReceiver& receiver) { 27 const RtpRtcp& rtp_rtcp, const RtpReceiver& receiver) {
28 if (!receiver.Timestamp(&stream->latest_timestamp)) 28 if (!receiver.Timestamp(&stream->latest_timestamp))
(...skipping 12 matching lines...) Expand all
41 bool new_rtcp_sr = false; 41 bool new_rtcp_sr = false;
42 if (!UpdateRtcpList( 42 if (!UpdateRtcpList(
43 ntp_secs, ntp_frac, rtp_timestamp, &stream->rtcp, &new_rtcp_sr)) { 43 ntp_secs, ntp_frac, rtp_timestamp, &stream->rtcp, &new_rtcp_sr)) {
44 return -1; 44 return -1;
45 } 45 }
46 46
47 return 0; 47 return 0;
48 } 48 }
49 } // namespace 49 } // namespace
50 50
51 ViESyncModule::ViESyncModule(VideoCodingModule* vcm) 51 ViESyncModule::ViESyncModule(vcm::VideoReceiver* video_receiver)
52 : vcm_(vcm), 52 : video_receiver_(video_receiver),
53 clock_(Clock::GetRealTimeClock()), 53 clock_(Clock::GetRealTimeClock()),
54 video_receiver_(nullptr), 54 rtp_receiver_(nullptr),
55 video_rtp_rtcp_(nullptr), 55 video_rtp_rtcp_(nullptr),
56 voe_channel_id_(-1), 56 voe_channel_id_(-1),
57 voe_sync_interface_(nullptr), 57 voe_sync_interface_(nullptr),
58 last_sync_time_(TickTime::Now()), 58 last_sync_time_(TickTime::Now()),
59 sync_() {} 59 sync_() {}
60 60
61 ViESyncModule::~ViESyncModule() { 61 ViESyncModule::~ViESyncModule() {
62 } 62 }
63 63
64 void ViESyncModule::ConfigureSync(int voe_channel_id, 64 void ViESyncModule::ConfigureSync(int voe_channel_id,
65 VoEVideoSync* voe_sync_interface, 65 VoEVideoSync* voe_sync_interface,
66 RtpRtcp* video_rtcp_module, 66 RtpRtcp* video_rtcp_module,
67 RtpReceiver* video_receiver) { 67 RtpReceiver* rtp_receiver) {
68 if (voe_channel_id != -1) 68 if (voe_channel_id != -1)
69 RTC_DCHECK(voe_sync_interface); 69 RTC_DCHECK(voe_sync_interface);
70 rtc::CritScope lock(&data_cs_); 70 rtc::CritScope lock(&data_cs_);
71 // Prevent expensive no-ops. 71 // Prevent expensive no-ops.
72 if (voe_channel_id_ == voe_channel_id && 72 if (voe_channel_id_ == voe_channel_id &&
73 voe_sync_interface_ == voe_sync_interface && 73 voe_sync_interface_ == voe_sync_interface &&
74 video_receiver_ == video_receiver && 74 rtp_receiver_ == rtp_receiver && video_rtp_rtcp_ == video_rtcp_module) {
75 video_rtp_rtcp_ == video_rtcp_module) {
76 return; 75 return;
77 } 76 }
78 voe_channel_id_ = voe_channel_id; 77 voe_channel_id_ = voe_channel_id;
79 voe_sync_interface_ = voe_sync_interface; 78 voe_sync_interface_ = voe_sync_interface;
80 video_receiver_ = video_receiver; 79 rtp_receiver_ = rtp_receiver;
81 video_rtp_rtcp_ = video_rtcp_module; 80 video_rtp_rtcp_ = video_rtcp_module;
82 sync_.reset( 81 sync_.reset(
83 new StreamSynchronization(video_rtp_rtcp_->SSRC(), voe_channel_id)); 82 new StreamSynchronization(video_rtp_rtcp_->SSRC(), voe_channel_id));
84 } 83 }
85 84
86 int64_t ViESyncModule::TimeUntilNextProcess() { 85 int64_t ViESyncModule::TimeUntilNextProcess() {
87 const int64_t kSyncIntervalMs = 1000; 86 const int64_t kSyncIntervalMs = 1000;
88 return kSyncIntervalMs - (TickTime::Now() - last_sync_time_).Milliseconds(); 87 return kSyncIntervalMs - (TickTime::Now() - last_sync_time_).Milliseconds();
89 } 88 }
90 89
91 void ViESyncModule::Process() { 90 void ViESyncModule::Process() {
92 rtc::CritScope lock(&data_cs_); 91 rtc::CritScope lock(&data_cs_);
93 last_sync_time_ = TickTime::Now(); 92 last_sync_time_ = TickTime::Now();
94 93
95 const int current_video_delay_ms = vcm_->Delay(); 94 const int current_video_delay_ms = video_receiver_->Delay();
96 95
97 if (voe_channel_id_ == -1) { 96 if (voe_channel_id_ == -1) {
98 return; 97 return;
99 } 98 }
100 assert(video_rtp_rtcp_ && voe_sync_interface_); 99 assert(video_rtp_rtcp_ && voe_sync_interface_);
101 assert(sync_.get()); 100 assert(sync_.get());
102 101
103 int audio_jitter_buffer_delay_ms = 0; 102 int audio_jitter_buffer_delay_ms = 0;
104 int playout_buffer_delay_ms = 0; 103 int playout_buffer_delay_ms = 0;
105 if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_, 104 if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_,
106 &audio_jitter_buffer_delay_ms, 105 &audio_jitter_buffer_delay_ms,
107 &playout_buffer_delay_ms) != 0) { 106 &playout_buffer_delay_ms) != 0) {
108 return; 107 return;
109 } 108 }
110 const int current_audio_delay_ms = audio_jitter_buffer_delay_ms + 109 const int current_audio_delay_ms = audio_jitter_buffer_delay_ms +
111 playout_buffer_delay_ms; 110 playout_buffer_delay_ms;
112 111
113 RtpRtcp* voice_rtp_rtcp = nullptr; 112 RtpRtcp* voice_rtp_rtcp = nullptr;
114 RtpReceiver* voice_receiver = nullptr; 113 RtpReceiver* voice_receiver = nullptr;
115 if (voe_sync_interface_->GetRtpRtcp(voe_channel_id_, &voice_rtp_rtcp, 114 if (voe_sync_interface_->GetRtpRtcp(voe_channel_id_, &voice_rtp_rtcp,
116 &voice_receiver) != 0) { 115 &voice_receiver) != 0) {
117 return; 116 return;
118 } 117 }
119 assert(voice_rtp_rtcp); 118 assert(voice_rtp_rtcp);
120 assert(voice_receiver); 119 assert(voice_receiver);
121 120
122 if (UpdateMeasurements(&video_measurement_, *video_rtp_rtcp_, 121 if (UpdateMeasurements(&video_measurement_, *video_rtp_rtcp_,
123 *video_receiver_) != 0) { 122 *rtp_receiver_) != 0) {
124 return; 123 return;
125 } 124 }
126 125
127 if (UpdateMeasurements(&audio_measurement_, *voice_rtp_rtcp, 126 if (UpdateMeasurements(&audio_measurement_, *voice_rtp_rtcp,
128 *voice_receiver) != 0) { 127 *voice_receiver) != 0) {
129 return; 128 return;
130 } 129 }
131 130
132 int relative_delay_ms; 131 int relative_delay_ms;
133 // Calculate how much later or earlier the audio stream is compared to video. 132 // Calculate how much later or earlier the audio stream is compared to video.
(...skipping 13 matching lines...) Expand all
147 current_audio_delay_ms, 146 current_audio_delay_ms,
148 &target_audio_delay_ms, 147 &target_audio_delay_ms,
149 &target_video_delay_ms)) { 148 &target_video_delay_ms)) {
150 return; 149 return;
151 } 150 }
152 151
153 if (voe_sync_interface_->SetMinimumPlayoutDelay( 152 if (voe_sync_interface_->SetMinimumPlayoutDelay(
154 voe_channel_id_, target_audio_delay_ms) == -1) { 153 voe_channel_id_, target_audio_delay_ms) == -1) {
155 LOG(LS_ERROR) << "Error setting voice delay."; 154 LOG(LS_ERROR) << "Error setting voice delay.";
156 } 155 }
157 vcm_->SetMinimumPlayoutDelay(target_video_delay_ms); 156 video_receiver_->SetMinimumPlayoutDelay(target_video_delay_ms);
158 } 157 }
159 158
160 bool ViESyncModule::GetStreamSyncOffsetInMs(const VideoFrame& frame, 159 bool ViESyncModule::GetStreamSyncOffsetInMs(const VideoFrame& frame,
161 int64_t* stream_offset_ms) const { 160 int64_t* stream_offset_ms) const {
162 rtc::CritScope lock(&data_cs_); 161 rtc::CritScope lock(&data_cs_);
163 if (voe_channel_id_ == -1) 162 if (voe_channel_id_ == -1)
164 return false; 163 return false;
165 164
166 uint32_t playout_timestamp = 0; 165 uint32_t playout_timestamp = 0;
167 if (voe_sync_interface_->GetPlayoutTimestamp(voe_channel_id_, 166 if (voe_sync_interface_->GetPlayoutTimestamp(voe_channel_id_,
(...skipping 16 matching lines...) Expand all
184 int64_t time_to_render_ms = 183 int64_t time_to_render_ms =
185 frame.render_time_ms() - clock_->TimeInMilliseconds(); 184 frame.render_time_ms() - clock_->TimeInMilliseconds();
186 if (time_to_render_ms > 0) 185 if (time_to_render_ms > 0)
187 latest_video_ntp += time_to_render_ms; 186 latest_video_ntp += time_to_render_ms;
188 187
189 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; 188 *stream_offset_ms = latest_audio_ntp - latest_video_ntp;
190 return true; 189 return true;
191 } 190 }
192 191
193 } // namespace webrtc 192 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_sync_module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698