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/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
21 #include "content/common/gpu/media/v4l2_video_device.h" | 21 #include "content/common/gpu/media/v4l2_video_device.h" |
| 22 #include "content/common/gpu/media/video_decode_accelerator_impl.h" |
22 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
23 #include "media/base/video_decoder_config.h" | 24 #include "media/base/video_decoder_config.h" |
24 #include "media/video/picture.h" | 25 #include "media/video/picture.h" |
25 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
26 #include "ui/gl/gl_bindings.h" | 27 #include "ui/gl/gl_bindings.h" |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class MessageLoopProxy; | 30 class MessageLoopProxy; |
30 } // namespace base | 31 } // namespace base |
31 | 32 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // Buffer creation is a two-step process that is serviced partially on the | 66 // Buffer creation is a two-step process that is serviced partially on the |
66 // Child thread, because we need to wait for the client to provide textures | 67 // Child thread, because we need to wait for the client to provide textures |
67 // for the buffers we allocate. We cannot keep the decoder thread running while | 68 // for the buffers we allocate. We cannot keep the decoder thread running while |
68 // the client allocates Pictures for us, because we need to REQBUFS first to get | 69 // the client allocates Pictures for us, because we need to REQBUFS first to get |
69 // the required number of output buffers from the device and that cannot be done | 70 // the required number of output buffers from the device and that cannot be done |
70 // unless we free the previous set of buffers, leaving the decoding in a | 71 // unless we free the previous set of buffers, leaving the decoding in a |
71 // inoperable state for the duration of the wait for Pictures. So to prevent | 72 // inoperable state for the duration of the wait for Pictures. So to prevent |
72 // subtle races (esp. if we get Reset() in the meantime), we block the decoder | 73 // subtle races (esp. if we get Reset() in the meantime), we block the decoder |
73 // thread while we wait for AssignPictureBuffers from the client. | 74 // thread while we wait for AssignPictureBuffers from the client. |
74 class CONTENT_EXPORT V4L2VideoDecodeAccelerator | 75 class CONTENT_EXPORT V4L2VideoDecodeAccelerator |
75 : public media::VideoDecodeAccelerator { | 76 : public VideoDecodeAcceleratorImpl { |
76 public: | 77 public: |
77 V4L2VideoDecodeAccelerator( | 78 V4L2VideoDecodeAccelerator( |
78 EGLDisplay egl_display, | 79 EGLDisplay egl_display, |
79 EGLContext egl_context, | 80 EGLContext egl_context, |
80 const base::WeakPtr<Client>& io_client_, | 81 const base::WeakPtr<Client>& io_client_, |
81 const base::Callback<bool(void)>& make_context_current, | 82 const base::Callback<bool(void)>& make_context_current, |
82 scoped_ptr<V4L2Device> device, | 83 scoped_ptr<V4L2Device> device, |
83 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy); | 84 const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy); |
84 virtual ~V4L2VideoDecodeAccelerator(); | 85 virtual ~V4L2VideoDecodeAccelerator(); |
85 | 86 |
86 // media::VideoDecodeAccelerator implementation. | 87 // media::VideoDecodeAccelerator implementation. |
87 // Note: Initialize() and Destroy() are synchronous. | 88 // Note: Initialize() and Destroy() are synchronous. |
88 virtual bool Initialize(media::VideoCodecProfile profile, | 89 virtual bool Initialize(media::VideoCodecProfile profile, |
89 Client* client) OVERRIDE; | 90 Client* client) OVERRIDE; |
90 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | 91 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
91 virtual void AssignPictureBuffers( | 92 virtual void AssignPictureBuffers( |
92 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | 93 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
93 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | 94 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
94 virtual void Flush() OVERRIDE; | 95 virtual void Flush() OVERRIDE; |
95 virtual void Reset() OVERRIDE; | 96 virtual void Reset() OVERRIDE; |
96 virtual void Destroy() OVERRIDE; | 97 virtual void Destroy() OVERRIDE; |
| 98 |
| 99 // VideoDecodeAcceleratorImpl implementation. |
97 virtual bool CanDecodeOnIOThread() OVERRIDE; | 100 virtual bool CanDecodeOnIOThread() OVERRIDE; |
98 | 101 |
99 private: | 102 private: |
100 // These are rather subjectively tuned. | 103 // These are rather subjectively tuned. |
101 enum { | 104 enum { |
102 kInputBufferCount = 8, | 105 kInputBufferCount = 8, |
103 // TODO(posciak): determine input buffer size based on level limits. | 106 // TODO(posciak): determine input buffer size based on level limits. |
104 // See http://crbug.com/255116. | 107 // See http://crbug.com/255116. |
105 // Input bitstream buffer size for up to 1080p streams. | 108 // Input bitstream buffer size for up to 1080p streams. |
106 kInputBufferMaxSizeFor1080p = 1024 * 1024, | 109 kInputBufferMaxSizeFor1080p = 1024 * 1024, |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 439 |
437 // The WeakPtrFactory for |weak_this_|. | 440 // The WeakPtrFactory for |weak_this_|. |
438 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; | 441 base::WeakPtrFactory<V4L2VideoDecodeAccelerator> weak_this_factory_; |
439 | 442 |
440 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); | 443 DISALLOW_COPY_AND_ASSIGN(V4L2VideoDecodeAccelerator); |
441 }; | 444 }; |
442 | 445 |
443 } // namespace content | 446 } // namespace content |
444 | 447 |
445 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ | 448 #endif // CONTENT_COMMON_GPU_MEDIA_V4L2_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |