Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_IMAGE_PROCESSOR_H_ | 5 #ifndef MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ |
| 6 #define MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ | 6 #define MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 // Initializes the processor to convert from |input_format| to |output_format| | 34 // Initializes the processor to convert from |input_format| to |output_format| |
| 35 // and/or scale from |input_visible_size| to |output_visible_size|. | 35 // and/or scale from |input_visible_size| to |output_visible_size|. |
| 36 // Request the input buffers to be of at least |input_allocated_size| and the | 36 // Request the input buffers to be of at least |input_allocated_size| and the |
| 37 // output buffers to be of at least |output_allocated_size|. The number of | 37 // output buffers to be of at least |output_allocated_size|. The number of |
| 38 // input buffers and output buffers will be |num_buffers|. Provided |error_cb| | 38 // input buffers and output buffers will be |num_buffers|. Provided |error_cb| |
| 39 // will be called if an error occurs. Return true if the requested | 39 // will be called if an error occurs. Return true if the requested |
| 40 // configuration is supported. | 40 // configuration is supported. |
| 41 bool Initialize(VideoPixelFormat input_format, | 41 bool Initialize(VideoPixelFormat input_format, |
| 42 VideoPixelFormat output_format, | 42 VideoPixelFormat output_format, |
| 43 v4l2_memory input_memory_type, | 43 v4l2_memory input_memory_type, |
| 44 v4l2_memory output_memory_type, | |
| 44 gfx::Size input_visible_size, | 45 gfx::Size input_visible_size, |
| 45 gfx::Size input_allocated_size, | 46 gfx::Size input_allocated_size, |
| 46 gfx::Size output_visible_size, | 47 gfx::Size output_visible_size, |
| 47 gfx::Size output_allocated_size, | 48 gfx::Size output_allocated_size, |
| 48 int num_buffers, | 49 int num_buffers, |
| 49 const base::Closure& error_cb); | 50 const base::Closure& error_cb); |
| 50 | 51 |
| 51 // Returns a vector of dmabuf file descriptors, exported for V4L2 output | 52 // Returns a vector of dmabuf file descriptors, exported for V4L2 output |
| 52 // buffer with |index|. The size of vector will be the number of planes of the | 53 // buffer with |index|. The size of vector will be the number of planes of the |
| 53 // buffer. Return an empty vector on failure. | 54 // buffer. Return an empty vector on failure. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 80 // client. After the client is done with the frame, call Process with the | 81 // client. After the client is done with the frame, call Process with the |
| 81 // index to return the output buffer to the image processor. | 82 // index to return the output buffer to the image processor. |
| 82 typedef base::Callback<void(int output_buffer_index)> FrameReadyCB; | 83 typedef base::Callback<void(int output_buffer_index)> FrameReadyCB; |
| 83 | 84 |
| 84 // Called by client to process |frame|. The resulting processed frame will be | 85 // Called by client to process |frame|. The resulting processed frame will be |
| 85 // stored in |output_buffer_index| output buffer and notified via |cb|. The | 86 // stored in |output_buffer_index| output buffer and notified via |cb|. The |
| 86 // processor will drop all its references to |frame| after it finishes | 87 // processor will drop all its references to |frame| after it finishes |
| 87 // accessing it. | 88 // accessing it. |
| 88 void Process(const scoped_refptr<VideoFrame>& frame, | 89 void Process(const scoped_refptr<VideoFrame>& frame, |
| 89 int output_buffer_index, | 90 int output_buffer_index, |
| 91 std::vector<base::ScopedFD> output_dmabuf_fds, | |
|
Pawel Osciak
2016/09/12 08:54:26
Please document.
wuchengli
2016/09/12 11:56:51
Done.
| |
| 90 const FrameReadyCB& cb); | 92 const FrameReadyCB& cb); |
| 91 | 93 |
| 92 // Stop all processing and clean up. After this method returns no more | 94 // Stop all processing and clean up. After this method returns no more |
| 93 // callbacks will be invoked. Deletes |this| unconditionally, so make sure | 95 // callbacks will be invoked. Deletes |this| unconditionally, so make sure |
| 94 // to drop all pointers to it! | 96 // to drop all pointers to it! |
| 95 void Destroy(); | 97 void Destroy(); |
| 96 | 98 |
| 97 private: | 99 private: |
| 98 // Record for input buffers. | 100 // Record for input buffers. |
| 99 struct InputRecord { | 101 struct InputRecord { |
| 100 InputRecord(); | 102 InputRecord(); |
| 101 ~InputRecord(); | 103 ~InputRecord(); |
| 102 scoped_refptr<VideoFrame> frame; | 104 scoped_refptr<VideoFrame> frame; |
| 103 bool at_device; | 105 bool at_device; |
| 104 }; | 106 }; |
| 105 | 107 |
| 106 // Record for output buffers. | 108 // Record for output buffers. |
| 107 struct OutputRecord { | 109 struct OutputRecord { |
| 108 OutputRecord(); | 110 OutputRecord(); |
| 111 OutputRecord(OutputRecord&&) = default; | |
| 109 ~OutputRecord(); | 112 ~OutputRecord(); |
| 110 bool at_device; | 113 bool at_device; |
| 114 std::vector<base::ScopedFD> dmabuf_fds; | |
| 111 }; | 115 }; |
| 112 | 116 |
| 113 // Job record. Jobs are processed in a FIFO order. This is separate from | 117 // Job record. Jobs are processed in a FIFO order. This is separate from |
| 114 // InputRecord, because an InputRecord may be returned before we dequeue | 118 // InputRecord, because an InputRecord may be returned before we dequeue |
| 115 // the corresponding output buffer. The processed frame will be stored in | 119 // the corresponding output buffer. The processed frame will be stored in |
| 116 // |output_buffer_index| output buffer. | 120 // |output_buffer_index| output buffer. |
| 117 struct JobRecord { | 121 struct JobRecord { |
| 118 JobRecord(); | 122 JobRecord(); |
| 119 ~JobRecord(); | 123 ~JobRecord(); |
| 120 scoped_refptr<VideoFrame> frame; | 124 scoped_refptr<VideoFrame> frame; |
| 121 int output_buffer_index; | 125 int output_buffer_index; |
| 126 std::vector<base::ScopedFD> output_dmabuf_fds; | |
| 122 FrameReadyCB ready_cb; | 127 FrameReadyCB ready_cb; |
| 123 }; | 128 }; |
| 124 | 129 |
| 125 void EnqueueInput(); | 130 void EnqueueInput(); |
| 126 void EnqueueOutput(int index); | 131 void EnqueueOutput(int index); |
| 127 void Dequeue(); | 132 void Dequeue(); |
| 128 bool EnqueueInputRecord(); | 133 bool EnqueueInputRecord(); |
| 129 bool EnqueueOutputRecord(int index); | 134 bool EnqueueOutputRecord(int index); |
| 130 bool CreateInputBuffers(); | 135 bool CreateInputBuffers(); |
| 131 bool CreateOutputBuffers(); | 136 bool CreateOutputBuffers(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 154 gfx::Size input_visible_size_; | 159 gfx::Size input_visible_size_; |
| 155 gfx::Size input_allocated_size_; | 160 gfx::Size input_allocated_size_; |
| 156 | 161 |
| 157 // The visible/allocated sizes of the destination frame. | 162 // The visible/allocated sizes of the destination frame. |
| 158 gfx::Size output_visible_size_; | 163 gfx::Size output_visible_size_; |
| 159 gfx::Size output_allocated_size_; | 164 gfx::Size output_allocated_size_; |
| 160 | 165 |
| 161 VideoPixelFormat input_format_; | 166 VideoPixelFormat input_format_; |
| 162 VideoPixelFormat output_format_; | 167 VideoPixelFormat output_format_; |
| 163 v4l2_memory input_memory_type_; | 168 v4l2_memory input_memory_type_; |
| 169 v4l2_memory output_memory_type_; | |
| 164 uint32_t input_format_fourcc_; | 170 uint32_t input_format_fourcc_; |
| 165 uint32_t output_format_fourcc_; | 171 uint32_t output_format_fourcc_; |
| 166 | 172 |
| 167 size_t input_planes_count_; | 173 size_t input_planes_count_; |
| 168 size_t output_planes_count_; | 174 size_t output_planes_count_; |
| 169 | 175 |
| 170 // Our original calling task runner for the child thread. | 176 // Our original calling task runner for the child thread. |
| 171 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | 177 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
| 172 | 178 |
| 173 // V4L2 device in use. | 179 // V4L2 device in use. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 220 |
| 215 // Weak factory for producing weak pointers on the child thread. | 221 // Weak factory for producing weak pointers on the child thread. |
| 216 base::WeakPtrFactory<V4L2ImageProcessor> weak_this_factory_; | 222 base::WeakPtrFactory<V4L2ImageProcessor> weak_this_factory_; |
| 217 | 223 |
| 218 DISALLOW_COPY_AND_ASSIGN(V4L2ImageProcessor); | 224 DISALLOW_COPY_AND_ASSIGN(V4L2ImageProcessor); |
| 219 }; | 225 }; |
| 220 | 226 |
| 221 } // namespace media | 227 } // namespace media |
| 222 | 228 |
| 223 #endif // MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ | 229 #endif // MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ |
| OLD | NEW |