Index: content/common/gpu/media/vaapi_video_decode_accelerator.h |
diff --git a/content/common/gpu/media/vaapi_video_decode_accelerator.h b/content/common/gpu/media/vaapi_video_decode_accelerator.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3132f64f2f1621134c1a750d7ca1138332ca7220 |
--- /dev/null |
+++ b/content/common/gpu/media/vaapi_video_decode_accelerator.h |
@@ -0,0 +1,204 @@ |
+// Copyright (c) 2012 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. |
+// |
+// This file contains an implementation of VideoDecoderAccelerator |
+// that utilizes hardware video decoder present on Intel CPUs. |
+ |
+#ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
+#define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
+ |
+#include "vaapi_h264_decoder.h" |
+ |
+#include <queue> |
+#include <utility> |
+#include <vector> |
+ |
+#include <GL/glx.h> |
+ |
+#include "base/logging.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/message_loop.h" |
+#include "base/shared_memory.h" |
+#include "base/synchronization/condition_variable.h" |
+#include "base/synchronization/lock.h" |
+#include "base/threading/non_thread_safe.h" |
+#include "base/threading/thread.h" |
+#include "media/base/bitstream_buffer.h" |
+#include "media/video/picture.h" |
+#include "media/video/video_decode_accelerator.h" |
+ |
+// Class to provide video decode acceleration for Intel systems with hardware |
+// support for it, and on which libva is available. |
+// Decoding tasks are performed in a separate decoding thread. |
+class VaapiVideoDecodeAccelerator |
+ : public media::VideoDecodeAccelerator { |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
fits on one line now?
Pawel Osciak
2012/05/06 17:49:19
Done.
|
+ public: |
+ |
+ VaapiVideoDecodeAccelerator(Client* client); |
+ |
+ // media::VideoDecodeAccelerator implementation. |
+ virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; |
+ virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
+ virtual void AssignPictureBuffers( |
+ const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
+ virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
+ virtual void Flush() OVERRIDE; |
+ virtual void Reset() OVERRIDE; |
+ virtual void Destroy() OVERRIDE; |
+ |
+ // Used by user of this class to pass X/GLX state. |
+ void SetGlxState(Display* x_display, GLXContext glx_context); |
+ |
+ private: |
+ virtual ~VaapiVideoDecodeAccelerator(); |
+ |
+ void NotifyInitializeDone(); |
+ |
+ // Notify the client that the input buffer has been consumed. |
+ void NotifyInputBufferRead(int input_buffer_id); |
+ |
+ // Ensure data has been synced with the output texture and notify |
+ // the client it is ready for displaying. |
+ void SyncAndNotifyPictureReady(int32 input_id, int32 output_id); |
+ |
+ // Posted by the decoder thread to notify VAVDA that the decoder has |
+ // initially parsed the stream is ready to decode. If the pictures have |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
s/is/and is/ ?
Pawel Osciak
2012/05/06 17:49:19
Done.
|
+ // not yet been requested, it will request the client to provide |num_pics| |
+ // textures of size |width| per |height| and wait for them, otherwise will |
+ // post a DecodeTask directly. |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
The conditionality makes me think this API can be
|
+ void ReadyToDecode(int num_pics, int width, int height); |
+ |
+ // Notify the client that an error has occurred and decoding cannot continue. |
+ void NotifyError(Error error); |
+ |
+ // Map the received input buffer into this process' address space and |
+ // queue it for decode. |
+ void MapAndQueueNewInputBuffer( |
+ const media::BitstreamBuffer& bitstream_buffer); |
+ |
+ // Get a new input buffer from the queue and set it up in decoder. This will |
+ // sleep if no input buffers are available. Return true if a new buffer has |
+ // been set up, false if an early exit has been requested (due to initiated |
+ // reset/flush/destroy). |
+ bool GetInputBuffer(); |
+ |
+ // Signal the client that the current buffer has been read and can be |
+ // returned. Will also release the mapping. |
+ void ReturnCurrInputBuffer(); |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
Any reason not to stay consistent with the VDA::Cl
Pawel Osciak
2012/05/06 17:49:19
It not only notifies, but cleans up as well (mappi
|
+ |
+ // Get and set up one or more output buffers in the decoder. This will sleep |
+ // if no buffers are available. Return true if buffers have been set up or |
+ // false if an early exit has been requested (due to initiated |
+ // reset/flush/destroy). |
+ bool GetOutputBuffers(); |
+ |
+ // Initial decode task: get the decoder to the point in the stream from which |
+ // it can start/continue decoding. Does not require output buffers and does |
+ // not produce output frames. Called either when starting with a new stream |
+ // or when playback is to be resumed from a different location in the stream. |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
s/from a different location in the stream/followin
Pawel Osciak
2012/05/06 17:49:19
Done.
|
+ void InitialDecodeTask(); |
+ |
+ // Decoding task. Will continue decoding given input buffers and sleep |
+ // waiting for input/output as needed. Will exit if a reset/flush/destroy |
+ // is requested. |
+ void DecodeTask(); |
+ |
+ // Scheduled after receiving a flush request and executed after the current |
+ // decoding task finishes decoding pending inputs. Makes the decoder flush |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
s/decoder flush/decoder return/
Pawel Osciak
2012/05/06 17:49:19
Done.
|
+ // all remaining output pictures and puts it in an idle state, ready |
+ // to resume if needed and schedules a FinishFlush. |
+ void FlushTask(); |
+ |
+ // Scheduled by the FlushTask after decoder is flushed to put VAVDA into idle |
+ // state and notify the client that flushing has been finished. |
+ void FinishFlush(); |
+ |
+ // Scheduled after receiving a reset request and executed after the current |
+ // decoding task finishes decoding the current frame. Puts the decoder into |
+ // an idle state, ready to resume if needed, discarding decoded but not yet |
+ // outputted pictures (decoder keeps ownership of their associated picture |
+ // buffers). Schedules a FinishReset afterwards. |
+ void ResetTask(); |
+ |
+ // Scheduled by ResetTask after it's done to put VAVDA into an idle state. |
+ // Drops remaining input buffers and notifies the client that reset has been |
+ // finished. |
+ void FinishReset(); |
+ |
+ // Scheduled on the decoder thread after receiving a Destroy() call from the |
+ // client, executed after the current decoding task finishes decoding the |
+ // current frame, ignoring any remaining inputs. Cleans up the decoder and |
+ // frees all resources. |
+ void DestroyTask(); |
+ |
+ // Client-provided X/GLX state. |
+ Display* x_display_; |
+ GLXContext glx_context_; |
+ |
+ // VAVDA state. |
+ enum State { |
+ // Initialize() not called yet. |
+ kUninitialized, |
+ // Initialize() succeeded, no initial decode and no pictures requested. |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
What state is used if Initialize() failed?
Pawel Osciak
2012/05/06 17:49:19
kUninitialized. Added comment about this.
|
+ kInitialized, |
+ // Initial decode finished, requested pictures and waiting for them. |
+ kPicturesRequested, |
+ // Everything initialized, pictures received and assigned, in decoding. |
+ kDecoding, |
+ // Resetting, waiting for decoder to finish current task and cleanup. |
+ kResetting, |
+ // Flushing, waiting for decoder to finish current task and cleanup. |
+ kFlushing, |
+ // Idle, decoder in state ready to resume decoding. |
+ kIdle, |
+ // Destroying, waiting for the decoder to finish current task. |
+ kDestroying, |
+ }; |
+ |
+ State state_; |
+ |
+ // An input buffer awaiting consumption, provided by the client. |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
enums, types, and typedefs belong at the top of th
Pawel Osciak
2012/05/06 17:49:19
Ok, moving it one member down above its only usage
|
+ struct InputBuffer { |
+ int32 id; |
+ size_t size; |
+ scoped_ptr<base::SharedMemory> shm; |
+ }; |
+ |
+ // Protects input and output buffer queues and state_. |
+ base::Lock lock_; |
+ |
+ // Queue for incoming input buffers. |
+ typedef std::queue<linked_ptr<InputBuffer> > InputBuffers; |
+ InputBuffers input_buffers_; |
+ // Signalled when input buffers are queued onto the input_buffers_ queue. |
+ base::ConditionVariable input_ready_; |
+ |
+ // Current input buffer at decoder. |
+ linked_ptr<InputBuffer> curr_input_buffer_; |
+ |
+ // Queue for incoming input buffers. |
+ typedef std::queue<int32> OutputBuffers; |
+ OutputBuffers output_buffers_; |
+ // Signalled when output buffers are queued onto the output_buffers_ queue. |
+ base::ConditionVariable output_ready_; |
+ |
+ // Main thread's message loop |
Ami GONE FROM CHROMIUM
2012/05/03 23:22:53
s/Main thread/ChildThread/ ;)
Pawel Osciak
2012/05/06 17:49:19
Done.
|
+ MessageLoop* message_loop_; |
+ |
+ // To expose client callbacks from VideoDecodeAccelerator. |
+ // NOTE: all calls to this object *MUST* be executed on message_loop_. |
+ Client* client_; |
+ |
+ base::Thread decoder_thread_; |
+ content::VaapiH264Decoder decoder_; |
+ |
+ // Callback passed to the decoder, which it will use to signal readiness |
+ // of an output picture to be displayed. |
+ void OutputPicCallback(int32 input_id, int32 output_id); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); |
+}; |
+ |
+#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
+ |