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