Chromium Code Reviews| 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 can have as many as three planes. | |
|
wuchengli
2016/12/15 09:18:25
It looks like the output is always three planes, n
jcliang
2016/12/15 14:55:47
Done.
I was thinking there are 2-plane and 4-plan
| |
| 48 static const uint32_t kOutputPlanes = 3; | |
| 49 // Maximum number of buffer planes we are able to handle. | |
| 50 static const uint32_t kMaxBufferPlanes = 3; | |
|
wuchengli
2016/12/15 09:18:25
We are hard-coding the number of planes to be alwa
jcliang
2016/12/15 14:55:47
Done.
| |
| 51 | |
| 45 // Record for input/output buffers. | 52 // Record for input/output buffers. |
| 46 struct BufferRecord { | 53 struct BufferRecord { |
| 47 BufferRecord(); | 54 BufferRecord(); |
| 48 ~BufferRecord(); | 55 ~BufferRecord(); |
| 49 void* address; // mmap() address. | 56 void* address[kMaxBufferPlanes]; // mmap() address. |
| 50 size_t length; // mmap() length. | 57 size_t length[kMaxBufferPlanes]; // mmap() length. |
| 58 size_t num_planes; // Number of mapped planes. | |
| 51 | 59 |
| 52 // Set true during QBUF and DQBUF. |address| will be accessed by hardware. | 60 // Set true during QBUF and DQBUF. |address| will be accessed by hardware. |
| 53 bool at_device; | 61 bool at_device; |
| 54 }; | 62 }; |
| 55 | 63 |
| 56 // Job record. Jobs are processed in a FIFO order. This is separate from | 64 // 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 | 65 // BufferRecord of input, because a BufferRecord of input may be returned |
| 58 // before we dequeue the corresponding output buffer. It can't always be | 66 // before we dequeue the corresponding output buffer. It can't always be |
| 59 // associated with a BufferRecord of output immediately either, because at | 67 // 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 | 68 // the time of submission we may not have one available (and don't need one |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 74 | 82 |
| 75 void EnqueueInput(); | 83 void EnqueueInput(); |
| 76 void EnqueueOutput(); | 84 void EnqueueOutput(); |
| 77 void Dequeue(); | 85 void Dequeue(); |
| 78 bool EnqueueInputRecord(); | 86 bool EnqueueInputRecord(); |
| 79 bool EnqueueOutputRecord(); | 87 bool EnqueueOutputRecord(); |
| 80 bool CreateInputBuffers(); | 88 bool CreateInputBuffers(); |
| 81 bool CreateOutputBuffers(); | 89 bool CreateOutputBuffers(); |
| 82 void DestroyInputBuffers(); | 90 void DestroyInputBuffers(); |
| 83 void DestroyOutputBuffers(); | 91 void DestroyOutputBuffers(); |
| 84 | 92 |
|
wuchengli
2016/12/15 09:18:25
Document this function. What's the output format?
jcliang
2016/12/15 14:55:47
Done.
| |
| 93 bool CopyOutputImage(const uint32_t src_pixelformat, | |
| 94 const BufferRecord& src_output_record, | |
| 95 const gfx::Size& src_coded_size, | |
| 96 const scoped_refptr<VideoFrame>& dst_frame); | |
| 97 | |
| 85 // Return the number of input/output buffers enqueued to the device. | 98 // Return the number of input/output buffers enqueued to the device. |
| 86 size_t InputBufferQueuedCount(); | 99 size_t InputBufferQueuedCount(); |
| 87 size_t OutputBufferQueuedCount(); | 100 size_t OutputBufferQueuedCount(); |
| 88 | 101 |
| 89 // Return true if input buffer size is not enough. | 102 // Return true if input buffer size is not enough. |
| 90 bool ShouldRecreateInputBuffers(); | 103 bool ShouldRecreateInputBuffers(); |
| 91 // Destroy and create input buffers. Return false on error. | 104 // Destroy and create input buffers. Return false on error. |
| 92 bool RecreateInputBuffers(); | 105 bool RecreateInputBuffers(); |
| 93 // Destroy and create output buffers. Return false on error. | 106 // Destroy and create output buffers. Return false on error. |
| 94 bool RecreateOutputBuffers(); | 107 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. | 159 // Thread used to poll the V4L2 for events only. |
| 147 base::Thread device_poll_thread_; | 160 base::Thread device_poll_thread_; |
| 148 // Device poll task runner. | 161 // Device poll task runner. |
| 149 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_; | 162 scoped_refptr<base::SingleThreadTaskRunner> device_poll_task_runner_; |
| 150 | 163 |
| 151 // All the below members except |weak_factory_| are accessed from | 164 // All the below members except |weak_factory_| are accessed from |
| 152 // |decoder_thread_| only (if it's running). | 165 // |decoder_thread_| only (if it's running). |
| 153 std::queue<linked_ptr<JobRecord>> input_jobs_; | 166 std::queue<linked_ptr<JobRecord>> input_jobs_; |
| 154 std::queue<linked_ptr<JobRecord>> running_jobs_; | 167 std::queue<linked_ptr<JobRecord>> running_jobs_; |
| 155 | 168 |
| 169 // V4L2 buffer type of the input buffer. | |
| 170 v4l2_buf_type input_buf_type_; | |
| 156 // Input queue state. | 171 // Input queue state. |
| 157 bool input_streamon_; | 172 bool input_streamon_; |
| 158 // Mapping of int index to an input buffer record. | 173 // Mapping of int index to an input buffer record. |
| 159 std::vector<BufferRecord> input_buffer_map_; | 174 std::vector<BufferRecord> input_buffer_map_; |
| 160 // Indices of input buffers ready to use; LIFO since we don't care about | 175 // Indices of input buffers ready to use; LIFO since we don't care about |
| 161 // ordering. | 176 // ordering. |
| 162 std::vector<int> free_input_buffers_; | 177 std::vector<int> free_input_buffers_; |
| 163 | 178 |
| 179 // V4L2 buffer type of the output buffer. | |
| 180 v4l2_buf_type output_buf_type_; | |
| 164 // Output queue state. | 181 // Output queue state. |
| 165 bool output_streamon_; | 182 bool output_streamon_; |
| 166 // Mapping of int index to an output buffer record. | 183 // Mapping of int index to an output buffer record. |
| 167 std::vector<BufferRecord> output_buffer_map_; | 184 std::vector<BufferRecord> output_buffer_map_; |
| 168 // Indices of output buffers ready to use; LIFO since we don't care about | 185 // Indices of output buffers ready to use; LIFO since we don't care about |
| 169 // ordering. | 186 // ordering. |
| 170 std::vector<int> free_output_buffers_; | 187 std::vector<int> free_output_buffers_; |
| 171 | 188 |
| 172 // Weak factory for producing weak pointers on the child thread. | 189 // Weak factory for producing weak pointers on the child thread. |
| 173 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> weak_factory_; | 190 base::WeakPtrFactory<V4L2JpegDecodeAccelerator> weak_factory_; |
| 174 // Point to |this| for use in posting tasks from the decoder thread back to | 191 // Point to |this| for use in posting tasks from the decoder thread back to |
| 175 // the ChildThread. | 192 // the ChildThread. |
| 176 base::WeakPtr<V4L2JpegDecodeAccelerator> weak_ptr_; | 193 base::WeakPtr<V4L2JpegDecodeAccelerator> weak_ptr_; |
| 177 | 194 |
| 178 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator); | 195 DISALLOW_COPY_AND_ASSIGN(V4L2JpegDecodeAccelerator); |
| 179 }; | 196 }; |
| 180 | 197 |
| 181 } // namespace media | 198 } // namespace media |
| 182 | 199 |
| 183 #endif // MEDIA_GPU_V4L2_JPEG_DECODE_ACCELERATOR_H_ | 200 #endif // MEDIA_GPU_V4L2_JPEG_DECODE_ACCELERATOR_H_ |
| OLD | NEW |