OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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/video_receive_stream.h" | 11 #include "webrtc/video/video_receive_stream.h" |
12 | 12 |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 | 14 |
15 #include <set> | 15 #include <set> |
16 #include <string> | 16 #include <string> |
17 #include <utility> | 17 #include <utility> |
18 | 18 |
19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
23 #include "webrtc/modules/utility/include/process_thread.h" | 23 #include "webrtc/modules/utility/include/process_thread.h" |
24 #include "webrtc/modules/video_coding/include/video_coding.h" | 24 #include "webrtc/modules/video_coding/include/video_coding.h" |
25 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 25 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
26 #include "webrtc/system_wrappers/include/clock.h" | 26 #include "webrtc/system_wrappers/include/clock.h" |
27 #include "webrtc/video/call_stats.h" | 27 #include "webrtc/video/call_stats.h" |
28 #include "webrtc/video/receive_statistics_proxy.h" | 28 #include "webrtc/video/receive_statistics_proxy.h" |
29 #include "webrtc/video_receive_stream.h" | 29 #include "webrtc/video_receive_stream.h" |
| 30 #include "webrtc/voice_engine/include/voe_video_sync.h" |
30 | 31 |
31 namespace webrtc { | 32 namespace webrtc { |
32 | 33 |
33 static const bool kEnableFrameRecording = false; | 34 static const bool kEnableFrameRecording = false; |
34 | 35 |
35 static bool UseSendSideBwe(const VideoReceiveStream::Config& config) { | 36 static bool UseSendSideBwe(const VideoReceiveStream::Config& config) { |
36 if (!config.rtp.transport_cc) | 37 if (!config.rtp.transport_cc) |
37 return false; | 38 return false; |
38 for (const auto& extension : config.rtp.extensions) { | 39 for (const auto& extension : config.rtp.extensions) { |
39 if (extension.uri == RtpExtension::kTransportSequenceNumberUri) | 40 if (extension.uri == RtpExtension::kTransportSequenceNumberUri) |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 UseSendSideBwe(config_)), | 170 UseSendSideBwe(config_)), |
170 &transport_adapter_, | 171 &transport_adapter_, |
171 call_stats_->rtcp_rtt_stats(), | 172 call_stats_->rtcp_rtt_stats(), |
172 congestion_controller_->pacer(), | 173 congestion_controller_->pacer(), |
173 congestion_controller_->packet_router(), | 174 congestion_controller_->packet_router(), |
174 remb, | 175 remb, |
175 &config_, | 176 &config_, |
176 &stats_proxy_, | 177 &stats_proxy_, |
177 process_thread_, | 178 process_thread_, |
178 congestion_controller_->GetRetransmissionRateLimiter()), | 179 congestion_controller_->GetRetransmissionRateLimiter()), |
179 vie_sync_(&video_receiver_) { | 180 rtp_stream_sync_(&video_receiver_, &rtp_stream_receiver_) { |
180 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 181 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
181 | 182 |
182 RTC_DCHECK(process_thread_); | 183 RTC_DCHECK(process_thread_); |
183 RTC_DCHECK(congestion_controller_); | 184 RTC_DCHECK(congestion_controller_); |
184 RTC_DCHECK(call_stats_); | 185 RTC_DCHECK(call_stats_); |
185 | 186 |
186 RTC_DCHECK(!config_.decoders.empty()); | 187 RTC_DCHECK(!config_.decoders.empty()); |
187 std::set<int> decoder_payload_types; | 188 std::set<int> decoder_payload_types; |
188 for (const Decoder& decoder : config_.decoders) { | 189 for (const Decoder& decoder : config_.decoders) { |
189 RTC_CHECK(decoder.decoder); | 190 RTC_CHECK(decoder.decoder); |
190 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == | 191 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
191 decoder_payload_types.end()) | 192 decoder_payload_types.end()) |
192 << "Duplicate payload type (" << decoder.payload_type | 193 << "Duplicate payload type (" << decoder.payload_type |
193 << ") for different decoders."; | 194 << ") for different decoders."; |
194 decoder_payload_types.insert(decoder.payload_type); | 195 decoder_payload_types.insert(decoder.payload_type); |
195 video_receiver_.RegisterExternalDecoder(decoder.decoder, | 196 video_receiver_.RegisterExternalDecoder(decoder.decoder, |
196 decoder.payload_type); | 197 decoder.payload_type); |
197 | 198 |
198 VideoCodec codec = CreateDecoderVideoCodec(decoder); | 199 VideoCodec codec = CreateDecoderVideoCodec(decoder); |
199 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); | 200 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); |
200 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( | 201 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( |
201 &codec, num_cpu_cores, false)); | 202 &codec, num_cpu_cores, false)); |
202 } | 203 } |
203 | 204 |
204 video_receiver_.SetRenderDelay(config.render_delay_ms); | 205 video_receiver_.SetRenderDelay(config.render_delay_ms); |
205 | 206 |
206 process_thread_->RegisterModule(&video_receiver_); | 207 process_thread_->RegisterModule(&video_receiver_); |
207 process_thread_->RegisterModule(&vie_sync_); | 208 process_thread_->RegisterModule(&rtp_stream_sync_); |
208 } | 209 } |
209 | 210 |
210 VideoReceiveStream::~VideoReceiveStream() { | 211 VideoReceiveStream::~VideoReceiveStream() { |
211 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 212 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
212 Stop(); | 213 Stop(); |
213 | 214 |
214 process_thread_->DeRegisterModule(&vie_sync_); | 215 process_thread_->DeRegisterModule(&rtp_stream_sync_); |
215 process_thread_->DeRegisterModule(&video_receiver_); | 216 process_thread_->DeRegisterModule(&video_receiver_); |
216 | 217 |
217 // Deregister external decoders so they are no longer running during | 218 // Deregister external decoders so they are no longer running during |
218 // destruction. This effectively stops the VCM since the decoder thread is | 219 // destruction. This effectively stops the VCM since the decoder thread is |
219 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 220 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
220 // running. | 221 // running. |
221 for (const Decoder& decoder : config_.decoders) | 222 for (const Decoder& decoder : config_.decoders) |
222 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); | 223 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
223 | 224 |
224 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) | 225 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 call_stats_->DeregisterStatsObserver(video_stream_decoder_.get()); | 279 call_stats_->DeregisterStatsObserver(video_stream_decoder_.get()); |
279 video_stream_decoder_.reset(); | 280 video_stream_decoder_.reset(); |
280 incoming_video_stream_.reset(); | 281 incoming_video_stream_.reset(); |
281 transport_adapter_.Disable(); | 282 transport_adapter_.Disable(); |
282 } | 283 } |
283 | 284 |
284 void VideoReceiveStream::SetSyncChannel(VoiceEngine* voice_engine, | 285 void VideoReceiveStream::SetSyncChannel(VoiceEngine* voice_engine, |
285 int audio_channel_id) { | 286 int audio_channel_id) { |
286 if (voice_engine && audio_channel_id != -1) { | 287 if (voice_engine && audio_channel_id != -1) { |
287 VoEVideoSync* voe_sync_interface = VoEVideoSync::GetInterface(voice_engine); | 288 VoEVideoSync* voe_sync_interface = VoEVideoSync::GetInterface(voice_engine); |
288 vie_sync_.ConfigureSync(audio_channel_id, voe_sync_interface, | 289 rtp_stream_sync_.ConfigureSync(audio_channel_id, voe_sync_interface); |
289 rtp_stream_receiver_.rtp_rtcp(), | |
290 rtp_stream_receiver_.GetRtpReceiver()); | |
291 voe_sync_interface->Release(); | 290 voe_sync_interface->Release(); |
292 } else { | 291 } else { |
293 vie_sync_.ConfigureSync(-1, nullptr, rtp_stream_receiver_.rtp_rtcp(), | 292 rtp_stream_sync_.ConfigureSync(-1, nullptr); |
294 rtp_stream_receiver_.GetRtpReceiver()); | |
295 } | 293 } |
296 } | 294 } |
297 | 295 |
298 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { | 296 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { |
299 return stats_proxy_.GetStats(); | 297 return stats_proxy_.GetStats(); |
300 } | 298 } |
301 | 299 |
302 // TODO(tommi): This method grabs a lock 6 times. | 300 // TODO(tommi): This method grabs a lock 6 times. |
303 void VideoReceiveStream::OnFrame(const VideoFrame& video_frame) { | 301 void VideoReceiveStream::OnFrame(const VideoFrame& video_frame) { |
304 // TODO(tommi): OnDecodedFrame grabs a lock, incidentally the same lock | 302 // TODO(tommi): OnDecodedFrame grabs a lock, incidentally the same lock |
305 // that OnSyncOffsetUpdated() and OnRenderedFrame() below grab. | 303 // that OnSyncOffsetUpdated() and OnRenderedFrame() below grab. |
306 stats_proxy_.OnDecodedFrame(); | 304 stats_proxy_.OnDecodedFrame(); |
307 | 305 |
308 int64_t sync_offset_ms; | 306 int64_t sync_offset_ms; |
309 // TODO(tommi): GetStreamSyncOffsetInMs grabs three locks. One inside the | 307 // TODO(tommi): GetStreamSyncOffsetInMs grabs three locks. One inside the |
310 // function itself, another in GetChannel() and a third in | 308 // function itself, another in GetChannel() and a third in |
311 // GetPlayoutTimestamp. Seems excessive. Anyhow, I'm assuming the function | 309 // GetPlayoutTimestamp. Seems excessive. Anyhow, I'm assuming the function |
312 // succeeds most of the time, which leads to grabbing a fourth lock. | 310 // succeeds most of the time, which leads to grabbing a fourth lock. |
313 if (vie_sync_.GetStreamSyncOffsetInMs(video_frame, &sync_offset_ms)) { | 311 if (rtp_stream_sync_.GetStreamSyncOffsetInMs(video_frame, &sync_offset_ms)) { |
314 // TODO(tommi): OnSyncOffsetUpdated grabs a lock. | 312 // TODO(tommi): OnSyncOffsetUpdated grabs a lock. |
315 stats_proxy_.OnSyncOffsetUpdated(sync_offset_ms); | 313 stats_proxy_.OnSyncOffsetUpdated(sync_offset_ms); |
316 } | 314 } |
317 | 315 |
318 // config_.renderer must never be null if we're getting this callback. | 316 // config_.renderer must never be null if we're getting this callback. |
319 config_.renderer->OnFrame(video_frame); | 317 config_.renderer->OnFrame(video_frame); |
320 | 318 |
321 // TODO(tommi): OnRenderFrame grabs a lock too. | 319 // TODO(tommi): OnRenderFrame grabs a lock too. |
322 stats_proxy_.OnRenderedFrame(video_frame.width(), video_frame.height()); | 320 stats_proxy_.OnRenderedFrame(video_frame.width(), video_frame.height()); |
323 } | 321 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 const std::vector<uint16_t>& sequence_numbers) { | 363 const std::vector<uint16_t>& sequence_numbers) { |
366 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); | 364 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); |
367 } | 365 } |
368 | 366 |
369 void VideoReceiveStream::RequestKeyFrame() { | 367 void VideoReceiveStream::RequestKeyFrame() { |
370 rtp_stream_receiver_.RequestKeyFrame(); | 368 rtp_stream_receiver_.RequestKeyFrame(); |
371 } | 369 } |
372 | 370 |
373 } // namespace internal | 371 } // namespace internal |
374 } // namespace webrtc | 372 } // namespace webrtc |
OLD | NEW |