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

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

Issue 1016773002: MJPEG acceleration for video capture using VAAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address most comments Created 5 years, 8 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_jpeg_decode_accelerator.h
diff --git a/content/common/gpu/media/vaapi_jpeg_decode_accelerator.h b/content/common/gpu/media/vaapi_jpeg_decode_accelerator.h
new file mode 100644
index 0000000000000000000000000000000000000000..c516019ea2de2c7e924d067f88224befe75968e4
--- /dev/null
+++ b/content/common/gpu/media/vaapi_jpeg_decode_accelerator.h
@@ -0,0 +1,156 @@
+// Copyright 2015 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_JPEG_DECODE_ACCELERATOR_H_
+#define CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_
+
+#include <map>
+#include <queue>
+#include <utility>
+#include <vector>
+
+#include "base/logging.h"
+#include "base/memory/linked_ptr.h"
+#include "base/memory/shared_memory.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop.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 "content/common/content_export.h"
+#include "content/common/gpu/media/vaapi_jpeg_decoder.h"
+#include "content/common/gpu/media/vaapi_wrapper.h"
+#include "media/base/bitstream_buffer.h"
+#include "media/video/jpeg_decode_accelerator.h"
+#include "media/video/picture.h"
+
+namespace content {
+
+// Class to provide JPEG 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.
+//
+// Threading/life-cycle: this object is created & destroyed on the GPU
+// ChildThread. A few methods on it are called on the decoder thread which is
+// stopped during |this->Destroy()|, so any tasks posted to the decoder thread
+// can assume |*this| is still alive. See |weak_this_| below for more details.
+class CONTENT_EXPORT VaapiJpegDecodeAccelerator
+ : public media::JpegDecodeAccelerator {
+ public:
+ VaapiJpegDecodeAccelerator();
+ ~VaapiJpegDecodeAccelerator() override;
+
+ // media::JpegDecodeAccelerator implementation.
+ bool Initialize(media::JpegDecodeAccelerator::Client* client) override;
+ void Decode(const media::BitstreamBuffer& bitstream_buffer,
+ const scoped_refptr<media::VideoFrame>& video_frame) override;
+ void Destroy() override;
+
+ private:
+ // Notify the client that an error has occurred and decoding cannot continue.
+ void NotifyError(int32_t bitstream_buffer_id, Error error);
+
+ // Map the received input buffer into this process' address space and
+ // queue it for decode.
+ void MapAndQueueNewInputBuffer(
+ const media::BitstreamBuffer& bitstream_buffer,
+ const scoped_refptr<media::VideoFrame>& video_frame);
+
+ // Continue decoding given input buffers and sleep waiting for input/output
wuchengli 2015/04/15 07:11:59 There is no sleep waiting.
kcwu 2015/04/16 14:38:29 Done.
+ // as needed. Will exit if a new set of surfaces or reset/flush/destroy
wuchengli 2015/04/15 07:11:59 Update the comment.
kcwu 2015/04/16 14:38:28 Done.
+ // is requested.
+ void DecodeTask();
+
+ // Helper for Destroy(), doing all the actual work except for deleting self.
+ void Cleanup();
+
+ // TODO(kcwu) fix comment
wuchengli 2015/04/15 07:11:59 Remove TODO and update the comment.
kcwu 2015/04/16 14:38:29 Done.
+ // Callback to be executed once we have a |va_surface| to be output and
+ // an available |tfp_picture| to use for output.
+ // Puts contents of |va_surface| into given |tfp_picture|, releases the
+ // surface and passes the resulting picture to client for output.
+ bool OutputPicture(VASurfaceID va_surface_id,
+ int32_t input_id,
+ const scoped_refptr<media::VideoFrame>& video_frame);
+
+ // VAVDA state.
+ enum State {
+ // Initialize() not called yet or failed.
+ kUninitialized,
+ // DecodeTask running.
+ kDecoding,
+ // Idle, decoder in state ready to start/resume decoding.
+ kIdle,
+ // Destroying, waiting for the decoder to finish current task.
+ kDestroying,
+ };
+
+ // Protects input buffer and surface queues and state_.
wuchengli 2015/04/15 07:11:59 Please list all the exact variable names instead o
kcwu 2015/04/20 17:47:59 Done.
+ base::Lock lock_;
+ State state_;
+
+ // An input buffer awaiting consumption, provided by the client.
+ struct InputBuffer {
+ InputBuffer();
+ ~InputBuffer();
+
+ int32 id;
+ size_t size;
+ scoped_ptr<base::SharedMemory> shm;
+
wuchengli 2015/04/15 07:11:59 remove blank line
kcwu 2015/04/16 14:38:29 Done.
+ scoped_refptr<media::VideoFrame> video_frame;
+ };
+
+ // 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.
wuchengli 2015/04/15 07:11:59 s/input_buffers_/|input_buffers_|/. Same for other
kcwu 2015/04/16 14:38:28 Done.
+ base::ConditionVariable input_ready_;
wuchengli 2015/04/15 07:11:59 not used. remove
kcwu 2015/04/16 14:38:29 Done.
+
+ // Current input buffer at decoder.
+ linked_ptr<InputBuffer> curr_input_buffer_;
+
+ // ChildThread's message loop
+ base::MessageLoop* message_loop_;
+
+ // To expose client callbacks from VideoDecodeAccelerator.
wuchengli 2015/04/15 07:11:59 s/VideoDecodeAccelerator/JpegDecodeAccelerator/
kcwu 2015/04/16 14:38:29 Done.
+ // NOTE: all calls to these objects *MUST* be executed on message_loop_.
+ scoped_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_;
+ base::WeakPtr<Client> client_;
+
+ // WeakPtr<> pointing to |this| for use in posting tasks from the decoder
+ // thread back to the ChildThread. Because the decoder thread is a member of
+ // this class, any task running on the decoder thread is guaranteed that this
+ // object is still alive. As a result, tasks posted from ChildThread to
+ // decoder thread should use base::Unretained(this), and tasks posted from the
+ // decoder thread to the ChildThread should use |weak_this_|.
+ base::WeakPtr<VaapiJpegDecodeAccelerator> weak_this_;
+
+ // Callback used when creating VASurface objects.
+ VASurface::ReleaseCB va_surface_release_cb_;
wuchengli 2015/04/15 07:11:59 not used
kcwu 2015/04/16 14:38:29 Done.
+
+ scoped_ptr<VaapiWrapper> vaapi_wrapper_;
+
+ // Comes after vaapi_wrapper_ to ensure its destructor is executed before
+ // vaapi_wrapper_ is destroyed.
+ scoped_ptr<VaapiJpegDecoder> decoder_;
+ base::Thread decoder_thread_;
+ // Use this to post tasks to |decoder_thread_| instead of
+ // |decoder_thread_.message_loop()| because the latter will be NULL once
+ // |decoder_thread_.Stop()| returns.
+ scoped_refptr<base::MessageLoopProxy> decoder_thread_proxy_;
+
+ // The WeakPtrFactory for |weak_this_|.
+ base::WeakPtrFactory<VaapiJpegDecodeAccelerator> weak_this_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecodeAccelerator);
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_

Powered by Google App Engine
This is Rietveld 408576698