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 // This file contains an implementation of VideoDecodeAccelerator | 5 // This file contains an implementation of VideoDecodeAccelerator |
6 // that utilizes hardware video decoders, which expose Video4Linux 2 API | 6 // that utilizes hardware video decoders, which expose Video4Linux 2 API |
7 // (http://linuxtv.org/downloads/v4l-dvb-apis/). | 7 // (http://linuxtv.org/downloads/v4l-dvb-apis/). |
8 | 8 |
9 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ | 9 #ifndef CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ |
10 #define CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ | 10 #define CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ |
11 | 11 |
12 #include <stddef.h> | 12 #include <stddef.h> |
13 #include <stdint.h> | 13 #include <stdint.h> |
14 | 14 |
15 #include <queue> | 15 #include <queue> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/callback_forward.h" | 18 #include "base/callback_forward.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/linked_ptr.h" | 20 #include "base/memory/linked_ptr.h" |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
23 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
25 #include "content/common/content_export.h" | 25 #include "content/common/content_export.h" |
| 26 #include "content/common/gpu/media/gpu_video_decode_accelerator_helpers.h" |
26 #include "content/common/gpu/media/v4l2_device.h" | 27 #include "content/common/gpu/media/v4l2_device.h" |
27 #include "media/base/limits.h" | 28 #include "media/base/limits.h" |
28 #include "media/base/video_decoder_config.h" | 29 #include "media/base/video_decoder_config.h" |
29 #include "media/video/picture.h" | 30 #include "media/video/picture.h" |
30 #include "media/video/video_decode_accelerator.h" | 31 #include "media/video/video_decode_accelerator.h" |
31 #include "ui/gfx/geometry/size.h" | 32 #include "ui/gfx/geometry/size.h" |
32 #include "ui/gl/gl_bindings.h" | 33 #include "ui/gl/gl_bindings.h" |
33 | 34 |
34 namespace media { | 35 namespace media { |
35 class H264Parser; | 36 class H264Parser; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // the required number of output buffers from the device and that cannot be done | 72 // the required number of output buffers from the device and that cannot be done |
72 // unless we free the previous set of buffers, leaving the decoding in a | 73 // unless we free the previous set of buffers, leaving the decoding in a |
73 // inoperable state for the duration of the wait for Pictures. So to prevent | 74 // inoperable state for the duration of the wait for Pictures. So to prevent |
74 // subtle races (esp. if we get Reset() in the meantime), we block the decoder | 75 // subtle races (esp. if we get Reset() in the meantime), we block the decoder |
75 // thread while we wait for AssignPictureBuffers from the client. | 76 // thread while we wait for AssignPictureBuffers from the client. |
76 class CONTENT_EXPORT V4L2VideoDecodeAccelerator | 77 class CONTENT_EXPORT V4L2VideoDecodeAccelerator |
77 : public media::VideoDecodeAccelerator { | 78 : public media::VideoDecodeAccelerator { |
78 public: | 79 public: |
79 V4L2VideoDecodeAccelerator( | 80 V4L2VideoDecodeAccelerator( |
80 EGLDisplay egl_display, | 81 EGLDisplay egl_display, |
81 EGLContext egl_context, | 82 const GetGLContextCallback& get_gl_context_cb, |
82 const base::WeakPtr<Client>& io_client_, | 83 const MakeGLContextCurrentCallback& make_context_current_cb, |
83 const base::Callback<bool(void)>& make_context_current, | 84 const scoped_refptr<V4L2Device>& device); |
84 const scoped_refptr<V4L2Device>& device, | |
85 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
86 ~V4L2VideoDecodeAccelerator() override; | 85 ~V4L2VideoDecodeAccelerator() override; |
87 | 86 |
88 // media::VideoDecodeAccelerator implementation. | 87 // media::VideoDecodeAccelerator implementation. |
89 // Note: Initialize() and Destroy() are synchronous. | 88 // Note: Initialize() and Destroy() are synchronous. |
90 bool Initialize(const Config& config, Client* client) override; | 89 bool Initialize(const Config& config, Client* client) override; |
91 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 90 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
92 void AssignPictureBuffers( | 91 void AssignPictureBuffers( |
93 const std::vector<media::PictureBuffer>& buffers) override; | 92 const std::vector<media::PictureBuffer>& buffers) override; |
94 void ReusePictureBuffer(int32_t picture_buffer_id) override; | 93 void ReusePictureBuffer(int32_t picture_buffer_id) override; |
95 void Flush() override; | 94 void Flush() override; |
96 void Reset() override; | 95 void Reset() override; |
97 void Destroy() override; | 96 void Destroy() override; |
98 bool CanDecodeOnIOThread() override; | 97 bool TryToSetupDecodeOnSeparateThread( |
| 98 const base::WeakPtr<Client>& decode_client, |
| 99 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) |
| 100 override; |
99 | 101 |
100 static media::VideoDecodeAccelerator::SupportedProfiles | 102 static media::VideoDecodeAccelerator::SupportedProfiles |
101 GetSupportedProfiles(); | 103 GetSupportedProfiles(); |
102 | 104 |
103 private: | 105 private: |
104 // These are rather subjectively tuned. | 106 // These are rather subjectively tuned. |
105 enum { | 107 enum { |
106 kInputBufferCount = 8, | 108 kInputBufferCount = 8, |
107 // TODO(posciak): determine input buffer size based on level limits. | 109 // TODO(posciak): determine input buffer size based on level limits. |
108 // See http://crbug.com/255116. | 110 // See http://crbug.com/255116. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 311 |
310 // Send decoded pictures to PictureReady. | 312 // Send decoded pictures to PictureReady. |
311 void SendPictureReady(); | 313 void SendPictureReady(); |
312 | 314 |
313 // Callback that indicates a picture has been cleared. | 315 // Callback that indicates a picture has been cleared. |
314 void PictureCleared(); | 316 void PictureCleared(); |
315 | 317 |
316 // Our original calling task runner for the child thread. | 318 // Our original calling task runner for the child thread. |
317 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | 319 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
318 | 320 |
319 // Task runner of the IO thread. | 321 // Task runner Decode() and PictureReady() run on. |
320 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 322 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; |
321 | 323 |
322 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or | 324 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or |
323 // device worker threads back to the child thread. Because the worker threads | 325 // device worker threads back to the child thread. Because the worker threads |
324 // are members of this class, any task running on those threads is guaranteed | 326 // are members of this class, any task running on those threads is guaranteed |
325 // that this object is still alive. As a result, tasks posted from the child | 327 // that this object is still alive. As a result, tasks posted from the child |
326 // thread to the decoder or device thread should use base::Unretained(this), | 328 // thread to the decoder or device thread should use base::Unretained(this), |
327 // and tasks posted the other way should use |weak_this_|. | 329 // and tasks posted the other way should use |weak_this_|. |
328 base::WeakPtr<V4L2VideoDecodeAccelerator> weak_this_; | 330 base::WeakPtr<V4L2VideoDecodeAccelerator> weak_this_; |
329 | 331 |
330 // To expose client callbacks from VideoDecodeAccelerator. | 332 // To expose client callbacks from VideoDecodeAccelerator. |
331 // NOTE: all calls to these objects *MUST* be executed on | 333 // NOTE: all calls to these objects *MUST* be executed on |
332 // child_task_runner_. | 334 // child_task_runner_. |
333 scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; | 335 scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; |
334 base::WeakPtr<Client> client_; | 336 base::WeakPtr<Client> client_; |
335 // Callbacks to |io_client_| must be executed on |io_task_runner_|. | 337 // Callbacks to |decode_client_| must be executed on |decode_task_runner_|. |
336 base::WeakPtr<Client> io_client_; | 338 base::WeakPtr<Client> decode_client_; |
337 | 339 |
338 // | 340 // |
339 // Decoder state, owned and operated by decoder_thread_. | 341 // Decoder state, owned and operated by decoder_thread_. |
340 // Before decoder_thread_ has started, the decoder state is managed by | 342 // Before decoder_thread_ has started, the decoder state is managed by |
341 // the child (main) thread. After decoder_thread_ has started, the decoder | 343 // the child (main) thread. After decoder_thread_ has started, the decoder |
342 // thread should be the only one managing these. | 344 // thread should be the only one managing these. |
343 // | 345 // |
344 | 346 |
345 // This thread services tasks posted from the VDA API entry points by the | 347 // This thread services tasks posted from the VDA API entry points by the |
346 // child thread and device service callbacks posted from the device thread. | 348 // child thread and device service callbacks posted from the device thread. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 // The device polling thread handles notifications of V4L2 device changes. | 433 // The device polling thread handles notifications of V4L2 device changes. |
432 // | 434 // |
433 | 435 |
434 // The thread. | 436 // The thread. |
435 base::Thread device_poll_thread_; | 437 base::Thread device_poll_thread_; |
436 | 438 |
437 // | 439 // |
438 // Other state, held by the child (main) thread. | 440 // Other state, held by the child (main) thread. |
439 // | 441 // |
440 | 442 |
441 // Make our context current before running any EGL entry points. | |
442 base::Callback<bool(void)> make_context_current_; | |
443 | |
444 // EGL state | 443 // EGL state |
445 EGLDisplay egl_display_; | 444 EGLDisplay egl_display_; |
446 EGLContext egl_context_; | 445 |
| 446 // Callback to get current GLContext. |
| 447 GetGLContextCallback get_gl_context_cb_; |
| 448 // Callback to set the correct gl context. |
| 449 MakeGLContextCurrentCallback make_context_current_cb_; |
447 | 450 |
448 // The codec we'll be decoding for. | 451 // The codec we'll be decoding for. |
449 media::VideoCodecProfile video_profile_; | 452 media::VideoCodecProfile video_profile_; |
450 // Chosen output format. | 453 // Chosen output format. |
451 uint32_t output_format_fourcc_; | 454 uint32_t output_format_fourcc_; |
452 | 455 |
453 // Input format V4L2 fourccs this class supports. | 456 // Input format V4L2 fourccs this class supports. |
454 static const uint32_t supported_input_fourccs_[]; | 457 static const uint32_t supported_input_fourccs_[]; |
455 | 458 |
456 // The WeakPtrFactory for |weak_this_|. | 459 // The WeakPtrFactory for |weak_this_|. |
457 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; | 460 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; |
458 | 461 |
459 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); | 462 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); |
460 }; | 463 }; |
461 | 464 |
462 } // namespace content | 465 } // namespace content |
463 | 466 |
464 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ | 467 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |