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

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

Issue 906403006: [Cast] Size-Adaptable platform video encoders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed hubbe's comments. Created 5 years, 10 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_frame_factory.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 <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/logging.h" 11 #include "base/logging.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "media/cast/cast_defines.h" 13 #include "media/cast/cast_defines.h"
14 #include "media/cast/net/cast_transport_config.h" 14 #include "media/cast/net/cast_transport_config.h"
15 #include "media/cast/sender/external_video_encoder.h" 15 #include "media/cast/sender/video_encoder.h"
16 #include "media/cast/sender/video_encoder_impl.h"
17 #include "media/cast/sender/video_frame_factory.h"
18
19 #if defined(OS_MACOSX)
20 #include "media/cast/sender/h264_vt_encoder.h"
21 #endif
22 16
23 namespace media { 17 namespace media {
24 namespace cast { 18 namespace cast {
25 19
26 namespace { 20 namespace {
27 21
28 // The following two constants are used to adjust the target 22 // The following two constants are used to adjust the target
29 // playout delay (when allowed). They were calculated using 23 // playout delay (when allowed). They were calculated using
30 // a combination of cast_benchmark runs and manual testing. 24 // a combination of cast_benchmark runs and manual testing.
31 // 25 //
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 NewFixedCongestionControl( 58 NewFixedCongestionControl(
65 (video_config.min_bitrate + video_config.max_bitrate) / 2) : 59 (video_config.min_bitrate + video_config.max_bitrate) / 2) :
66 NewAdaptiveCongestionControl(cast_environment->Clock(), 60 NewAdaptiveCongestionControl(cast_environment->Clock(),
67 video_config.max_bitrate, 61 video_config.max_bitrate,
68 video_config.min_bitrate, 62 video_config.min_bitrate,
69 video_config.max_frame_rate)), 63 video_config.max_frame_rate)),
70 frames_in_encoder_(0), 64 frames_in_encoder_(0),
71 last_bitrate_(0), 65 last_bitrate_(0),
72 playout_delay_change_cb_(playout_delay_change_cb), 66 playout_delay_change_cb_(playout_delay_change_cb),
73 weak_factory_(this) { 67 weak_factory_(this) {
74 #if defined(OS_MACOSX) 68 video_encoder_ = VideoEncoder::Create(
75 // On Apple platforms, use the hardware H.264 encoder if possible. It is the 69 cast_environment_,
76 // only reasonable option for iOS. 70 video_config,
77 if (!video_config.use_external_encoder && 71 status_change_cb,
78 video_config.codec == CODEC_VIDEO_H264) { 72 create_vea_cb,
79 video_encoder_.reset(new H264VideoToolboxEncoder( 73 create_video_encode_mem_cb);
80 cast_environment,
81 video_config,
82 gfx::Size(video_config.width, video_config.height),
83 status_change_cb));
84 }
85 #endif // defined(OS_MACOSX)
86 #if !defined(OS_IOS)
87 if (video_config.use_external_encoder) {
88 video_encoder_.reset(new ExternalVideoEncoder(
89 cast_environment,
90 video_config,
91 gfx::Size(video_config.width, video_config.height),
92 status_change_cb,
93 create_vea_cb,
94 create_video_encode_mem_cb));
95 } else if (!video_encoder_) {
96 // Software encoder is initialized immediately.
97 video_encoder_.reset(new VideoEncoderImpl(
98 cast_environment, video_config, status_change_cb));
99 }
100 #endif // !defined(OS_IOS)
101
102 if (!video_encoder_) { 74 if (!video_encoder_) {
103 cast_environment_->PostTask( 75 cast_environment_->PostTask(
104 CastEnvironment::MAIN, 76 CastEnvironment::MAIN,
105 FROM_HERE, 77 FROM_HERE,
106 base::Bind(status_change_cb, STATUS_UNSUPPORTED_CODEC)); 78 base::Bind(status_change_cb, STATUS_UNSUPPORTED_CODEC));
107 } 79 }
108 80
109 media::cast::CastTransportRtpConfig transport_config; 81 media::cast::CastTransportRtpConfig transport_config;
110 transport_config.ssrc = video_config.ssrc; 82 transport_config.ssrc = video_config.ssrc;
111 transport_config.feedback_ssrc = video_config.receiver_ssrc; 83 transport_config.feedback_ssrc = video_config.receiver_ssrc;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return; 167 return;
196 } 168 }
197 169
198 uint32 bitrate = congestion_control_->GetBitrate( 170 uint32 bitrate = congestion_control_->GetBitrate(
199 reference_time + target_playout_delay_, target_playout_delay_); 171 reference_time + target_playout_delay_, target_playout_delay_);
200 if (bitrate != last_bitrate_) { 172 if (bitrate != last_bitrate_) {
201 video_encoder_->SetBitRate(bitrate); 173 video_encoder_->SetBitRate(bitrate);
202 last_bitrate_ = bitrate; 174 last_bitrate_ = bitrate;
203 } 175 }
204 176
177 if (video_frame->visible_rect().IsEmpty()) {
178 VLOG(1) << "Rejecting empty video frame.";
179 return;
180 }
181
205 if (video_encoder_->EncodeVideoFrame( 182 if (video_encoder_->EncodeVideoFrame(
206 video_frame, 183 video_frame,
207 reference_time, 184 reference_time,
208 base::Bind(&VideoSender::OnEncodedVideoFrame, 185 base::Bind(&VideoSender::OnEncodedVideoFrame,
209 weak_factory_.GetWeakPtr(), 186 weak_factory_.GetWeakPtr(),
210 bitrate))) { 187 bitrate))) {
211 frames_in_encoder_++; 188 frames_in_encoder_++;
212 duration_in_encoder_ += duration_added_by_next_frame; 189 duration_in_encoder_ += duration_added_by_next_frame;
213 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; 190 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp;
214 last_enqueued_frame_reference_time_ = reference_time; 191 last_enqueued_frame_reference_time_ = reference_time;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 DCHECK_GE(frames_in_encoder_, 0); 225 DCHECK_GE(frames_in_encoder_, 0);
249 226
250 duration_in_encoder_ = 227 duration_in_encoder_ =
251 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; 228 last_enqueued_frame_reference_time_ - encoded_frame->reference_time;
252 229
253 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); 230 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass());
254 } 231 }
255 232
256 } // namespace cast 233 } // namespace cast
257 } // namespace media 234 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/sender/video_frame_factory.h ('k') | media/cast/sender/video_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698