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 CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_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> |
11 #include <queue> | 11 #include <queue> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
21 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
22 #include "content/common/gpu/media/gpu_video_decode_accelerator_helpers.h" | |
23 #include "content/common/gpu/media/h264_decoder.h" | 22 #include "content/common/gpu/media/h264_decoder.h" |
24 #include "content/common/gpu/media/v4l2_device.h" | 23 #include "content/common/gpu/media/v4l2_device.h" |
25 #include "content/common/gpu/media/vp8_decoder.h" | 24 #include "content/common/gpu/media/vp8_decoder.h" |
26 #include "media/video/video_decode_accelerator.h" | 25 #include "media/video/video_decode_accelerator.h" |
27 | 26 |
28 namespace content { | 27 namespace content { |
29 | 28 |
30 // An implementation of VideoDecodeAccelerator that utilizes the V4L2 slice | 29 // An implementation of VideoDecodeAccelerator that utilizes the V4L2 slice |
31 // level codec API for decoding. The slice level API provides only a low-level | 30 // level codec API for decoding. The slice level API provides only a low-level |
32 // decoding functionality and requires userspace to provide support for parsing | 31 // decoding functionality and requires userspace to provide support for parsing |
33 // the input stream and managing decoder state across frames. | 32 // the input stream and managing decoder state across frames. |
34 class CONTENT_EXPORT V4L2SliceVideoDecodeAccelerator | 33 class CONTENT_EXPORT V4L2SliceVideoDecodeAccelerator |
35 : public media::VideoDecodeAccelerator { | 34 : public media::VideoDecodeAccelerator { |
36 public: | 35 public: |
37 class V4L2DecodeSurface; | 36 class V4L2DecodeSurface; |
38 | 37 |
39 V4L2SliceVideoDecodeAccelerator( | 38 V4L2SliceVideoDecodeAccelerator( |
40 const scoped_refptr<V4L2Device>& device, | 39 const scoped_refptr<V4L2Device>& device, |
41 EGLDisplay egl_display, | 40 EGLDisplay egl_display, |
42 const GetGLContextCallback& get_gl_context_cb, | 41 EGLContext egl_context, |
43 const MakeGLContextCurrentCallback& make_context_current_cb); | 42 const base::WeakPtr<Client>& io_client_, |
| 43 const base::Callback<bool(void)>& make_context_current, |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
44 ~V4L2SliceVideoDecodeAccelerator() override; | 45 ~V4L2SliceVideoDecodeAccelerator() override; |
45 | 46 |
46 // media::VideoDecodeAccelerator implementation. | 47 // media::VideoDecodeAccelerator implementation. |
47 bool Initialize(const Config& config, Client* client) override; | 48 bool Initialize(const Config& config, Client* client) override; |
48 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 49 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
49 void AssignPictureBuffers( | 50 void AssignPictureBuffers( |
50 const std::vector<media::PictureBuffer>& buffers) override; | 51 const std::vector<media::PictureBuffer>& buffers) override; |
51 void ReusePictureBuffer(int32_t picture_buffer_id) override; | 52 void ReusePictureBuffer(int32_t picture_buffer_id) override; |
52 void Flush() override; | 53 void Flush() override; |
53 void Reset() override; | 54 void Reset() override; |
54 void Destroy() override; | 55 void Destroy() override; |
55 bool TryToSetupDecodeOnSeparateThread( | 56 bool CanDecodeOnIOThread() override; |
56 const base::WeakPtr<Client>& decode_client, | |
57 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) | |
58 override; | |
59 | 57 |
60 static media::VideoDecodeAccelerator::SupportedProfiles | 58 static media::VideoDecodeAccelerator::SupportedProfiles |
61 GetSupportedProfiles(); | 59 GetSupportedProfiles(); |
62 | 60 |
63 private: | 61 private: |
64 class V4L2H264Accelerator; | 62 class V4L2H264Accelerator; |
65 class V4L2VP8Accelerator; | 63 class V4L2VP8Accelerator; |
66 | 64 |
67 // Record for input buffers. | 65 // Record for input buffers. |
68 struct InputRecord { | 66 struct InputRecord { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 296 |
299 // Callback that indicates a picture has been cleared. | 297 // Callback that indicates a picture has been cleared. |
300 void PictureCleared(); | 298 void PictureCleared(); |
301 | 299 |
302 size_t input_planes_count_; | 300 size_t input_planes_count_; |
303 size_t output_planes_count_; | 301 size_t output_planes_count_; |
304 | 302 |
305 // GPU Child thread task runner. | 303 // GPU Child thread task runner. |
306 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | 304 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
307 | 305 |
308 // Task runner Decode() and PictureReady() run on. | 306 // IO thread task runner. |
309 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; | 307 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
310 | 308 |
311 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or | 309 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or |
312 // device worker threads back to the child thread. | 310 // device worker threads back to the child thread. |
313 base::WeakPtr<V4L2SliceVideoDecodeAccelerator> weak_this_; | 311 base::WeakPtr<V4L2SliceVideoDecodeAccelerator> weak_this_; |
314 | 312 |
315 // To expose client callbacks from VideoDecodeAccelerator. | 313 // To expose client callbacks from VideoDecodeAccelerator. |
316 // NOTE: all calls to these objects *MUST* be executed on | 314 // NOTE: all calls to these objects *MUST* be executed on |
317 // child_task_runner_. | 315 // child_task_runner_. |
318 scoped_ptr<base::WeakPtrFactory<VideoDecodeAccelerator::Client>> | 316 scoped_ptr<base::WeakPtrFactory<VideoDecodeAccelerator::Client>> |
319 client_ptr_factory_; | 317 client_ptr_factory_; |
320 base::WeakPtr<VideoDecodeAccelerator::Client> client_; | 318 base::WeakPtr<VideoDecodeAccelerator::Client> client_; |
321 // Callbacks to |decode_client_| must be executed on |decode_task_runner_|. | 319 // Callbacks to |io_client_| must be executed on |io_task_runner_|. |
322 base::WeakPtr<Client> decode_client_; | 320 base::WeakPtr<Client> io_client_; |
323 | 321 |
324 // V4L2 device in use. | 322 // V4L2 device in use. |
325 scoped_refptr<V4L2Device> device_; | 323 scoped_refptr<V4L2Device> device_; |
326 | 324 |
327 // Thread to communicate with the device on. | 325 // Thread to communicate with the device on. |
328 base::Thread decoder_thread_; | 326 base::Thread decoder_thread_; |
329 scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_; | 327 scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_; |
330 | 328 |
331 // Thread used to poll the device for events. | 329 // Thread used to poll the device for events. |
332 base::Thread device_poll_thread_; | 330 base::Thread device_poll_thread_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 V4L2DecodeSurfaceByPictureBufferId surfaces_at_display_; | 391 V4L2DecodeSurfaceByPictureBufferId surfaces_at_display_; |
394 | 392 |
395 // Record for decoded pictures that can be sent to PictureReady. | 393 // Record for decoded pictures that can be sent to PictureReady. |
396 struct PictureRecord; | 394 struct PictureRecord; |
397 // Pictures that are ready but not sent to PictureReady yet. | 395 // Pictures that are ready but not sent to PictureReady yet. |
398 std::queue<PictureRecord> pending_picture_ready_; | 396 std::queue<PictureRecord> pending_picture_ready_; |
399 | 397 |
400 // The number of pictures that are sent to PictureReady and will be cleared. | 398 // The number of pictures that are sent to PictureReady and will be cleared. |
401 int picture_clearing_count_; | 399 int picture_clearing_count_; |
402 | 400 |
| 401 // Make the GL context current callback. |
| 402 base::Callback<bool(void)> make_context_current_; |
| 403 |
403 // EGL state | 404 // EGL state |
404 EGLDisplay egl_display_; | 405 EGLDisplay egl_display_; |
405 | 406 EGLContext egl_context_; |
406 // Callback to get current GLContext. | |
407 GetGLContextCallback get_gl_context_cb_; | |
408 // Callback to set the correct gl context. | |
409 MakeGLContextCurrentCallback make_context_current_cb_; | |
410 | 407 |
411 // The WeakPtrFactory for |weak_this_|. | 408 // The WeakPtrFactory for |weak_this_|. |
412 base::WeakPtrFactory<V4L2SliceVideoDecodeAccelerator> weak_this_factory_; | 409 base::WeakPtrFactory<V4L2SliceVideoDecodeAccelerator> weak_this_factory_; |
413 | 410 |
414 DISALLOW_COPY_AND_ASSIGN(V4L2SliceVideoDecodeAccelerator); | 411 DISALLOW_COPY_AND_ASSIGN(V4L2SliceVideoDecodeAccelerator); |
415 }; | 412 }; |
416 | 413 |
417 class V4L2H264Picture; | 414 class V4L2H264Picture; |
418 class V4L2VP8Picture; | 415 class V4L2VP8Picture; |
419 | 416 |
420 } // namespace content | 417 } // namespace content |
421 | 418 |
422 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ | 419 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_SLICE_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |