OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_GPU_V4L2_JPEG_DECODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_GPU_V4L2_JPEG_DECODE_ACCELERATOR_H_ |
6 #define MEDIA_GPU_V4L2_JPEG_DECODE_ACCELERATOR_H_ | 6 #define MEDIA_GPU_V4L2_JPEG_DECODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | 35 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
36 ~V4L2JpegDecodeAccelerator() override; | 36 ~V4L2JpegDecodeAccelerator() override; |
37 | 37 |
38 // JpegDecodeAccelerator implementation. | 38 // JpegDecodeAccelerator implementation. |
39 bool Initialize(Client* client) override; | 39 bool Initialize(Client* client) override; |
40 void Decode(const BitstreamBuffer& bitstream_buffer, | 40 void Decode(const BitstreamBuffer& bitstream_buffer, |
41 const scoped_refptr<VideoFrame>& video_frame) override; | 41 const scoped_refptr<VideoFrame>& video_frame) override; |
42 bool IsSupported() override; | 42 bool IsSupported() override; |
43 | 43 |
44 private: | 44 private: |
45 // Input pixel format is alwasy V4L2_PIX_FMT_JPEG. | |
46 static const uint32_t kInputPlanes = 1; | |
47 // Ouput buffer has three physical planes. | |
wuchengli
2016/12/16 03:15:15
I found the number of planes can be 1 V4L2_PIX_FMT
| |
48 static const uint32_t kOutputPlanes = 3; | |
49 | |
45 // Record for input/output buffers. | 50 // Record for input/output buffers. |
46 struct BufferRecord { | 51 struct BufferRecord { |
47 BufferRecord(); | 52 BufferRecord(); |
48 ~BufferRecord(); | 53 ~BufferRecord(); |
49 void* address; // mmap() address. | 54 void* address[kOutputPlanes]; // mmap() address. |
50 size_t length; // mmap() length. | 55 size_t length[kOutputPlanes]; // mmap() length. |
56 size_t num_planes; // Number of mapped planes. | |
wuchengli
2016/12/16 03:15:15
s/planes/physical planes/. So it's clear this is n
| |
51 | 57 |
52 // Set true during QBUF and DQBUF. |address| will be accessed by hardware. | 58 // Set true during QBUF and DQBUF. |address| will be accessed by hardware. |
53 bool at_device; | 59 bool at_device; |
54 }; | 60 }; |
55 | 61 |
56 // Job record. Jobs are processed in a FIFO order. This is separate from | 62 // Job record. Jobs are processed in a FIFO order. This is separate from |
57 // BufferRecord of input, because a BufferRecord of input may be returned | 63 // BufferRecord of input, because a BufferRecord of input may be returned |
58 // before we dequeue the corresponding output buffer. It can't always be | 64 // before we dequeue the corresponding output buffer. It can't always be |
59 // associated with a BufferRecord of output immediately either, because at | 65 // associated with a BufferRecord of output immediately either, because at |
60 // the time of submission we may not have one available (and don't need one | 66 // the time of submission we may not have one available (and don't need one |
(...skipping 14 matching lines...) Expand all Loading... | |
75 void EnqueueInput(); | 81 void EnqueueInput(); |
76 void EnqueueOutput(); | 82 void EnqueueOutput(); |
77 void Dequeue(); | 83 void Dequeue(); |
78 bool EnqueueInputRecord(); | 84 bool EnqueueInputRecord(); |
79 bool EnqueueOutputRecord(); | 85 bool EnqueueOutputRecord(); |
80 bool CreateInputBuffers(); | 86 bool CreateInputBuffers(); |
81 bool CreateOutputBuffers(); | 87 bool CreateOutputBuffers(); |
82 void DestroyInputBuffers(); | 88 void DestroyInputBuffers(); |
83 void DestroyOutputBuffers(); | 89 void DestroyOutputBuffers(); |
84 | 90 |
91 // Convert |src_buffer| to I420 and copy the result to |dst_frame|. | |
92 // The function currently accepts the following format as |src_pixelformat|: | |
93 // - All splane formats that libyuv::ConvertToI420 can handle. | |
94 // - V4L2_YUV_420M | |
95 // - V4L2_YUV_422MV | |
96 bool ConvertOutputImage(const uint32_t src_pixelformat, | |
97 const BufferRecord& src_buffer, | |
98 const gfx::Size& src_coded_size, | |
99 const scoped_refptr<VideoFrame>& dst_frame); | |
100 | |
85 // Return the number of input/output buffers enqueued to the device. | 101 // Return the number of input/output buffers enqueued to the device. |
86 size_t InputBufferQueuedCount(); | 102 size_t InputBufferQueuedCount(); |
87 size_t OutputBufferQueuedCount(); | 103 size_t OutputBufferQueuedCount(); |
88 | 104 |
89 // Return true if input buffer size is not enough. | 105 // Return true if input buffer size is not enough. |
90 bool ShouldRecreateInputBuffers(); | 106 bool ShouldRecreateInputBuffers(); |
91 // Destroy and create input buffers. Return false on error. | 107 // Destroy and create input buffers. Return false on error. |
92 bool RecreateInputBuffers(); | 108 bool RecreateInputBuffers(); |
93 // Destroy and create output buffers. Return false on error. | 109 // Destroy and create output buffers. Return false on error. |
94 bool RecreateOutputBuffers(); | 110 bool RecreateOutputBuffers(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 // Thread used to poll the V4L2 for events only. | 162 // Thread used to poll the V4L2 for events only. |
147 base::Thread device_poll_thread_; | 163 base::Thread device_poll_thread_; |
148 // Device poll task runner. | 164 // Device poll task runner. |
149 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_; | 165 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_; |
150 | 166 |
151 // All the below members except |weak_factory_| are accessed from | 167 // All the below members except |weak_factory_| are accessed from |
152 // |decoder_thread_| only (if it's running). | 168 // |decoder_thread_| only (if it's running). |
153 std::queue<linked_ptr<JobRecord>> input_jobs_; | 169 std::queue<linked_ptr<JobRecord>> input_jobs_; |
154 std::queue<linked_ptr<JobRecord>> running_jobs_; | 170 std::queue<linked_ptr<JobRecord>> running_jobs_; |
155 | 171 |
172 // V4L2 buffer type of the input buffer. | |
173 v4l2_buf_type input_buf_type_; | |
156 // Input queue state. | 174 // Input queue state. |
157 bool input_streamon_; | 175 bool input_streamon_; |
158 // Mapping of int index to an input buffer record. | 176 // Mapping of int index to an input buffer record. |
159 std::vector<BufferRecord> input_buffer_map_; | 177 std::vector<BufferRecord> input_buffer_map_; |
160 // Indices of input buffers ready to use; LIFO since we don't care about | 178 // Indices of input buffers ready to use; LIFO since we don't care about |
161 // ordering. | 179 // ordering. |
162 std::vector<int> free_input_buffers_; | 180 std::vector<int> free_input_buffers_; |
163 | 181 |
182 // V4L2 buffer type of the output buffer. | |
183 v4l2_buf_type output_buf_type_; | |
164 // Output queue state. | 184 // Output queue state. |
165 bool output_streamon_; | 185 bool output_streamon_; |
166 // Mapping of int index to an output buffer record. | 186 // Mapping of int index to an output buffer record. |
167 std::vector<BufferRecord> output_buffer_map_; | 187 std::vector<BufferRecord> output_buffer_map_; |
168 // Indices of output buffers ready to use; LIFO since we don't care about | 188 // Indices of output buffers ready to use; LIFO since we don't care about |
169 // ordering. | 189 // ordering. |
170 std::vector<int> free_output_buffers_; | 190 std::vector<int> free_output_buffers_; |
171 | 191 |
172 // Weak factory for producing weak pointers on the child thread. | 192 // Weak factory for producing weak pointers on the child thread. |
173 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> weak_factory_; | 193 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> weak_factory_; |
174 // Point to |this| for use in posting tasks from the decoder thread back to | 194 // Point to |this| for use in posting tasks from the decoder thread back to |
175 // the ChildThread. | 195 // the ChildThread. |
176 base::WeakPtr<V4L2JpegDecodeAccelerator> weak_ptr_; | 196 base::WeakPtr<V4L2JpegDecodeAccelerator> weak_ptr_; |
177 | 197 |
178 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator); | 198 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator); |
179 }; | 199 }; |
180 | 200 |
181 } // namespace media | 201 } // namespace media |
182 | 202 |
183 #endif // MEDIA_GPU_V4L2_JPEG_DECODE_ACCELERATOR_H_ | 203 #endif // MEDIA_GPU_V4L2_JPEG_DECODE_ACCELERATOR_H_ |
OLD | NEW |