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 #include "media/cast/sender/video_frame_factory.h" | 18 #include "media/cast/sender/video_frame_factory.h" |
19 | 19 |
| 20 #if defined(OS_MACOSX) |
| 21 #include "media/cast/sender/h264_vt_encoder.h" |
| 22 #endif |
| 23 |
20 namespace media { | 24 namespace media { |
21 namespace cast { | 25 namespace cast { |
22 | 26 |
23 namespace { | 27 namespace { |
24 | 28 |
25 // The following two constants are used to adjust the target | 29 // The following two constants are used to adjust the target |
26 // playout delay (when allowed). They were calculated using | 30 // playout delay (when allowed). They were calculated using |
27 // a combination of cast_benchmark runs and manual testing. | 31 // a combination of cast_benchmark runs and manual testing. |
28 // | 32 // |
29 // This is how many round trips we think we need on the network. | 33 // This is how many round trips we think we need on the network. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 NewAdaptiveCongestionControl(cast_environment->Clock(), | 67 NewAdaptiveCongestionControl(cast_environment->Clock(), |
64 video_config.max_bitrate, | 68 video_config.max_bitrate, |
65 video_config.min_bitrate, | 69 video_config.min_bitrate, |
66 video_config.max_frame_rate)), | 70 video_config.max_frame_rate)), |
67 frames_in_encoder_(0), | 71 frames_in_encoder_(0), |
68 last_bitrate_(0), | 72 last_bitrate_(0), |
69 playout_delay_change_cb_(playout_delay_change_cb), | 73 playout_delay_change_cb_(playout_delay_change_cb), |
70 weak_factory_(this) { | 74 weak_factory_(this) { |
71 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; | 75 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; |
72 | 76 |
| 77 #if defined(OS_MACOSX) |
| 78 // On Apple platforms, use the hardware H.264 encoder if possible. It is the |
| 79 // only reasonable option for iOS. |
| 80 if (!video_config.use_external_encoder && |
| 81 video_config.codec == CODEC_VIDEO_H264) { |
| 82 video_encoder_.reset(new H264VideoToolboxEncoder( |
| 83 cast_environment, video_config, |
| 84 base::Bind(&VideoSender::OnEncoderInitialized, |
| 85 weak_factory_.GetWeakPtr(), initialization_cb))); |
| 86 } |
| 87 #endif // defined(OS_MACOSX) |
| 88 #if !defined(OS_IOS) |
73 if (video_config.use_external_encoder) { | 89 if (video_config.use_external_encoder) { |
74 video_encoder_.reset(new ExternalVideoEncoder( | 90 video_encoder_.reset(new ExternalVideoEncoder( |
75 cast_environment, | 91 cast_environment, |
76 video_config, | 92 video_config, |
77 base::Bind(&VideoSender::OnEncoderInitialized, | 93 base::Bind(&VideoSender::OnEncoderInitialized, |
78 weak_factory_.GetWeakPtr(), initialization_cb), | 94 weak_factory_.GetWeakPtr(), initialization_cb), |
79 create_vea_cb, | 95 create_vea_cb, |
80 create_video_encode_mem_cb)); | 96 create_video_encode_mem_cb)); |
81 } else { | 97 } else if (!video_encoder_) { |
82 // Software encoder is initialized immediately. | 98 // Software encoder is initialized immediately. |
83 video_encoder_.reset(new VideoEncoderImpl(cast_environment, video_config)); | 99 video_encoder_.reset(new VideoEncoderImpl(cast_environment, video_config)); |
84 cast_initialization_status_ = STATUS_VIDEO_INITIALIZED; | 100 cast_initialization_status_ = STATUS_VIDEO_INITIALIZED; |
85 } | 101 } |
| 102 #endif // !defined(OS_IOS) |
86 | 103 |
87 if (cast_initialization_status_ == STATUS_VIDEO_INITIALIZED) { | 104 if (cast_initialization_status_ == STATUS_VIDEO_INITIALIZED) { |
88 cast_environment->PostTask( | 105 cast_environment->PostTask( |
89 CastEnvironment::MAIN, | 106 CastEnvironment::MAIN, |
90 FROM_HERE, | 107 FROM_HERE, |
91 base::Bind(initialization_cb, cast_initialization_status_)); | 108 base::Bind(initialization_cb, cast_initialization_status_)); |
92 } | 109 } |
93 | 110 |
94 media::cast::CastTransportRtpConfig transport_config; | 111 media::cast::CastTransportRtpConfig transport_config; |
95 transport_config.ssrc = video_config.ssrc; | 112 transport_config.ssrc = video_config.ssrc; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 DCHECK_GE(frames_in_encoder_, 0); | 251 DCHECK_GE(frames_in_encoder_, 0); |
235 | 252 |
236 duration_in_encoder_ = | 253 duration_in_encoder_ = |
237 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; | 254 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; |
238 | 255 |
239 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 256 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
240 } | 257 } |
241 | 258 |
242 } // namespace cast | 259 } // namespace cast |
243 } // namespace media | 260 } // namespace media |
OLD | NEW |