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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/big_endian.h" | 9 #include "base/big_endian.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 video_config.max_frame_rate); | 302 video_config.max_frame_rate); |
303 SetSessionProperty( | 303 SetSessionProperty( |
304 videotoolbox_glue_->kVTCompressionPropertyKey_ColorPrimaries(), | 304 videotoolbox_glue_->kVTCompressionPropertyKey_ColorPrimaries(), |
305 kCVImageBufferColorPrimaries_ITU_R_709_2); | 305 kCVImageBufferColorPrimaries_ITU_R_709_2); |
306 SetSessionProperty( | 306 SetSessionProperty( |
307 videotoolbox_glue_->kVTCompressionPropertyKey_TransferFunction(), | 307 videotoolbox_glue_->kVTCompressionPropertyKey_TransferFunction(), |
308 kCVImageBufferTransferFunction_ITU_R_709_2); | 308 kCVImageBufferTransferFunction_ITU_R_709_2); |
309 SetSessionProperty( | 309 SetSessionProperty( |
310 videotoolbox_glue_->kVTCompressionPropertyKey_YCbCrMatrix(), | 310 videotoolbox_glue_->kVTCompressionPropertyKey_YCbCrMatrix(), |
311 kCVImageBufferYCbCrMatrix_ITU_R_709_2); | 311 kCVImageBufferYCbCrMatrix_ITU_R_709_2); |
| 312 if (video_config.max_number_of_video_buffers_used > 0) { |
| 313 SetSessionProperty( |
| 314 videotoolbox_glue_->kVTCompressionPropertyKey_MaxFrameDelayCount(), |
| 315 video_config.max_number_of_video_buffers_used); |
| 316 } |
312 } | 317 } |
313 | 318 |
314 void H264VideoToolboxEncoder::Teardown() { | 319 void H264VideoToolboxEncoder::Teardown() { |
315 DCHECK(thread_checker_.CalledOnValidThread()); | 320 DCHECK(thread_checker_.CalledOnValidThread()); |
316 | 321 |
317 // If the compression session exists, invalidate it. This blocks until all | 322 // If the compression session exists, invalidate it. This blocks until all |
318 // pending output callbacks have returned and any internal threads have | 323 // pending output callbacks have returned and any internal threads have |
319 // joined, ensuring no output callback ever sees a dangling encoder pointer. | 324 // joined, ensuring no output callback ever sees a dangling encoder pointer. |
320 if (compression_session_) { | 325 if (compression_session_) { |
321 videotoolbox_glue_->VTCompressionSessionInvalidate(compression_session_); | 326 videotoolbox_glue_->VTCompressionSessionInvalidate(compression_session_); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 scoped_ptr<VideoFrameFactory> | 402 scoped_ptr<VideoFrameFactory> |
398 H264VideoToolboxEncoder::CreateVideoFrameFactory() { | 403 H264VideoToolboxEncoder::CreateVideoFrameFactory() { |
399 base::ScopedCFTypeRef<CVPixelBufferPoolRef> pool( | 404 base::ScopedCFTypeRef<CVPixelBufferPoolRef> pool( |
400 videotoolbox_glue_->VTCompressionSessionGetPixelBufferPool( | 405 videotoolbox_glue_->VTCompressionSessionGetPixelBufferPool( |
401 compression_session_), | 406 compression_session_), |
402 base::scoped_policy::RETAIN); | 407 base::scoped_policy::RETAIN); |
403 return scoped_ptr<VideoFrameFactory>( | 408 return scoped_ptr<VideoFrameFactory>( |
404 new VideoFrameFactoryCVPixelBufferPoolImpl(pool)); | 409 new VideoFrameFactoryCVPixelBufferPoolImpl(pool)); |
405 } | 410 } |
406 | 411 |
| 412 void H264VideoToolboxEncoder::EmitFrames() { |
| 413 DCHECK(thread_checker_.CalledOnValidThread()); |
| 414 |
| 415 if (!compression_session_) { |
| 416 DLOG(ERROR) << " compression session is null"; |
| 417 return; |
| 418 } |
| 419 |
| 420 OSStatus status = videotoolbox_glue_->VTCompressionSessionCompleteFrames( |
| 421 compression_session_, CoreMediaGlue::CMTime{0, 0, 0, 0}); |
| 422 if (status != noErr) { |
| 423 DLOG(ERROR) << " VTCompressionSessionCompleteFrames failed: " << status; |
| 424 } |
| 425 } |
| 426 |
407 bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key, | 427 bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key, |
408 int32_t value) { | 428 int32_t value) { |
409 base::ScopedCFTypeRef<CFNumberRef> cfvalue( | 429 base::ScopedCFTypeRef<CFNumberRef> cfvalue( |
410 CFNumberCreate(nullptr, kCFNumberSInt32Type, &value)); | 430 CFNumberCreate(nullptr, kCFNumberSInt32Type, &value)); |
411 return videotoolbox_glue_->VTSessionSetProperty(compression_session_, key, | 431 return videotoolbox_glue_->VTSessionSetProperty(compression_session_, key, |
412 cfvalue) == noErr; | 432 cfvalue) == noErr; |
413 } | 433 } |
414 | 434 |
415 bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key, bool value) { | 435 bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key, bool value) { |
416 CFBooleanRef cfvalue = (value) ? kCFBooleanTrue : kCFBooleanFalse; | 436 CFBooleanRef cfvalue = (value) ? kCFBooleanTrue : kCFBooleanFalse; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 CopySampleBufferToAnnexBBuffer(sbuf, &encoded_frame->data, keyframe); | 499 CopySampleBufferToAnnexBBuffer(sbuf, &encoded_frame->data, keyframe); |
480 | 500 |
481 encoder->cast_environment_->PostTask( | 501 encoder->cast_environment_->PostTask( |
482 CastEnvironment::MAIN, FROM_HERE, | 502 CastEnvironment::MAIN, FROM_HERE, |
483 base::Bind(request->frame_encoded_callback, | 503 base::Bind(request->frame_encoded_callback, |
484 base::Passed(&encoded_frame))); | 504 base::Passed(&encoded_frame))); |
485 } | 505 } |
486 | 506 |
487 } // namespace cast | 507 } // namespace cast |
488 } // namespace media | 508 } // namespace media |
OLD | NEW |