Chromium Code Reviews| 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..b327b5a7e907a199faccbc54c6544db8877e684e |
| --- /dev/null |
| +++ b/content/common/gpu/media/vaapi_jpeg_decode_accelerator.h |
| @@ -0,0 +1,140 @@ |
| +// 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. |
|
wuchengli
2015/04/23 09:35:19
This is already explained in the class documentati
kcwu
2015/05/08 14:42:41
Done.
|
| + |
| +#ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ |
| +#define CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ |
| + |
| +#include <map> |
|
wuchengli
2015/04/23 09:35:19
not used
kcwu
2015/05/08 14:42:41
Done.
|
| +#include <queue> |
| +#include <utility> |
|
wuchengli
2015/04/23 09:35:19
not used?
kcwu
2015/05/08 14:42:41
Done.
|
| +#include <vector> |
|
wuchengli
2015/04/23 09:35:19
not used
kcwu
2015/05/08 14:42:41
Done.
|
| + |
| +#include "base/logging.h" |
|
wuchengli
2015/04/23 09:35:19
Move to .cc?
kcwu
2015/05/08 14:42:41
Done.
|
| +#include "base/memory/linked_ptr.h" |
| +#include "base/memory/shared_memory.h" |
|
wuchengli
2015/04/23 09:35:18
not used?
kcwu
2015/05/08 14:42:41
Done.
|
| +#include "base/memory/weak_ptr.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/synchronization/condition_variable.h" |
|
wuchengli
2015/04/23 09:35:19
not used
kcwu
2015/05/08 14:42:41
Done.
|
| +#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( |
| + const scoped_refptr<base::MessageLoopProxy>& io_message_loop); |
| + ~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); |
| + |
| + // Queue decoding request. |
| + void QueueNewDecodeRequest( |
| + const media::BitstreamBuffer& bitstream_buffer, |
| + const scoped_refptr<media::VideoFrame>& video_frame); |
| + |
| + // Process one debuging request in the queue. |
|
wuchengli
2015/04/23 09:35:18
s/debuging/decode/
kcwu
2015/05/08 14:42:41
Done.
|
| + void DecodeTask(); |
| + |
| + // Helper for Destroy(), doing all the actual work except for deleting self. |
| + void Cleanup(); |
| + |
| + // Puts contents of |va_surface| into given |video_frame|, releases the |
|
wuchengli
2015/04/23 09:35:19
s/Puts/Put/. s/releases/release/. s/passes/pass/ t
kcwu
2015/05/08 14:42:41
Done. Change others instead.
|
| + // surface and passes the resulting picture to client for output. |
|
wuchengli
2015/04/23 09:35:19
s/passes the resulting picture/passes the buffer i
kcwu
2015/05/08 14:42:41
Done.
|
| + bool OutputPicture(VASurfaceID va_surface_id, |
| + int32_t input_id, |
|
wuchengli
2015/04/23 09:35:19
s/input_id/input_buffer_id/ to be more descriptive
kcwu
2015/05/08 14:42:41
Done.
|
| + const scoped_refptr<media::VideoFrame>& video_frame); |
| + |
| + // VAVDA state. |
| + enum State { |
|
wuchengli
2015/04/23 09:35:18
Use a boolean if you only need two states.
kcwu
2015/05/08 14:42:41
Done.
|
| + // Initialize() not called yet or failed. |
| + kUninitialized, |
| + // Initialize() succeeded. |
| + kInitialized, |
| + }; |
| + |
| + // Protects |decode_requests_| and |state_|. |
| + base::Lock lock_; |
| + State state_; |
| + |
| + // An input buffer awaiting consumption, provided by the client. |
|
wuchengli
2015/04/23 09:35:19
|video_frame| is the output, so this is not only i
kcwu
2015/05/08 14:42:41
Done.
|
| + struct DecodeRequest { |
| + DecodeRequest(media::BitstreamBuffer bitstream_buffer, |
|
wuchengli
2015/04/23 09:35:19
const &
kcwu
2015/05/08 14:42:41
Done.
|
| + scoped_refptr<media::VideoFrame> video_frame); |
| + ~DecodeRequest(); |
| + |
| + media::BitstreamBuffer bitstream_buffer; |
| + scoped_refptr<media::VideoFrame> video_frame; |
| + }; |
| + |
| + // Queue for incoming decode requests. |
| + typedef std::queue<linked_ptr<DecodeRequest>> DecodeRequests; |
| + DecodeRequests decode_requests_; |
| + |
| + // ChildThread's message loop |
| + base::MessageLoop* message_loop_; |
| + |
| + // GPU IO message loop. |
| + scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
| + |
| + // To expose client callbacks from JpegDecodeAccelerator. |
| + // 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_; |
| + |
| + 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_ |