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

Side by Side Diff: webrtc/modules/video_coding/video_receiver.cc

Issue 2575473004: Create VideoReceiver with external VCMTiming object. (Closed)
Patch Set: Created 4 years 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
OLDNEW
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 NackSender* nack_sender, 29 NackSender* nack_sender,
30 KeyFrameRequestSender* keyframe_request_sender) 30 KeyFrameRequestSender* keyframe_request_sender,
31 VCMTiming* timing)
31 : clock_(clock), 32 : clock_(clock),
32 _timing(clock_), 33 _ownsTiming(timing == nullptr),
33 _receiver(&_timing, 34 _timing(_ownsTiming ? new VCMTiming(clock_) : timing),
35 _receiver(_timing,
34 clock_, 36 clock_,
35 event_factory, 37 event_factory,
36 nack_sender, 38 nack_sender,
37 keyframe_request_sender), 39 keyframe_request_sender),
38 _decodedFrameCallback(&_timing, clock_), 40 _decodedFrameCallback(_timing, clock_),
39 _frameTypeCallback(nullptr), 41 _frameTypeCallback(nullptr),
40 _receiveStatsCallback(nullptr), 42 _receiveStatsCallback(nullptr),
41 _decoderTimingCallback(nullptr), 43 _decoderTimingCallback(nullptr),
42 _packetRequestCallback(nullptr), 44 _packetRequestCallback(nullptr),
43 _decoder(nullptr), 45 _decoder(nullptr),
44 _frameFromFile(), 46 _frameFromFile(),
45 _scheduleKeyRequest(false), 47 _scheduleKeyRequest(false),
46 drop_frames_until_keyframe_(false), 48 drop_frames_until_keyframe_(false),
47 max_nack_list_size_(0), 49 max_nack_list_size_(0),
48 _codecDataBase(nullptr), 50 _codecDataBase(nullptr),
49 pre_decode_image_callback_(pre_decode_image_callback), 51 pre_decode_image_callback_(pre_decode_image_callback),
50 _receiveStatsTimer(1000, clock_), 52 _receiveStatsTimer(1000, clock_),
51 _retransmissionTimer(10, clock_), 53 _retransmissionTimer(10, clock_),
52 _keyRequestTimer(500, clock_) {} 54 _keyRequestTimer(500, clock_) {}
53 55
54 VideoReceiver::~VideoReceiver() {} 56 VideoReceiver::~VideoReceiver() {
57 if (_ownsTiming)
58 delete _timing;
59 }
55 60
56 void VideoReceiver::Process() { 61 void VideoReceiver::Process() {
57 // Receive-side statistics 62 // Receive-side statistics
58 if (_receiveStatsTimer.TimeUntilProcess() == 0) { 63 if (_receiveStatsTimer.TimeUntilProcess() == 0) {
59 _receiveStatsTimer.Processed(); 64 _receiveStatsTimer.Processed();
60 rtc::CritScope cs(&process_crit_); 65 rtc::CritScope cs(&process_crit_);
61 if (_receiveStatsCallback != nullptr) { 66 if (_receiveStatsCallback != nullptr) {
62 uint32_t bitRate; 67 uint32_t bitRate;
63 uint32_t frameRate; 68 uint32_t frameRate;
64 _receiver.ReceiveStatistics(&bitRate, &frameRate); 69 _receiver.ReceiveStatistics(&bitRate, &frameRate);
65 _receiveStatsCallback->OnReceiveRatesUpdated(bitRate, frameRate); 70 _receiveStatsCallback->OnReceiveRatesUpdated(bitRate, frameRate);
66 } 71 }
67 72
68 if (_decoderTimingCallback != nullptr) { 73 if (_decoderTimingCallback != nullptr) {
69 int decode_ms; 74 int decode_ms;
70 int max_decode_ms; 75 int max_decode_ms;
71 int current_delay_ms; 76 int current_delay_ms;
72 int target_delay_ms; 77 int target_delay_ms;
73 int jitter_buffer_ms; 78 int jitter_buffer_ms;
74 int min_playout_delay_ms; 79 int min_playout_delay_ms;
75 int render_delay_ms; 80 int render_delay_ms;
76 _timing.GetTimings(&decode_ms, &max_decode_ms, &current_delay_ms, 81 _timing->GetTimings(&decode_ms, &max_decode_ms, &current_delay_ms,
77 &target_delay_ms, &jitter_buffer_ms, 82 &target_delay_ms, &jitter_buffer_ms,
78 &min_playout_delay_ms, &render_delay_ms); 83 &min_playout_delay_ms, &render_delay_ms);
79 _decoderTimingCallback->OnDecoderTiming( 84 _decoderTimingCallback->OnDecoderTiming(
80 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms, 85 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms,
81 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms); 86 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms);
82 } 87 }
83 } 88 }
84 89
85 // Key frame requests 90 // Key frame requests
86 if (_keyRequestTimer.TimeUntilProcess() == 0) { 91 if (_keyRequestTimer.TimeUntilProcess() == 0) {
87 _keyRequestTimer.Processed(); 92 _keyRequestTimer.Processed();
88 bool request_key_frame = false; 93 bool request_key_frame = false;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 int qp = -1; 274 int qp = -1;
270 if (qp_parser_.GetQp(*frame, &qp)) { 275 if (qp_parser_.GetQp(*frame, &qp)) {
271 encoded_image.qp_ = qp; 276 encoded_image.qp_ = qp;
272 } 277 }
273 pre_decode_image_callback_->OnEncodedImage(encoded_image, 278 pre_decode_image_callback_->OnEncodedImage(encoded_image,
274 frame->CodecSpecific(), nullptr); 279 frame->CodecSpecific(), nullptr);
275 } 280 }
276 281
277 rtc::CritScope cs(&receive_crit_); 282 rtc::CritScope cs(&receive_crit_);
278 // If this frame was too late, we should adjust the delay accordingly 283 // If this frame was too late, we should adjust the delay accordingly
279 _timing.UpdateCurrentDelay(frame->RenderTimeMs(), 284 _timing->UpdateCurrentDelay(frame->RenderTimeMs(),
280 clock_->TimeInMilliseconds()); 285 clock_->TimeInMilliseconds());
281 286
282 if (first_frame_received_()) { 287 if (first_frame_received_()) {
283 LOG(LS_INFO) << "Received first " 288 LOG(LS_INFO) << "Received first "
284 << (frame->Complete() ? "complete" : "incomplete") 289 << (frame->Complete() ? "complete" : "incomplete")
285 << " decodable video frame"; 290 << " decodable video frame";
286 } 291 }
287 292
288 const int32_t ret = Decode(*frame); 293 const int32_t ret = Decode(*frame);
289 _receiver.ReleaseFrame(frame); 294 _receiver.ReleaseFrame(frame);
290 return ret; 295 return ret;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } else if (ret < 0) { 438 } else if (ret < 0) {
434 return ret; 439 return ret;
435 } 440 }
436 return VCM_OK; 441 return VCM_OK;
437 } 442 }
438 443
439 // Minimum playout delay (used for lip-sync). This is the minimum delay required 444 // Minimum playout delay (used for lip-sync). This is the minimum delay required
440 // to sync with audio. Not included in VideoCodingModule::Delay() 445 // to sync with audio. Not included in VideoCodingModule::Delay()
441 // Defaults to 0 ms. 446 // Defaults to 0 ms.
442 int32_t VideoReceiver::SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs) { 447 int32_t VideoReceiver::SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs) {
443 _timing.set_min_playout_delay(minPlayoutDelayMs); 448 _timing->set_min_playout_delay(minPlayoutDelayMs);
444 return VCM_OK; 449 return VCM_OK;
445 } 450 }
446 451
447 // The estimated delay caused by rendering, defaults to 452 // The estimated delay caused by rendering, defaults to
448 // kDefaultRenderDelayMs = 10 ms 453 // kDefaultRenderDelayMs = 10 ms
449 int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) { 454 int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) {
450 _timing.set_render_delay(timeMS); 455 _timing->set_render_delay(timeMS);
451 return VCM_OK; 456 return VCM_OK;
452 } 457 }
453 458
454 // Current video delay 459 // Current video delay
455 int32_t VideoReceiver::Delay() const { 460 int32_t VideoReceiver::Delay() const {
456 return _timing.TargetVideoDelay(); 461 return _timing->TargetVideoDelay();
457 } 462 }
458 463
459 uint32_t VideoReceiver::DiscardedPackets() const { 464 uint32_t VideoReceiver::DiscardedPackets() const {
460 return _receiver.DiscardedPackets(); 465 return _receiver.DiscardedPackets();
461 } 466 }
462 467
463 int VideoReceiver::SetReceiverRobustnessMode( 468 int VideoReceiver::SetReceiverRobustnessMode(
464 ReceiverRobustness robustnessMode, 469 ReceiverRobustness robustnessMode,
465 VCMDecodeErrorMode decode_error_mode) { 470 VCMDecodeErrorMode decode_error_mode) {
466 rtc::CritScope cs(&receive_crit_); 471 rtc::CritScope cs(&receive_crit_);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 _receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack, 518 _receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack,
514 max_incomplete_time_ms); 519 max_incomplete_time_ms);
515 } 520 }
516 521
517 int VideoReceiver::SetMinReceiverDelay(int desired_delay_ms) { 522 int VideoReceiver::SetMinReceiverDelay(int desired_delay_ms) {
518 return _receiver.SetMinReceiverDelay(desired_delay_ms); 523 return _receiver.SetMinReceiverDelay(desired_delay_ms);
519 } 524 }
520 525
521 } // namespace vcm 526 } // namespace vcm
522 } // namespace webrtc 527 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698