Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: media/cast/sender/video_sender.cc

Issue 1709863002: Add Cast PLI support on sender side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address dcheng's comments. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cast/sender/video_sender.h ('k') | media/cast/sender/video_sender_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 // network quality (e.g., additional time that accounts for encode and decode 34 // network quality (e.g., additional time that accounts for encode and decode
35 // time). 35 // time).
36 const int kConstantTimeMs = 75; 36 const int kConstantTimeMs = 75;
37 37
38 // The target maximum utilization of the encoder and network resources. This is 38 // The target maximum utilization of the encoder and network resources. This is
39 // used to attenuate the actual measured utilization values in order to provide 39 // used to attenuate the actual measured utilization values in order to provide
40 // "breathing room" (i.e., to ensure there will be sufficient CPU and bandwidth 40 // "breathing room" (i.e., to ensure there will be sufficient CPU and bandwidth
41 // available to handle the occasional more-complex frames). 41 // available to handle the occasional more-complex frames).
42 const int kTargetUtilizationPercentage = 75; 42 const int kTargetUtilizationPercentage = 75;
43 43
44 // This is the minimum duration in milliseconds that the sender sends key frame
45 // 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 // frame or receiving multiple Pli messages in a short period.
48 const int64_t kMinKeyFrameRequestOnPliIntervalMs = 500;
49
44 // Extract capture begin/end timestamps from |video_frame|'s metadata and log 50 // Extract capture begin/end timestamps from |video_frame|'s metadata and log
45 // it. 51 // it.
46 void LogVideoCaptureTimestamps(CastEnvironment* cast_environment, 52 void LogVideoCaptureTimestamps(CastEnvironment* cast_environment,
47 const media::VideoFrame& video_frame, 53 const media::VideoFrame& video_frame,
48 RtpTimeTicks rtp_timestamp) { 54 RtpTimeTicks rtp_timestamp) {
49 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); 55 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent());
50 capture_begin_event->type = FRAME_CAPTURE_BEGIN; 56 capture_begin_event->type = FRAME_CAPTURE_BEGIN;
51 capture_begin_event->media_type = VIDEO_EVENT; 57 capture_begin_event->media_type = VIDEO_EVENT;
52 capture_begin_event->rtp_timestamp = rtp_timestamp; 58 capture_begin_event->rtp_timestamp = rtp_timestamp;
53 59
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 133 }
128 134
129 media::cast::CastTransportRtpConfig transport_config; 135 media::cast::CastTransportRtpConfig transport_config;
130 transport_config.ssrc = video_config.ssrc; 136 transport_config.ssrc = video_config.ssrc;
131 transport_config.feedback_ssrc = video_config.receiver_ssrc; 137 transport_config.feedback_ssrc = video_config.receiver_ssrc;
132 transport_config.rtp_payload_type = video_config.rtp_payload_type; 138 transport_config.rtp_payload_type = video_config.rtp_payload_type;
133 transport_config.aes_key = video_config.aes_key; 139 transport_config.aes_key = video_config.aes_key;
134 transport_config.aes_iv_mask = video_config.aes_iv_mask; 140 transport_config.aes_iv_mask = video_config.aes_iv_mask;
135 141
136 transport_sender->InitializeVideo( 142 transport_sender->InitializeVideo(
137 transport_config, 143 transport_config, base::Bind(&VideoSender::OnReceivedCastFeedback,
138 base::Bind(&VideoSender::OnReceivedCastFeedback, 144 weak_factory_.GetWeakPtr()),
145 base::Bind(&VideoSender::OnMeasuredRoundTripTime,
139 weak_factory_.GetWeakPtr()), 146 weak_factory_.GetWeakPtr()),
140 base::Bind(&VideoSender::OnMeasuredRoundTripTime, 147 base::Bind(&VideoSender::OnReceivedPli, weak_factory_.GetWeakPtr()));
141 weak_factory_.GetWeakPtr()));
142 } 148 }
143 149
144 VideoSender::~VideoSender() { 150 VideoSender::~VideoSender() {
145 } 151 }
146 152
147 void VideoSender::InsertRawVideoFrame( 153 void VideoSender::InsertRawVideoFrame(
148 const scoped_refptr<media::VideoFrame>& video_frame, 154 const scoped_refptr<media::VideoFrame>& video_frame,
149 const base::TimeTicks& reference_time) { 155 const base::TimeTicks& reference_time) {
150 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 156 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
151 157
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 (rtp_timestamp <= last_enqueued_frame_rtp_timestamp_ || 191 (rtp_timestamp <= last_enqueued_frame_rtp_timestamp_ ||
186 reference_time <= last_enqueued_frame_reference_time_)) { 192 reference_time <= last_enqueued_frame_reference_time_)) {
187 VLOG(1) << "Dropping video frame: RTP or reference time did not increase."; 193 VLOG(1) << "Dropping video frame: RTP or reference time did not increase.";
188 TRACE_EVENT_INSTANT2("cast.stream", "Video Frame Drop", 194 TRACE_EVENT_INSTANT2("cast.stream", "Video Frame Drop",
189 TRACE_EVENT_SCOPE_THREAD, 195 TRACE_EVENT_SCOPE_THREAD,
190 "rtp_timestamp", rtp_timestamp.lower_32_bits(), 196 "rtp_timestamp", rtp_timestamp.lower_32_bits(),
191 "reason", "time did not increase"); 197 "reason", "time did not increase");
192 return; 198 return;
193 } 199 }
194 200
201 // Request a key frame when a Pli message was received, and it has been passed
202 // long enough from the last time sending key frame request on receiving a Pli
203 // message.
204 if (picture_lost_at_receiver_) {
205 const int64_t min_attemp_interval_ms =
206 std::max(kMinKeyFrameRequestOnPliIntervalMs,
207 6 * target_playout_delay_.InMilliseconds());
208 if (last_time_attempted_to_resolve_pli_.is_null() ||
209 ((reference_time - last_time_attempted_to_resolve_pli_)
210 .InMilliseconds() > min_attemp_interval_ms)) {
211 video_encoder_->GenerateKeyFrame();
212 last_time_attempted_to_resolve_pli_ = reference_time;
213 }
214 }
215
195 // Two video frames are needed to compute the exact media duration added by 216 // Two video frames are needed to compute the exact media duration added by
196 // the next frame. If there are no frames in the encoder, compute a guess 217 // the next frame. If there are no frames in the encoder, compute a guess
197 // based on the configured |max_frame_rate_|. Any error introduced by this 218 // based on the configured |max_frame_rate_|. Any error introduced by this
198 // guess will be eliminated when |duration_in_encoder_| is updated in 219 // guess will be eliminated when |duration_in_encoder_| is updated in
199 // OnEncodedVideoFrame(). 220 // OnEncodedVideoFrame().
200 const base::TimeDelta duration_added_by_next_frame = frames_in_encoder_ > 0 ? 221 const base::TimeDelta duration_added_by_next_frame = frames_in_encoder_ > 0 ?
201 reference_time - last_enqueued_frame_reference_time_ : 222 reference_time - last_enqueued_frame_reference_time_ :
202 base::TimeDelta::FromSecondsD(1.0 / max_frame_rate_); 223 base::TimeDelta::FromSecondsD(1.0 / max_frame_rate_);
203 224
204 if (ShouldDropNextFrame(duration_added_by_next_frame)) { 225 if (ShouldDropNextFrame(duration_added_by_next_frame)) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 media::VideoFrameMetadata::RESOURCE_UTILIZATION, 352 media::VideoFrameMetadata::RESOURCE_UTILIZATION,
332 encoded_frame->dependency == EncodedFrame::KEY ? 353 encoded_frame->dependency == EncodedFrame::KEY ?
333 std::min(1.0, attenuated_utilization) : attenuated_utilization); 354 std::min(1.0, attenuated_utilization) : attenuated_utilization);
334 } 355 }
335 356
336 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); 357 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame));
337 } 358 }
338 359
339 } // namespace cast 360 } // namespace cast
340 } // namespace media 361 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/sender/video_sender.h ('k') | media/cast/sender/video_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698