| OLD | NEW | 
|---|
| 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/video_stream_decoder.h" | 11 #include "webrtc/video/video_stream_decoder.h" | 
| 12 | 12 | 
| 13 #include <algorithm> | 13 #include <algorithm> | 
| 14 #include <map> | 14 #include <map> | 
| 15 #include <vector> | 15 #include <vector> | 
| 16 | 16 | 
| 17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" | 
| 18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" | 
| 19 #include "webrtc/common_video/include/frame_callback.h" | 19 #include "webrtc/common_video/include/frame_callback.h" | 
|  | 20 #include "webrtc/common_video/include/incoming_video_stream.h" | 
| 20 #include "webrtc/modules/video_coding/video_coding_impl.h" | 21 #include "webrtc/modules/video_coding/video_coding_impl.h" | 
| 21 #include "webrtc/modules/video_processing/include/video_processing.h" | 22 #include "webrtc/modules/video_processing/include/video_processing.h" | 
| 22 #include "webrtc/system_wrappers/include/metrics.h" | 23 #include "webrtc/system_wrappers/include/metrics.h" | 
| 23 #include "webrtc/video/call_stats.h" | 24 #include "webrtc/video/call_stats.h" | 
| 24 #include "webrtc/video/payload_router.h" | 25 #include "webrtc/video/payload_router.h" | 
| 25 #include "webrtc/video/receive_statistics_proxy.h" | 26 #include "webrtc/video/receive_statistics_proxy.h" | 
| 26 | 27 | 
| 27 namespace webrtc { | 28 namespace webrtc { | 
| 28 | 29 | 
| 29 VideoStreamDecoder::VideoStreamDecoder( | 30 VideoStreamDecoder::VideoStreamDecoder( | 
| 30     vcm::VideoReceiver* video_receiver, | 31     vcm::VideoReceiver* video_receiver, | 
| 31     VCMFrameTypeCallback* vcm_frame_type_callback, | 32     VCMFrameTypeCallback* vcm_frame_type_callback, | 
| 32     VCMPacketRequestCallback* vcm_packet_request_callback, | 33     VCMPacketRequestCallback* vcm_packet_request_callback, | 
| 33     bool enable_nack, | 34     bool enable_nack, | 
| 34     bool enable_fec, | 35     bool enable_fec,  // TODO(philipel): Actually use this. | 
| 35     ReceiveStatisticsProxy* receive_statistics_proxy, | 36     ReceiveStatisticsProxy* receive_statistics_proxy, | 
| 36     rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream, | 37     IncomingVideoStream* incoming_video_stream, | 
| 37     I420FrameCallback* pre_render_callback) | 38     I420FrameCallback* pre_render_callback) | 
| 38     : video_receiver_(video_receiver), | 39     : video_receiver_(video_receiver), | 
| 39       receive_stats_callback_(receive_statistics_proxy), | 40       receive_stats_callback_(receive_statistics_proxy), | 
| 40       incoming_video_stream_(incoming_video_stream), | 41       incoming_video_stream_(incoming_video_stream), | 
| 41       pre_render_callback_(pre_render_callback), | 42       pre_render_callback_(pre_render_callback), | 
| 42       last_rtt_ms_(0) { | 43       last_rtt_ms_(0) { | 
| 43   RTC_DCHECK(video_receiver_); | 44   RTC_DCHECK(video_receiver_); | 
| 44 | 45 | 
| 45   static const int kMaxPacketAgeToNack = 450; | 46   static const int kMaxPacketAgeToNack = 450; | 
| 46   static const int kMaxNackListSize = 250; | 47   static const int kMaxNackListSize = 250; | 
| 47   video_receiver_->SetNackSettings(kMaxNackListSize, | 48   video_receiver_->SetNackSettings(kMaxNackListSize, | 
| 48                                    kMaxPacketAgeToNack, 0); | 49                                    kMaxPacketAgeToNack, 0); | 
| 49   video_receiver_->RegisterReceiveCallback(this); | 50   video_receiver_->RegisterReceiveCallback(this); | 
| 50   video_receiver_->RegisterFrameTypeCallback(vcm_frame_type_callback); | 51   video_receiver_->RegisterFrameTypeCallback(vcm_frame_type_callback); | 
| 51   video_receiver_->RegisterReceiveStatisticsCallback(this); | 52   video_receiver_->RegisterReceiveStatisticsCallback(this); | 
| 52   video_receiver_->RegisterDecoderTimingCallback(this); | 53   video_receiver_->RegisterDecoderTimingCallback(this); | 
|  | 54   static const int kDefaultRenderDelayMs = 10; | 
|  | 55   video_receiver_->SetRenderDelay(kDefaultRenderDelayMs); | 
| 53 | 56 | 
| 54   VCMVideoProtection video_protection = | 57   VCMVideoProtection video_protection = kProtectionNone; | 
| 55       enable_nack ? (enable_fec ? kProtectionNackFEC : kProtectionNack) | 58   if (enable_nack) { | 
| 56                   : kProtectionNone; | 59     if (enable_fec) | 
|  | 60       video_protection = kProtectionNackFEC; | 
|  | 61     else | 
|  | 62       video_protection = kProtectionNack; | 
|  | 63   } | 
| 57 | 64 | 
| 58   VCMDecodeErrorMode decode_error_mode = enable_nack ? kNoErrors : kWithErrors; | 65   VCMDecodeErrorMode decode_error_mode = enable_nack ? kNoErrors : kWithErrors; | 
| 59   video_receiver_->SetVideoProtection(video_protection, true); | 66   video_receiver_->SetVideoProtection(video_protection, true); | 
| 60   video_receiver_->SetDecodeErrorMode(decode_error_mode); | 67   video_receiver_->SetDecodeErrorMode(decode_error_mode); | 
| 61   VCMPacketRequestCallback* packet_request_callback = | 68   VCMPacketRequestCallback* packet_request_callback = | 
| 62       enable_nack ? vcm_packet_request_callback : nullptr; | 69       enable_nack ? vcm_packet_request_callback : nullptr; | 
| 63   video_receiver_->RegisterPacketRequestCallback(packet_request_callback); | 70   video_receiver_->RegisterPacketRequestCallback(packet_request_callback); | 
| 64 } | 71 } | 
| 65 | 72 | 
| 66 VideoStreamDecoder::~VideoStreamDecoder() { | 73 VideoStreamDecoder::~VideoStreamDecoder() {} | 
| 67   // Unset all the callback pointers that we set in the ctor. |  | 
| 68   video_receiver_->RegisterPacketRequestCallback(nullptr); |  | 
| 69   video_receiver_->RegisterDecoderTimingCallback(nullptr); |  | 
| 70   video_receiver_->RegisterReceiveStatisticsCallback(nullptr); |  | 
| 71   video_receiver_->RegisterFrameTypeCallback(nullptr); |  | 
| 72   video_receiver_->RegisterReceiveCallback(nullptr); |  | 
| 73 } |  | 
| 74 | 74 | 
| 75 // Do not acquire the lock of |video_receiver_| in this function. Decode | 75 // Do not acquire the lock of |video_receiver_| in this function. Decode | 
| 76 // callback won't necessarily be called from the decoding thread. The decoding | 76 // callback won't necessarily be called from the decoding thread. The decoding | 
| 77 // thread may have held the lock when calling VideoDecoder::Decode, Reset, or | 77 // thread may have held the lock when calling VideoDecoder::Decode, Reset, or | 
| 78 // Release. Acquiring the same lock in the path of decode callback can deadlock. | 78 // Release. Acquiring the same lock in the path of decode callback can deadlock. | 
| 79 int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame) {  // NOLINT | 79 int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame) {  // NOLINT | 
| 80   if (pre_render_callback_) { | 80   if (pre_render_callback_) { | 
| 81     // Post processing is not supported if the frame is backed by a texture. | 81     // Post processing is not supported if the frame is backed by a texture. | 
| 82     if (!video_frame.video_frame_buffer()->native_handle()) { | 82     if (!video_frame.video_frame_buffer()->native_handle()) { | 
| 83       pre_render_callback_->FrameCallback(&video_frame); | 83       pre_render_callback_->FrameCallback(&video_frame); | 
| 84     } | 84     } | 
| 85   } | 85   } | 
| 86 | 86 | 
| 87   if (incoming_video_stream_) | 87   incoming_video_stream_->OnFrame(video_frame); | 
| 88     incoming_video_stream_->OnFrame(video_frame); |  | 
| 89 |  | 
| 90   return 0; | 88   return 0; | 
| 91 } | 89 } | 
| 92 | 90 | 
| 93 int32_t VideoStreamDecoder::ReceivedDecodedReferenceFrame( | 91 int32_t VideoStreamDecoder::ReceivedDecodedReferenceFrame( | 
| 94   const uint64_t picture_id) { | 92   const uint64_t picture_id) { | 
| 95   RTC_NOTREACHED(); | 93   RTC_NOTREACHED(); | 
| 96   return 0; | 94   return 0; | 
| 97 } | 95 } | 
| 98 | 96 | 
| 99 void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) { | 97 void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) { | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 136       jitter_buffer_ms, min_playout_delay_ms, render_delay_ms, last_rtt); | 134       jitter_buffer_ms, min_playout_delay_ms, render_delay_ms, last_rtt); | 
| 137 } | 135 } | 
| 138 | 136 | 
| 139 void VideoStreamDecoder::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 137 void VideoStreamDecoder::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 
| 140   video_receiver_->SetReceiveChannelParameters(max_rtt_ms); | 138   video_receiver_->SetReceiveChannelParameters(max_rtt_ms); | 
| 141 | 139 | 
| 142   rtc::CritScope lock(&crit_); | 140   rtc::CritScope lock(&crit_); | 
| 143   last_rtt_ms_ = avg_rtt_ms; | 141   last_rtt_ms_ = avg_rtt_ms; | 
| 144 } | 142 } | 
| 145 }  // namespace webrtc | 143 }  // namespace webrtc | 
| OLD | NEW | 
|---|