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