| 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> |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 (video_config.min_bitrate + video_config.max_bitrate) / 2) | 103 (video_config.min_bitrate + video_config.max_bitrate) / 2) |
| 104 : NewAdaptiveCongestionControl(cast_environment->Clock(), | 104 : NewAdaptiveCongestionControl(cast_environment->Clock(), |
| 105 video_config.max_bitrate, | 105 video_config.max_bitrate, |
| 106 video_config.min_bitrate, | 106 video_config.min_bitrate, |
| 107 video_config.max_frame_rate)), | 107 video_config.max_frame_rate)), |
| 108 frames_in_encoder_(0), | 108 frames_in_encoder_(0), |
| 109 last_bitrate_(0), | 109 last_bitrate_(0), |
| 110 playout_delay_change_cb_(playout_delay_change_cb), | 110 playout_delay_change_cb_(playout_delay_change_cb), |
| 111 low_latency_mode_(false), | 111 low_latency_mode_(false), |
| 112 last_reported_encoder_utilization_(-1.0), | 112 last_reported_encoder_utilization_(-1.0), |
| 113 last_reported_lossy_utilization_(-1.0), | 113 last_reported_lossy_utilization_(-1.0) { |
| 114 weak_factory_(this) { | |
| 115 video_encoder_ = VideoEncoder::Create( | 114 video_encoder_ = VideoEncoder::Create( |
| 116 cast_environment_, | 115 cast_environment_, |
| 117 video_config, | 116 video_config, |
| 118 status_change_cb, | 117 status_change_cb, |
| 119 create_vea_cb, | 118 create_vea_cb, |
| 120 create_video_encode_mem_cb); | 119 create_video_encode_mem_cb); |
| 121 if (!video_encoder_) { | 120 if (!video_encoder_) { |
| 122 cast_environment_->PostTask( | 121 cast_environment_->PostTask( |
| 123 CastEnvironment::MAIN, | 122 CastEnvironment::MAIN, |
| 124 FROM_HERE, | 123 FROM_HERE, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 249 |
| 251 TRACE_COUNTER_ID1("cast.stream", "Video Target Bitrate", this, bitrate); | 250 TRACE_COUNTER_ID1("cast.stream", "Video Target Bitrate", this, bitrate); |
| 252 | 251 |
| 253 const scoped_refptr<VideoFrame> frame_to_encode = | 252 const scoped_refptr<VideoFrame> frame_to_encode = |
| 254 MaybeRenderPerformanceMetricsOverlay( | 253 MaybeRenderPerformanceMetricsOverlay( |
| 255 GetTargetPlayoutDelay(), low_latency_mode_, bitrate, | 254 GetTargetPlayoutDelay(), low_latency_mode_, bitrate, |
| 256 frames_in_encoder_ + 1, last_reported_encoder_utilization_, | 255 frames_in_encoder_ + 1, last_reported_encoder_utilization_, |
| 257 last_reported_lossy_utilization_, video_frame); | 256 last_reported_lossy_utilization_, video_frame); |
| 258 if (video_encoder_->EncodeVideoFrame( | 257 if (video_encoder_->EncodeVideoFrame( |
| 259 frame_to_encode, reference_time, | 258 frame_to_encode, reference_time, |
| 260 base::Bind(&VideoSender::OnEncodedVideoFrame, | 259 base::Bind(&VideoSender::OnEncodedVideoFrame, AsWeakPtr(), |
| 261 weak_factory_.GetWeakPtr(), frame_to_encode, bitrate))) { | 260 frame_to_encode, bitrate))) { |
| 262 TRACE_EVENT_ASYNC_BEGIN1("cast.stream", "Video Encode", | 261 TRACE_EVENT_ASYNC_BEGIN1("cast.stream", "Video Encode", |
| 263 frame_to_encode.get(), "rtp_timestamp", | 262 frame_to_encode.get(), "rtp_timestamp", |
| 264 rtp_timestamp.lower_32_bits()); | 263 rtp_timestamp.lower_32_bits()); |
| 265 frames_in_encoder_++; | 264 frames_in_encoder_++; |
| 266 duration_in_encoder_ += duration_added_by_next_frame; | 265 duration_in_encoder_ += duration_added_by_next_frame; |
| 267 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; | 266 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; |
| 268 last_enqueued_frame_reference_time_ = reference_time; | 267 last_enqueued_frame_reference_time_ = reference_time; |
| 269 } else { | 268 } else { |
| 270 VLOG(1) << "Encoder rejected a frame. Skipping..."; | 269 VLOG(1) << "Encoder rejected a frame. Skipping..."; |
| 271 TRACE_EVENT_INSTANT1("cast.stream", "Video Encode Reject", | 270 TRACE_EVENT_INSTANT1("cast.stream", "Video Encode Reject", |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 330 media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 332 encoded_frame->dependency == EncodedFrame::KEY ? | 331 encoded_frame->dependency == EncodedFrame::KEY ? |
| 333 std::min(1.0, attenuated_utilization) : attenuated_utilization); | 332 std::min(1.0, attenuated_utilization) : attenuated_utilization); |
| 334 } | 333 } |
| 335 | 334 |
| 336 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); | 335 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); |
| 337 } | 336 } |
| 338 | 337 |
| 339 } // namespace cast | 338 } // namespace cast |
| 340 } // namespace media | 339 } // namespace media |
| OLD | NEW |