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 CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_ENCODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_ENCODE_ACCELERATOR_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_ENCODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_ENCODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
9 #include <list> | 9 #include <list> |
10 #include <vector> | 10 #include <vector> |
(...skipping 24 matching lines...) Expand all Loading... |
35 // This class handles video encode acceleration by interfacing with a V4L2 | 35 // This class handles video encode acceleration by interfacing with a V4L2 |
36 // device exposed by the codec hardware driver. The threading model of this | 36 // device exposed by the codec hardware driver. The threading model of this |
37 // class is the same as in the V4L2VideoDecodeAccelerator (from which class this | 37 // class is the same as in the V4L2VideoDecodeAccelerator (from which class this |
38 // was designed). | 38 // was designed). |
39 // This class may try to instantiate and use a V4L2ImageProcessor for input | 39 // This class may try to instantiate and use a V4L2ImageProcessor for input |
40 // format conversion, if the input format requested via Initialize() is not | 40 // format conversion, if the input format requested via Initialize() is not |
41 // accepted by the hardware codec. | 41 // accepted by the hardware codec. |
42 class CONTENT_EXPORT V4L2VideoEncodeAccelerator | 42 class CONTENT_EXPORT V4L2VideoEncodeAccelerator |
43 : public media::VideoEncodeAccelerator { | 43 : public media::VideoEncodeAccelerator { |
44 public: | 44 public: |
45 explicit V4L2VideoEncodeAccelerator(scoped_ptr<V4L2Device> device); | 45 explicit V4L2VideoEncodeAccelerator(scoped_refptr<V4L2Device> device); |
46 virtual ~V4L2VideoEncodeAccelerator(); | 46 virtual ~V4L2VideoEncodeAccelerator(); |
47 | 47 |
48 // media::VideoEncodeAccelerator implementation. | 48 // media::VideoEncodeAccelerator implementation. |
49 virtual std::vector<media::VideoEncodeAccelerator::SupportedProfile> | 49 virtual std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
50 GetSupportedProfiles() override; | 50 GetSupportedProfiles() override; |
51 virtual bool Initialize(media::VideoFrame::Format format, | 51 virtual bool Initialize(media::VideoFrame::Format format, |
52 const gfx::Size& input_visible_size, | 52 const gfx::Size& input_visible_size, |
53 media::VideoCodecProfile output_profile, | 53 media::VideoCodecProfile output_profile, |
54 uint32 initial_bitrate, | 54 uint32 initial_bitrate, |
55 Client* client) override; | 55 Client* client) override; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // The device task. | 147 // The device task. |
148 void DevicePollTask(bool poll_device); | 148 void DevicePollTask(bool poll_device); |
149 | 149 |
150 // | 150 // |
151 // Safe from any thread. | 151 // Safe from any thread. |
152 // | 152 // |
153 | 153 |
154 // Error notification (using PostTask() to child thread, if necessary). | 154 // Error notification (using PostTask() to child thread, if necessary). |
155 void NotifyError(Error error); | 155 void NotifyError(Error error); |
156 | 156 |
157 // Set the encoder_thread_ state (using PostTask to encoder thread, if | 157 // Set the encoder_state_ to kError and notify the client (if necessary). |
158 // necessary). | 158 void SetErrorState(Error error); |
159 void SetEncoderState(State state); | |
160 | 159 |
161 // | 160 // |
162 // Other utility functions. Called on encoder_thread_, unless | 161 // Other utility functions. Called on encoder_thread_, unless |
163 // encoder_thread_ is not yet started, in which case the child thread can call | 162 // encoder_thread_ is not yet started, in which case the child thread can call |
164 // these (e.g. in Initialize() or Destroy()). | 163 // these (e.g. in Initialize() or Destroy()). |
165 // | 164 // |
166 | 165 |
167 // Change encoding parameters. | 166 // Change encoding parameters. |
168 void RequestEncodingParametersChangeTask(uint32 bitrate, uint32 framerate); | 167 void RequestEncodingParametersChangeTask(uint32 bitrate, uint32 framerate); |
169 | 168 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 217 |
219 // We need to provide the stream header with every keyframe, to allow | 218 // We need to provide the stream header with every keyframe, to allow |
220 // midstream decoding restarts. Store it here. | 219 // midstream decoding restarts. Store it here. |
221 scoped_ptr<uint8[]> stream_header_; | 220 scoped_ptr<uint8[]> stream_header_; |
222 size_t stream_header_size_; | 221 size_t stream_header_size_; |
223 | 222 |
224 // Video frames ready to be encoded. | 223 // Video frames ready to be encoded. |
225 std::list<scoped_refptr<media::VideoFrame> > encoder_input_queue_; | 224 std::list<scoped_refptr<media::VideoFrame> > encoder_input_queue_; |
226 | 225 |
227 // Encoder device. | 226 // Encoder device. |
228 scoped_ptr<V4L2Device> device_; | 227 scoped_refptr<V4L2Device> device_; |
229 | 228 |
230 // Input queue state. | 229 // Input queue state. |
231 bool input_streamon_; | 230 bool input_streamon_; |
232 // Input buffers enqueued to device. | 231 // Input buffers enqueued to device. |
233 int input_buffer_queued_count_; | 232 int input_buffer_queued_count_; |
234 // Input buffers ready to use; LIFO since we don't care about ordering. | 233 // Input buffers ready to use; LIFO since we don't care about ordering. |
235 std::vector<int> free_input_buffers_; | 234 std::vector<int> free_input_buffers_; |
236 // Mapping of int index to input buffer record. | 235 // Mapping of int index to input buffer record. |
237 std::vector<InputRecord> input_buffer_map_; | 236 std::vector<InputRecord> input_buffer_map_; |
238 enum v4l2_memory input_memory_type_; | 237 enum v4l2_memory input_memory_type_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // as both threads will not outlive this object. | 272 // as both threads will not outlive this object. |
274 base::WeakPtr<V4L2VideoEncodeAccelerator> weak_this_; | 273 base::WeakPtr<V4L2VideoEncodeAccelerator> weak_this_; |
275 base::WeakPtrFactory<V4L2VideoEncodeAccelerator> weak_this_ptr_factory_; | 274 base::WeakPtrFactory<V4L2VideoEncodeAccelerator> weak_this_ptr_factory_; |
276 | 275 |
277 DISALLOW_COPY_AND_ASSIGN(V4L2VideoEncodeAccelerator); | 276 DISALLOW_COPY_AND_ASSIGN(V4L2VideoEncodeAccelerator); |
278 }; | 277 }; |
279 | 278 |
280 } // namespace content | 279 } // namespace content |
281 | 280 |
282 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_ENCODE_ACCELERATOR_H_ | 281 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_ENCODE_ACCELERATOR_H_ |
OLD | NEW |