Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/video/video_stream_decoder.h" | |
| 12 | |
| 13 #include <algorithm> | |
| 14 #include <map> | |
| 15 #include <vector> | |
| 16 | |
| 17 #include "webrtc/base/checks.h" | |
| 18 #include "webrtc/base/logging.h" | |
| 19 #include "webrtc/common_video/include/frame_callback.h" | |
| 20 #include "webrtc/common_video/include/incoming_video_stream.h" | |
| 21 #include "webrtc/modules/video_coding/video_coding_impl.h" | |
| 22 #include "webrtc/modules/video_processing/include/video_processing.h" | |
| 23 #include "webrtc/system_wrappers/include/metrics.h" | |
| 24 #include "webrtc/video/call_stats.h" | |
| 25 #include "webrtc/video/payload_router.h" | |
| 26 #include "webrtc/video/receive_statistics_proxy.h" | |
| 27 | |
| 28 namespace webrtc { | |
| 29 | |
| 30 VideoStreamDecoder::VideoStreamDecoder( | |
| 31 vcm::VideoReceiver* video_receiver, | |
| 32 VCMFrameTypeCallback* vcm_frame_type_callback, | |
| 33 VCMPacketRequestCallback* vcm_packet_request_callback, | |
| 34 bool enable_nack, | |
| 35 ReceiveStatisticsProxy* receive_statistics_proxy, | |
| 36 IncomingVideoStream* incoming_video_stream, | |
| 37 I420FrameCallback* pre_render_callback) | |
| 38 : video_receiver_(video_receiver), | |
| 39 receive_stats_callback_(receive_statistics_proxy), | |
| 40 incoming_video_stream_(incoming_video_stream), | |
| 41 pre_render_callback_(pre_render_callback), | |
| 42 last_rtt_ms_(0) { | |
| 43 RTC_DCHECK(video_receiver_); | |
| 44 | |
| 45 static const int kMaxPacketAgeToNack = 450; | |
| 46 static const int kMaxNackListSize = 250; | |
| 47 video_receiver_->SetNackSettings(kMaxNackListSize, | |
| 48 kMaxPacketAgeToNack, 0); | |
| 49 video_receiver_->RegisterReceiveCallback(this); | |
| 50 video_receiver_->RegisterFrameTypeCallback(vcm_frame_type_callback); | |
| 51 video_receiver_->RegisterReceiveStatisticsCallback(this); | |
| 52 video_receiver_->RegisterDecoderTimingCallback(this); | |
| 53 static const int kDefaultRenderDelayMs = 10; | |
| 54 video_receiver_->SetRenderDelay(kDefaultRenderDelayMs); | |
| 55 | |
| 56 VCMVideoProtection video_protection = enable_nack ? kProtectionNack | |
| 57 : kProtectionNone; | |
|
stefan-webrtc
2016/05/03 07:48:08
We should inform about FEC here as well if both NA
mflodman
2016/05/03 07:56:52
Acknowledged.
| |
| 58 VCMDecodeErrorMode decode_error_mode = enable_nack ? kNoErrors : kWithErrors; | |
| 59 video_receiver_->SetVideoProtection(video_protection, true); | |
| 60 video_receiver_->SetDecodeErrorMode(decode_error_mode); | |
| 61 VCMPacketRequestCallback* packet_request_callback = | |
| 62 enable_nack ? vcm_packet_request_callback : nullptr; | |
| 63 video_receiver_->RegisterPacketRequestCallback(packet_request_callback); | |
| 64 } | |
| 65 | |
| 66 VideoStreamDecoder::~VideoStreamDecoder() {} | |
| 67 | |
| 68 // Do not acquire the lock of |video_receiver_| in this function. Decode | |
| 69 // callback won't necessarily be called from the decoding thread. The decoding | |
| 70 // thread may have held the lock when calling VideoDecoder::Decode, Reset, or | |
| 71 // Release. Acquiring the same lock in the path of decode callback can deadlock. | |
| 72 int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame) { // NOLINT | |
| 73 if (pre_render_callback_) | |
| 74 pre_render_callback_->FrameCallback(&video_frame); | |
| 75 | |
| 76 // TODO(pbos): Remove stream id argument. | |
| 77 incoming_video_stream_->RenderFrame(0xFFFFFFFF, video_frame); | |
| 78 return 0; | |
| 79 } | |
| 80 | |
| 81 int32_t VideoStreamDecoder::ReceivedDecodedReferenceFrame( | |
| 82 const uint64_t picture_id) { | |
| 83 RTC_NOTREACHED(); | |
| 84 return 0; | |
| 85 } | |
| 86 | |
| 87 void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) { | |
| 88 receive_stats_callback_->OnIncomingPayloadType(payload_type); | |
| 89 } | |
| 90 | |
| 91 void VideoStreamDecoder::OnDecoderImplementationName( | |
| 92 const char* implementation_name) { | |
| 93 receive_stats_callback_->OnDecoderImplementationName(implementation_name); | |
| 94 } | |
| 95 | |
| 96 void VideoStreamDecoder::OnReceiveRatesUpdated(uint32_t bit_rate, | |
| 97 uint32_t frame_rate) { | |
| 98 receive_stats_callback_->OnIncomingRate(frame_rate, bit_rate); | |
| 99 } | |
| 100 | |
| 101 void VideoStreamDecoder::OnDiscardedPacketsUpdated(int discarded_packets) { | |
| 102 receive_stats_callback_->OnDiscardedPacketsUpdated(discarded_packets); | |
| 103 } | |
| 104 | |
| 105 void VideoStreamDecoder::OnFrameCountsUpdated(const FrameCounts& frame_counts) { | |
| 106 receive_stats_callback_->OnFrameCountsUpdated(frame_counts); | |
| 107 } | |
| 108 | |
| 109 void VideoStreamDecoder::OnDecoderTiming(int decode_ms, | |
| 110 int max_decode_ms, | |
| 111 int current_delay_ms, | |
| 112 int target_delay_ms, | |
| 113 int jitter_buffer_ms, | |
| 114 int min_playout_delay_ms, | |
| 115 int render_delay_ms) { | |
| 116 int last_rtt = -1; | |
| 117 { | |
| 118 rtc::CritScope lock(&crit_); | |
| 119 last_rtt = last_rtt_ms_; | |
| 120 } | |
| 121 | |
| 122 receive_stats_callback_->OnDecoderTiming( | |
| 123 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms, | |
| 124 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms, last_rtt); | |
| 125 } | |
| 126 | |
| 127 void VideoStreamDecoder::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | |
| 128 video_receiver_->SetReceiveChannelParameters(max_rtt_ms); | |
| 129 | |
| 130 rtc::CritScope lock(&crit_); | |
| 131 last_rtt_ms_ = avg_rtt_ms; | |
| 132 } | |
| 133 } // namespace webrtc | |
| OLD | NEW |