Index: content/common/gpu/media/vt_video_encode_accelerator.h |
diff --git a/content/common/gpu/media/vt_video_encode_accelerator.h b/content/common/gpu/media/vt_video_encode_accelerator.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4b9700ad5ccac01d7bce4394eb9a4000e82efc2c |
--- /dev/null |
+++ b/content/common/gpu/media/vt_video_encode_accelerator.h |
@@ -0,0 +1,95 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_ENCODE_ACCELERATOR_H_ |
+#define CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_ENCODE_ACCELERATOR_H_ |
+ |
+#include "base/mac/scoped_cftyperef.h" |
+#include "content/common/content_export.h" |
+#include "media/base/mac/videotoolbox_glue.h" |
+#include "media/video/video_encode_accelerator.h" |
+ |
+namespace content { |
+ |
+// VideoToolbox.framework implementation of the VideoEncodeAccelerator |
+// interface for MacOSX. |
+class CONTENT_EXPORT VTVideoEncodeAccelerator |
+ : public media::VideoEncodeAccelerator { |
+ public: |
+ VTVideoEncodeAccelerator(); |
+ ~VTVideoEncodeAccelerator() override; |
+ |
+ // media::VideoEncodeAccelerator implementation. |
+ media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() |
+ override; |
+ bool Initialize(media::VideoPixelFormat format, |
+ const gfx::Size& input_visible_size, |
+ media::VideoCodecProfile output_profile, |
+ uint32_t initial_bitrate, |
+ Client* client) override; |
+ void Encode(const scoped_refptr<media::VideoFrame>& frame, |
+ bool force_keyframe) override; |
+ void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; |
+ void RequestEncodingParametersChange(uint32_t bitrate, |
+ uint32_t framerate) override; |
+ void Destroy() override; |
+ |
+ // Holds output buffers coming from the client ready to be filled. |
+ struct BitstreamBufferRef; |
+ |
+ private: |
+ typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef; |
mcasas
2016/02/03 20:01:31
using CMSampleBufferRef = CoreMediaGlue::CMSampleB
emircan
2016/02/04 05:18:52
Done.
|
+ typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef; |
+ typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags; |
+ |
+ // Compression session callback function to handle compressed frames. |
+ static void CompressionCallback(void* encoder_opaque, |
+ void* request_opaque, |
+ OSStatus status, |
+ VTEncodeInfoFlags info, |
+ CMSampleBufferRef sbuf); |
+ |
+ // Reset the encoder's compression session by destroying the existing one |
+ // using DestroyCompressionSession() and creating a new one. The new session |
+ // is configured using ConfigureCompressionSession(). |
+ bool ResetCompressionSession(); |
+ |
+ // Configure the current compression session using current encoder settings. |
+ void ConfigureCompressionSession(); |
+ |
+ // Destroy the current compression session if any. Blocks until all pending |
+ // frames have been flushed out (similar to EmitFrames without doing any |
+ // encoding work). |
+ void DestroyCompressionSession(); |
+ |
+ // VideoToolboxGlue provides access to VideoToolbox at runtime. |
+ const VideoToolboxGlue* const videotoolbox_glue_; |
+ base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_; |
+ |
+ // Initial parameters given by media::VideoEncodeAccelerator::Initialize() |
+ uint32_t bitrate_; |
+ gfx::Size input_visible_size_; |
+ |
+ // Bitstream buffers ready to be used to return encoded output, as a LIFO |
+ // since we don't care about ordering. |
+ std::deque<scoped_ptr<BitstreamBufferRef>> encoder_output_queue_; |
+ |
+ // Our original calling task runner for the child thread. |
+ const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
mcasas
2016/02/03 20:01:31
nit: s/child_task_runner_/callback_task_runner_/ ?
emircan
2016/02/04 05:18:52
callback might be confusing since there are callba
|
+ |
+ // To expose client callbacks from VideoEncodeAccelerator. |
+ // NOTE: all calls to these objects *MUST* be executed on |
+ // child_task_runner_. |
mcasas
2016/02/03 20:01:31
|child_task_runner_|
emircan
2016/02/04 05:18:52
Done.
|
+ scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; |
+ base::WeakPtr<Client> client_; |
+ |
+ // Thread checker to enforce that this object is used on a specific thread. |
+ base::ThreadChecker thread_checker_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(VTVideoEncodeAccelerator); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_ENCODE_ACCELERATOR_H_ |