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/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 437 |
438 void VTVideoEncodeAccelerator::ReturnBitstreamBuffer( | 438 void VTVideoEncodeAccelerator::ReturnBitstreamBuffer( |
439 std::unique_ptr<EncodeOutput> encode_output, | 439 std::unique_ptr<EncodeOutput> encode_output, |
440 std::unique_ptr<VTVideoEncodeAccelerator::BitstreamBufferRef> buffer_ref) { | 440 std::unique_ptr<VTVideoEncodeAccelerator::BitstreamBufferRef> buffer_ref) { |
441 DVLOG(3) << __FUNCTION__; | 441 DVLOG(3) << __FUNCTION__; |
442 DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); | 442 DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); |
443 | 443 |
444 if (encode_output->info & VideoToolboxGlue::kVTEncodeInfo_FrameDropped) { | 444 if (encode_output->info & VideoToolboxGlue::kVTEncodeInfo_FrameDropped) { |
445 DVLOG(2) << " frame dropped"; | 445 DVLOG(2) << " frame dropped"; |
446 client_task_runner_->PostTask( | 446 client_task_runner_->PostTask( |
447 FROM_HERE, base::Bind(&Client::BitstreamBufferReady, client_, | 447 FROM_HERE, |
448 buffer_ref->id, 0, false)); | 448 base::Bind(&Client::BitstreamBufferReady, client_, buffer_ref->id, 0, |
| 449 false, base::Time::Now() - base::Time())); |
449 return; | 450 return; |
450 } | 451 } |
451 | 452 |
452 auto sample_attachments = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex( | 453 auto sample_attachments = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex( |
453 CoreMediaGlue::CMSampleBufferGetSampleAttachmentsArray( | 454 CoreMediaGlue::CMSampleBufferGetSampleAttachmentsArray( |
454 encode_output->sample_buffer.get(), true), | 455 encode_output->sample_buffer.get(), true), |
455 0)); | 456 0)); |
456 const bool keyframe = !CFDictionaryContainsKey( | 457 const bool keyframe = !CFDictionaryContainsKey( |
457 sample_attachments, CoreMediaGlue::kCMSampleAttachmentKey_NotSync()); | 458 sample_attachments, CoreMediaGlue::kCMSampleAttachmentKey_NotSync()); |
458 | 459 |
459 size_t used_buffer_size = 0; | 460 size_t used_buffer_size = 0; |
460 const bool copy_rv = media::video_toolbox::CopySampleBufferToAnnexBBuffer( | 461 const bool copy_rv = media::video_toolbox::CopySampleBufferToAnnexBBuffer( |
461 encode_output->sample_buffer.get(), keyframe, buffer_ref->size, | 462 encode_output->sample_buffer.get(), keyframe, buffer_ref->size, |
462 reinterpret_cast<char*>(buffer_ref->shm->memory()), &used_buffer_size); | 463 reinterpret_cast<char*>(buffer_ref->shm->memory()), &used_buffer_size); |
463 if (!copy_rv) { | 464 if (!copy_rv) { |
464 DLOG(ERROR) << "Cannot copy output from SampleBuffer to AnnexBBuffer."; | 465 DLOG(ERROR) << "Cannot copy output from SampleBuffer to AnnexBBuffer."; |
465 used_buffer_size = 0; | 466 used_buffer_size = 0; |
466 } | 467 } |
467 bitrate_adjuster_.Update(used_buffer_size); | 468 bitrate_adjuster_.Update(used_buffer_size); |
468 | 469 |
469 client_task_runner_->PostTask( | 470 client_task_runner_->PostTask( |
470 FROM_HERE, base::Bind(&Client::BitstreamBufferReady, client_, | 471 FROM_HERE, |
471 buffer_ref->id, used_buffer_size, keyframe)); | 472 base::Bind(&Client::BitstreamBufferReady, client_, buffer_ref->id, |
| 473 used_buffer_size, keyframe, base::Time::Now() - base::Time())); |
472 } | 474 } |
473 | 475 |
474 bool VTVideoEncodeAccelerator::ResetCompressionSession() { | 476 bool VTVideoEncodeAccelerator::ResetCompressionSession() { |
475 DCHECK(thread_checker_.CalledOnValidThread()); | 477 DCHECK(thread_checker_.CalledOnValidThread()); |
476 | 478 |
477 DestroyCompressionSession(); | 479 DestroyCompressionSession(); |
478 | 480 |
479 CFTypeRef attributes_keys[] = {kCVPixelBufferOpenGLCompatibilityKey, | 481 CFTypeRef attributes_keys[] = {kCVPixelBufferOpenGLCompatibilityKey, |
480 kCVPixelBufferIOSurfacePropertiesKey, | 482 kCVPixelBufferIOSurfacePropertiesKey, |
481 kCVPixelBufferPixelFormatTypeKey}; | 483 kCVPixelBufferPixelFormatTypeKey}; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 (encoder_thread_.IsRunning() && | 579 (encoder_thread_.IsRunning() && |
578 encoder_thread_task_runner_->BelongsToCurrentThread())); | 580 encoder_thread_task_runner_->BelongsToCurrentThread())); |
579 | 581 |
580 if (compression_session_) { | 582 if (compression_session_) { |
581 videotoolbox_glue_->VTCompressionSessionInvalidate(compression_session_); | 583 videotoolbox_glue_->VTCompressionSessionInvalidate(compression_session_); |
582 compression_session_.reset(); | 584 compression_session_.reset(); |
583 } | 585 } |
584 } | 586 } |
585 | 587 |
586 } // namespace media | 588 } // namespace media |
OLD | NEW |