| 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 23 matching lines...) Expand all Loading... |
| 77 gfx::Size output_allocated_size() const { return output_allocated_size_; } | 78 gfx::Size output_allocated_size() const { return output_allocated_size_; } |
| 78 | 79 |
| 79 // Callback to be used to return the index of a processed image to the | 80 // Callback to be used to return the index of a processed image to the |
| 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. If |output_memory_type_| is V4L2_MEMORY_DMABUF, the caller |
| 88 void Process(const scoped_refptr<VideoFrame>& frame, | 89 // should pass non-empty |output_dmabuf_fds| and the processed frame will be |
| 90 // stored in those buffers. If the number of |output_dmabuf_fds| is not |
| 91 // expected, this function will return false. |
| 92 bool Process(const scoped_refptr<VideoFrame>& frame, |
| 89 int output_buffer_index, | 93 int output_buffer_index, |
| 94 std::vector<base::ScopedFD> output_dmabuf_fds, |
| 90 const FrameReadyCB& cb); | 95 const FrameReadyCB& cb); |
| 91 | 96 |
| 92 // Reset all processing frames. After this method returns, no more callbacks | 97 // Reset all processing frames. After this method returns, no more callbacks |
| 93 // will be invoked. V4L2ImageProcessor is ready to process more frames. | 98 // will be invoked. V4L2ImageProcessor is ready to process more frames. |
| 94 bool Reset(); | 99 bool Reset(); |
| 95 | 100 |
| 96 // Stop all processing and clean up. After this method returns no more | 101 // Stop all processing and clean up. After this method returns no more |
| 97 // callbacks will be invoked. Deletes |this| unconditionally, so make sure | 102 // callbacks will be invoked. Deletes |this| unconditionally, so make sure |
| 98 // to drop all pointers to it! | 103 // to drop all pointers to it! |
| 99 void Destroy(); | 104 void Destroy(); |
| 100 | 105 |
| 101 private: | 106 private: |
| 102 // Record for input buffers. | 107 // Record for input buffers. |
| 103 struct InputRecord { | 108 struct InputRecord { |
| 104 InputRecord(); | 109 InputRecord(); |
| 105 ~InputRecord(); | 110 ~InputRecord(); |
| 106 scoped_refptr<VideoFrame> frame; | 111 scoped_refptr<VideoFrame> frame; |
| 107 bool at_device; | 112 bool at_device; |
| 108 }; | 113 }; |
| 109 | 114 |
| 110 // Record for output buffers. | 115 // Record for output buffers. |
| 111 struct OutputRecord { | 116 struct OutputRecord { |
| 112 OutputRecord(); | 117 OutputRecord(); |
| 118 OutputRecord(OutputRecord&&) = default; |
| 113 ~OutputRecord(); | 119 ~OutputRecord(); |
| 114 bool at_device; | 120 bool at_device; |
| 121 // The processed frame will be stored in these buffers if |
| 122 // |output_memory_type_| is V4L2_MEMORY_DMABUF |
| 123 std::vector<base::ScopedFD> dmabuf_fds; |
| 115 }; | 124 }; |
| 116 | 125 |
| 117 // Job record. Jobs are processed in a FIFO order. This is separate from | 126 // Job record. Jobs are processed in a FIFO order. This is separate from |
| 118 // InputRecord, because an InputRecord may be returned before we dequeue | 127 // InputRecord, because an InputRecord may be returned before we dequeue |
| 119 // the corresponding output buffer. The processed frame will be stored in | 128 // the corresponding output buffer. The processed frame will be stored in |
| 120 // |output_buffer_index| output buffer. | 129 // |output_buffer_index| output buffer. If |output_memory_type_| is |
| 130 // V4L2_MEMORY_DMABUF, the processed frame will be stored in |
| 131 // |output_dmabuf_fds|. |
| 121 struct JobRecord { | 132 struct JobRecord { |
| 122 JobRecord(); | 133 JobRecord(); |
| 123 ~JobRecord(); | 134 ~JobRecord(); |
| 124 scoped_refptr<VideoFrame> frame; | 135 scoped_refptr<VideoFrame> frame; |
| 125 int output_buffer_index; | 136 int output_buffer_index; |
| 137 std::vector<base::ScopedFD> output_dmabuf_fds; |
| 126 FrameReadyCB ready_cb; | 138 FrameReadyCB ready_cb; |
| 127 }; | 139 }; |
| 128 | 140 |
| 129 void EnqueueInput(); | 141 void EnqueueInput(); |
| 130 void EnqueueOutput(int index); | 142 void EnqueueOutput(int index); |
| 131 void Dequeue(); | 143 void Dequeue(); |
| 132 bool EnqueueInputRecord(); | 144 bool EnqueueInputRecord(); |
| 133 bool EnqueueOutputRecord(int index); | 145 bool EnqueueOutputRecord(int index); |
| 134 bool CreateInputBuffers(); | 146 bool CreateInputBuffers(); |
| 135 bool CreateOutputBuffers(); | 147 bool CreateOutputBuffers(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 157 gfx::Size input_visible_size_; | 169 gfx::Size input_visible_size_; |
| 158 gfx::Size input_allocated_size_; | 170 gfx::Size input_allocated_size_; |
| 159 | 171 |
| 160 // The visible/allocated sizes of the destination frame. | 172 // The visible/allocated sizes of the destination frame. |
| 161 gfx::Size output_visible_size_; | 173 gfx::Size output_visible_size_; |
| 162 gfx::Size output_allocated_size_; | 174 gfx::Size output_allocated_size_; |
| 163 | 175 |
| 164 VideoPixelFormat input_format_; | 176 VideoPixelFormat input_format_; |
| 165 VideoPixelFormat output_format_; | 177 VideoPixelFormat output_format_; |
| 166 v4l2_memory input_memory_type_; | 178 v4l2_memory input_memory_type_; |
| 179 v4l2_memory output_memory_type_; |
| 167 uint32_t input_format_fourcc_; | 180 uint32_t input_format_fourcc_; |
| 168 uint32_t output_format_fourcc_; | 181 uint32_t output_format_fourcc_; |
| 169 | 182 |
| 170 size_t input_planes_count_; | 183 size_t input_planes_count_; |
| 171 size_t output_planes_count_; | 184 size_t output_planes_count_; |
| 172 | 185 |
| 173 // Our original calling task runner for the child thread. | 186 // Our original calling task runner for the child thread. |
| 174 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | 187 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
| 175 | 188 |
| 176 // V4L2 device in use. | 189 // V4L2 device in use. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 230 |
| 218 // Weak factory for producing weak pointers on the child thread. | 231 // Weak factory for producing weak pointers on the child thread. |
| 219 base::WeakPtrFactory<V4L2ImageProcessor> weak_this_factory_; | 232 base::WeakPtrFactory<V4L2ImageProcessor> weak_this_factory_; |
| 220 | 233 |
| 221 DISALLOW_COPY_AND_ASSIGN(V4L2ImageProcessor); | 234 DISALLOW_COPY_AND_ASSIGN(V4L2ImageProcessor); |
| 222 }; | 235 }; |
| 223 | 236 |
| 224 } // namespace media | 237 } // namespace media |
| 225 | 238 |
| 226 #endif // MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ | 239 #endif // MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ |
| OLD | NEW |