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