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/h264_vt_encoder.h" | 5 #include "media/cast/sender/h264_vt_encoder.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 private: | 140 private: |
141 ~Proxy() final {} | 141 ~Proxy() final {} |
142 | 142 |
143 const scoped_refptr<VideoFrameFactoryImpl> video_frame_factory_; | 143 const scoped_refptr<VideoFrameFactoryImpl> video_frame_factory_; |
144 | 144 |
145 DISALLOW_COPY_AND_ASSIGN(Proxy); | 145 DISALLOW_COPY_AND_ASSIGN(Proxy); |
146 }; | 146 }; |
147 | 147 |
148 // static | 148 // static |
149 bool H264VideoToolboxEncoder::IsSupported( | 149 bool H264VideoToolboxEncoder::IsSupported( |
150 const VideoSenderConfig& video_config) { | 150 const FrameSenderConfig& video_config) { |
151 return video_config.codec == CODEC_VIDEO_H264 && VideoToolboxGlue::Get(); | 151 return video_config.codec == CODEC_VIDEO_H264 && VideoToolboxGlue::Get(); |
152 } | 152 } |
153 | 153 |
154 H264VideoToolboxEncoder::H264VideoToolboxEncoder( | 154 H264VideoToolboxEncoder::H264VideoToolboxEncoder( |
155 const scoped_refptr<CastEnvironment>& cast_environment, | 155 const scoped_refptr<CastEnvironment>& cast_environment, |
156 const VideoSenderConfig& video_config, | 156 const FrameSenderConfig& video_config, |
157 const StatusChangeCallback& status_change_cb) | 157 const StatusChangeCallback& status_change_cb) |
158 : cast_environment_(cast_environment), | 158 : cast_environment_(cast_environment), |
159 videotoolbox_glue_(VideoToolboxGlue::Get()), | 159 videotoolbox_glue_(VideoToolboxGlue::Get()), |
160 video_config_(video_config), | 160 video_config_(video_config), |
161 status_change_cb_(status_change_cb), | 161 status_change_cb_(status_change_cb), |
162 next_frame_id_(FrameId::first()), | 162 next_frame_id_(FrameId::first()), |
163 encode_next_frame_as_keyframe_(false), | 163 encode_next_frame_as_keyframe_(false), |
164 power_suspended_(false), | 164 power_suspended_(false), |
165 weak_factory_(this) { | 165 weak_factory_(this) { |
166 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 166 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 videotoolbox_glue_ | 315 videotoolbox_glue_ |
316 ->kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration(), | 316 ->kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration(), |
317 240); | 317 240); |
318 // TODO(jfroy): implement better bitrate control | 318 // TODO(jfroy): implement better bitrate control |
319 // https://crbug.com/425352 | 319 // https://crbug.com/425352 |
320 session_property_setter.Set( | 320 session_property_setter.Set( |
321 videotoolbox_glue_->kVTCompressionPropertyKey_AverageBitRate(), | 321 videotoolbox_glue_->kVTCompressionPropertyKey_AverageBitRate(), |
322 (video_config_.min_bitrate + video_config_.max_bitrate) / 2); | 322 (video_config_.min_bitrate + video_config_.max_bitrate) / 2); |
323 session_property_setter.Set( | 323 session_property_setter.Set( |
324 videotoolbox_glue_->kVTCompressionPropertyKey_ExpectedFrameRate(), | 324 videotoolbox_glue_->kVTCompressionPropertyKey_ExpectedFrameRate(), |
325 video_config_.max_frame_rate); | 325 static_cast<int>(video_config_.max_frame_rate + 0.5)); |
326 // Keep these attachment settings in-sync with those in Initialize(). | 326 // Keep these attachment settings in-sync with those in Initialize(). |
327 session_property_setter.Set( | 327 session_property_setter.Set( |
328 videotoolbox_glue_->kVTCompressionPropertyKey_ColorPrimaries(), | 328 videotoolbox_glue_->kVTCompressionPropertyKey_ColorPrimaries(), |
329 kCVImageBufferColorPrimaries_ITU_R_709_2); | 329 kCVImageBufferColorPrimaries_ITU_R_709_2); |
330 session_property_setter.Set( | 330 session_property_setter.Set( |
331 videotoolbox_glue_->kVTCompressionPropertyKey_TransferFunction(), | 331 videotoolbox_glue_->kVTCompressionPropertyKey_TransferFunction(), |
332 kCVImageBufferTransferFunction_ITU_R_709_2); | 332 kCVImageBufferTransferFunction_ITU_R_709_2); |
333 session_property_setter.Set( | 333 session_property_setter.Set( |
334 videotoolbox_glue_->kVTCompressionPropertyKey_YCbCrMatrix(), | 334 videotoolbox_glue_->kVTCompressionPropertyKey_YCbCrMatrix(), |
335 kCVImageBufferYCbCrMatrix_ITU_R_709_2); | 335 kCVImageBufferYCbCrMatrix_ITU_R_709_2); |
336 if (video_config_.max_number_of_video_buffers_used > 0) { | 336 if (video_config_.video_codec_params.max_number_of_video_buffers_used > 0) { |
337 session_property_setter.Set( | 337 session_property_setter.Set( |
338 videotoolbox_glue_->kVTCompressionPropertyKey_MaxFrameDelayCount(), | 338 videotoolbox_glue_->kVTCompressionPropertyKey_MaxFrameDelayCount(), |
339 video_config_.max_number_of_video_buffers_used); | 339 video_config_.video_codec_params.max_number_of_video_buffers_used); |
340 } | 340 } |
341 } | 341 } |
342 | 342 |
343 void H264VideoToolboxEncoder::DestroyCompressionSession() { | 343 void H264VideoToolboxEncoder::DestroyCompressionSession() { |
344 DCHECK(thread_checker_.CalledOnValidThread()); | 344 DCHECK(thread_checker_.CalledOnValidThread()); |
345 | 345 |
346 // If the compression session exists, invalidate it. This blocks until all | 346 // If the compression session exists, invalidate it. This blocks until all |
347 // pending output callbacks have returned and any internal threads have | 347 // pending output callbacks have returned and any internal threads have |
348 // joined, ensuring no output callback ever sees a dangling encoder pointer. | 348 // joined, ensuring no output callback ever sees a dangling encoder pointer. |
349 // | 349 // |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 encoded_frame->encode_completion_time = | 579 encoded_frame->encode_completion_time = |
580 encoder->cast_environment_->Clock()->NowTicks(); | 580 encoder->cast_environment_->Clock()->NowTicks(); |
581 encoder->cast_environment_->PostTask( | 581 encoder->cast_environment_->PostTask( |
582 CastEnvironment::MAIN, FROM_HERE, | 582 CastEnvironment::MAIN, FROM_HERE, |
583 base::Bind(request->frame_encoded_callback, | 583 base::Bind(request->frame_encoded_callback, |
584 base::Passed(&encoded_frame))); | 584 base::Passed(&encoded_frame))); |
585 } | 585 } |
586 | 586 |
587 } // namespace cast | 587 } // namespace cast |
588 } // namespace media | 588 } // namespace media |
OLD | NEW |