Chromium Code Reviews| Index: content/common/gpu/media/arc/arc_gpu_video_decode_accelerator.h |
| diff --git a/content/common/gpu/media/arc/arc_gpu_video_decode_accelerator.h b/content/common/gpu/media/arc/arc_gpu_video_decode_accelerator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..076a5a97464682a576a5d1faac2d37ccf2a688b4 |
| --- /dev/null |
| +++ b/content/common/gpu/media/arc/arc_gpu_video_decode_accelerator.h |
| @@ -0,0 +1,121 @@ |
| +// 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_ARC_ARC_VIDEO_ACCELERATOR_ADAPTER_H_ |
| +#define CONTENT_COMMON_GPU_MEDIA_ARC_ARC_VIDEO_ACCELERATOR_ADAPTER_H_ |
| + |
| +#include <queue> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "content/common/gpu/media/arc/arc_video_accelerator.h" |
| +#include "media/video/video_decode_accelerator.h" |
| + |
| +namespace content { |
| +namespace arc { |
| + |
| +// This class is excuted in Chromium's GPU process. It takes decoding requests |
| +// from ARC container via IPC channels and translates and send those requests |
| +// to the real VDA on Chromium. It also returns the decoded frames back to the |
| +// ARC side. |
| +class ArcGpuVideoDecodeAccelerator |
| + : public ArcVideoAccelerator, |
| + public media::VideoDecodeAccelerator::Client { |
| + public: |
| + ArcGpuVideoDecodeAccelerator(); |
| + |
| + // Implementation of the ArcVideoAccelerator interface. |
| + bool Initialize(DeviceType device, |
| + ArcVideoAccelerator::Client* client) override; |
| + bool SetBufferCount(PortType port, size_t* count) override; |
| + bool SetBufferFormat(PortType port, const BufferFormat& format) override; |
| + bool BindSharedMemory(PortType port, |
| + uint32_t index, |
| + int ashmem_fd, |
| + size_t offset, |
| + size_t length) override; |
| + bool BindDmabuf(PortType port, uint32_t index, int dmabuf_fd) override; |
| + void UseBuffer(PortType port, |
| + uint32_t index, |
| + const BufferMetadata& metadata) override; |
| + void Reset() override; |
| + |
| + // Implementation of the VideoDecodeAccelerator::Client interface. |
| + void ProvidePictureBuffers(uint32_t requested_num_of_buffers, |
| + const gfx::Size& dimensions, |
| + uint32_t texture_target) override; |
| + void DismissPictureBuffer(int32_t picture_buffer) override; |
| + void PictureReady(const media::Picture& picture) override; |
| + void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override; |
| + void NotifyFlushDone() override; |
| + void NotifyResetDone() override; |
| + void NotifyError(media::VideoDecodeAccelerator::Error error) override; |
| + |
| + private: |
| + struct InputRecord { |
| + // The file handle to access the buffer. It is owned by this ArcGVDA and |
| + // should be freed if not used. |
| + base::ScopedFD handle; |
| + off_t offset; |
| + size_t length; |
| + int32_t bitstream_buffer_id; |
| + int64_t timestamp; |
| + |
| + InputRecord(); |
| + }; |
| + |
| + struct PortInfo { |
| + MemoryType memory_type; |
| + size_t num_buffers; |
| + |
| + PortInfo(); |
| + }; |
| + |
| + // Helper function to Send the end-of-stream output buffer if |
| + // |pending_eos_output_buffer_| is true, or reuse the picture in ArcVDA. |
| + void SendEosIfNeededOrReusePicture(uint32_t index); |
| + |
| + // Helper functions to validate |port| (and |index|). |
| + bool ValidatePort(PortType port); |
| + bool ValidatePortAndIndex(PortType port, uint32_t index); |
| + |
| + // Indicates a pending EOS output buffer. When it is true, an EOS output |
| + // buffer need to be sent to |arc_client_| once an output buffer is available. |
| + bool pending_eos_output_buffer_; |
| + scoped_ptr<media::VideoDecodeAccelerator> vda_; |
| + |
| + // Help functions to find the index of the InputRecord which matches to given |
| + // |bitstream_buffer_id|. Returns the size of |input_records_| if it cannot be |
| + // found. |
| + uint32_t FindInputRecordByBitstreamBufferId(int32_t bitstream_buffer_id); |
|
kcwu
2016/01/20 09:11:05
move this to line 85.
To keep methods in front of
Owen Lin
2016/02/02 09:08:06
Done.
|
| + |
| + // It's safe to use the pointer here, the life cycle of the |arc_client_| |
| + // is longer than this ArcGpuVideoDecodeAccelerator. |
| + ArcVideoAccelerator::Client* arc_client_; |
| + |
| + // The callback called when reset completes. |
| + base::Closure reset_done_callback_; |
| + |
| + PortInfo port_info_[PORT_COUNT]; |
| + |
| + // The next bitstream_buffer_id, started from 0. |
| + int32_t next_bitstream_buffer_id_; |
| + |
| + gfx::Size coded_size_; |
| + |
| + // The index of buffers returned while Flushing, will be used for sending |
| + // EOS buffer back to |arc_client_|. |
| + std::queue<uint32_t> buffers_pending_eos_; |
| + |
| + std::vector<InputRecord> input_records_; |
| + |
| + base::ThreadChecker thread_checker_; |
| +}; |
| + |
| +} // namespace arc |
| +} // namespace content |
| + |
| +#endif // CONTENT_COMMON_GPU_MEDIA_ARC_ARC_VIDEO_ACCELERATOR_ADAPTER_H_ |