Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: content/common/gpu/media/vaapi_video_decode_accelerator.h

Issue 9814001: Add VAVDA, the VAAPI Video Decode Accelerator for Intel CPUs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..86b5c7fb4a859f0734fd5acc9ca0b62202545efa
--- /dev/null
+++ b/content/common/gpu/media/vaapi_video_decode_accelerator.h
@@ -0,0 +1,155 @@
+// 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 <map>
+#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/waitable_event.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,
+ NON_EXPORTED_BASE(public base::NonThreadSafe) {
+ public:
+
+ VaapiVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client);
+
+ // media::VideoDecodeAccelerator implementation.
+ bool Initialize(Profile profile) OVERRIDE;
+ void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE;
+ virtual void AssignPictureBuffers(
+ const std::vector<media::PictureBuffer>& buffers) OVERRIDE;
+ void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE;
+ void Flush() OVERRIDE;
+ void Reset() OVERRIDE;
+ 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();
+
+ // Notify the client that initialization is finished (successful or not).
+ 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);
+
+ // Notify the client that Reset or Flush have finished.
+ void NotifyResetDone();
+ void NotifyFlushDone();
+
+ // Ask the client to provide |num_pics| textures of size |width| per |height|
+ void RequestPictureBuffers(int num_pics, int width, int height);
+
+ // Notify the client that an error has occured and decoding cannot continue.
+ void StopOnError(media::VideoDecodeAccelerator::Error error);
+
+ // Map the received input buffer into this process' address space and
+ // queue it for use.
+ void MapAndQueueNewInputBuffer(
+ const media::BitstreamBuffer& bitstream_buffer);
+
+ // Request and sets up a new input stream buffer for decoder if available.
+ // Will release and give back the current input buffer, if present.
+ void TryGetNewInputBuffer();
+
+ // Decoding task, executed in decoder's thread context.
+ void DecodeTask();
+
+ // Give back an output buffer to the decoder after displaying it.
+ // Must be executed on the decoder thread.
+ void ReusePictureTask(int32 picture_buffer_id);
+
+ // Force the decoder to flush all output pictures.
+ // Must be run on the decoder thread.
+ void FlushTask();
+
+ // Put the decoder into reset state.
+ // Must be run on the decoder thread.
+ void ResetTask();
+
+ // Used by the decoder thread to request more input stream.
+ // Must be run on the decoder thread and will sleep until new input
+ // becomes available.
+ void WaitForInput();
+
+ // Client-provided X/GLX state.
+ Display* x_display_;
+ GLXContext glx_context_;
+
+ // An input buffer awaiting consumption, provided by the client.
+ struct InputBuffer {
+ int32 id;
+ size_t size;
+ scoped_ptr<base::SharedMemory> shm;
+ };
+
+ // Queue for incoming input buffers.
+ typedef std::queue<InputBuffer*> InputBuffers;
+ InputBuffers input_buffers_;
+ // Current input buffer set in decoder.
+ scoped_ptr<InputBuffer> curr_input_buffer_;
+
+ // Signalled if a valid stream is set up in decoder. Used to synchronize
+ // between decoder and main thread to safely update current stream in decoder
+ // from the |input_buffers_| queue.
+ base::WaitableEvent input_ready_;
+
+ // Main thread's message loop
+ MessageLoop* message_loop_;
+
+ // To expose client callbacks from VideoDecodeAccelerator.
+ // NOTE: all calls to this object *MUST* be executed in message_loop_.
+ Client* client_;
+
+ // True if output pictures have been requested from the client.
+ bool pictures_requested_;
+
+ // True if we are after reset and need to resume.
+ bool after_reset_;
+
+ // True if we are resetting.
+ bool resetting_;
+
+ base::Thread decoder_thread_;
+ VaapiH264Decoder decoder_;
+
+ // Callback passed to the decoder, which it will use to signal readiness
+ // of an output picture to be displayed.
+ static void OutputPicCallback(void* priv, int32 input_id, int32 output_id);
+
+ DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator);
+};
+
+#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_
+

Powered by Google App Engine
This is Rietveld 408576698