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 <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "media/cast/cast_defines.h" | 14 #include "media/cast/cast_defines.h" |
15 #include "media/cast/net/cast_transport_config.h" | 15 #include "media/cast/net/cast_transport_config.h" |
16 #include "media/cast/sender/external_video_encoder.h" | 16 #include "media/cast/sender/external_video_encoder.h" |
17 #include "media/cast/sender/video_encoder_impl.h" | 17 #include "media/cast/sender/video_encoder_impl.h" |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 namespace cast { | 20 namespace cast { |
21 | 21 |
| 22 const int kRoundTripsNeeded = 4; |
| 23 |
22 // Note, we use a fixed bitrate value when external video encoder is used. | 24 // Note, we use a fixed bitrate value when external video encoder is used. |
23 // Some hardware encoder shows bad behavior if we set the bitrate too | 25 // Some hardware encoder shows bad behavior if we set the bitrate too |
24 // frequently, e.g. quality drop, not abiding by target bitrate, etc. | 26 // frequently, e.g. quality drop, not abiding by target bitrate, etc. |
25 // See details: crbug.com/392086. | 27 // See details: crbug.com/392086. |
26 VideoSender::VideoSender( | 28 VideoSender::VideoSender( |
27 scoped_refptr<CastEnvironment> cast_environment, | 29 scoped_refptr<CastEnvironment> cast_environment, |
28 const VideoSenderConfig& video_config, | 30 const VideoSenderConfig& video_config, |
29 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 31 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
30 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, | 32 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, |
31 CastTransportSender* const transport_sender) | 33 CastTransportSender* const transport_sender, |
| 34 const PlayoutDelayChangeCB& playout_delay_change_cb) |
32 : FrameSender( | 35 : FrameSender( |
33 cast_environment, | 36 cast_environment, |
34 false, | 37 false, |
35 transport_sender, | 38 transport_sender, |
36 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), | 39 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), |
37 kVideoFrequency, | 40 kVideoFrequency, |
38 video_config.ssrc, | 41 video_config.ssrc, |
39 video_config.max_frame_rate, | 42 video_config.max_frame_rate, |
40 video_config.target_playout_delay, | 43 video_config.min_playout_delay, |
| 44 video_config.max_playout_delay, |
41 NewFixedCongestionControl( | 45 NewFixedCongestionControl( |
42 (video_config.min_bitrate + video_config.max_bitrate) / 2)), | 46 (video_config.min_bitrate + video_config.max_bitrate) / 2)), |
43 frames_in_encoder_(0), | 47 frames_in_encoder_(0), |
44 last_bitrate_(0), | 48 last_bitrate_(0), |
| 49 playout_delay_change_cb_(playout_delay_change_cb), |
45 weak_factory_(this) { | 50 weak_factory_(this) { |
46 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; | 51 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; |
47 VLOG(1) << "max_unacked_frames is " << max_unacked_frames_ | 52 VLOG(1) << "max_unacked_frames is " << max_unacked_frames_ |
48 << " for target_playout_delay=" | 53 << " for target_playout_delay=" |
49 << target_playout_delay_.InMilliseconds() << " ms" | 54 << target_playout_delay_.InMilliseconds() << " ms" |
50 << " and max_frame_rate=" << video_config.max_frame_rate; | 55 << " and max_frame_rate=" << video_config.max_frame_rate; |
51 DCHECK_GT(max_unacked_frames_, 0); | 56 DCHECK_GT(max_unacked_frames_, 0); |
52 | 57 |
53 if (video_config.use_external_encoder) { | 58 if (video_config.use_external_encoder) { |
54 video_encoder_.reset(new ExternalVideoEncoder(cast_environment, | 59 video_encoder_.reset(new ExternalVideoEncoder(cast_environment, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 kFrameIdUnknown); | 111 kFrameIdUnknown); |
107 | 112 |
108 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 113 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
109 TRACE_EVENT_INSTANT2( | 114 TRACE_EVENT_INSTANT2( |
110 "cast_perf_test", "InsertRawVideoFrame", | 115 "cast_perf_test", "InsertRawVideoFrame", |
111 TRACE_EVENT_SCOPE_THREAD, | 116 TRACE_EVENT_SCOPE_THREAD, |
112 "timestamp", capture_time.ToInternalValue(), | 117 "timestamp", capture_time.ToInternalValue(), |
113 "rtp_timestamp", rtp_timestamp); | 118 "rtp_timestamp", rtp_timestamp); |
114 | 119 |
115 if (ShouldDropNextFrame(capture_time)) { | 120 if (ShouldDropNextFrame(capture_time)) { |
| 121 base::TimeDelta new_target_delay = std::min( |
| 122 AverageRTT() * kRoundTripsNeeded, |
| 123 max_playout_delay_); |
| 124 if (new_target_delay > target_playout_delay_) { |
| 125 playout_delay_change_cb_.Run(new_target_delay); |
| 126 } |
116 VLOG(1) << "Dropping frame due to too many frames currently in-flight."; | 127 VLOG(1) << "Dropping frame due to too many frames currently in-flight."; |
117 return; | 128 return; |
118 } | 129 } |
119 | 130 |
120 uint32 bitrate = congestion_control_->GetBitrate( | 131 uint32 bitrate = congestion_control_->GetBitrate( |
121 capture_time + target_playout_delay_, target_playout_delay_); | 132 capture_time + target_playout_delay_, target_playout_delay_); |
122 if (bitrate != last_bitrate_) { | 133 if (bitrate != last_bitrate_) { |
123 video_encoder_->SetBitRate(bitrate); | 134 video_encoder_->SetBitRate(bitrate); |
124 last_bitrate_ = bitrate; | 135 last_bitrate_ = bitrate; |
125 } | 136 } |
(...skipping 24 matching lines...) Expand all Loading... |
150 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 161 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
151 | 162 |
152 frames_in_encoder_--; | 163 frames_in_encoder_--; |
153 DCHECK_GE(frames_in_encoder_, 0); | 164 DCHECK_GE(frames_in_encoder_, 0); |
154 | 165 |
155 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 166 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
156 } | 167 } |
157 | 168 |
158 } // namespace cast | 169 } // namespace cast |
159 } // namespace media | 170 } // namespace media |
OLD | NEW |