| 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/video/video_receive_stream.h" | 11 #include "webrtc/video/video_receive_stream.h" |
| 12 | 12 |
| 13 #include <stdlib.h> | 13 #include <stdlib.h> |
| 14 | 14 |
| 15 #include <set> | 15 #include <set> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <utility> | 17 #include <utility> |
| 18 | 18 |
| 19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
| 20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/optional.h" | 21 #include "webrtc/base/optional.h" |
| 22 #include "webrtc/common_video/h264/profile_level_id.h" | 22 #include "webrtc/common_video/h264/profile_level_id.h" |
| 23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 24 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | |
| 25 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
| 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 27 #include "webrtc/modules/utility/include/process_thread.h" | 26 #include "webrtc/modules/utility/include/process_thread.h" |
| 28 #include "webrtc/modules/video_coding/frame_object.h" | 27 #include "webrtc/modules/video_coding/frame_object.h" |
| 29 #include "webrtc/modules/video_coding/include/video_coding.h" | 28 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 30 #include "webrtc/modules/video_coding/jitter_estimator.h" | 29 #include "webrtc/modules/video_coding/jitter_estimator.h" |
| 31 #include "webrtc/modules/video_coding/timing.h" | 30 #include "webrtc/modules/video_coding/timing.h" |
| 32 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 31 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
| 33 #include "webrtc/system_wrappers/include/clock.h" | 32 #include "webrtc/system_wrappers/include/clock.h" |
| 34 #include "webrtc/system_wrappers/include/field_trial.h" | 33 #include "webrtc/system_wrappers/include/field_trial.h" |
| 35 #include "webrtc/video/call_stats.h" | 34 #include "webrtc/video/call_stats.h" |
| 36 #include "webrtc/video/receive_statistics_proxy.h" | 35 #include "webrtc/video/receive_statistics_proxy.h" |
| 37 #include "webrtc/video_receive_stream.h" | 36 #include "webrtc/video_receive_stream.h" |
| 38 | 37 |
| 39 namespace webrtc { | 38 namespace webrtc { |
| 40 | 39 |
| 41 static bool UseSendSideBwe(const VideoReceiveStream::Config& config) { | |
| 42 if (!config.rtp.transport_cc) | |
| 43 return false; | |
| 44 for (const auto& extension : config.rtp.extensions) { | |
| 45 if (extension.uri == RtpExtension::kTransportSequenceNumberUri) | |
| 46 return true; | |
| 47 } | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 std::string VideoReceiveStream::Decoder::ToString() const { | 40 std::string VideoReceiveStream::Decoder::ToString() const { |
| 52 std::stringstream ss; | 41 std::stringstream ss; |
| 53 ss << "{decoder: " << (decoder ? "(VideoDecoder)" : "nullptr"); | 42 ss << "{decoder: " << (decoder ? "(VideoDecoder)" : "nullptr"); |
| 54 ss << ", payload_type: " << payload_type; | 43 ss << ", payload_type: " << payload_type; |
| 55 ss << ", payload_name: " << payload_name; | 44 ss << ", payload_name: " << payload_name; |
| 56 ss << ", codec_params: {"; | 45 ss << ", codec_params: {"; |
| 57 for (const auto& it : codec_params) | 46 for (const auto& it : codec_params) |
| 58 ss << it.first << ": " << it.second; | 47 ss << it.first << ": " << it.second; |
| 59 ss << '}'; | 48 ss << '}'; |
| 60 ss << '}'; | 49 ss << '}'; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 170 |
| 182 return codec; | 171 return codec; |
| 183 } | 172 } |
| 184 } // namespace | 173 } // namespace |
| 185 | 174 |
| 186 namespace internal { | 175 namespace internal { |
| 187 | 176 |
| 188 VideoReceiveStream::VideoReceiveStream( | 177 VideoReceiveStream::VideoReceiveStream( |
| 189 int num_cpu_cores, | 178 int num_cpu_cores, |
| 190 bool protected_by_flexfec, | 179 bool protected_by_flexfec, |
| 191 CongestionController* congestion_controller, | |
| 192 PacketRouter* packet_router, | 180 PacketRouter* packet_router, |
| 193 VideoReceiveStream::Config config, | 181 VideoReceiveStream::Config config, |
| 194 ProcessThread* process_thread, | 182 ProcessThread* process_thread, |
| 195 CallStats* call_stats, | 183 CallStats* call_stats, |
| 196 VieRemb* remb) | 184 VieRemb* remb) |
| 197 : transport_adapter_(config.rtcp_send_transport), | 185 : transport_adapter_(config.rtcp_send_transport), |
| 198 config_(std::move(config)), | 186 config_(std::move(config)), |
| 199 num_cpu_cores_(num_cpu_cores), | 187 num_cpu_cores_(num_cpu_cores), |
| 200 protected_by_flexfec_(protected_by_flexfec), | 188 protected_by_flexfec_(protected_by_flexfec), |
| 201 process_thread_(process_thread), | 189 process_thread_(process_thread), |
| 202 clock_(Clock::GetRealTimeClock()), | 190 clock_(Clock::GetRealTimeClock()), |
| 203 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), | 191 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), |
| 204 congestion_controller_(congestion_controller), | |
| 205 call_stats_(call_stats), | 192 call_stats_(call_stats), |
| 206 timing_(new VCMTiming(clock_)), | 193 timing_(new VCMTiming(clock_)), |
| 207 video_receiver_(clock_, nullptr, this, timing_.get(), this, this), | 194 video_receiver_(clock_, nullptr, this, timing_.get(), this, this), |
| 208 stats_proxy_(&config_, clock_), | 195 stats_proxy_(&config_, clock_), |
| 209 rtp_stream_receiver_(congestion_controller_->GetRemoteBitrateEstimator( | 196 rtp_stream_receiver_(&transport_adapter_, |
| 210 UseSendSideBwe(config_)), | |
| 211 &transport_adapter_, | |
| 212 call_stats_->rtcp_rtt_stats(), | 197 call_stats_->rtcp_rtt_stats(), |
| 213 packet_router, | 198 packet_router, |
| 214 remb, | 199 remb, |
| 215 &config_, | 200 &config_, |
| 216 &stats_proxy_, | 201 &stats_proxy_, |
| 217 process_thread_, | 202 process_thread_, |
| 218 this, // NackSender | 203 this, // NackSender |
| 219 this, // KeyFrameRequestSender | 204 this, // KeyFrameRequestSender |
| 220 this, // OnCompleteFrameCallback | 205 this, // OnCompleteFrameCallback |
| 221 timing_.get()), | 206 timing_.get()), |
| 222 rtp_stream_sync_(this) { | 207 rtp_stream_sync_(this) { |
| 223 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 208 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
| 224 | 209 |
| 225 RTC_DCHECK(process_thread_); | 210 RTC_DCHECK(process_thread_); |
| 226 RTC_DCHECK(congestion_controller_); | |
| 227 RTC_DCHECK(call_stats_); | 211 RTC_DCHECK(call_stats_); |
| 228 | 212 |
| 229 module_process_thread_checker_.DetachFromThread(); | 213 module_process_thread_checker_.DetachFromThread(); |
| 230 | 214 |
| 231 RTC_DCHECK(!config_.decoders.empty()); | 215 RTC_DCHECK(!config_.decoders.empty()); |
| 232 std::set<int> decoder_payload_types; | 216 std::set<int> decoder_payload_types; |
| 233 for (const Decoder& decoder : config_.decoders) { | 217 for (const Decoder& decoder : config_.decoders) { |
| 234 RTC_CHECK(decoder.decoder); | 218 RTC_CHECK(decoder.decoder); |
| 235 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == | 219 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
| 236 decoder_payload_types.end()) | 220 decoder_payload_types.end()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 249 process_thread_->RegisterModule(&rtp_stream_sync_); | 233 process_thread_->RegisterModule(&rtp_stream_sync_); |
| 250 } | 234 } |
| 251 | 235 |
| 252 VideoReceiveStream::~VideoReceiveStream() { | 236 VideoReceiveStream::~VideoReceiveStream() { |
| 253 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 237 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 254 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 238 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
| 255 Stop(); | 239 Stop(); |
| 256 | 240 |
| 257 process_thread_->DeRegisterModule(&rtp_stream_sync_); | 241 process_thread_->DeRegisterModule(&rtp_stream_sync_); |
| 258 process_thread_->DeRegisterModule(&video_receiver_); | 242 process_thread_->DeRegisterModule(&video_receiver_); |
| 259 | |
| 260 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) | |
| 261 ->RemoveStream(rtp_stream_receiver_.GetRemoteSsrc()); | |
| 262 } | 243 } |
| 263 | 244 |
| 264 void VideoReceiveStream::SignalNetworkState(NetworkState state) { | 245 void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
| 265 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 246 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 266 rtp_stream_receiver_.SignalNetworkState(state); | 247 rtp_stream_receiver_.SignalNetworkState(state); |
| 267 } | 248 } |
| 268 | 249 |
| 269 | 250 |
| 270 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 251 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 271 return rtp_stream_receiver_.DeliverRtcp(packet, length); | 252 return rtp_stream_receiver_.DeliverRtcp(packet, length); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 if (video_receiver_.Decode(frame.get()) == VCM_OK) | 493 if (video_receiver_.Decode(frame.get()) == VCM_OK) |
| 513 rtp_stream_receiver_.FrameDecoded(frame->picture_id); | 494 rtp_stream_receiver_.FrameDecoded(frame->picture_id); |
| 514 } else { | 495 } else { |
| 515 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs | 496 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs |
| 516 << " ms, requesting keyframe."; | 497 << " ms, requesting keyframe."; |
| 517 RequestKeyFrame(); | 498 RequestKeyFrame(); |
| 518 } | 499 } |
| 519 } | 500 } |
| 520 } // namespace internal | 501 } // namespace internal |
| 521 } // namespace webrtc | 502 } // namespace webrtc |
| OLD | NEW |