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/base/checks.h" | 11 #include "webrtc/base/checks.h" |
12 #include "webrtc/base/logging.h" | 12 #include "webrtc/base/logging.h" |
13 #include "webrtc/base/trace_event.h" | 13 #include "webrtc/base/trace_event.h" |
14 #include "webrtc/common_types.h" | 14 #include "webrtc/common_types.h" |
15 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 15 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
16 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 16 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
17 #include "webrtc/modules/video_coding/encoded_frame.h" | 17 #include "webrtc/modules/video_coding/encoded_frame.h" |
18 #include "webrtc/modules/video_coding/jitter_buffer.h" | 18 #include "webrtc/modules/video_coding/jitter_buffer.h" |
19 #include "webrtc/modules/video_coding/packet.h" | 19 #include "webrtc/modules/video_coding/packet.h" |
20 #include "webrtc/modules/video_coding/video_coding_impl.h" | 20 #include "webrtc/modules/video_coding/video_coding_impl.h" |
21 #include "webrtc/system_wrappers/include/clock.h" | 21 #include "webrtc/system_wrappers/include/clock.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 namespace vcm { | 24 namespace vcm { |
25 | 25 |
26 VideoReceiver::VideoReceiver(Clock* clock, | 26 VideoReceiver::VideoReceiver(Clock* clock, |
27 EventFactory* event_factory, | 27 EventFactory* event_factory, |
28 EncodedImageCallback* pre_decode_image_callback, | 28 EncodedImageCallback* pre_decode_image_callback, |
| 29 VCMTiming* timing, |
29 NackSender* nack_sender, | 30 NackSender* nack_sender, |
30 KeyFrameRequestSender* keyframe_request_sender) | 31 KeyFrameRequestSender* keyframe_request_sender) |
31 : clock_(clock), | 32 : clock_(clock), |
32 _timing(clock_), | 33 _timing(timing), |
33 _receiver(&_timing, | 34 _receiver(_timing, |
34 clock_, | 35 clock_, |
35 event_factory, | 36 event_factory, |
36 nack_sender, | 37 nack_sender, |
37 keyframe_request_sender), | 38 keyframe_request_sender), |
38 _decodedFrameCallback(&_timing, clock_), | 39 _decodedFrameCallback(_timing, clock_), |
39 _frameTypeCallback(nullptr), | 40 _frameTypeCallback(nullptr), |
40 _receiveStatsCallback(nullptr), | 41 _receiveStatsCallback(nullptr), |
41 _decoderTimingCallback(nullptr), | 42 _decoderTimingCallback(nullptr), |
42 _packetRequestCallback(nullptr), | 43 _packetRequestCallback(nullptr), |
43 _decoder(nullptr), | 44 _decoder(nullptr), |
44 _frameFromFile(), | 45 _frameFromFile(), |
45 _scheduleKeyRequest(false), | 46 _scheduleKeyRequest(false), |
46 drop_frames_until_keyframe_(false), | 47 drop_frames_until_keyframe_(false), |
47 max_nack_list_size_(0), | 48 max_nack_list_size_(0), |
48 _codecDataBase(nullptr), | 49 _codecDataBase(nullptr), |
(...skipping 17 matching lines...) Expand all Loading... |
66 } | 67 } |
67 | 68 |
68 if (_decoderTimingCallback != nullptr) { | 69 if (_decoderTimingCallback != nullptr) { |
69 int decode_ms; | 70 int decode_ms; |
70 int max_decode_ms; | 71 int max_decode_ms; |
71 int current_delay_ms; | 72 int current_delay_ms; |
72 int target_delay_ms; | 73 int target_delay_ms; |
73 int jitter_buffer_ms; | 74 int jitter_buffer_ms; |
74 int min_playout_delay_ms; | 75 int min_playout_delay_ms; |
75 int render_delay_ms; | 76 int render_delay_ms; |
76 _timing.GetTimings(&decode_ms, &max_decode_ms, ¤t_delay_ms, | 77 _timing->GetTimings(&decode_ms, &max_decode_ms, ¤t_delay_ms, |
77 &target_delay_ms, &jitter_buffer_ms, | 78 &target_delay_ms, &jitter_buffer_ms, |
78 &min_playout_delay_ms, &render_delay_ms); | 79 &min_playout_delay_ms, &render_delay_ms); |
79 _decoderTimingCallback->OnDecoderTiming( | 80 _decoderTimingCallback->OnDecoderTiming( |
80 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms, | 81 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms, |
81 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms); | 82 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms); |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
85 // Key frame requests | 86 // Key frame requests |
86 if (_keyRequestTimer.TimeUntilProcess() == 0) { | 87 if (_keyRequestTimer.TimeUntilProcess() == 0) { |
87 _keyRequestTimer.Processed(); | 88 _keyRequestTimer.Processed(); |
88 bool request_key_frame = false; | 89 bool request_key_frame = false; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 int qp = -1; | 270 int qp = -1; |
270 if (qp_parser_.GetQp(*frame, &qp)) { | 271 if (qp_parser_.GetQp(*frame, &qp)) { |
271 encoded_image.qp_ = qp; | 272 encoded_image.qp_ = qp; |
272 } | 273 } |
273 pre_decode_image_callback_->OnEncodedImage(encoded_image, | 274 pre_decode_image_callback_->OnEncodedImage(encoded_image, |
274 frame->CodecSpecific(), nullptr); | 275 frame->CodecSpecific(), nullptr); |
275 } | 276 } |
276 | 277 |
277 rtc::CritScope cs(&receive_crit_); | 278 rtc::CritScope cs(&receive_crit_); |
278 // If this frame was too late, we should adjust the delay accordingly | 279 // If this frame was too late, we should adjust the delay accordingly |
279 _timing.UpdateCurrentDelay(frame->RenderTimeMs(), | 280 _timing->UpdateCurrentDelay(frame->RenderTimeMs(), |
280 clock_->TimeInMilliseconds()); | 281 clock_->TimeInMilliseconds()); |
281 | 282 |
282 if (first_frame_received_()) { | 283 if (first_frame_received_()) { |
283 LOG(LS_INFO) << "Received first " | 284 LOG(LS_INFO) << "Received first " |
284 << (frame->Complete() ? "complete" : "incomplete") | 285 << (frame->Complete() ? "complete" : "incomplete") |
285 << " decodable video frame"; | 286 << " decodable video frame"; |
286 } | 287 } |
287 | 288 |
288 const int32_t ret = Decode(*frame); | 289 const int32_t ret = Decode(*frame); |
289 _receiver.ReleaseFrame(frame); | 290 _receiver.ReleaseFrame(frame); |
290 return ret; | 291 return ret; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 } else if (ret < 0) { | 434 } else if (ret < 0) { |
434 return ret; | 435 return ret; |
435 } | 436 } |
436 return VCM_OK; | 437 return VCM_OK; |
437 } | 438 } |
438 | 439 |
439 // Minimum playout delay (used for lip-sync). This is the minimum delay required | 440 // Minimum playout delay (used for lip-sync). This is the minimum delay required |
440 // to sync with audio. Not included in VideoCodingModule::Delay() | 441 // to sync with audio. Not included in VideoCodingModule::Delay() |
441 // Defaults to 0 ms. | 442 // Defaults to 0 ms. |
442 int32_t VideoReceiver::SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs) { | 443 int32_t VideoReceiver::SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs) { |
443 _timing.set_min_playout_delay(minPlayoutDelayMs); | 444 _timing->set_min_playout_delay(minPlayoutDelayMs); |
444 return VCM_OK; | 445 return VCM_OK; |
445 } | 446 } |
446 | 447 |
447 // The estimated delay caused by rendering, defaults to | 448 // The estimated delay caused by rendering, defaults to |
448 // kDefaultRenderDelayMs = 10 ms | 449 // kDefaultRenderDelayMs = 10 ms |
449 int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) { | 450 int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) { |
450 _timing.set_render_delay(timeMS); | 451 _timing->set_render_delay(timeMS); |
451 return VCM_OK; | 452 return VCM_OK; |
452 } | 453 } |
453 | 454 |
454 // Current video delay | 455 // Current video delay |
455 int32_t VideoReceiver::Delay() const { | 456 int32_t VideoReceiver::Delay() const { |
456 return _timing.TargetVideoDelay(); | 457 return _timing->TargetVideoDelay(); |
457 } | 458 } |
458 | 459 |
459 uint32_t VideoReceiver::DiscardedPackets() const { | 460 uint32_t VideoReceiver::DiscardedPackets() const { |
460 return _receiver.DiscardedPackets(); | 461 return _receiver.DiscardedPackets(); |
461 } | 462 } |
462 | 463 |
463 int VideoReceiver::SetReceiverRobustnessMode( | 464 int VideoReceiver::SetReceiverRobustnessMode( |
464 ReceiverRobustness robustnessMode, | 465 ReceiverRobustness robustnessMode, |
465 VCMDecodeErrorMode decode_error_mode) { | 466 VCMDecodeErrorMode decode_error_mode) { |
466 rtc::CritScope cs(&receive_crit_); | 467 rtc::CritScope cs(&receive_crit_); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 _receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack, | 514 _receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack, |
514 max_incomplete_time_ms); | 515 max_incomplete_time_ms); |
515 } | 516 } |
516 | 517 |
517 int VideoReceiver::SetMinReceiverDelay(int desired_delay_ms) { | 518 int VideoReceiver::SetMinReceiverDelay(int desired_delay_ms) { |
518 return _receiver.SetMinReceiverDelay(desired_delay_ms); | 519 return _receiver.SetMinReceiverDelay(desired_delay_ms); |
519 } | 520 } |
520 | 521 |
521 } // namespace vcm | 522 } // namespace vcm |
522 } // namespace webrtc | 523 } // namespace webrtc |
OLD | NEW |