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 <queue> | 12 #include <queue> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_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/v4l2_device.h" | 22 #include "content/common/gpu/media/v4l2_device.h" |
23 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
24 #include "media/base/video_decoder_config.h" | 24 #include "media/base/video_decoder_config.h" |
25 #include "media/video/picture.h" | 25 #include "media/video/picture.h" |
26 #include "media/video/video_decode_accelerator.h" | 26 #include "media/video/video_decode_accelerator.h" |
27 #include "ui/gfx/geometry/size.h" | 27 #include "ui/gfx/geometry/size.h" |
28 #include "ui/gl/gl_bindings.h" | 28 #include "ui/gl/gl_bindings.h" |
29 | 29 |
30 namespace base { | |
31 class MessageLoopProxy; | |
32 } // namespace base | |
33 | |
34 namespace media { | 30 namespace media { |
35 class H264Parser; | 31 class H264Parser; |
36 } // namespace media | 32 } // namespace media |
37 | 33 |
38 namespace content { | 34 namespace content { |
39 // This class handles video accelerators directly through a V4L2 device exported | 35 // This class handles video accelerators directly through a V4L2 device exported |
40 // by the hardware blocks. | 36 // by the hardware blocks. |
41 // | 37 // |
42 // The threading model of this class is driven by the fact that it needs to | 38 // The threading model of this class is driven by the fact that it needs to |
43 // interface two fundamentally different event queues -- the one Chromium | 39 // interface two fundamentally different event queues -- the one Chromium |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // thread while we wait for AssignPictureBuffers from the client. | 71 // thread while we wait for AssignPictureBuffers from the client. |
76 class CONTENT_EXPORT V4L2VideoDecodeAccelerator | 72 class CONTENT_EXPORT V4L2VideoDecodeAccelerator |
77 : public media::VideoDecodeAccelerator { | 73 : public media::VideoDecodeAccelerator { |
78 public: | 74 public: |
79 V4L2VideoDecodeAccelerator( | 75 V4L2VideoDecodeAccelerator( |
80 EGLDisplay egl_display, | 76 EGLDisplay egl_display, |
81 EGLContext egl_context, | 77 EGLContext egl_context, |
82 const base::WeakPtr<Client>& io_client_, | 78 const base::WeakPtr<Client>& io_client_, |
83 const base::Callback<bool(void)>& make_context_current, | 79 const base::Callback<bool(void)>& make_context_current, |
84 const scoped_refptr<V4L2Device>& device, | 80 const scoped_refptr<V4L2Device>& device, |
85 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy); | 81 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
86 ~V4L2VideoDecodeAccelerator() override; | 82 ~V4L2VideoDecodeAccelerator() override; |
87 | 83 |
88 // media::VideoDecodeAccelerator implementation. | 84 // media::VideoDecodeAccelerator implementation. |
89 // Note: Initialize() and Destroy() are synchronous. | 85 // Note: Initialize() and Destroy() are synchronous. |
90 bool Initialize(media::VideoCodecProfile profile, | 86 bool Initialize(media::VideoCodecProfile profile, |
91 Client* client) override; | 87 Client* client) override; |
92 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 88 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
93 void AssignPictureBuffers( | 89 void AssignPictureBuffers( |
94 const std::vector<media::PictureBuffer>& buffers) override; | 90 const std::vector<media::PictureBuffer>& buffers) override; |
95 void ReusePictureBuffer(int32 picture_buffer_id) override; | 91 void ReusePictureBuffer(int32 picture_buffer_id) override; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 304 |
309 // Callback that indicates a picture has been cleared. | 305 // Callback that indicates a picture has been cleared. |
310 void PictureCleared(); | 306 void PictureCleared(); |
311 | 307 |
312 // This method determines whether a resolution change event processing | 308 // This method determines whether a resolution change event processing |
313 // is indeed required by returning true iff: | 309 // is indeed required by returning true iff: |
314 // - width or height of the new format is different than previous format; or | 310 // - width or height of the new format is different than previous format; or |
315 // - V4L2_CID_MIN_BUFFERS_FOR_CAPTURE has changed. | 311 // - V4L2_CID_MIN_BUFFERS_FOR_CAPTURE has changed. |
316 bool IsResolutionChangeNecessary(); | 312 bool IsResolutionChangeNecessary(); |
317 | 313 |
318 // Our original calling message loop for the child thread. | 314 // Our original calling task runner for the child thread. |
319 scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; | 315 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
320 | 316 |
321 // Message loop of the IO thread. | 317 // Task runner of the IO thread. |
322 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 318 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
323 | 319 |
324 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or | 320 // 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 | 321 // 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 | 322 // 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 | 323 // 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), | 324 // thread to the decoder or device thread should use base::Unretained(this), |
329 // and tasks posted the other way should use |weak_this_|. | 325 // and tasks posted the other way should use |weak_this_|. |
330 base::WeakPtr<V4L2VideoDecodeAccelerator> weak_this_; | 326 base::WeakPtr<V4L2VideoDecodeAccelerator> weak_this_; |
331 | 327 |
332 // To expose client callbacks from VideoDecodeAccelerator. | 328 // To expose client callbacks from VideoDecodeAccelerator. |
333 // NOTE: all calls to these objects *MUST* be executed on | 329 // NOTE: all calls to these objects *MUST* be executed on |
334 // child_message_loop_proxy_. | 330 // child_task_runner_. |
335 scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; | 331 scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; |
336 base::WeakPtr<Client> client_; | 332 base::WeakPtr<Client> client_; |
337 // Callbacks to |io_client_| must be executed on |io_message_loop_proxy_|. | 333 // Callbacks to |io_client_| must be executed on |io_task_runner_|. |
338 base::WeakPtr<Client> io_client_; | 334 base::WeakPtr<Client> io_client_; |
339 | 335 |
340 // | 336 // |
341 // Decoder state, owned and operated by decoder_thread_. | 337 // Decoder state, owned and operated by decoder_thread_. |
342 // Before decoder_thread_ has started, the decoder state is managed by | 338 // Before decoder_thread_ has started, the decoder state is managed by |
343 // the child (main) thread. After decoder_thread_ has started, the decoder | 339 // the child (main) thread. After decoder_thread_ has started, the decoder |
344 // thread should be the only one managing these. | 340 // thread should be the only one managing these. |
345 // | 341 // |
346 | 342 |
347 // This thread services tasks posted from the VDA API entry points by the | 343 // This thread services tasks posted from the VDA API entry points by the |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 | 453 |
458 // The WeakPtrFactory for |weak_this_|. | 454 // The WeakPtrFactory for |weak_this_|. |
459 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; | 455 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; |
460 | 456 |
461 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); | 457 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); |
462 }; | 458 }; |
463 | 459 |
464 } // namespace content | 460 } // namespace content |
465 | 461 |
466 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ | 462 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |