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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 250 |
251 TRACE_COUNTER_ID1("cast.stream", "Video Target Bitrate", this, bitrate); | 251 TRACE_COUNTER_ID1("cast.stream", "Video Target Bitrate", this, bitrate); |
252 | 252 |
253 const scoped_refptr<VideoFrame> frame_to_encode = | 253 const scoped_refptr<VideoFrame> frame_to_encode = |
254 MaybeRenderPerformanceMetricsOverlay( | 254 MaybeRenderPerformanceMetricsOverlay( |
255 GetTargetPlayoutDelay(), low_latency_mode_, bitrate, | 255 GetTargetPlayoutDelay(), low_latency_mode_, bitrate, |
256 frames_in_encoder_ + 1, last_reported_encoder_utilization_, | 256 frames_in_encoder_ + 1, last_reported_encoder_utilization_, |
257 last_reported_lossy_utilization_, video_frame); | 257 last_reported_lossy_utilization_, video_frame); |
258 if (video_encoder_->EncodeVideoFrame( | 258 if (video_encoder_->EncodeVideoFrame( |
259 frame_to_encode, reference_time, | 259 frame_to_encode, reference_time, |
260 base::Bind(&VideoSender::OnEncodedVideoFrame, | 260 base::Bind(&VideoSender::OnEncodedVideoFrame, AsWeakPtr(), |
261 weak_factory_.GetWeakPtr(), frame_to_encode, bitrate))) { | 261 frame_to_encode, bitrate))) { |
262 TRACE_EVENT_ASYNC_BEGIN1("cast.stream", "Video Encode", | 262 TRACE_EVENT_ASYNC_BEGIN1("cast.stream", "Video Encode", |
263 frame_to_encode.get(), "rtp_timestamp", | 263 frame_to_encode.get(), "rtp_timestamp", |
264 rtp_timestamp.lower_32_bits()); | 264 rtp_timestamp.lower_32_bits()); |
265 frames_in_encoder_++; | 265 frames_in_encoder_++; |
266 duration_in_encoder_ += duration_added_by_next_frame; | 266 duration_in_encoder_ += duration_added_by_next_frame; |
267 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; | 267 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; |
268 last_enqueued_frame_reference_time_ = reference_time; | 268 last_enqueued_frame_reference_time_ = reference_time; |
269 } else { | 269 } else { |
270 VLOG(1) << "Encoder rejected a frame. Skipping..."; | 270 VLOG(1) << "Encoder rejected a frame. Skipping..."; |
271 TRACE_EVENT_INSTANT1("cast.stream", "Video Encode Reject", | 271 TRACE_EVENT_INSTANT1("cast.stream", "Video Encode Reject", |
272 TRACE_EVENT_SCOPE_THREAD, | 272 TRACE_EVENT_SCOPE_THREAD, |
273 "rtp_timestamp", rtp_timestamp.lower_32_bits()); | 273 "rtp_timestamp", rtp_timestamp.lower_32_bits()); |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 std::unique_ptr<VideoFrameFactory> VideoSender::CreateVideoFrameFactory() { | 277 std::unique_ptr<VideoFrameFactory> VideoSender::CreateVideoFrameFactory() { |
278 return video_encoder_ ? video_encoder_->CreateVideoFrameFactory() : nullptr; | 278 return video_encoder_ ? video_encoder_->CreateVideoFrameFactory() : nullptr; |
279 } | 279 } |
280 | 280 |
| 281 base::WeakPtr<VideoSender> VideoSender::AsWeakPtr() { |
| 282 return weak_factory_.GetWeakPtr(); |
| 283 } |
| 284 |
281 int VideoSender::GetNumberOfFramesInEncoder() const { | 285 int VideoSender::GetNumberOfFramesInEncoder() const { |
282 return frames_in_encoder_; | 286 return frames_in_encoder_; |
283 } | 287 } |
284 | 288 |
285 base::TimeDelta VideoSender::GetInFlightMediaDuration() const { | 289 base::TimeDelta VideoSender::GetInFlightMediaDuration() const { |
286 if (GetUnacknowledgedFrameCount() > 0) { | 290 if (GetUnacknowledgedFrameCount() > 0) { |
287 const FrameId oldest_unacked_frame_id = latest_acked_frame_id_ + 1; | 291 const FrameId oldest_unacked_frame_id = latest_acked_frame_id_ + 1; |
288 return last_enqueued_frame_reference_time_ - | 292 return last_enqueued_frame_reference_time_ - |
289 GetRecordedReferenceTime(oldest_unacked_frame_id); | 293 GetRecordedReferenceTime(oldest_unacked_frame_id); |
290 } else { | 294 } else { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 335 media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
332 encoded_frame->dependency == EncodedFrame::KEY ? | 336 encoded_frame->dependency == EncodedFrame::KEY ? |
333 std::min(1.0, attenuated_utilization) : attenuated_utilization); | 337 std::min(1.0, attenuated_utilization) : attenuated_utilization); |
334 } | 338 } |
335 | 339 |
336 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); | 340 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); |
337 } | 341 } |
338 | 342 |
339 } // namespace cast | 343 } // namespace cast |
340 } // namespace media | 344 } // namespace media |
OLD | NEW |