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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 video_config.max_frame_rate); | 328 video_config.max_frame_rate); |
329 SetSessionProperty( | 329 SetSessionProperty( |
330 videotoolbox_glue_->kVTCompressionPropertyKey_ColorPrimaries(), | 330 videotoolbox_glue_->kVTCompressionPropertyKey_ColorPrimaries(), |
331 kCVImageBufferColorPrimaries_ITU_R_709_2); | 331 kCVImageBufferColorPrimaries_ITU_R_709_2); |
332 SetSessionProperty( | 332 SetSessionProperty( |
333 videotoolbox_glue_->kVTCompressionPropertyKey_TransferFunction(), | 333 videotoolbox_glue_->kVTCompressionPropertyKey_TransferFunction(), |
334 kCVImageBufferTransferFunction_ITU_R_709_2); | 334 kCVImageBufferTransferFunction_ITU_R_709_2); |
335 SetSessionProperty( | 335 SetSessionProperty( |
336 videotoolbox_glue_->kVTCompressionPropertyKey_YCbCrMatrix(), | 336 videotoolbox_glue_->kVTCompressionPropertyKey_YCbCrMatrix(), |
337 kCVImageBufferYCbCrMatrix_ITU_R_709_2); | 337 kCVImageBufferYCbCrMatrix_ITU_R_709_2); |
| 338 if (video_config.max_number_of_video_buffers_used > 0) { |
| 339 SetSessionProperty( |
| 340 videotoolbox_glue_->kVTCompressionPropertyKey_MaxFrameDelayCount(), |
| 341 video_config.max_number_of_video_buffers_used); |
| 342 } |
338 } | 343 } |
339 | 344 |
340 void H264VideoToolboxEncoder::Teardown() { | 345 void H264VideoToolboxEncoder::Teardown() { |
341 DCHECK(thread_checker_.CalledOnValidThread()); | 346 DCHECK(thread_checker_.CalledOnValidThread()); |
342 | 347 |
343 // If the compression session exists, invalidate it. This blocks until all | 348 // If the compression session exists, invalidate it. This blocks until all |
344 // pending output callbacks have returned and any internal threads have | 349 // pending output callbacks have returned and any internal threads have |
345 // joined, ensuring no output callback ever sees a dangling encoder pointer. | 350 // joined, ensuring no output callback ever sees a dangling encoder pointer. |
346 if (compression_session_) { | 351 if (compression_session_) { |
347 videotoolbox_glue_->VTCompressionSessionInvalidate(compression_session_); | 352 videotoolbox_glue_->VTCompressionSessionInvalidate(compression_session_); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 scoped_ptr<VideoFrameFactory> | 428 scoped_ptr<VideoFrameFactory> |
424 H264VideoToolboxEncoder::CreateVideoFrameFactory() { | 429 H264VideoToolboxEncoder::CreateVideoFrameFactory() { |
425 base::ScopedCFTypeRef<CVPixelBufferPoolRef> pool( | 430 base::ScopedCFTypeRef<CVPixelBufferPoolRef> pool( |
426 videotoolbox_glue_->VTCompressionSessionGetPixelBufferPool( | 431 videotoolbox_glue_->VTCompressionSessionGetPixelBufferPool( |
427 compression_session_), | 432 compression_session_), |
428 base::scoped_policy::RETAIN); | 433 base::scoped_policy::RETAIN); |
429 return scoped_ptr<VideoFrameFactory>( | 434 return scoped_ptr<VideoFrameFactory>( |
430 new VideoFrameFactoryCVPixelBufferPoolImpl(pool)); | 435 new VideoFrameFactoryCVPixelBufferPoolImpl(pool)); |
431 } | 436 } |
432 | 437 |
| 438 void H264VideoToolboxEncoder::EmitFrames() { |
| 439 DCHECK(thread_checker_.CalledOnValidThread()); |
| 440 |
| 441 if (!compression_session_) { |
| 442 DLOG(ERROR) << " compression session is null"; |
| 443 return; |
| 444 } |
| 445 |
| 446 OSStatus status = videotoolbox_glue_->VTCompressionSessionCompleteFrames( |
| 447 compression_session_, CoreMediaGlue::CMTime{0, 0, 0, 0}); |
| 448 if (status != noErr) { |
| 449 DLOG(ERROR) << " VTCompressionSessionCompleteFrames failed: " << status; |
| 450 } |
| 451 } |
| 452 |
433 bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key, | 453 bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key, |
434 int32_t value) { | 454 int32_t value) { |
435 base::ScopedCFTypeRef<CFNumberRef> cfvalue( | 455 base::ScopedCFTypeRef<CFNumberRef> cfvalue( |
436 CFNumberCreate(nullptr, kCFNumberSInt32Type, &value)); | 456 CFNumberCreate(nullptr, kCFNumberSInt32Type, &value)); |
437 return videotoolbox_glue_->VTSessionSetProperty(compression_session_, key, | 457 return videotoolbox_glue_->VTSessionSetProperty(compression_session_, key, |
438 cfvalue) == noErr; | 458 cfvalue) == noErr; |
439 } | 459 } |
440 | 460 |
441 bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key, bool value) { | 461 bool H264VideoToolboxEncoder::SetSessionProperty(CFStringRef key, bool value) { |
442 CFBooleanRef cfvalue = (value) ? kCFBooleanTrue : kCFBooleanFalse; | 462 CFBooleanRef cfvalue = (value) ? kCFBooleanTrue : kCFBooleanFalse; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 CopySampleBufferToAnnexBBuffer(sbuf, &encoded_frame->data, keyframe); | 525 CopySampleBufferToAnnexBBuffer(sbuf, &encoded_frame->data, keyframe); |
506 | 526 |
507 encoder->cast_environment_->PostTask( | 527 encoder->cast_environment_->PostTask( |
508 CastEnvironment::MAIN, FROM_HERE, | 528 CastEnvironment::MAIN, FROM_HERE, |
509 base::Bind(request->frame_encoded_callback, | 529 base::Bind(request->frame_encoded_callback, |
510 base::Passed(&encoded_frame))); | 530 base::Passed(&encoded_frame))); |
511 } | 531 } |
512 | 532 |
513 } // namespace cast | 533 } // namespace cast |
514 } // namespace media | 534 } // namespace media |
OLD | NEW |