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 enum HalPixelFormatExtension { | |
12 HAL_PIXEL_FORMAT_H264 = 0x34363248, | |
13 HAL_PIXEL_FORMAT_VP8 = 0x00385056, | |
14 }; | |
15 | |
16 enum PortType { | |
17 PORT_INPUT = 0, | |
18 PORT_OUTPUT = 1, | |
19 PORT_COUNT = 2, | |
20 }; | |
21 | |
22 enum DeviceType { | |
23 DEVICE_ENCODER = 0, | |
24 DEVICE_DECODER = 1, | |
25 }; | |
26 | |
27 enum MemoryType { | |
28 MEMORY_SHARED_MEMORY = 0, | |
29 MEMORY_DMABUF = 1, | |
30 }; | |
31 | |
32 enum BufferFlag { | |
33 BUFFER_FLAG_EOS = 1, | |
34 }; | |
35 | |
36 struct BufferMetadata { | |
kcwu
2016/03/10 07:27:26
How about to use "Non-Static Class Member Initiali
Owen Lin
2016/03/14 08:46:59
Nice.
| |
37 int64_t timestamp; // in microseconds | |
38 uint32_t flags; | |
39 uint32_t bytes_used; | |
40 | |
41 BufferMetadata() : timestamp(0), flags(0), bytes_used(0) {} | |
42 }; | |
43 | |
44 struct VideoFormat { | |
45 uint32_t pixel_format; | |
46 uint32_t image_size; | |
kcwu
2016/03/04 13:32:59
buffer_size ?
Owen Lin
2016/03/14 08:46:59
Done.
| |
47 | |
48 // minimal number of buffers required to process the video. | |
49 uint32_t min_num_buffers; | |
50 uint32_t coded_width; | |
51 uint32_t coded_height; | |
52 uint32_t crop_left; | |
53 uint32_t crop_width; | |
54 uint32_t crop_top; | |
55 uint32_t crop_height; | |
56 | |
57 VideoFormat() | |
58 : pixel_format(0), | |
59 image_size(0), | |
60 min_num_buffers(0), | |
61 coded_width(0), | |
62 coded_height(0), | |
63 crop_left(0), | |
64 crop_width(0), | |
65 crop_top(0), | |
66 crop_height(0) {} | |
67 }; | |
68 | |
69 // ArcVideoAccelerator is a component of ArcCodec to deal with video | |
70 // buffers. It is also an IPC interface between Android and Chromium. | |
71 // So that the video buffers are sent to Chromium side and decoded. | |
72 // ArcCodec implements ArcVideoAccelerator::Client and is responsible for | |
73 // rendering and interacting with the Android media framework. | |
74 class ArcVideoAccelerator { | |
75 public: | |
76 enum Error { | |
77 ILLEGAL_STATE = 1, | |
78 INVALID_ARGUMENT = 2, | |
79 UNREADABLE_INPUT = 3, | |
80 PLATFORM_FAILURE = 4, | |
81 }; | |
82 | |
83 struct Config { | |
84 DeviceType device_type; | |
85 size_t num_input_buffers; | |
86 uint32_t input_pixel_format; | |
87 | |
88 Config() | |
89 : device_type(DEVICE_DECODER), | |
90 num_input_buffers(0), | |
91 input_pixel_format(0) {} | |
92 }; | |
93 | |
94 // The callbacks of the ArcVideoAccelerator. ArcCodec implmenets this | |
95 // interface. | |
96 class Client { | |
97 public: | |
98 virtual ~Client() {} | |
99 | |
100 // Called when an asynchronous error happens. Asynchronous errors happen | |
101 // only when the accelerator processes the input buffer and tried to | |
102 // generate the output to the output buffer. | |
103 virtual void OnError(Error error) = 0; | |
104 | |
105 // Called when a buffer with the specified |index| and |port| has been | |
106 // processed and is no longer used in the accelerator. For input buffer, | |
107 // it can be filled with new content. For output buffer, it is ready to | |
108 // be consumed by the client. | |
109 virtual void OnBufferDone(PortType port, | |
110 uint32_t index, | |
111 const BufferMetadata& metadata) = 0; | |
112 | |
113 // Called when the output format has changed or the output format | |
114 // becomes available at beginning of the stream after initial parsing. | |
115 virtual void OnOutputFormatChanged(const VideoFormat& format) = 0; | |
116 }; | |
117 | |
118 virtual bool Initialize(const Config& device, Client* client) = 0; | |
119 | |
120 // Assigns a shared memory to be used for the accelerator at the specified | |
121 // port and index. A buffer must be bound before asking the accelerator to | |
122 // use it via useBuffer(). | |
123 virtual void BindSharedMemory(PortType port, | |
124 uint32_t index, | |
125 int ashmem_fd, | |
126 off_t offset, | |
127 size_t length) = 0; | |
128 | |
129 // Assigns a graphic buffer to be used for the accelerator at the specified | |
130 // port and index. A buffer must be bound before asking the accelerator to | |
131 // use it via useBuffer(). | |
132 virtual void BindDmabuf(PortType port, uint32_t index, int dmabuf_fd) = 0; | |
133 | |
134 // Passes a buffer to the accelerator. For input buffer, the accelerator | |
135 // will process it. For output buffer, the accelerator will output content | |
136 // to it. | |
137 virtual void UseBuffer(PortType port, | |
138 uint32_t index, | |
139 const BufferMetadata& metadata) = 0; | |
140 | |
141 // Sets the number of output buffers. The accelerator may change the | |
142 // count due to hardware limitation. The caller is responsible to check | |
143 // the returned value to see if it is acceptable. | |
144 virtual void SetNumberOfOutputBuffers(size_t number) = 0; | |
145 | |
146 // Resets the accelerator. After this function, all buffers won't be | |
147 // accessed by the accelerator and there won't be more callbacks. | |
148 virtual void Reset() = 0; | |
149 | |
150 virtual ~ArcVideoAccelerator() {} | |
151 }; | |
152 | |
153 } // namespace arc | |
154 } // namespace chromeos | |
155 | |
156 #endif // CHROME_GPU_ARC_VIDEO_ACCELERATOR_H_ | |
OLD | NEW |