| 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 #ifndef MEDIA_GPU_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ | 5 #ifndef MEDIA_GPU_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ |
| 6 #define MEDIA_GPU_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ | 6 #define MEDIA_GPU_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "media/base/mac/videotoolbox_glue.h" | |
| 18 #include "media/base/mac/videotoolbox_helpers.h" | 17 #include "media/base/mac/videotoolbox_helpers.h" |
| 19 #include "media/gpu/media_gpu_export.h" | 18 #include "media/gpu/media_gpu_export.h" |
| 20 #include "media/video/video_encode_accelerator.h" | 19 #include "media/video/video_encode_accelerator.h" |
| 21 #include "third_party/webrtc/common_video/include/bitrate_adjuster.h" | 20 #include "third_party/webrtc/common_video/include/bitrate_adjuster.h" |
| 22 | 21 |
| 23 namespace media { | 22 namespace media { |
| 24 | 23 |
| 25 // VideoToolbox.framework implementation of the VideoEncodeAccelerator | 24 // VideoToolbox.framework implementation of the VideoEncodeAccelerator |
| 26 // interface for MacOSX. VideoToolbox makes no guarantees that it is thread | 25 // interface for MacOSX. VideoToolbox makes no guarantees that it is thread |
| 27 // safe, so this object is pinned to the thread on which it is constructed. | 26 // safe, so this object is pinned to the thread on which it is constructed. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 uint32_t initial_bitrate, | 38 uint32_t initial_bitrate, |
| 40 Client* client) override; | 39 Client* client) override; |
| 41 void Encode(const scoped_refptr<VideoFrame>& frame, | 40 void Encode(const scoped_refptr<VideoFrame>& frame, |
| 42 bool force_keyframe) override; | 41 bool force_keyframe) override; |
| 43 void UseOutputBitstreamBuffer(const BitstreamBuffer& buffer) override; | 42 void UseOutputBitstreamBuffer(const BitstreamBuffer& buffer) override; |
| 44 void RequestEncodingParametersChange(uint32_t bitrate, | 43 void RequestEncodingParametersChange(uint32_t bitrate, |
| 45 uint32_t framerate) override; | 44 uint32_t framerate) override; |
| 46 void Destroy() override; | 45 void Destroy() override; |
| 47 | 46 |
| 48 private: | 47 private: |
| 49 using CMSampleBufferRef = CoreMediaGlue::CMSampleBufferRef; | |
| 50 using VTCompressionSessionRef = VideoToolboxGlue::VTCompressionSessionRef; | |
| 51 using VTEncodeInfoFlags = VideoToolboxGlue::VTEncodeInfoFlags; | |
| 52 | |
| 53 // Holds the associated data of a video frame being processed. | 48 // Holds the associated data of a video frame being processed. |
| 54 struct InProgressFrameEncode; | 49 struct InProgressFrameEncode; |
| 55 | 50 |
| 56 // Holds output buffers coming from the encoder. | 51 // Holds output buffers coming from the encoder. |
| 57 struct EncodeOutput; | 52 struct EncodeOutput; |
| 58 | 53 |
| 59 // Holds output buffers coming from the client ready to be filled. | 54 // Holds output buffers coming from the client ready to be filled. |
| 60 struct BitstreamBufferRef; | 55 struct BitstreamBufferRef; |
| 61 | 56 |
| 62 // Encoding tasks to be run on |encoder_thread_|. | 57 // Encoding tasks to be run on |encoder_thread_|. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 bool require_hw_encoding); | 95 bool require_hw_encoding); |
| 101 | 96 |
| 102 // Configure the current compression session using current encoder settings. | 97 // Configure the current compression session using current encoder settings. |
| 103 bool ConfigureCompressionSession(); | 98 bool ConfigureCompressionSession(); |
| 104 | 99 |
| 105 // Destroy the current compression session if any. Blocks until all pending | 100 // Destroy the current compression session if any. Blocks until all pending |
| 106 // frames have been flushed out (similar to EmitFrames without doing any | 101 // frames have been flushed out (similar to EmitFrames without doing any |
| 107 // encoding work). | 102 // encoding work). |
| 108 void DestroyCompressionSession(); | 103 void DestroyCompressionSession(); |
| 109 | 104 |
| 110 // VideoToolboxGlue provides access to VideoToolbox at runtime. | |
| 111 const VideoToolboxGlue* videotoolbox_glue_; | |
| 112 base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_; | 105 base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_; |
| 113 | 106 |
| 114 gfx::Size input_visible_size_; | 107 gfx::Size input_visible_size_; |
| 115 size_t bitstream_buffer_size_; | 108 size_t bitstream_buffer_size_; |
| 116 int32_t frame_rate_; | 109 int32_t frame_rate_; |
| 117 int32_t initial_bitrate_; | 110 int32_t initial_bitrate_; |
| 118 int32_t target_bitrate_; | 111 int32_t target_bitrate_; |
| 119 int32_t encoder_set_bitrate_; | 112 int32_t encoder_set_bitrate_; |
| 120 | 113 |
| 121 // Bitrate adjuster used to fix VideoToolbox's inconsistent bitrate issues. | 114 // Bitrate adjuster used to fix VideoToolbox's inconsistent bitrate issues. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 149 // other destructors run. | 142 // other destructors run. |
| 150 base::WeakPtr<VTVideoEncodeAccelerator> encoder_weak_ptr_; | 143 base::WeakPtr<VTVideoEncodeAccelerator> encoder_weak_ptr_; |
| 151 base::WeakPtrFactory<VTVideoEncodeAccelerator> encoder_task_weak_factory_; | 144 base::WeakPtrFactory<VTVideoEncodeAccelerator> encoder_task_weak_factory_; |
| 152 | 145 |
| 153 DISALLOW_COPY_AND_ASSIGN(VTVideoEncodeAccelerator); | 146 DISALLOW_COPY_AND_ASSIGN(VTVideoEncodeAccelerator); |
| 154 }; | 147 }; |
| 155 | 148 |
| 156 } // namespace media | 149 } // namespace media |
| 157 | 150 |
| 158 #endif // MEDIA_GPU_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ | 151 #endif // MEDIA_GPU_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ |
| OLD | NEW |