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" |
15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
16 #include "media/cast/cast_defines.h" | 17 #include "media/cast/cast_defines.h" |
17 #include "media/cast/net/cast_transport_config.h" | 18 #include "media/cast/net/cast_transport_config.h" |
18 #include "media/cast/sender/performance_metrics_overlay.h" | 19 #include "media/cast/sender/performance_metrics_overlay.h" |
19 #include "media/cast/sender/video_encoder.h" | 20 #include "media/cast/sender/video_encoder.h" |
20 | 21 |
21 namespace media { | 22 namespace media { |
22 namespace cast { | 23 namespace cast { |
23 | 24 |
24 namespace { | 25 namespace { |
(...skipping 20 matching lines...) Expand all Loading... |
45 // request to the encoder on receiving Pli messages. This is used to prevent | 46 // request to the encoder on receiving Pli messages. This is used to prevent |
46 // sending multiple requests while the sender is waiting for an encoded key | 47 // sending multiple requests while the sender is waiting for an encoded key |
47 // frame or receiving multiple Pli messages in a short period. | 48 // frame or receiving multiple Pli messages in a short period. |
48 const int64_t kMinKeyFrameRequestOnPliIntervalMs = 500; | 49 const int64_t kMinKeyFrameRequestOnPliIntervalMs = 500; |
49 | 50 |
50 // Extract capture begin/end timestamps from |video_frame|'s metadata and log | 51 // Extract capture begin/end timestamps from |video_frame|'s metadata and log |
51 // it. | 52 // it. |
52 void LogVideoCaptureTimestamps(CastEnvironment* cast_environment, | 53 void LogVideoCaptureTimestamps(CastEnvironment* cast_environment, |
53 const media::VideoFrame& video_frame, | 54 const media::VideoFrame& video_frame, |
54 RtpTimeTicks rtp_timestamp) { | 55 RtpTimeTicks rtp_timestamp) { |
55 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); | 56 std::unique_ptr<FrameEvent> capture_begin_event(new FrameEvent()); |
56 capture_begin_event->type = FRAME_CAPTURE_BEGIN; | 57 capture_begin_event->type = FRAME_CAPTURE_BEGIN; |
57 capture_begin_event->media_type = VIDEO_EVENT; | 58 capture_begin_event->media_type = VIDEO_EVENT; |
58 capture_begin_event->rtp_timestamp = rtp_timestamp; | 59 capture_begin_event->rtp_timestamp = rtp_timestamp; |
59 | 60 |
60 scoped_ptr<FrameEvent> capture_end_event(new FrameEvent()); | 61 std::unique_ptr<FrameEvent> capture_end_event(new FrameEvent()); |
61 capture_end_event->type = FRAME_CAPTURE_END; | 62 capture_end_event->type = FRAME_CAPTURE_END; |
62 capture_end_event->media_type = VIDEO_EVENT; | 63 capture_end_event->media_type = VIDEO_EVENT; |
63 capture_end_event->rtp_timestamp = rtp_timestamp; | 64 capture_end_event->rtp_timestamp = rtp_timestamp; |
64 capture_end_event->width = video_frame.visible_rect().width(); | 65 capture_end_event->width = video_frame.visible_rect().width(); |
65 capture_end_event->height = video_frame.visible_rect().height(); | 66 capture_end_event->height = video_frame.visible_rect().height(); |
66 | 67 |
67 if (!video_frame.metadata()->GetTimeTicks( | 68 if (!video_frame.metadata()->GetTimeTicks( |
68 media::VideoFrameMetadata::CAPTURE_BEGIN_TIME, | 69 media::VideoFrameMetadata::CAPTURE_BEGIN_TIME, |
69 &capture_begin_event->timestamp) || | 70 &capture_begin_event->timestamp) || |
70 !video_frame.metadata()->GetTimeTicks( | 71 !video_frame.metadata()->GetTimeTicks( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 134 } |
134 | 135 |
135 media::cast::CastTransportRtpConfig transport_config; | 136 media::cast::CastTransportRtpConfig transport_config; |
136 transport_config.ssrc = video_config.ssrc; | 137 transport_config.ssrc = video_config.ssrc; |
137 transport_config.feedback_ssrc = video_config.receiver_ssrc; | 138 transport_config.feedback_ssrc = video_config.receiver_ssrc; |
138 transport_config.rtp_payload_type = video_config.rtp_payload_type; | 139 transport_config.rtp_payload_type = video_config.rtp_payload_type; |
139 transport_config.aes_key = video_config.aes_key; | 140 transport_config.aes_key = video_config.aes_key; |
140 transport_config.aes_iv_mask = video_config.aes_iv_mask; | 141 transport_config.aes_iv_mask = video_config.aes_iv_mask; |
141 | 142 |
142 transport_sender->InitializeVideo( | 143 transport_sender->InitializeVideo( |
143 transport_config, base::Bind(&VideoSender::OnReceivedCastFeedback, | 144 transport_config, base::WrapUnique(new FrameSender::RtcpObserver( |
144 weak_factory_.GetWeakPtr()), | 145 weak_factory_.GetWeakPtr()))); |
145 base::Bind(&VideoSender::OnMeasuredRoundTripTime, | |
146 weak_factory_.GetWeakPtr()), | |
147 base::Bind(&VideoSender::OnReceivedPli, weak_factory_.GetWeakPtr())); | |
148 } | 146 } |
149 | 147 |
150 VideoSender::~VideoSender() { | 148 VideoSender::~VideoSender() { |
151 } | 149 } |
152 | 150 |
153 void VideoSender::InsertRawVideoFrame( | 151 void VideoSender::InsertRawVideoFrame( |
154 const scoped_refptr<media::VideoFrame>& video_frame, | 152 const scoped_refptr<media::VideoFrame>& video_frame, |
155 const base::TimeTicks& reference_time) { | 153 const base::TimeTicks& reference_time) { |
156 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 154 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
157 | 155 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; | 291 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; |
294 last_enqueued_frame_reference_time_ = reference_time; | 292 last_enqueued_frame_reference_time_ = reference_time; |
295 } else { | 293 } else { |
296 VLOG(1) << "Encoder rejected a frame. Skipping..."; | 294 VLOG(1) << "Encoder rejected a frame. Skipping..."; |
297 TRACE_EVENT_INSTANT1("cast.stream", "Video Encode Reject", | 295 TRACE_EVENT_INSTANT1("cast.stream", "Video Encode Reject", |
298 TRACE_EVENT_SCOPE_THREAD, | 296 TRACE_EVENT_SCOPE_THREAD, |
299 "rtp_timestamp", rtp_timestamp.lower_32_bits()); | 297 "rtp_timestamp", rtp_timestamp.lower_32_bits()); |
300 } | 298 } |
301 } | 299 } |
302 | 300 |
303 scoped_ptr<VideoFrameFactory> VideoSender::CreateVideoFrameFactory() { | 301 std::unique_ptr<VideoFrameFactory> VideoSender::CreateVideoFrameFactory() { |
304 return video_encoder_ ? video_encoder_->CreateVideoFrameFactory() : nullptr; | 302 return video_encoder_ ? video_encoder_->CreateVideoFrameFactory() : nullptr; |
305 } | 303 } |
306 | 304 |
307 int VideoSender::GetNumberOfFramesInEncoder() const { | 305 int VideoSender::GetNumberOfFramesInEncoder() const { |
308 return frames_in_encoder_; | 306 return frames_in_encoder_; |
309 } | 307 } |
310 | 308 |
311 base::TimeDelta VideoSender::GetInFlightMediaDuration() const { | 309 base::TimeDelta VideoSender::GetInFlightMediaDuration() const { |
312 if (GetUnacknowledgedFrameCount() > 0) { | 310 if (GetUnacknowledgedFrameCount() > 0) { |
313 const uint32_t oldest_unacked_frame_id = latest_acked_frame_id_ + 1; | 311 const uint32_t oldest_unacked_frame_id = latest_acked_frame_id_ + 1; |
314 return last_enqueued_frame_reference_time_ - | 312 return last_enqueued_frame_reference_time_ - |
315 GetRecordedReferenceTime(oldest_unacked_frame_id); | 313 GetRecordedReferenceTime(oldest_unacked_frame_id); |
316 } else { | 314 } else { |
317 return duration_in_encoder_; | 315 return duration_in_encoder_; |
318 } | 316 } |
319 } | 317 } |
320 | 318 |
321 void VideoSender::OnEncodedVideoFrame( | 319 void VideoSender::OnEncodedVideoFrame( |
322 const scoped_refptr<media::VideoFrame>& video_frame, | 320 const scoped_refptr<media::VideoFrame>& video_frame, |
323 int encoder_bitrate, | 321 int encoder_bitrate, |
324 scoped_ptr<SenderEncodedFrame> encoded_frame) { | 322 std::unique_ptr<SenderEncodedFrame> encoded_frame) { |
325 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 323 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
326 | 324 |
327 frames_in_encoder_--; | 325 frames_in_encoder_--; |
328 DCHECK_GE(frames_in_encoder_, 0); | 326 DCHECK_GE(frames_in_encoder_, 0); |
329 | 327 |
330 duration_in_encoder_ = | 328 duration_in_encoder_ = |
331 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; | 329 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; |
332 | 330 |
333 last_reported_deadline_utilization_ = encoded_frame->deadline_utilization; | 331 last_reported_deadline_utilization_ = encoded_frame->deadline_utilization; |
334 last_reported_lossy_utilization_ = encoded_frame->lossy_utilization; | 332 last_reported_lossy_utilization_ = encoded_frame->lossy_utilization; |
(...skipping 17 matching lines...) Expand all Loading... |
352 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 350 media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
353 encoded_frame->dependency == EncodedFrame::KEY ? | 351 encoded_frame->dependency == EncodedFrame::KEY ? |
354 std::min(1.0, attenuated_utilization) : attenuated_utilization); | 352 std::min(1.0, attenuated_utilization) : attenuated_utilization); |
355 } | 353 } |
356 | 354 |
357 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); | 355 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); |
358 } | 356 } |
359 | 357 |
360 } // namespace cast | 358 } // namespace cast |
361 } // namespace media | 359 } // namespace media |
OLD | NEW |