OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_GPU_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
6 #define MEDIA_GPU_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define MEDIA_GPU_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "media/gpu/vp8_decoder.h" | 27 #include "media/gpu/vp8_decoder.h" |
28 #include "media/video/video_decode_accelerator.h" | 28 #include "media/video/video_decode_accelerator.h" |
29 | 29 |
30 namespace media { | 30 namespace media { |
31 | 31 |
32 // An implementation of VideoDecodeAccelerator that utilizes the V4L2 slice | 32 // An implementation of VideoDecodeAccelerator that utilizes the V4L2 slice |
33 // level codec API for decoding. The slice level API provides only a low-level | 33 // level codec API for decoding. The slice level API provides only a low-level |
34 // decoding functionality and requires userspace to provide support for parsing | 34 // decoding functionality and requires userspace to provide support for parsing |
35 // the input stream and managing decoder state across frames. | 35 // the input stream and managing decoder state across frames. |
36 class MEDIA_GPU_EXPORT V4L2SliceVideoDecodeAccelerator | 36 class MEDIA_GPU_EXPORT V4L2SliceVideoDecodeAccelerator |
37 : public media::VideoDecodeAccelerator { | 37 : public VideoDecodeAccelerator { |
38 public: | 38 public: |
39 class V4L2DecodeSurface; | 39 class V4L2DecodeSurface; |
40 | 40 |
41 V4L2SliceVideoDecodeAccelerator( | 41 V4L2SliceVideoDecodeAccelerator( |
42 const scoped_refptr<V4L2Device>& device, | 42 const scoped_refptr<V4L2Device>& device, |
43 EGLDisplay egl_display, | 43 EGLDisplay egl_display, |
44 const GetGLContextCallback& get_gl_context_cb, | 44 const GetGLContextCallback& get_gl_context_cb, |
45 const MakeGLContextCurrentCallback& make_context_current_cb); | 45 const MakeGLContextCurrentCallback& make_context_current_cb); |
46 ~V4L2SliceVideoDecodeAccelerator() override; | 46 ~V4L2SliceVideoDecodeAccelerator() override; |
47 | 47 |
48 // media::VideoDecodeAccelerator implementation. | 48 // VideoDecodeAccelerator implementation. |
49 bool Initialize(const Config& config, Client* client) override; | 49 bool Initialize(const Config& config, Client* client) override; |
50 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 50 void Decode(const BitstreamBuffer& bitstream_buffer) override; |
51 void AssignPictureBuffers( | 51 void AssignPictureBuffers(const std::vector<PictureBuffer>& buffers) override; |
52 const std::vector<media::PictureBuffer>& buffers) override; | |
53 void ImportBufferForPicture( | 52 void ImportBufferForPicture( |
54 int32_t picture_buffer_id, | 53 int32_t picture_buffer_id, |
55 const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) override; | 54 const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) override; |
56 void ReusePictureBuffer(int32_t picture_buffer_id) override; | 55 void ReusePictureBuffer(int32_t picture_buffer_id) override; |
57 void Flush() override; | 56 void Flush() override; |
58 void Reset() override; | 57 void Reset() override; |
59 void Destroy() override; | 58 void Destroy() override; |
60 bool TryToSetupDecodeOnSeparateThread( | 59 bool TryToSetupDecodeOnSeparateThread( |
61 const base::WeakPtr<Client>& decode_client, | 60 const base::WeakPtr<Client>& decode_client, |
62 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) | 61 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) |
63 override; | 62 override; |
64 | 63 |
65 static media::VideoDecodeAccelerator::SupportedProfiles | 64 static VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(); |
66 GetSupportedProfiles(); | |
67 | 65 |
68 private: | 66 private: |
69 class V4L2H264Accelerator; | 67 class V4L2H264Accelerator; |
70 class V4L2VP8Accelerator; | 68 class V4L2VP8Accelerator; |
71 | 69 |
72 // Record for input buffers. | 70 // Record for input buffers. |
73 struct InputRecord { | 71 struct InputRecord { |
74 InputRecord(); | 72 InputRecord(); |
75 int32_t input_id; | 73 int32_t input_id; |
76 void* address; | 74 void* address; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 220 |
223 // Called after all events are processed successfully (i.e. all Finish*() | 221 // Called after all events are processed successfully (i.e. all Finish*() |
224 // methods return true) to return to decoding state. | 222 // methods return true) to return to decoding state. |
225 bool FinishEventProcessing(); | 223 bool FinishEventProcessing(); |
226 | 224 |
227 // Process pending events, if any. | 225 // Process pending events, if any. |
228 void ProcessPendingEventsIfNeeded(); | 226 void ProcessPendingEventsIfNeeded(); |
229 | 227 |
230 // Allocate V4L2 buffers and assign them to |buffers| provided by the client | 228 // Allocate V4L2 buffers and assign them to |buffers| provided by the client |
231 // via AssignPictureBuffers() on decoder thread. | 229 // via AssignPictureBuffers() on decoder thread. |
232 void AssignPictureBuffersTask( | 230 void AssignPictureBuffersTask(const std::vector<PictureBuffer>& buffers); |
233 const std::vector<media::PictureBuffer>& buffers); | |
234 | 231 |
235 // Use buffer backed by dmabuf file descriptors in |passed_dmabuf_fds| for the | 232 // Use buffer backed by dmabuf file descriptors in |passed_dmabuf_fds| for the |
236 // OutputRecord associated with |picture_buffer_id|, taking ownership of the | 233 // OutputRecord associated with |picture_buffer_id|, taking ownership of the |
237 // file descriptors. | 234 // file descriptors. |
238 void ImportBufferForPictureTask( | 235 void ImportBufferForPictureTask( |
239 int32_t picture_buffer_id, | 236 int32_t picture_buffer_id, |
240 // TODO(posciak): (crbug.com/561749) we should normally be able to pass | 237 // TODO(posciak): (crbug.com/561749) we should normally be able to pass |
241 // the vector by itself via std::move, but it's not possible to do this | 238 // the vector by itself via std::move, but it's not possible to do this |
242 // if this method is used as a callback. | 239 // if this method is used as a callback. |
243 std::unique_ptr<std::vector<base::ScopedFD>> passed_dmabuf_fds); | 240 std::unique_ptr<std::vector<base::ScopedFD>> passed_dmabuf_fds); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // AssignPictureBuffers(). | 297 // AssignPictureBuffers(). |
301 kAwaitingPictureBuffers, | 298 kAwaitingPictureBuffers, |
302 // Error state, set when sending NotifyError to client. | 299 // Error state, set when sending NotifyError to client. |
303 kError, | 300 kError, |
304 }; | 301 }; |
305 | 302 |
306 // Buffer id for flush buffer, queued by FlushTask(). | 303 // Buffer id for flush buffer, queued by FlushTask(). |
307 const int kFlushBufferId = -2; | 304 const int kFlushBufferId = -2; |
308 | 305 |
309 // Handler for Decode() on decoder_thread_. | 306 // Handler for Decode() on decoder_thread_. |
310 void DecodeTask(const media::BitstreamBuffer& bitstream_buffer); | 307 void DecodeTask(const BitstreamBuffer& bitstream_buffer); |
311 | 308 |
312 // Schedule a new DecodeBufferTask if we are decoding. | 309 // Schedule a new DecodeBufferTask if we are decoding. |
313 void ScheduleDecodeBufferTaskIfNeeded(); | 310 void ScheduleDecodeBufferTaskIfNeeded(); |
314 | 311 |
315 // Main decoder loop. Keep decoding the current buffer in decoder_, asking | 312 // Main decoder loop. Keep decoding the current buffer in decoder_, asking |
316 // for more stream via TrySetNewBistreamBuffer() if decoder_ requests so, | 313 // for more stream via TrySetNewBistreamBuffer() if decoder_ requests so, |
317 // and handle other returns from it appropriately. | 314 // and handle other returns from it appropriately. |
318 void DecodeBufferTask(); | 315 void DecodeBufferTask(); |
319 | 316 |
320 // Check decoder_input_queue_ for any available buffers to decode and | 317 // Check decoder_input_queue_ for any available buffers to decode and |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 386 |
390 // Output queue state. | 387 // Output queue state. |
391 bool output_streamon_; | 388 bool output_streamon_; |
392 // Number of output buffers enqueued to the device. | 389 // Number of output buffers enqueued to the device. |
393 int output_buffer_queued_count_; | 390 int output_buffer_queued_count_; |
394 // Output buffers ready to use. | 391 // Output buffers ready to use. |
395 std::list<int> free_output_buffers_; | 392 std::list<int> free_output_buffers_; |
396 // Mapping of int index to an output buffer record. | 393 // Mapping of int index to an output buffer record. |
397 std::vector<OutputRecord> output_buffer_map_; | 394 std::vector<OutputRecord> output_buffer_map_; |
398 | 395 |
399 media::VideoCodecProfile video_profile_; | 396 VideoCodecProfile video_profile_; |
400 uint32_t output_format_fourcc_; | 397 uint32_t output_format_fourcc_; |
401 gfx::Size visible_size_; | 398 gfx::Size visible_size_; |
402 gfx::Size coded_size_; | 399 gfx::Size coded_size_; |
403 | 400 |
404 struct BitstreamBufferRef; | 401 struct BitstreamBufferRef; |
405 // Input queue of stream buffers coming from the client. | 402 // Input queue of stream buffers coming from the client. |
406 std::queue<linked_ptr<BitstreamBufferRef>> decoder_input_queue_; | 403 std::queue<linked_ptr<BitstreamBufferRef>> decoder_input_queue_; |
407 // BitstreamBuffer currently being processed. | 404 // BitstreamBuffer currently being processed. |
408 std::unique_ptr<BitstreamBufferRef> decoder_current_bitstream_buffer_; | 405 std::unique_ptr<BitstreamBufferRef> decoder_current_bitstream_buffer_; |
409 | 406 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 459 |
463 DISALLOW_COPY_AND_ASSIGN(V4L2SliceVideoDecodeAccelerator); | 460 DISALLOW_COPY_AND_ASSIGN(V4L2SliceVideoDecodeAccelerator); |
464 }; | 461 }; |
465 | 462 |
466 class V4L2H264Picture; | 463 class V4L2H264Picture; |
467 class V4L2VP8Picture; | 464 class V4L2VP8Picture; |
468 | 465 |
469 } // namespace media | 466 } // namespace media |
470 | 467 |
471 #endif // MEDIA_GPU_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 468 #endif // MEDIA_GPU_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |