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