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 20 matching lines...) Expand all Loading... |
31 explicit V4L2ImageProcessor(const scoped_refptr<V4L2Device>& device); | 31 explicit V4L2ImageProcessor(const scoped_refptr<V4L2Device>& device); |
32 virtual ~V4L2ImageProcessor(); | 32 virtual ~V4L2ImageProcessor(); |
33 | 33 |
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(media::VideoPixelFormat input_format, | 41 bool Initialize(VideoPixelFormat input_format, |
42 media::VideoPixelFormat output_format, | 42 VideoPixelFormat output_format, |
43 v4l2_memory input_memory_type, | 43 v4l2_memory input_memory_type, |
44 gfx::Size input_visible_size, | 44 gfx::Size input_visible_size, |
45 gfx::Size input_allocated_size, | 45 gfx::Size input_allocated_size, |
46 gfx::Size output_visible_size, | 46 gfx::Size output_visible_size, |
47 gfx::Size output_allocated_size, | 47 gfx::Size output_allocated_size, |
48 int num_buffers, | 48 int num_buffers, |
49 const base::Closure& error_cb); | 49 const base::Closure& error_cb); |
50 | 50 |
51 // Returns a vector of dmabuf file descriptors, exported for V4L2 output | 51 // 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 | 52 // buffer with |index|. The size of vector will be the number of planes of the |
(...skipping 25 matching lines...) Expand all Loading... |
78 | 78 |
79 // Callback to be used to return the index of a processed image to the | 79 // 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 | 80 // client. After the client is done with the frame, call Process with the |
81 // index to return the output buffer to the image processor. | 81 // index to return the output buffer to the image processor. |
82 typedef base::Callback<void(int output_buffer_index)> FrameReadyCB; | 82 typedef base::Callback<void(int output_buffer_index)> FrameReadyCB; |
83 | 83 |
84 // Called by client to process |frame|. The resulting processed frame will be | 84 // 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 | 85 // stored in |output_buffer_index| output buffer and notified via |cb|. The |
86 // processor will drop all its references to |frame| after it finishes | 86 // processor will drop all its references to |frame| after it finishes |
87 // accessing it. | 87 // accessing it. |
88 void Process(const scoped_refptr<media::VideoFrame>& frame, | 88 void Process(const scoped_refptr<VideoFrame>& frame, |
89 int output_buffer_index, | 89 int output_buffer_index, |
90 const FrameReadyCB& cb); | 90 const FrameReadyCB& cb); |
91 | 91 |
92 // Stop all processing and clean up. After this method returns no more | 92 // Stop all processing and clean up. After this method returns no more |
93 // callbacks will be invoked. Deletes |this| unconditionally, so make sure | 93 // callbacks will be invoked. Deletes |this| unconditionally, so make sure |
94 // to drop all pointers to it! | 94 // to drop all pointers to it! |
95 void Destroy(); | 95 void Destroy(); |
96 | 96 |
97 private: | 97 private: |
98 // Record for input buffers. | 98 // Record for input buffers. |
99 struct InputRecord { | 99 struct InputRecord { |
100 InputRecord(); | 100 InputRecord(); |
101 ~InputRecord(); | 101 ~InputRecord(); |
102 scoped_refptr<media::VideoFrame> frame; | 102 scoped_refptr<VideoFrame> frame; |
103 bool at_device; | 103 bool at_device; |
104 }; | 104 }; |
105 | 105 |
106 // Record for output buffers. | 106 // Record for output buffers. |
107 struct OutputRecord { | 107 struct OutputRecord { |
108 OutputRecord(); | 108 OutputRecord(); |
109 ~OutputRecord(); | 109 ~OutputRecord(); |
110 bool at_device; | 110 bool at_device; |
111 }; | 111 }; |
112 | 112 |
113 // Job record. Jobs are processed in a FIFO order. This is separate from | 113 // Job record. Jobs are processed in a FIFO order. This is separate from |
114 // InputRecord, because an InputRecord may be returned before we dequeue | 114 // InputRecord, because an InputRecord may be returned before we dequeue |
115 // the corresponding output buffer. The processed frame will be stored in | 115 // the corresponding output buffer. The processed frame will be stored in |
116 // |output_buffer_index| output buffer. | 116 // |output_buffer_index| output buffer. |
117 struct JobRecord { | 117 struct JobRecord { |
118 JobRecord(); | 118 JobRecord(); |
119 ~JobRecord(); | 119 ~JobRecord(); |
120 scoped_refptr<media::VideoFrame> frame; | 120 scoped_refptr<VideoFrame> frame; |
121 int output_buffer_index; | 121 int output_buffer_index; |
122 FrameReadyCB ready_cb; | 122 FrameReadyCB ready_cb; |
123 }; | 123 }; |
124 | 124 |
125 void EnqueueInput(); | 125 void EnqueueInput(); |
126 void EnqueueOutput(int index); | 126 void EnqueueOutput(int index); |
127 void Dequeue(); | 127 void Dequeue(); |
128 bool EnqueueInputRecord(); | 128 bool EnqueueInputRecord(); |
129 bool EnqueueOutputRecord(int index); | 129 bool EnqueueOutputRecord(int index); |
130 bool CreateInputBuffers(); | 130 bool CreateInputBuffers(); |
(...skipping 20 matching lines...) Expand all Loading... |
151 | 151 |
152 // Size and format-related members remain constant after initialization. | 152 // Size and format-related members remain constant after initialization. |
153 // The visible/allocated sizes of the input frame. | 153 // The visible/allocated sizes of the input frame. |
154 gfx::Size input_visible_size_; | 154 gfx::Size input_visible_size_; |
155 gfx::Size input_allocated_size_; | 155 gfx::Size input_allocated_size_; |
156 | 156 |
157 // The visible/allocated sizes of the destination frame. | 157 // The visible/allocated sizes of the destination frame. |
158 gfx::Size output_visible_size_; | 158 gfx::Size output_visible_size_; |
159 gfx::Size output_allocated_size_; | 159 gfx::Size output_allocated_size_; |
160 | 160 |
161 media::VideoPixelFormat input_format_; | 161 VideoPixelFormat input_format_; |
162 media::VideoPixelFormat output_format_; | 162 VideoPixelFormat output_format_; |
163 v4l2_memory input_memory_type_; | 163 v4l2_memory input_memory_type_; |
164 uint32_t input_format_fourcc_; | 164 uint32_t input_format_fourcc_; |
165 uint32_t output_format_fourcc_; | 165 uint32_t output_format_fourcc_; |
166 | 166 |
167 size_t input_planes_count_; | 167 size_t input_planes_count_; |
168 size_t output_planes_count_; | 168 size_t output_planes_count_; |
169 | 169 |
170 // Our original calling task runner for the child thread. | 170 // Our original calling task runner for the child thread. |
171 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | 171 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
172 | 172 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 214 |
215 // Weak factory for producing weak pointers on the child thread. | 215 // Weak factory for producing weak pointers on the child thread. |
216 base::WeakPtrFactory<V4L2ImageProcessor> weak_this_factory_; | 216 base::WeakPtrFactory<V4L2ImageProcessor> weak_this_factory_; |
217 | 217 |
218 DISALLOW_COPY_AND_ASSIGN(V4L2ImageProcessor); | 218 DISALLOW_COPY_AND_ASSIGN(V4L2ImageProcessor); |
219 }; | 219 }; |
220 | 220 |
221 } // namespace media | 221 } // namespace media |
222 | 222 |
223 #endif // MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ | 223 #endif // MEDIA_GPU_V4L2_IMAGE_PROCESSOR_H_ |
OLD | NEW |