pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "video/video_receive_stream.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <stdlib.h> |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 14 | |
mflodman | d1590b2 | 2015-12-09 07:07:59 -0800 | [diff] [blame] | 15 | #include <set> |
mflodman@webrtc.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 16 | #include <string> |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 17 | #include <utility> |
mflodman@webrtc.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 18 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 19 | #include "absl/memory/memory.h" |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "call/rtp_stream_receiver_controller_interface.h" |
| 22 | #include "call/rtx_receive_stream.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 23 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "common_video/h264/profile_level_id.h" |
Patrik Höglund | be214a2 | 2018-01-04 12:14:35 +0100 | [diff] [blame] | 25 | #include "common_video/include/incoming_video_stream.h" |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 26 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "modules/rtp_rtcp/include/rtp_receiver.h" |
| 28 | #include "modules/rtp_rtcp/include/rtp_rtcp.h" |
| 29 | #include "modules/utility/include/process_thread.h" |
| 30 | #include "modules/video_coding/frame_object.h" |
| 31 | #include "modules/video_coding/include/video_coding.h" |
| 32 | #include "modules/video_coding/jitter_estimator.h" |
| 33 | #include "modules/video_coding/timing.h" |
| 34 | #include "modules/video_coding/utility/ivf_file_writer.h" |
| 35 | #include "rtc_base/checks.h" |
| 36 | #include "rtc_base/location.h" |
| 37 | #include "rtc_base/logging.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 38 | #include "rtc_base/trace_event.h" |
| 39 | #include "system_wrappers/include/clock.h" |
| 40 | #include "system_wrappers/include/field_trial.h" |
| 41 | #include "video/call_stats.h" |
| 42 | #include "video/receive_statistics_proxy.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 43 | |
| 44 | namespace webrtc { |
mflodman | a20de20 | 2015-10-18 22:08:19 -0700 | [diff] [blame] | 45 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 46 | namespace { |
| 47 | VideoCodec CreateDecoderVideoCodec(const VideoReceiveStream::Decoder& decoder) { |
| 48 | VideoCodec codec; |
| 49 | memset(&codec, 0, sizeof(codec)); |
| 50 | |
| 51 | codec.plType = decoder.payload_type; |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 52 | codec.codecType = PayloadStringToCodecType(decoder.payload_name); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 53 | |
| 54 | if (codec.codecType == kVideoCodecVP8) { |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 55 | *(codec.VP8()) = VideoEncoder::GetDefaultVp8Settings(); |
ivica | 05cfcd3 | 2015-09-07 06:04:16 -0700 | [diff] [blame] | 56 | } else if (codec.codecType == kVideoCodecVP9) { |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 57 | *(codec.VP9()) = VideoEncoder::GetDefaultVp9Settings(); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 58 | } else if (codec.codecType == kVideoCodecH264) { |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 59 | *(codec.H264()) = VideoEncoder::GetDefaultH264Settings(); |
magjed | e69a1a9 | 2016-11-25 10:06:31 -0800 | [diff] [blame] | 60 | codec.H264()->profile = |
| 61 | H264::ParseSdpProfileLevelId(decoder.codec_params)->profile; |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 62 | } else if (codec.codecType == kVideoCodecMultiplex) { |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 63 | VideoReceiveStream::Decoder associated_decoder = decoder; |
| 64 | associated_decoder.payload_name = CodecTypeToPayloadString(kVideoCodecVP9); |
| 65 | VideoCodec associated_codec = CreateDecoderVideoCodec(associated_decoder); |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 66 | associated_codec.codecType = kVideoCodecMultiplex; |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 67 | return associated_codec; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | codec.width = 320; |
| 71 | codec.height = 180; |
stefan | b4bc65b | 2016-11-02 10:10:20 -0700 | [diff] [blame] | 72 | const int kDefaultStartBitrate = 300; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 73 | codec.startBitrate = codec.minBitrate = codec.maxBitrate = |
stefan | b4bc65b | 2016-11-02 10:10:20 -0700 | [diff] [blame] | 74 | kDefaultStartBitrate; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 75 | |
| 76 | return codec; |
| 77 | } |
| 78 | } // namespace |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 79 | |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 80 | namespace internal { |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 81 | |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 82 | VideoReceiveStream::VideoReceiveStream( |
| 83 | RtpStreamReceiverControllerInterface* receiver_controller, |
| 84 | int num_cpu_cores, |
| 85 | PacketRouter* packet_router, |
| 86 | VideoReceiveStream::Config config, |
| 87 | ProcessThread* process_thread, |
| 88 | CallStats* call_stats) |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 89 | : transport_adapter_(config.rtcp_send_transport), |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 90 | config_(std::move(config)), |
sprang | 113bdca | 2016-10-11 03:10:10 -0700 | [diff] [blame] | 91 | num_cpu_cores_(num_cpu_cores), |
Peter Boström | 1d04ac6 | 2016-02-05 11:25:46 +0100 | [diff] [blame] | 92 | process_thread_(process_thread), |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 93 | clock_(Clock::GetRealTimeClock()), |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 94 | decode_thread_(&DecodeThreadFunction, |
| 95 | this, |
| 96 | "DecodingThread", |
| 97 | rtc::kHighestPriority), |
Peter Boström | 1d04ac6 | 2016-02-05 11:25:46 +0100 | [diff] [blame] | 98 | call_stats_(call_stats), |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 99 | rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 100 | timing_(new VCMTiming(clock_)), |
philipel | 721d402 | 2016-12-15 07:10:57 -0800 | [diff] [blame] | 101 | video_receiver_(clock_, nullptr, this, timing_.get(), this, this), |
| 102 | stats_proxy_(&config_, clock_), |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 103 | rtp_video_stream_receiver_(&transport_adapter_, |
Tommi | 38c5d93 | 2018-03-27 23:11:09 +0200 | [diff] [blame] | 104 | call_stats, |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 105 | packet_router, |
| 106 | &config_, |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 107 | rtp_receive_statistics_.get(), |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 108 | &stats_proxy_, |
| 109 | process_thread_, |
philipel | 0a9f6de | 2018-02-28 11:29:47 +0100 | [diff] [blame] | 110 | this, // NackSender |
| 111 | this, // KeyFrameRequestSender |
| 112 | this), // OnCompleteFrameCallback |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 113 | rtp_stream_sync_(this) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 114 | RTC_LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 115 | |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 116 | RTC_DCHECK(process_thread_); |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 117 | RTC_DCHECK(call_stats_); |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 118 | |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 119 | module_process_sequence_checker_.Detach(); |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 120 | |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 121 | RTC_DCHECK(!config_.decoders.empty()); |
Peter Boström | 521af4e | 2015-11-27 16:35:04 +0100 | [diff] [blame] | 122 | std::set<int> decoder_payload_types; |
Peter Boström | b1ae3a4 | 2016-02-15 17:52:40 +0100 | [diff] [blame] | 123 | for (const Decoder& decoder : config_.decoders) { |
Peter Boström | 795dbe4 | 2015-11-27 14:09:07 +0100 | [diff] [blame] | 124 | RTC_CHECK(decoder.decoder); |
Peter Boström | 521af4e | 2015-11-27 16:35:04 +0100 | [diff] [blame] | 125 | RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
| 126 | decoder_payload_types.end()) |
| 127 | << "Duplicate payload type (" << decoder.payload_type |
| 128 | << ") for different decoders."; |
| 129 | decoder_payload_types.insert(decoder.payload_type); |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 130 | } |
| 131 | |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 132 | video_receiver_.SetRenderDelay(config_.render_delay_ms); |
Peter Boström | 1d04ac6 | 2016-02-05 11:25:46 +0100 | [diff] [blame] | 133 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 134 | jitter_estimator_.reset(new VCMJitterEstimator(clock_)); |
| 135 | frame_buffer_.reset(new video_coding::FrameBuffer( |
| 136 | clock_, jitter_estimator_.get(), timing_.get(), &stats_proxy_)); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 137 | |
tommi | dea489f | 2017-03-03 03:20:24 -0800 | [diff] [blame] | 138 | process_thread_->RegisterModule(&rtp_stream_sync_, RTC_FROM_HERE); |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 139 | |
| 140 | // Register with RtpStreamReceiverController. |
| 141 | media_receiver_ = receiver_controller->CreateReceiver( |
| 142 | config_.rtp.remote_ssrc, &rtp_video_stream_receiver_); |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 143 | if (config_.rtp.rtx_ssrc) { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 144 | rtx_receive_stream_ = absl::make_unique<RtxReceiveStream>( |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 145 | &rtp_video_stream_receiver_, config.rtp.rtx_associated_payload_types, |
| 146 | config_.rtp.remote_ssrc, rtp_receive_statistics_.get()); |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 147 | rtx_receiver_ = receiver_controller->CreateReceiver( |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 148 | config_.rtp.rtx_ssrc, rtx_receive_stream_.get()); |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 149 | } |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | VideoReceiveStream::~VideoReceiveStream() { |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 153 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_sequence_checker_); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 154 | RTC_LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 155 | Stop(); |
| 156 | |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 157 | process_thread_->DeRegisterModule(&rtp_stream_sync_); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 158 | } |
| 159 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 160 | void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 161 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_sequence_checker_); |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 162 | rtp_video_stream_receiver_.SignalNetworkState(state); |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 163 | } |
| 164 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 165 | bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 166 | return rtp_video_stream_receiver_.DeliverRtcp(packet, length); |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 167 | } |
| 168 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 169 | void VideoReceiveStream::SetSync(Syncable* audio_syncable) { |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 170 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_sequence_checker_); |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 171 | rtp_stream_sync_.ConfigureSync(audio_syncable); |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 172 | } |
| 173 | |
pbos@webrtc.org | a5c8d2c | 2014-04-24 11:13:21 +0000 | [diff] [blame] | 174 | void VideoReceiveStream::Start() { |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 175 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_sequence_checker_); |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 176 | if (decode_thread_.IsRunning()) |
| 177 | return; |
brandtr | fb45c6c | 2017-01-27 06:47:55 -0800 | [diff] [blame] | 178 | |
nisse | c69385d | 2017-03-09 06:13:20 -0800 | [diff] [blame] | 179 | bool protected_by_fec = config_.rtp.protected_by_flexfec || |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 180 | rtp_video_stream_receiver_.IsUlpfecEnabled(); |
brandtr | fb45c6c | 2017-01-27 06:47:55 -0800 | [diff] [blame] | 181 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 182 | frame_buffer_->Start(); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 183 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 184 | if (rtp_video_stream_receiver_.IsRetransmissionsEnabled() && |
| 185 | protected_by_fec) { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 186 | frame_buffer_->SetProtectionMode(kProtectionNackFEC); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 187 | } |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 188 | |
sprang@webrtc.org | d9b9560 | 2014-01-27 13:03:02 +0000 | [diff] [blame] | 189 | transport_adapter_.Enable(); |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 190 | rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; |
| 191 | if (config_.renderer) { |
| 192 | if (config_.disable_prerenderer_smoothing) { |
| 193 | renderer = this; |
| 194 | } else { |
| 195 | incoming_video_stream_.reset( |
| 196 | new IncomingVideoStream(config_.render_delay_ms, this)); |
| 197 | renderer = incoming_video_stream_.get(); |
| 198 | } |
| 199 | } |
sakal | 55d932b | 2016-09-30 06:19:08 -0700 | [diff] [blame] | 200 | RTC_DCHECK(renderer != nullptr); |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 201 | |
sprang | 113bdca | 2016-10-11 03:10:10 -0700 | [diff] [blame] | 202 | for (const Decoder& decoder : config_.decoders) { |
| 203 | video_receiver_.RegisterExternalDecoder(decoder.decoder, |
| 204 | decoder.payload_type); |
sprang | 113bdca | 2016-10-11 03:10:10 -0700 | [diff] [blame] | 205 | VideoCodec codec = CreateDecoderVideoCodec(decoder); |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 206 | RTC_CHECK(rtp_video_stream_receiver_.AddReceiveCodec(codec, |
| 207 | decoder.codec_params)); |
sprang | 113bdca | 2016-10-11 03:10:10 -0700 | [diff] [blame] | 208 | RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( |
| 209 | &codec, num_cpu_cores_, false)); |
| 210 | } |
| 211 | |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 212 | video_stream_decoder_.reset(new VideoStreamDecoder( |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 213 | &video_receiver_, &rtp_video_stream_receiver_, |
| 214 | &rtp_video_stream_receiver_, |
| 215 | rtp_video_stream_receiver_.IsRetransmissionsEnabled(), protected_by_fec, |
nisse | 76bc8e8 | 2017-02-07 09:37:41 -0800 | [diff] [blame] | 216 | &stats_proxy_, renderer)); |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 217 | |
Tommi | ef3e28a | 2018-03-30 08:42:39 +0200 | [diff] [blame] | 218 | // Make sure we register as a stats observer *after* we've prepared the |
| 219 | // |video_stream_decoder_|. |
| 220 | call_stats_->RegisterStatsObserver(this); |
| 221 | |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 222 | process_thread_->RegisterModule(&video_receiver_, RTC_FROM_HERE); |
| 223 | |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 224 | // Start the decode thread |
Tommi | fbf3bce | 2018-02-21 15:56:05 +0100 | [diff] [blame] | 225 | video_receiver_.DecoderThreadStarting(); |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 226 | stats_proxy_.DecoderThreadStarting(); |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 227 | decode_thread_.Start(); |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 228 | rtp_video_stream_receiver_.StartReceive(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 229 | } |
| 230 | |
pbos@webrtc.org | a5c8d2c | 2014-04-24 11:13:21 +0000 | [diff] [blame] | 231 | void VideoReceiveStream::Stop() { |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 232 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_sequence_checker_); |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 233 | rtp_video_stream_receiver_.StopReceive(); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 234 | |
Ilya Nikolaevskiy | d397a0d | 2018-02-21 15:57:09 +0100 | [diff] [blame] | 235 | stats_proxy_.OnUniqueFramesCounted( |
| 236 | rtp_video_stream_receiver_.GetUniqueFramesSeen()); |
| 237 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 238 | frame_buffer_->Stop(); |
philipel | e21be1d | 2017-09-25 06:37:12 -0700 | [diff] [blame] | 239 | call_stats_->DeregisterStatsObserver(this); |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 240 | process_thread_->DeRegisterModule(&video_receiver_); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 241 | |
sprang | 0d348d6 | 2016-10-07 08:28:39 -0700 | [diff] [blame] | 242 | if (decode_thread_.IsRunning()) { |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 243 | // TriggerDecoderShutdown will release any waiting decoder thread and make |
| 244 | // it stop immediately, instead of waiting for a timeout. Needs to be called |
| 245 | // before joining the decoder thread. |
| 246 | video_receiver_.TriggerDecoderShutdown(); |
| 247 | |
sprang | 0d348d6 | 2016-10-07 08:28:39 -0700 | [diff] [blame] | 248 | decode_thread_.Stop(); |
Tommi | fbf3bce | 2018-02-21 15:56:05 +0100 | [diff] [blame] | 249 | video_receiver_.DecoderThreadStopped(); |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 250 | stats_proxy_.DecoderThreadStopped(); |
sprang | 0d348d6 | 2016-10-07 08:28:39 -0700 | [diff] [blame] | 251 | // Deregister external decoders so they are no longer running during |
| 252 | // destruction. This effectively stops the VCM since the decoder thread is |
| 253 | // stopped, the VCM is deregistered and no asynchronous decoder threads are |
| 254 | // running. |
| 255 | for (const Decoder& decoder : config_.decoders) |
| 256 | video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
| 257 | } |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 258 | |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 259 | video_stream_decoder_.reset(); |
| 260 | incoming_video_stream_.reset(); |
sprang@webrtc.org | d9b9560 | 2014-01-27 13:03:02 +0000 | [diff] [blame] | 261 | transport_adapter_.Disable(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 262 | } |
| 263 | |
sprang@webrtc.org | 9510e53 | 2014-02-07 15:32:45 +0000 | [diff] [blame] | 264 | VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { |
Peter Boström | f751bf8 | 2016-02-05 14:00:53 +0100 | [diff] [blame] | 265 | return stats_proxy_.GetStats(); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 266 | } |
| 267 | |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 268 | void VideoReceiveStream::EnableEncodedFrameRecording(rtc::PlatformFile file, |
| 269 | size_t byte_limit) { |
| 270 | { |
| 271 | rtc::CritScope lock(&ivf_writer_lock_); |
| 272 | if (file == rtc::kInvalidPlatformFileValue) { |
| 273 | ivf_writer_.reset(); |
| 274 | } else { |
| 275 | ivf_writer_ = IvfFileWriter::Wrap(rtc::File(file), byte_limit); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | if (file != rtc::kInvalidPlatformFileValue) { |
| 280 | // Make a keyframe appear as early as possible in the logs, to give actually |
| 281 | // decodable output. |
| 282 | RequestKeyFrame(); |
| 283 | } |
| 284 | } |
| 285 | |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 286 | void VideoReceiveStream::AddSecondarySink(RtpPacketSinkInterface* sink) { |
| 287 | rtp_video_stream_receiver_.AddSecondarySink(sink); |
| 288 | } |
| 289 | |
| 290 | void VideoReceiveStream::RemoveSecondarySink( |
| 291 | const RtpPacketSinkInterface* sink) { |
| 292 | rtp_video_stream_receiver_.RemoveSecondarySink(sink); |
| 293 | } |
| 294 | |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 295 | // TODO(tommi): This method grabs a lock 6 times. |
Tommi | bd3380f | 2016-06-10 17:38:17 +0200 | [diff] [blame] | 296 | void VideoReceiveStream::OnFrame(const VideoFrame& video_frame) { |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 297 | int64_t sync_offset_ms; |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 298 | double estimated_freq_khz; |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 299 | // TODO(tommi): GetStreamSyncOffsetInMs grabs three locks. One inside the |
| 300 | // function itself, another in GetChannel() and a third in |
| 301 | // GetPlayoutTimestamp. Seems excessive. Anyhow, I'm assuming the function |
| 302 | // succeeds most of the time, which leads to grabbing a fourth lock. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 303 | if (rtp_stream_sync_.GetStreamSyncOffsetInMs( |
| 304 | video_frame.timestamp(), video_frame.render_time_ms(), |
| 305 | &sync_offset_ms, &estimated_freq_khz)) { |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 306 | // TODO(tommi): OnSyncOffsetUpdated grabs a lock. |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 307 | stats_proxy_.OnSyncOffsetUpdated(sync_offset_ms, estimated_freq_khz); |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 308 | } |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 309 | // config_.renderer must never be null if we're getting this callback. |
| 310 | config_.renderer->OnFrame(video_frame); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 311 | |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 312 | // TODO(tommi): OnRenderFrame grabs a lock too. |
asapersson | 1490f7a | 2016-09-23 02:09:46 -0700 | [diff] [blame] | 313 | stats_proxy_.OnRenderedFrame(video_frame); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 314 | } |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 315 | |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 316 | // TODO(asapersson): Consider moving callback from video_encoder.h or |
| 317 | // creating a different callback. |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 318 | EncodedImageCallback::Result VideoReceiveStream::OnEncodedImage( |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 319 | const EncodedImage& encoded_image, |
| 320 | const CodecSpecificInfo* codec_specific_info, |
| 321 | const RTPFragmentationHeader* fragmentation) { |
Peter Boström | f751bf8 | 2016-02-05 14:00:53 +0100 | [diff] [blame] | 322 | stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 323 | size_t simulcast_idx = 0; |
| 324 | if (codec_specific_info->codecType == kVideoCodecVP8) { |
| 325 | simulcast_idx = codec_specific_info->codecSpecific.VP8.simulcastIdx; |
| 326 | } |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 327 | { |
| 328 | rtc::CritScope lock(&ivf_writer_lock_); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 329 | if (ivf_writer_.get()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 330 | RTC_DCHECK(codec_specific_info); |
| 331 | bool ok = ivf_writer_->WriteFrame(encoded_image, |
| 332 | codec_specific_info->codecType); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 333 | RTC_DCHECK(ok); |
| 334 | } |
| 335 | } |
| 336 | |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 337 | return Result(Result::OK, encoded_image._timeStamp); |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 338 | } |
| 339 | |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 340 | void VideoReceiveStream::SendNack( |
| 341 | const std::vector<uint16_t>& sequence_numbers) { |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 342 | rtp_video_stream_receiver_.RequestPacketRetransmit(sequence_numbers); |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | void VideoReceiveStream::RequestKeyFrame() { |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 346 | rtp_video_stream_receiver_.RequestKeyFrame(); |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void VideoReceiveStream::OnCompleteFrame( |
philipel | e7c891f | 2018-02-22 14:35:06 +0100 | [diff] [blame] | 350 | std::unique_ptr<video_coding::EncodedFrame> frame) { |
Sergey Silkin | acb4cba | 2018-05-08 17:16:39 +0200 | [diff] [blame] | 351 | // TODO(webrtc:9249): Workaround to allow decoding of VP9 SVC stream with |
| 352 | // partially enabled inter-layer prediction. |
| 353 | frame->id.spatial_layer = 0; |
| 354 | |
philipel | 1610f94 | 2017-12-12 13:58:31 +0100 | [diff] [blame] | 355 | int64_t last_continuous_pid = frame_buffer_->InsertFrame(std::move(frame)); |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 356 | if (last_continuous_pid != -1) |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 357 | rtp_video_stream_receiver_.FrameContinuous(last_continuous_pid); |
brandtr | 090c940 | 2017-01-25 08:28:02 -0800 | [diff] [blame] | 358 | } |
| 359 | |
philipel | e21be1d | 2017-09-25 06:37:12 -0700 | [diff] [blame] | 360 | void VideoReceiveStream::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
Tommi | 81de14f | 2018-03-25 22:19:25 +0200 | [diff] [blame] | 361 | RTC_DCHECK_CALLED_SEQUENTIALLY(&module_process_sequence_checker_); |
philipel | e21be1d | 2017-09-25 06:37:12 -0700 | [diff] [blame] | 362 | frame_buffer_->UpdateRtt(max_rtt_ms); |
Tommi | 81de14f | 2018-03-25 22:19:25 +0200 | [diff] [blame] | 363 | rtp_video_stream_receiver_.UpdateRtt(max_rtt_ms); |
| 364 | video_stream_decoder_->UpdateRtt(max_rtt_ms); |
philipel | e21be1d | 2017-09-25 06:37:12 -0700 | [diff] [blame] | 365 | } |
| 366 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 367 | int VideoReceiveStream::id() const { |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 368 | RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_sequence_checker_); |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 369 | return config_.rtp.remote_ssrc; |
| 370 | } |
| 371 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 372 | absl::optional<Syncable::Info> VideoReceiveStream::GetInfo() const { |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 373 | RTC_DCHECK_CALLED_SEQUENTIALLY(&module_process_sequence_checker_); |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 374 | Syncable::Info info; |
| 375 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 376 | RtpReceiver* rtp_receiver = rtp_video_stream_receiver_.GetRtpReceiver(); |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 377 | RTC_DCHECK(rtp_receiver); |
Niels Möller | c3fa8e1 | 2017-10-03 15:28:26 +0200 | [diff] [blame] | 378 | if (!rtp_receiver->GetLatestTimestamps( |
| 379 | &info.latest_received_capture_timestamp, |
| 380 | &info.latest_receive_time_ms)) |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 381 | return absl::nullopt; |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 382 | |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 383 | RtpRtcp* rtp_rtcp = rtp_video_stream_receiver_.rtp_rtcp(); |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 384 | RTC_DCHECK(rtp_rtcp); |
| 385 | if (rtp_rtcp->RemoteNTP(&info.capture_time_ntp_secs, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 386 | &info.capture_time_ntp_frac, nullptr, nullptr, |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 387 | &info.capture_time_source_clock) != 0) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 388 | return absl::nullopt; |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | info.current_delay_ms = video_receiver_.Delay(); |
Oskar Sundbom | 8e07c13 | 2018-01-08 16:45:42 +0100 | [diff] [blame] | 392 | return info; |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | uint32_t VideoReceiveStream::GetPlayoutTimestamp() const { |
| 396 | RTC_NOTREACHED(); |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | void VideoReceiveStream::SetMinimumPlayoutDelay(int delay_ms) { |
eladalon | a28122f | 2017-08-18 04:02:48 -0700 | [diff] [blame] | 401 | RTC_DCHECK_CALLED_SEQUENTIALLY(&module_process_sequence_checker_); |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 402 | video_receiver_.SetMinimumPlayoutDelay(delay_ms); |
| 403 | } |
| 404 | |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 405 | void VideoReceiveStream::DecodeThreadFunction(void* ptr) { |
| 406 | while (static_cast<VideoReceiveStream*>(ptr)->Decode()) { |
| 407 | } |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 408 | } |
| 409 | |
philipel | 2dfea3e | 2017-02-28 07:19:43 -0800 | [diff] [blame] | 410 | bool VideoReceiveStream::Decode() { |
tommi | db23ea6 | 2017-03-03 07:21:18 -0800 | [diff] [blame] | 411 | TRACE_EVENT0("webrtc", "VideoReceiveStream::Decode"); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 412 | static const int kMaxWaitForFrameMs = 3000; |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 413 | static const int kMaxWaitForKeyFrameMs = 200; |
| 414 | |
| 415 | int wait_ms = keyframe_required_ ? kMaxWaitForKeyFrameMs : kMaxWaitForFrameMs; |
philipel | e7c891f | 2018-02-22 14:35:06 +0100 | [diff] [blame] | 416 | std::unique_ptr<video_coding::EncodedFrame> frame; |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 417 | // TODO(philipel): Call NextFrame with |keyframe_required| argument when |
| 418 | // downstream project has been fixed. |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 419 | video_coding::FrameBuffer::ReturnReason res = |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 420 | frame_buffer_->NextFrame(wait_ms, &frame); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 421 | |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 422 | if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { |
philipel | 2dfea3e | 2017-02-28 07:19:43 -0800 | [diff] [blame] | 423 | return false; |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 424 | } |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 425 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 426 | if (frame) { |
philipel | 48462b6 | 2017-09-26 02:54:58 -0700 | [diff] [blame] | 427 | int64_t now_ms = clock_->TimeInMilliseconds(); |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 428 | RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); |
philipel | 49b46e0 | 2017-12-11 14:52:58 +0100 | [diff] [blame] | 429 | int decode_result = video_receiver_.Decode(frame.get()); |
| 430 | if (decode_result == WEBRTC_VIDEO_CODEC_OK || |
| 431 | decode_result == WEBRTC_VIDEO_CODEC_OK_REQUEST_KEYFRAME) { |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 432 | keyframe_required_ = false; |
| 433 | frame_decoded_ = true; |
philipel | 0fa82a6 | 2018-03-19 15:34:53 +0100 | [diff] [blame] | 434 | rtp_video_stream_receiver_.FrameDecoded(frame->id.picture_id); |
philipel | 49b46e0 | 2017-12-11 14:52:58 +0100 | [diff] [blame] | 435 | |
| 436 | if (decode_result == WEBRTC_VIDEO_CODEC_OK_REQUEST_KEYFRAME) |
| 437 | RequestKeyFrame(); |
philipel | 48462b6 | 2017-09-26 02:54:58 -0700 | [diff] [blame] | 438 | } else if (!frame_decoded_ || !keyframe_required_ || |
| 439 | (last_keyframe_request_ms_ + kMaxWaitForKeyFrameMs < now_ms)) { |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 440 | keyframe_required_ = true; |
| 441 | // TODO(philipel): Remove this keyframe request when downstream project |
| 442 | // has been fixed. |
| 443 | RequestKeyFrame(); |
philipel | 48462b6 | 2017-09-26 02:54:58 -0700 | [diff] [blame] | 444 | last_keyframe_request_ms_ = now_ms; |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 445 | } |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 446 | } else { |
tommi | c8ece43 | 2017-06-20 02:44:38 -0700 | [diff] [blame] | 447 | RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kTimeout); |
philipel | 3184f8e | 2017-05-18 08:08:53 -0700 | [diff] [blame] | 448 | int64_t now_ms = clock_->TimeInMilliseconds(); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 449 | absl::optional<int64_t> last_packet_ms = |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 450 | rtp_video_stream_receiver_.LastReceivedPacketMs(); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 451 | absl::optional<int64_t> last_keyframe_packet_ms = |
nisse | b1f2ff9 | 2017-06-09 04:01:55 -0700 | [diff] [blame] | 452 | rtp_video_stream_receiver_.LastReceivedKeyframePacketMs(); |
philipel | 3184f8e | 2017-05-18 08:08:53 -0700 | [diff] [blame] | 453 | |
| 454 | // To avoid spamming keyframe requests for a stream that is not active we |
| 455 | // check if we have received a packet within the last 5 seconds. |
| 456 | bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000; |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 457 | if (!stream_is_active) |
| 458 | stats_proxy_.OnStreamInactive(); |
philipel | 3184f8e | 2017-05-18 08:08:53 -0700 | [diff] [blame] | 459 | |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 460 | // If we recently have been receiving packets belonging to a keyframe then |
| 461 | // we assume a keyframe is currently being received. |
philipel | 3184f8e | 2017-05-18 08:08:53 -0700 | [diff] [blame] | 462 | bool receiving_keyframe = |
| 463 | last_keyframe_packet_ms && |
philipel | 3042c2d | 2017-08-18 04:55:02 -0700 | [diff] [blame] | 464 | now_ms - *last_keyframe_packet_ms < kMaxWaitForKeyFrameMs; |
philipel | 3184f8e | 2017-05-18 08:08:53 -0700 | [diff] [blame] | 465 | |
| 466 | if (stream_is_active && !receiving_keyframe) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 467 | RTC_LOG(LS_WARNING) << "No decodable frame in " << wait_ms |
| 468 | << " ms, requesting keyframe."; |
philipel | 3184f8e | 2017-05-18 08:08:53 -0700 | [diff] [blame] | 469 | RequestKeyFrame(); |
| 470 | } |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 471 | } |
philipel | 2dfea3e | 2017-02-28 07:19:43 -0800 | [diff] [blame] | 472 | return true; |
Peter Boström | ca83525 | 2016-02-11 15:59:46 +0100 | [diff] [blame] | 473 | } |
mflodman@webrtc.org | f3973e8 | 2013-12-13 09:40:45 +0000 | [diff] [blame] | 474 | } // namespace internal |
| 475 | } // namespace webrtc |