Chromium Code Reviews| 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 #if defined(OS_MACOSX) | |
| 20 #include "media/cast/sender/h264_vt_encoder.h" | |
| 21 #endif | |
| 22 | |
| 19 namespace media { | 23 namespace media { |
| 20 namespace cast { | 24 namespace cast { |
| 21 | 25 |
| 22 // The following two constants are used to adjust the target | 26 // The following two constants are used to adjust the target |
| 23 // playout delay (when allowed). They were calculated using | 27 // playout delay (when allowed). They were calculated using |
| 24 // a combination of cast_benchmark runs and manual testing. | 28 // a combination of cast_benchmark runs and manual testing. |
| 25 | 29 |
| 26 // This is how many round trips we think we need on the network. | 30 // This is how many round trips we think we need on the network. |
| 27 const int kRoundTripsNeeded = 4; | 31 const int kRoundTripsNeeded = 4; |
| 28 // This is an estimate of all the the constant time needed | 32 // This is an estimate of all the the constant time needed |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 57 last_bitrate_(0), | 61 last_bitrate_(0), |
| 58 playout_delay_change_cb_(playout_delay_change_cb), | 62 playout_delay_change_cb_(playout_delay_change_cb), |
| 59 weak_factory_(this) { | 63 weak_factory_(this) { |
| 60 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; | 64 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; |
| 61 VLOG(1) << "max_unacked_frames is " << max_unacked_frames_ | 65 VLOG(1) << "max_unacked_frames is " << max_unacked_frames_ |
| 62 << " for target_playout_delay=" | 66 << " for target_playout_delay=" |
| 63 << target_playout_delay_.InMilliseconds() << " ms" | 67 << target_playout_delay_.InMilliseconds() << " ms" |
| 64 << " and max_frame_rate=" << video_config.max_frame_rate; | 68 << " and max_frame_rate=" << video_config.max_frame_rate; |
| 65 DCHECK_GT(max_unacked_frames_, 0); | 69 DCHECK_GT(max_unacked_frames_, 0); |
| 66 | 70 |
| 71 #if defined(OS_MACOSX) | |
| 72 // On Apple platforms, use the hardware H.264 encoder if possible. It is the | |
| 73 // only reasonable option for iOS. | |
| 74 if (!video_config.use_external_encoder && | |
|
miu
2014/09/24 00:10:14
|use_external_encoder| is set to true when the har
jfroy
2014/09/24 01:00:58
I understood |use_external_encoder| from the point
| |
| 75 video_config.codec == CODEC_VIDEO_H264) { | |
| 76 video_encoder_.reset(new H264VideoToolboxEncoder( | |
| 77 cast_environment, | |
| 78 video_config, | |
| 79 base::Bind(&VideoSender::OnEncoderInitialized, | |
| 80 weak_factory_.GetWeakPtr(), | |
| 81 initialization_cb))); | |
| 82 } | |
| 83 #endif // defined(OS_MACOSX) | |
| 84 #if !defined(OS_IOS) | |
| 67 if (video_config.use_external_encoder) { | 85 if (video_config.use_external_encoder) { |
| 68 video_encoder_.reset(new ExternalVideoEncoder( | 86 video_encoder_.reset(new ExternalVideoEncoder( |
| 69 cast_environment, | 87 cast_environment, |
| 70 video_config, | 88 video_config, |
| 71 base::Bind(&VideoSender::OnEncoderInitialized, | 89 base::Bind(&VideoSender::OnEncoderInitialized, |
| 72 weak_factory_.GetWeakPtr(), initialization_cb), | 90 weak_factory_.GetWeakPtr(), initialization_cb), |
| 73 create_vea_cb, | 91 create_vea_cb, |
| 74 create_video_encode_mem_cb)); | 92 create_video_encode_mem_cb)); |
| 75 } else { | 93 } else { |
| 76 // Software encoder is initialized immediately. | 94 // Software encoder is initialized immediately. |
| 77 congestion_control_.reset( | 95 congestion_control_.reset( |
| 78 NewAdaptiveCongestionControl(cast_environment->Clock(), | 96 NewAdaptiveCongestionControl(cast_environment->Clock(), |
| 79 video_config.max_bitrate, | 97 video_config.max_bitrate, |
| 80 video_config.min_bitrate, | 98 video_config.min_bitrate, |
| 81 max_unacked_frames_)); | 99 max_unacked_frames_)); |
| 82 video_encoder_.reset(new VideoEncoderImpl( | 100 video_encoder_.reset(new VideoEncoderImpl( |
|
miu
2014/09/24 00:10:14
On desktop Mac OS, |video_encoder_| will be recrea
jfroy
2014/09/24 01:00:58
Oh man that is embarrassing. Thanks for catching t
jfroy
2014/09/24 18:43:53
I also wanted to mention why I did not integrate t
| |
| 83 cast_environment, video_config, max_unacked_frames_)); | 101 cast_environment, video_config, max_unacked_frames_)); |
| 84 cast_initialization_status_ = STATUS_VIDEO_INITIALIZED; | 102 cast_initialization_status_ = STATUS_VIDEO_INITIALIZED; |
| 85 } | 103 } |
| 104 #endif // !defined(OS_IOS) | |
| 86 | 105 |
| 87 if (cast_initialization_status_ == STATUS_VIDEO_INITIALIZED) { | 106 if (cast_initialization_status_ == STATUS_VIDEO_INITIALIZED) { |
| 88 cast_environment->PostTask( | 107 cast_environment->PostTask( |
| 89 CastEnvironment::MAIN, | 108 CastEnvironment::MAIN, |
| 90 FROM_HERE, | 109 FROM_HERE, |
| 91 base::Bind(initialization_cb, cast_initialization_status_)); | 110 base::Bind(initialization_cb, cast_initialization_status_)); |
| 92 } | 111 } |
| 93 | 112 |
| 94 media::cast::CastTransportRtpConfig transport_config; | 113 media::cast::CastTransportRtpConfig transport_config; |
| 95 transport_config.ssrc = video_config.ssrc; | 114 transport_config.ssrc = video_config.ssrc; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 213 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 195 | 214 |
| 196 frames_in_encoder_--; | 215 frames_in_encoder_--; |
| 197 DCHECK_GE(frames_in_encoder_, 0); | 216 DCHECK_GE(frames_in_encoder_, 0); |
| 198 | 217 |
| 199 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 218 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
| 200 } | 219 } |
| 201 | 220 |
| 202 } // namespace cast | 221 } // namespace cast |
| 203 } // namespace media | 222 } // namespace media |
| OLD | NEW |