OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_GPU_ARC_VIDEO_ACCELERATOR_H_ |
| 6 #define CHROME_GPU_ARC_VIDEO_ACCELERATOR_H_ |
| 7 |
| 8 namespace chromeos { |
| 9 namespace arc { |
| 10 |
| 11 // The pixel formats defined in Android but are used here. They are defined in |
| 12 // "system/core/include/system/graphics.h" |
| 13 enum { |
| 14 HAL_PIXEL_FORMAT_YCbCr_420_888 = 0x23, |
| 15 }; |
| 16 |
| 17 // The extension to the Android HAL_PIXEL_FORMAT for input pixel formats. |
| 18 enum HalPixelFormatExtension { |
| 19 HAL_PIXEL_FORMAT_H264 = 0x34363248, |
| 20 HAL_PIXEL_FORMAT_VP8 = 0x00385056, |
| 21 }; |
| 22 |
| 23 enum PortType { |
| 24 PORT_INPUT = 0, |
| 25 PORT_OUTPUT = 1, |
| 26 PORT_COUNT = 2, |
| 27 }; |
| 28 |
| 29 enum BufferFlag { |
| 30 BUFFER_FLAG_EOS = 1 << 0, |
| 31 }; |
| 32 |
| 33 struct BufferMetadata { |
| 34 int64_t timestamp = 0; // in microseconds |
| 35 uint32_t flags = 0; // Flags defined in BufferFlag. |
| 36 uint32_t bytes_used = 0; |
| 37 }; |
| 38 |
| 39 struct VideoFormat { |
| 40 uint32_t pixel_format = 0; |
| 41 uint32_t buffer_size = 0; |
| 42 |
| 43 // Minimum number of buffers required to decode/encode the stream. |
| 44 uint32_t min_num_buffers = 0; |
| 45 uint32_t coded_width = 0; |
| 46 uint32_t coded_height = 0; |
| 47 uint32_t crop_left = 0; |
| 48 uint32_t crop_width = 0; |
| 49 uint32_t crop_top = 0; |
| 50 uint32_t crop_height = 0; |
| 51 }; |
| 52 |
| 53 // The IPC interface between Android and Chromium for video decoding and |
| 54 // encoding. Input buffers are sent from Android side and get processed in |
| 55 // Chromium and the output buffers are returned back to Android side. |
| 56 class ArcVideoAccelerator { |
| 57 public: |
| 58 enum Error { |
| 59 ILLEGAL_STATE = 1, |
| 60 INVALID_ARGUMENT = 2, |
| 61 UNREADABLE_INPUT = 3, |
| 62 PLATFORM_FAILURE = 4, |
| 63 }; |
| 64 |
| 65 struct Config { |
| 66 enum DeviceType { |
| 67 DEVICE_ENCODER = 0, |
| 68 DEVICE_DECODER = 1, |
| 69 }; |
| 70 |
| 71 DeviceType device_type = DEVICE_DECODER; |
| 72 size_t num_input_buffers = 0; |
| 73 uint32_t input_pixel_format = 0; |
| 74 // TODO(owenlin): Add output_pixel_format. For now only the native pixel |
| 75 // format of each VDA on Chromium is supported. |
| 76 }; |
| 77 |
| 78 // The callbacks of the ArcVideoAccelerator. The user of this class should |
| 79 // implement this interface. |
| 80 class Client { |
| 81 public: |
| 82 virtual ~Client() {} |
| 83 |
| 84 // Called when an asynchronous error happens. The errors in Initialize() |
| 85 // will not be reported here, but will be indicated by a false return value |
| 86 // there. |
| 87 virtual void OnError(Error error) = 0; |
| 88 |
| 89 // Called when a buffer with the specified |index| and |port| has been |
| 90 // processed and is no longer used in the accelerator. For input buffers, |
| 91 // the Client may fill them with new content. For output buffers, indicates |
| 92 // they are ready to be consumed by the client. |
| 93 virtual void OnBufferDone(PortType port, |
| 94 uint32_t index, |
| 95 const BufferMetadata& metadata) = 0; |
| 96 |
| 97 // Called when the output format has changed or the output format |
| 98 // becomes available at beginning of the stream after initial parsing. |
| 99 virtual void OnOutputFormatChanged(const VideoFormat& format) = 0; |
| 100 |
| 101 // Called as a completion notification for Reset(). |
| 102 virtual void OnResetDone() = 0; |
| 103 }; |
| 104 |
| 105 // Initializes the ArcVideoAccelerator with specific configuration. This |
| 106 // must be called before any other methods. This call is synchronous and |
| 107 // returns true iff initialization is successful. |
| 108 virtual bool Initialize(const Config& config, Client* client) = 0; |
| 109 |
| 110 // Assigns a shared memory to be used for the accelerator at the specified |
| 111 // port and index. A buffer must be successfully bound before it can be passed |
| 112 // to the accelerator via UseBuffer(). Already bound buffers may be reused |
| 113 // multiple times without additional bindings. |
| 114 virtual void BindSharedMemory(PortType port, |
| 115 uint32_t index, |
| 116 int ashmem_fd, |
| 117 off_t offset, |
| 118 size_t length) = 0; |
| 119 |
| 120 // Assigns a buffer to be used for the accelerator at the specified |
| 121 // port and index. A buffer must be successfully bound before it can be |
| 122 // passed to the accelerator via UseBuffer(). Already bound buffers may be |
| 123 // reused multiple times without additional bindings. |
| 124 virtual void BindDmabuf(PortType port, uint32_t index, int dmabuf_fd) = 0; |
| 125 |
| 126 // Passes a buffer to the accelerator. For input buffer, the accelerator |
| 127 // will process it. For output buffer, the accelerator will output content |
| 128 // to it. |
| 129 virtual void UseBuffer(PortType port, |
| 130 uint32_t index, |
| 131 const BufferMetadata& metadata) = 0; |
| 132 |
| 133 // Sets the number of output buffers. When it fails, Client::OnError() will |
| 134 // be called. |
| 135 virtual void SetNumberOfOutputBuffers(size_t number) = 0; |
| 136 |
| 137 // Resets the accelerator. When it is done, Client::OnResetDone() will |
| 138 // be called. Afterwards, all buffers won't be accessed by the accelerator |
| 139 // and there won't be more callbacks. |
| 140 virtual void Reset() = 0; |
| 141 |
| 142 virtual ~ArcVideoAccelerator() {} |
| 143 }; |
| 144 |
| 145 } // namespace arc |
| 146 } // namespace chromeos |
| 147 |
| 148 #endif // CHROME_GPU_ARC_VIDEO_ACCELERATOR_H_ |
OLD | NEW |