Chromium Code Reviews| Index: content/common/gpu/media/vt_video_encode_accelerator_mac.h |
| diff --git a/content/common/gpu/media/android_video_encode_accelerator.h b/content/common/gpu/media/vt_video_encode_accelerator_mac.h |
| similarity index 26% |
| copy from content/common/gpu/media/android_video_encode_accelerator.h |
| copy to content/common/gpu/media/vt_video_encode_accelerator_mac.h |
| index 426360dca7c175a73bd94b85e63dfaff16f57bca..6a04d0c15dbd31226dd184c62906f50630949c7b 100644 |
| --- a/content/common/gpu/media/android_video_encode_accelerator.h |
| +++ b/content/common/gpu/media/vt_video_encode_accelerator_mac.h |
| @@ -1,42 +1,26 @@ |
| -// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// 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_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_ |
| -#define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_ |
| +#ifndef CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ |
| +#define CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ |
| -#include <stddef.h> |
| -#include <stdint.h> |
| - |
| -#include <list> |
| -#include <queue> |
| -#include <vector> |
| - |
| -#include "base/macros.h" |
| -#include "base/memory/weak_ptr.h" |
| -#include "base/threading/thread_checker.h" |
| -#include "base/timer/timer.h" |
| -#include "base/tuple.h" |
| +#include "base/mac/scoped_cftyperef.h" |
| #include "content/common/content_export.h" |
| -#include "media/base/android/sdk_media_codec_bridge.h" |
| +#include "media/base/mac/videotoolbox_glue.h" |
| +#include "media/base/mac/videotoolbox_helpers.h" |
| #include "media/video/video_encode_accelerator.h" |
| -namespace media { |
| -class BitstreamBuffer; |
| -} // namespace media |
| - |
| namespace content { |
| -// Android-specific implementation of media::VideoEncodeAccelerator, enabling |
| -// hardware-acceleration of video encoding, based on Android's MediaCodec class |
| -// (http://developer.android.com/reference/android/media/MediaCodec.html). This |
| -// class expects to live and be called on a single thread (the GPU process' |
| -// ChildThread). |
| -class CONTENT_EXPORT AndroidVideoEncodeAccelerator |
| +// VideoToolbox.framework implementation of the VideoEncodeAccelerator |
| +// interface for MacOSX. VideoToolbox makes no guarantees that it is thread |
| +// safe, so this object is pinned to the thread on which it is constructed. |
| +class CONTENT_EXPORT VTVideoEncodeAccelerator |
| : public media::VideoEncodeAccelerator { |
| public: |
| - AndroidVideoEncodeAccelerator(); |
| - ~AndroidVideoEncodeAccelerator() override; |
| + VTVideoEncodeAccelerator(); |
| + ~VTVideoEncodeAccelerator() override; |
| // media::VideoEncodeAccelerator implementation. |
| media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() |
| @@ -54,64 +38,69 @@ class CONTENT_EXPORT AndroidVideoEncodeAccelerator |
| void Destroy() override; |
| private: |
| - enum { |
| - // Arbitrary choice. |
| - INITIAL_FRAMERATE = 30, |
| - // Until there are non-realtime users, no need for unrequested I-frames. |
| - IFRAME_INTERVAL = INT32_MAX, |
| - }; |
| - |
| - // Impedance-mismatch fixers: MediaCodec is a poll-based API but VEA is a |
| - // push-based API; these methods turn the crank to make the two work together. |
| - void DoIOTask(); |
| - void QueueInput(); |
| - void DequeueOutput(); |
| - |
| - // Returns true if we don't need more or bigger output buffers. |
| - bool DoOutputBuffersSuffice(); |
| - |
| - // Start & stop |io_timer_| if the time seems right. |
| - void MaybeStartIOTimer(); |
| - void MaybeStopIOTimer(); |
| - |
| - // Used to DCHECK that we are called on the correct thread. |
| - base::ThreadChecker thread_checker_; |
| + using CMSampleBufferRef = CoreMediaGlue::CMSampleBufferRef; |
| + using VTCompressionSessionRef = VideoToolboxGlue::VTCompressionSessionRef; |
| + using VTEncodeInfoFlags = VideoToolboxGlue::VTEncodeInfoFlags; |
| - // VideoDecodeAccelerator::Client callbacks go here. Invalidated once any |
| - // error triggers. |
| - scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; |
| + // Holds the associated data of a video frame being processed. |
| + struct InProgressFrameEncode; |
| + |
| + // Holds output buffers coming from the client ready to be filled. |
| + struct BitstreamBufferRef; |
| - scoped_ptr<media::VideoCodecBridge> media_codec_; |
| + // Compression session callback function to handle compressed frames. |
| + static void CompressionCallback(void* encoder_opaque, |
| + void* request_opaque, |
| + OSStatus status, |
| + VTEncodeInfoFlags info, |
| + CMSampleBufferRef sbuf); |
| + void CompressionCallbackTask(CMSampleBufferRef sbuf); |
| - // Bitstream buffers waiting to be populated & returned to the client. |
| - std::vector<media::BitstreamBuffer> available_bitstream_buffers_; |
| + // 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(); |
| - // Frames waiting to be passed to the codec, queued until an input buffer is |
| - // available. Each element is a tuple of <Frame, key_frame, enqueue_time>. |
| - typedef std::queue< |
| - base::Tuple<scoped_refptr<media::VideoFrame>, bool, base::Time>> |
| - PendingFrames; |
| - PendingFrames pending_frames_; |
| + // Configure the current compression session using current encoder settings. |
| + bool ConfigureCompressionSession(); |
| - // Repeating timer responsible for draining pending IO to the codec. |
| - base::RepeatingTimer io_timer_; |
| + // 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(); |
| - // The difference between number of buffers queued & dequeued at the codec. |
| - int32_t num_buffers_at_codec_; |
| + // VideoToolboxGlue provides access to VideoToolbox at runtime. |
| + const VideoToolboxGlue* videotoolbox_glue_; |
| + base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_; |
| - // A monotonically-growing value, used as a fake timestamp just to keep things |
| - // appearing to move forward. |
| - base::TimeDelta fake_input_timestamp_; |
| + int32_t bitrate_; |
| + gfx::Size input_visible_size_; |
| - // Number of requested output buffers and their capacity. |
| - int num_output_buffers_; // -1 until RequireBitstreamBuffers. |
| - size_t output_buffers_capacity_; // 0 until RequireBitstreamBuffers. |
| + // Set parameters for VTCompressionSession. |
| + scoped_ptr<media::video_toolbox::SessionPropertySetter> |
|
miu
2016/02/09 23:29:22
Please remove (see comment in .cc file).
|
| + session_property_setter_; |
| - uint32_t last_set_bitrate_; // In bps. |
| + // Bitstream buffers ready to be used to return encoded output as a FIFO. |
| + std::deque<scoped_ptr<BitstreamBufferRef>> encoder_output_queue_; |
| + |
| + // CMSampleBufferRef needs to be copied into a BitstreamBufferRef as a FIFO. |
| + std::deque<CMSampleBufferRef> encoder_output_sample_buffer_queue_; |
| + |
| + // Our original calling task runner for the child thread. |
| + const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; |
| + |
| + // To expose client callbacks from VideoEncodeAccelerator. |
| + // NOTE: all calls to this object *MUST* be executed on |
| + // |client_task_runner_|. |
| + 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(AndroidVideoEncodeAccelerator); |
| + DISALLOW_COPY_AND_ASSIGN(VTVideoEncodeAccelerator); |
| }; |
| -} // namespace content |
| +} // namespace content |
| -#endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_ |
| +#endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_ENCODE_ACCELERATOR_MAC_H_ |