| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cast/sender/video_sender.h" | 5 #include "media/cast/sender/video_sender.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <cstring> | 10 #include <cstring> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | |
| 16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 17 #include "media/cast/net/cast_transport_config.h" | 16 #include "media/cast/net/cast_transport_config.h" |
| 18 #include "media/cast/sender/performance_metrics_overlay.h" | 17 #include "media/cast/sender/performance_metrics_overlay.h" |
| 19 #include "media/cast/sender/video_encoder.h" | 18 #include "media/cast/sender/video_encoder.h" |
| 20 | 19 |
| 21 namespace media { | 20 namespace media { |
| 22 namespace cast { | 21 namespace cast { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 VideoSender::VideoSender( | 89 VideoSender::VideoSender( |
| 91 scoped_refptr<CastEnvironment> cast_environment, | 90 scoped_refptr<CastEnvironment> cast_environment, |
| 92 const FrameSenderConfig& video_config, | 91 const FrameSenderConfig& video_config, |
| 93 const StatusChangeCallback& status_change_cb, | 92 const StatusChangeCallback& status_change_cb, |
| 94 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 93 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
| 95 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, | 94 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, |
| 96 CastTransport* const transport_sender, | 95 CastTransport* const transport_sender, |
| 97 const PlayoutDelayChangeCB& playout_delay_change_cb) | 96 const PlayoutDelayChangeCB& playout_delay_change_cb) |
| 98 : FrameSender( | 97 : FrameSender( |
| 99 cast_environment, | 98 cast_environment, |
| 100 false, | |
| 101 transport_sender, | 99 transport_sender, |
| 102 kVideoFrequency, | 100 video_config, |
| 103 video_config.sender_ssrc, | |
| 104 video_config.max_frame_rate, | |
| 105 video_config.min_playout_delay, | |
| 106 video_config.max_playout_delay, | |
| 107 video_config.animated_playout_delay, | |
| 108 video_config.use_external_encoder | 101 video_config.use_external_encoder |
| 109 ? NewFixedCongestionControl( | 102 ? NewFixedCongestionControl( |
| 110 (video_config.min_bitrate + video_config.max_bitrate) / 2) | 103 (video_config.min_bitrate + video_config.max_bitrate) / 2) |
| 111 : NewAdaptiveCongestionControl(cast_environment->Clock(), | 104 : NewAdaptiveCongestionControl(cast_environment->Clock(), |
| 112 video_config.max_bitrate, | 105 video_config.max_bitrate, |
| 113 video_config.min_bitrate, | 106 video_config.min_bitrate, |
| 114 video_config.max_frame_rate)), | 107 video_config.max_frame_rate)), |
| 115 frames_in_encoder_(0), | 108 frames_in_encoder_(0), |
| 116 last_bitrate_(0), | 109 last_bitrate_(0), |
| 117 playout_delay_change_cb_(playout_delay_change_cb), | 110 playout_delay_change_cb_(playout_delay_change_cb), |
| 118 low_latency_mode_(false), | 111 low_latency_mode_(false), |
| 119 last_reported_encoder_utilization_(-1.0), | 112 last_reported_encoder_utilization_(-1.0), |
| 120 last_reported_lossy_utilization_(-1.0), | 113 last_reported_lossy_utilization_(-1.0), |
| 121 weak_factory_(this) { | 114 weak_factory_(this) { |
| 122 video_encoder_ = VideoEncoder::Create( | 115 video_encoder_ = VideoEncoder::Create( |
| 123 cast_environment_, | 116 cast_environment_, |
| 124 video_config, | 117 video_config, |
| 125 status_change_cb, | 118 status_change_cb, |
| 126 create_vea_cb, | 119 create_vea_cb, |
| 127 create_video_encode_mem_cb); | 120 create_video_encode_mem_cb); |
| 128 if (!video_encoder_) { | 121 if (!video_encoder_) { |
| 129 cast_environment_->PostTask( | 122 cast_environment_->PostTask( |
| 130 CastEnvironment::MAIN, | 123 CastEnvironment::MAIN, |
| 131 FROM_HERE, | 124 FROM_HERE, |
| 132 base::Bind(status_change_cb, STATUS_UNSUPPORTED_CODEC)); | 125 base::Bind(status_change_cb, STATUS_UNSUPPORTED_CODEC)); |
| 133 } | 126 } |
| 134 | |
| 135 media::cast::CastTransportRtpConfig transport_config; | |
| 136 transport_config.ssrc = video_config.sender_ssrc; | |
| 137 transport_config.feedback_ssrc = video_config.receiver_ssrc; | |
| 138 transport_config.rtp_payload_type = video_config.rtp_payload_type; | |
| 139 transport_config.aes_key = video_config.aes_key; | |
| 140 transport_config.aes_iv_mask = video_config.aes_iv_mask; | |
| 141 | |
| 142 transport_sender->InitializeVideo( | |
| 143 transport_config, base::WrapUnique(new FrameSender::RtcpClient( | |
| 144 weak_factory_.GetWeakPtr()))); | |
| 145 } | 127 } |
| 146 | 128 |
| 147 VideoSender::~VideoSender() { | 129 VideoSender::~VideoSender() { |
| 148 } | 130 } |
| 149 | 131 |
| 150 void VideoSender::InsertRawVideoFrame( | 132 void VideoSender::InsertRawVideoFrame( |
| 151 const scoped_refptr<media::VideoFrame>& video_frame, | 133 const scoped_refptr<media::VideoFrame>& video_frame, |
| 152 const base::TimeTicks& reference_time) { | 134 const base::TimeTicks& reference_time) { |
| 153 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 135 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 154 | 136 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 333 media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 352 encoded_frame->dependency == EncodedFrame::KEY ? | 334 encoded_frame->dependency == EncodedFrame::KEY ? |
| 353 std::min(1.0, attenuated_utilization) : attenuated_utilization); | 335 std::min(1.0, attenuated_utilization) : attenuated_utilization); |
| 354 } | 336 } |
| 355 | 337 |
| 356 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); | 338 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); |
| 357 } | 339 } |
| 358 | 340 |
| 359 } // namespace cast | 341 } // namespace cast |
| 360 } // namespace media | 342 } // namespace media |
| OLD | NEW |