| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/gpu/vt_video_encode_accelerator_mac.h" | 5 #include "media/gpu/vt_video_encode_accelerator_mac.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "media/base/mac/coremedia_glue.h" | 10 #include "media/base/mac/coremedia_glue.h" |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // static | 375 // static |
| 376 void VTVideoEncodeAccelerator::CompressionCallback(void* encoder_opaque, | 376 void VTVideoEncodeAccelerator::CompressionCallback(void* encoder_opaque, |
| 377 void* request_opaque, | 377 void* request_opaque, |
| 378 OSStatus status, | 378 OSStatus status, |
| 379 VTEncodeInfoFlags info, | 379 VTEncodeInfoFlags info, |
| 380 CMSampleBufferRef sbuf) { | 380 CMSampleBufferRef sbuf) { |
| 381 // This function may be called asynchronously, on a different thread from the | 381 // This function may be called asynchronously, on a different thread from the |
| 382 // one that calls VTCompressionSessionEncodeFrame. | 382 // one that calls VTCompressionSessionEncodeFrame. |
| 383 DVLOG(3) << __FUNCTION__; | 383 DVLOG(3) << __FUNCTION__; |
| 384 | 384 |
| 385 auto encoder = reinterpret_cast<VTVideoEncodeAccelerator*>(encoder_opaque); | 385 auto* encoder = reinterpret_cast<VTVideoEncodeAccelerator*>(encoder_opaque); |
| 386 DCHECK(encoder); | 386 DCHECK(encoder); |
| 387 | 387 |
| 388 // InProgressFrameEncode holds timestamp information of the encoded frame. | 388 // InProgressFrameEncode holds timestamp information of the encoded frame. |
| 389 std::unique_ptr<InProgressFrameEncode> frame_info( | 389 std::unique_ptr<InProgressFrameEncode> frame_info( |
| 390 reinterpret_cast<InProgressFrameEncode*>(request_opaque)); | 390 reinterpret_cast<InProgressFrameEncode*>(request_opaque)); |
| 391 | 391 |
| 392 // EncodeOutput holds onto CMSampleBufferRef when posting task between | 392 // EncodeOutput holds onto CMSampleBufferRef when posting task between |
| 393 // threads. | 393 // threads. |
| 394 std::unique_ptr<EncodeOutput> encode_output( | 394 std::unique_ptr<EncodeOutput> encode_output( |
| 395 new EncodeOutput(info, sbuf, frame_info->timestamp)); | 395 new EncodeOutput(info, sbuf, frame_info->timestamp)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 434 |
| 435 if (encode_output->info & VideoToolboxGlue::kVTEncodeInfo_FrameDropped) { | 435 if (encode_output->info & VideoToolboxGlue::kVTEncodeInfo_FrameDropped) { |
| 436 DVLOG(2) << " frame dropped"; | 436 DVLOG(2) << " frame dropped"; |
| 437 client_task_runner_->PostTask( | 437 client_task_runner_->PostTask( |
| 438 FROM_HERE, | 438 FROM_HERE, |
| 439 base::Bind(&Client::BitstreamBufferReady, client_, buffer_ref->id, 0, | 439 base::Bind(&Client::BitstreamBufferReady, client_, buffer_ref->id, 0, |
| 440 false, encode_output->capture_timestamp)); | 440 false, encode_output->capture_timestamp)); |
| 441 return; | 441 return; |
| 442 } | 442 } |
| 443 | 443 |
| 444 auto sample_attachments = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex( | 444 auto* sample_attachments = |
| 445 CoreMediaGlue::CMSampleBufferGetSampleAttachmentsArray( | 445 static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex( |
| 446 encode_output->sample_buffer.get(), true), | 446 CoreMediaGlue::CMSampleBufferGetSampleAttachmentsArray( |
| 447 0)); | 447 encode_output->sample_buffer.get(), true), |
| 448 0)); |
| 448 const bool keyframe = !CFDictionaryContainsKey( | 449 const bool keyframe = !CFDictionaryContainsKey( |
| 449 sample_attachments, CoreMediaGlue::kCMSampleAttachmentKey_NotSync()); | 450 sample_attachments, CoreMediaGlue::kCMSampleAttachmentKey_NotSync()); |
| 450 | 451 |
| 451 size_t used_buffer_size = 0; | 452 size_t used_buffer_size = 0; |
| 452 const bool copy_rv = video_toolbox::CopySampleBufferToAnnexBBuffer( | 453 const bool copy_rv = video_toolbox::CopySampleBufferToAnnexBBuffer( |
| 453 encode_output->sample_buffer.get(), keyframe, buffer_ref->size, | 454 encode_output->sample_buffer.get(), keyframe, buffer_ref->size, |
| 454 reinterpret_cast<char*>(buffer_ref->shm->memory()), &used_buffer_size); | 455 reinterpret_cast<char*>(buffer_ref->shm->memory()), &used_buffer_size); |
| 455 if (!copy_rv) { | 456 if (!copy_rv) { |
| 456 DLOG(ERROR) << "Cannot copy output from SampleBuffer to AnnexBBuffer."; | 457 DLOG(ERROR) << "Cannot copy output from SampleBuffer to AnnexBBuffer."; |
| 457 used_buffer_size = 0; | 458 used_buffer_size = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 474 kCVPixelBufferPixelFormatTypeKey}; | 475 kCVPixelBufferPixelFormatTypeKey}; |
| 475 const int format[] = { | 476 const int format[] = { |
| 476 CoreVideoGlue::kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange}; | 477 CoreVideoGlue::kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange}; |
| 477 CFTypeRef attributes_values[] = { | 478 CFTypeRef attributes_values[] = { |
| 478 kCFBooleanTrue, | 479 kCFBooleanTrue, |
| 479 video_toolbox::DictionaryWithKeysAndValues(nullptr, nullptr, 0).release(), | 480 video_toolbox::DictionaryWithKeysAndValues(nullptr, nullptr, 0).release(), |
| 480 video_toolbox::ArrayWithIntegers(format, arraysize(format)).release()}; | 481 video_toolbox::ArrayWithIntegers(format, arraysize(format)).release()}; |
| 481 const base::ScopedCFTypeRef<CFDictionaryRef> attributes = | 482 const base::ScopedCFTypeRef<CFDictionaryRef> attributes = |
| 482 video_toolbox::DictionaryWithKeysAndValues( | 483 video_toolbox::DictionaryWithKeysAndValues( |
| 483 attributes_keys, attributes_values, arraysize(attributes_keys)); | 484 attributes_keys, attributes_values, arraysize(attributes_keys)); |
| 484 for (auto& v : attributes_values) | 485 for (auto* v : attributes_values) |
| 485 CFRelease(v); | 486 CFRelease(v); |
| 486 | 487 |
| 487 bool session_rv = | 488 bool session_rv = |
| 488 CreateCompressionSession(attributes, input_visible_size_, false); | 489 CreateCompressionSession(attributes, input_visible_size_, false); |
| 489 if (!session_rv) { | 490 if (!session_rv) { |
| 490 DestroyCompressionSession(); | 491 DestroyCompressionSession(); |
| 491 return false; | 492 return false; |
| 492 } | 493 } |
| 493 | 494 |
| 494 const bool configure_rv = ConfigureCompressionSession(); | 495 const bool configure_rv = ConfigureCompressionSession(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 (encoder_thread_.IsRunning() && | 569 (encoder_thread_.IsRunning() && |
| 569 encoder_thread_task_runner_->BelongsToCurrentThread())); | 570 encoder_thread_task_runner_->BelongsToCurrentThread())); |
| 570 | 571 |
| 571 if (compression_session_) { | 572 if (compression_session_) { |
| 572 videotoolbox_glue_->VTCompressionSessionInvalidate(compression_session_); | 573 videotoolbox_glue_->VTCompressionSessionInvalidate(compression_session_); |
| 573 compression_session_.reset(); | 574 compression_session_.reset(); |
| 574 } | 575 } |
| 575 } | 576 } |
| 576 | 577 |
| 577 } // namespace media | 578 } // namespace media |
| OLD | NEW |