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

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

Issue 450693006: VideoToolbox encoder for cast senders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modernize to C++11 per the rules at http://chromium-cpp.appspot.com/ Created 6 years, 2 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
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 <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 namespace { 26 namespace {
23 27
24 // The following two constants are used to adjust the target 28 // The following two constants are used to adjust the target
25 // playout delay (when allowed). They were calculated using 29 // playout delay (when allowed). They were calculated using
26 // a combination of cast_benchmark runs and manual testing. 30 // a combination of cast_benchmark runs and manual testing.
27 // 31 //
28 // This is how many round trips we think we need on the network. 32 // 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
62 last_bitrate_(0), 66 last_bitrate_(0),
63 playout_delay_change_cb_(playout_delay_change_cb), 67 playout_delay_change_cb_(playout_delay_change_cb),
64 weak_factory_(this) { 68 weak_factory_(this) {
65 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED; 69 cast_initialization_status_ = STATUS_VIDEO_UNINITIALIZED;
66 VLOG(1) << "max_unacked_frames is " << max_unacked_frames_ 70 VLOG(1) << "max_unacked_frames is " << max_unacked_frames_
67 << " for target_playout_delay=" 71 << " for target_playout_delay="
68 << target_playout_delay_.InMilliseconds() << " ms" 72 << target_playout_delay_.InMilliseconds() << " ms"
69 << " and max_frame_rate=" << video_config.max_frame_rate; 73 << " and max_frame_rate=" << video_config.max_frame_rate;
70 DCHECK_GT(max_unacked_frames_, 0); 74 DCHECK_GT(max_unacked_frames_, 0);
71 75
76 #if defined(OS_MACOSX)
77 // On Apple platforms, use the hardware H.264 encoder if possible. It is the
78 // only reasonable option for iOS.
79 if (!video_config.use_external_encoder &&
80 video_config.codec == CODEC_VIDEO_H264) {
81 video_encoder_.reset(new H264VideoToolboxEncoder(
82 cast_environment,
83 video_config,
84 base::Bind(&VideoSender::OnEncoderInitialized,
85 weak_factory_.GetWeakPtr(),
86 initialization_cb)));
87 }
88 #endif // defined(OS_MACOSX)
89 #if !defined(OS_IOS)
72 if (video_config.use_external_encoder) { 90 if (video_config.use_external_encoder) {
73 video_encoder_.reset(new ExternalVideoEncoder( 91 video_encoder_.reset(new ExternalVideoEncoder(
74 cast_environment, 92 cast_environment,
75 video_config, 93 video_config,
76 base::Bind(&VideoSender::OnEncoderInitialized, 94 base::Bind(&VideoSender::OnEncoderInitialized,
77 weak_factory_.GetWeakPtr(), initialization_cb), 95 weak_factory_.GetWeakPtr(), initialization_cb),
78 create_vea_cb, 96 create_vea_cb,
79 create_video_encode_mem_cb)); 97 create_video_encode_mem_cb));
80 } else { 98 } else if (!video_encoder_) {
81 // Software encoder is initialized immediately. 99 // Software encoder is initialized immediately.
82 congestion_control_.reset( 100 congestion_control_.reset(
83 NewAdaptiveCongestionControl(cast_environment->Clock(), 101 NewAdaptiveCongestionControl(cast_environment->Clock(),
84 video_config.max_bitrate, 102 video_config.max_bitrate,
85 video_config.min_bitrate, 103 video_config.min_bitrate,
86 max_unacked_frames_)); 104 max_unacked_frames_));
87 video_encoder_.reset(new VideoEncoderImpl( 105 video_encoder_.reset(new VideoEncoderImpl(
88 cast_environment, video_config, max_unacked_frames_)); 106 cast_environment, video_config, max_unacked_frames_));
89 cast_initialization_status_ = STATUS_VIDEO_INITIALIZED; 107 cast_initialization_status_ = STATUS_VIDEO_INITIALIZED;
90 } 108 }
109 #endif // !defined(OS_IOS)
91 110
92 if (cast_initialization_status_ == STATUS_VIDEO_INITIALIZED) { 111 if (cast_initialization_status_ == STATUS_VIDEO_INITIALIZED) {
93 cast_environment->PostTask( 112 cast_environment->PostTask(
94 CastEnvironment::MAIN, 113 CastEnvironment::MAIN,
95 FROM_HERE, 114 FROM_HERE,
96 base::Bind(initialization_cb, cast_initialization_status_)); 115 base::Bind(initialization_cb, cast_initialization_status_));
97 } 116 }
98 117
99 media::cast::CastTransportRtpConfig transport_config; 118 media::cast::CastTransportRtpConfig transport_config;
100 transport_config.ssrc = video_config.ssrc; 119 transport_config.ssrc = video_config.ssrc;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DCHECK_GE(frames_in_encoder_, 0); 246 DCHECK_GE(frames_in_encoder_, 0);
228 247
229 duration_in_encoder_ = 248 duration_in_encoder_ =
230 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; 249 last_enqueued_frame_reference_time_ - encoded_frame->reference_time;
231 250
232 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); 251 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass());
233 } 252 }
234 253
235 } // namespace cast 254 } // namespace cast
236 } // namespace media 255 } // namespace media
OLDNEW
« media/cast/sender/h264_vt_encoder.cc ('K') | « media/cast/sender/video_encoder_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698