Chromium Code Reviews| Index: content/common/gpu/media/arc/arc_video_accelerator.h |
| diff --git a/content/common/gpu/media/arc/arc_video_accelerator.h b/content/common/gpu/media/arc/arc_video_accelerator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e9073c329c6d6a720d58b39e2a70219e18032b22 |
| --- /dev/null |
| +++ b/content/common/gpu/media/arc/arc_video_accelerator.h |
| @@ -0,0 +1,149 @@ |
| +// 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. |
| + |
| +#ifndef CONTENT_COMMON_GPU_MEDIA_ARC_ARC_VIDEO_ACCELERATOR_H_ |
| +#define CONTENT_COMMON_GPU_MEDIA_ARC_ARC_VIDEO_ACCELERATOR_H_ |
| + |
| +namespace content { |
| +namespace arc { |
| + |
| +typedef uint32_t status_t; |
| + |
| +enum HalPixelFormatExtension { |
| + HAL_PIXEL_FORMAT_H264 = 0x34363248, |
| + HAL_PIXEL_FORMAT_VP8 = 0x00385056, |
| +}; |
| + |
| +enum PortType { |
| + PORT_INPUT = 0, |
| + PORT_OUTPUT = 1, |
| + PORT_COUNT = 2, |
| +}; |
| + |
| +enum DeviceType { |
| + DEVICE_ENCODER = 0, |
| + DEVICE_DECODER = 1, |
| +}; |
| + |
| +enum MemoryType { |
| + MEMORY_SHARED_MEMORY = 1, |
|
Pawel Osciak
2016/01/07 09:22:36
Is there any specific reason to start with 1 here?
Owen Lin
2016/01/12 09:30:23
I don't really remember why. Let's start with 0 ju
|
| + MEMORY_DMABUF = 2, |
| +}; |
| + |
| +enum BufferFlag { |
| + BUFFER_FLAG_EOS = 1, |
| +}; |
| + |
| +struct BufferMetadata { |
| + int64_t timestamp; // in microseconds |
| + uint32_t flags; |
| + uint32_t bytes_used; |
| +}; |
| + |
| +struct BufferFormat { |
| + uint32_t pixel_format; // the v4l2 fourcc format |
|
Pawel Osciak
2016/01/07 09:22:36
could we call this fourcc and remove v4l2 mention
Owen Lin
2016/01/12 09:30:23
Done.
|
| + uint32_t image_size; |
|
Pawel Osciak
2016/01/07 09:22:36
Is this used?
Owen Lin
2016/01/12 09:30:23
Actually not. Removed.
|
| + MemoryType memory_type; |
| +}; |
| + |
| +struct VideoFormat { |
| + uint32_t pixel_format; |
| + uint32_t image_size; |
| + |
| + // minimal number of buffers required to process the video. |
| + uint32_t min_num_buffers; |
| + uint32_t coded_width; |
| + uint32_t coded_height; |
| + uint32_t crop_left; |
| + uint32_t crop_width; |
| + uint32_t crop_top; |
| + uint32_t crop_height; |
| +}; |
| + |
| +// ArcVideoAccelerator is a component of ArcCodec to deal with video |
| +// buffers. It is also an IPC interface between Android and Chromium. |
| +// So that the video buffers are sent to Chromium side and decoded. |
| +// ArcCodec implements ArcVideoAccelerator::Client and is responsible for |
| +// rendering and interacting with the Android media framework. |
| +class ArcVideoAccelerator { |
| + public: |
| + enum Error { |
| + NO_ERROR = 0, |
| + ILLEGAL_STATE = 1, |
| + INVALID_ARGUMENT = 2, |
| + UNREADABLE_INPUT = 3, |
| + PLATFORM_FAILURE = 4, |
| + }; |
| + |
| + // The callbacks of the ArcVideoAccelerator. ArcCodec implmenets this |
| + // interface. |
| + class Client { |
| + public: |
| + virtual ~Client(); |
| + |
| + // Called when an asynchronous error happens. Asynchronous errors happen |
| + // only when the accelerator processes the input buffer and tried to |
| + // generate the output to the output buffer. |
| + virtual void OnError(Error error) = 0; |
| + |
| + // Called when a buffer with the specified @index and @port has been |
|
Pawel Osciak
2016/01/07 09:22:36
|index| |port|
Owen Lin
2016/01/12 09:30:23
Done.
|
| + // processed and is no longer used in the accelerator. For input buffer, |
| + // it can be filled with new content. For output buffer, it is ready to |
| + // be used. |
|
Pawel Osciak
2016/01/07 09:22:36
s/used/consumed by the client/
Owen Lin
2016/01/12 09:30:23
Done.
|
| + virtual void OnBufferDone(PortType port, |
| + uint32_t index, |
| + const BufferMetadata& metadata) = 0; |
| + |
| + // Called when the output format has changed or the output format |
| + // becomes available at beginning of the stream after initial parsing. |
| + virtual void OnOutputFormatChanged(const VideoFormat& format) = 0; |
| + }; |
| + |
| + virtual status_t Initialize(DeviceType device, Client* client); |
|
Pawel Osciak
2016/01/07 09:22:36
= 0 here and in methods below please
Owen Lin
2016/01/12 09:30:23
Done.
|
| + |
| + // Assigns a shared memory to be used for the accelerator at the specified |
| + // port and index. A buffer must be bound before asking the accelerator to |
| + // use it via useBuffer(). |
| + virtual status_t BindSharedBuffer(PortType port, |
|
Pawel Osciak
2016/01/07 09:22:36
BindSharedMemory
Owen Lin
2016/01/12 09:30:23
Done.
|
| + uint32_t index, |
| + int ashmem_fd, |
|
Pawel Osciak
2016/01/07 09:22:36
Could we use base::SharedMemoryHandle here?
Owen Lin
2016/01/12 09:30:23
No, it's a common interface used on both Android a
|
| + size_t offset, |
| + size_t length); |
| + |
| + // Assigns a graphic buffer to be used for the accelerator at the specified |
| + // port and index. A buffer must be bound before asking the accelerator to |
| + // use it via useBuffer(). |
| + virtual status_t BindGraphicBuffer(PortType port, |
|
Pawel Osciak
2016/01/07 09:22:36
BindDmabuf
Owen Lin
2016/01/12 09:30:23
Done.
|
| + uint32_t index, |
| + int dmabuf_fd); |
| + |
| + // Passes a buffer to the accelerator. For input buffer, the accelerator |
| + // will process it. For output buffer, the accelerator will output content |
| + // to it. |
| + virtual void UseBuffer(PortType port, |
| + uint32_t index, |
| + const BufferMetadata& metadata) = 0; |
| + |
| + // Sets the number of requested buffers. The accelerator may change the |
| + // count due to hardware limitation. The caller is responsible to check |
| + // the returned value to see if it is acceptable. |
| + virtual status_t SetBufferCount(PortType port, size_t* count) = 0; |
| + |
| + // Resets the accelerator. After this function, all buffers won't be |
| + // accessed by the accelerator and there won't be more callbacks. |
|
Pawel Osciak
2016/01/07 09:22:36
Does this mean we require the VDA to return all bu
Owen Lin
2016/01/12 09:30:23
I have modified the code in ArcCodec to allow VDA
|
| + virtual void Reset() = 0; |
| + |
| + // Sets the buffer format of the given port. |
| + virtual status_t SetBufferFormat(PortType port, const BufferFormat& format); |
|
Pawel Osciak
2016/01/07 09:22:36
Sorry, I think I'm forgetting why we needed this c
Owen Lin
2016/01/12 09:30:23
For output, we only use it to set the MemoryType.
|
| + |
| + virtual ~ArcVideoAccelerator(); |
| + |
| + private: |
| + // DISALLOW_EVIL_CONSTRUCTORS(ArcVideoAccelerator); |
|
Pawel Osciak
2016/01/07 09:22:36
I think we should remove this?
Owen Lin
2016/01/12 09:30:23
Done.
|
| +}; |
| + |
| +} // namespace arc |
| +} // namespace content |
| + |
| +#endif // CONTENT_COMMON_GPU_MEDIA_ARC_ARC_VIDEO_ACCELERATOR_H_ |