OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 VideoDecoderAccelerator | 5 // This file contains an implementation of VideoDecoderAccelerator |
6 // that utilizes hardware video decoder present on Intel CPUs. | 6 // that utilizes hardware video decoder present on Intel CPUs. |
7 | 7 |
8 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 8 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
9 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 9 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <queue> | 12 #include <queue> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/linked_ptr.h" | |
Pawel Osciak
2014/08/25 01:13:23
linked_ptr is used in this file. Please keep this
| |
18 #include "base/memory/shared_memory.h" | 17 #include "base/memory/shared_memory.h" |
19 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
20 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
21 #include "base/synchronization/condition_variable.h" | 20 #include "base/synchronization/condition_variable.h" |
22 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
23 #include "base/threading/non_thread_safe.h" | |
24 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
25 #include "content/common/content_export.h" | 23 #include "content/common/content_export.h" |
26 #include "content/common/gpu/media/vaapi_h264_decoder.h" | 24 #include "content/common/gpu/media/vaapi_h264_decoder.h" |
27 #include "content/common/gpu/media/vaapi_wrapper.h" | 25 #include "content/common/gpu/media/vaapi_wrapper.h" |
28 #include "media/base/bitstream_buffer.h" | 26 #include "media/base/bitstream_buffer.h" |
29 #include "media/video/picture.h" | 27 #include "media/video/picture.h" |
30 #include "media/video/video_decode_accelerator.h" | 28 #include "media/video/video_decode_accelerator.h" |
31 #include "ui/gl/gl_bindings.h" | 29 |
30 namespace gfx { | |
31 class GLContext; | |
32 }; // namespace gfx | |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 | 35 |
35 // Class to provide video decode acceleration for Intel systems with hardware | 36 // Class to provide video decode acceleration for Intel systems with hardware |
36 // support for it, and on which libva is available. | 37 // support for it, and on which libva is available. |
37 // Decoding tasks are performed in a separate decoding thread. | 38 // Decoding tasks are performed in a separate decoding thread. |
38 // | 39 // |
39 // Threading/life-cycle: this object is created & destroyed on the GPU | 40 // Threading/life-cycle: this object is created & destroyed on the GPU |
40 // ChildThread. A few methods on it are called on the decoder thread which is | 41 // ChildThread. A few methods on it are called on the decoder thread which is |
41 // stopped during |this->Destroy()|, so any tasks posted to the decoder thread | 42 // stopped during |this->Destroy()|, so any tasks posted to the decoder thread |
42 // can assume |*this| is still alive. See |weak_this_| below for more details. | 43 // can assume |*this| is still alive. See |weak_this_| below for more details. |
43 class CONTENT_EXPORT VaapiVideoDecodeAccelerator | 44 class CONTENT_EXPORT VaapiVideoDecodeAccelerator |
44 : public media::VideoDecodeAccelerator { | 45 : public media::VideoDecodeAccelerator { |
45 public: | 46 public: |
46 VaapiVideoDecodeAccelerator( | 47 VaapiVideoDecodeAccelerator( |
47 Display* x_display, | 48 gfx::GLContext* gl_context, |
48 const base::Callback<bool(void)>& make_context_current); | 49 const base::Callback<bool(void)>& make_context_current); |
49 virtual ~VaapiVideoDecodeAccelerator(); | 50 virtual ~VaapiVideoDecodeAccelerator(); |
50 | 51 |
51 // media::VideoDecodeAccelerator implementation. | 52 // media::VideoDecodeAccelerator implementation. |
52 virtual bool Initialize(media::VideoCodecProfile profile, | 53 virtual bool Initialize(media::VideoCodecProfile profile, |
53 Client* client) OVERRIDE; | 54 Client* client) OVERRIDE; |
54 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | 55 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
55 virtual void AssignPictureBuffers( | 56 virtual void AssignPictureBuffers( |
56 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | 57 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
57 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | 58 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 void Cleanup(); | 117 void Cleanup(); |
117 | 118 |
118 // Get a usable framebuffer configuration for use in binding textures | 119 // Get a usable framebuffer configuration for use in binding textures |
119 // or return false on failure. | 120 // or return false on failure. |
120 bool InitializeFBConfig(); | 121 bool InitializeFBConfig(); |
121 | 122 |
122 // Callback for the decoder to execute when it wants us to output given | 123 // Callback for the decoder to execute when it wants us to output given |
123 // |va_surface|. | 124 // |va_surface|. |
124 void SurfaceReady(int32 input_id, const scoped_refptr<VASurface>& va_surface); | 125 void SurfaceReady(int32 input_id, const scoped_refptr<VASurface>& va_surface); |
125 | 126 |
126 // Represents a texture bound to an X Pixmap for output purposes. | |
127 class TFPPicture; | |
128 | |
129 // Callback to be executed once we have a |va_surface| to be output and | 127 // Callback to be executed once we have a |va_surface| to be output and |
130 // an available |tfp_picture| to use for output. | 128 // an available |picture| to use for output. |
131 // Puts contents of |va_surface| into given |tfp_picture|, releases the | 129 // Puts contents of |va_surface| into given |picture|, releases the |
132 // surface and passes the resulting picture to client for output. | 130 // surface and passes the resulting picture to client for output. |
133 void OutputPicture(const scoped_refptr<VASurface>& va_surface, | 131 void OutputPicture(const scoped_refptr<VASurface>& va_surface, |
134 int32 input_id, | 132 int32 input_id, |
135 TFPPicture* tfp_picture); | 133 VaapiWrapper::Picture* picture); |
136 | 134 |
137 // Try to OutputPicture() if we have both a ready surface and picture. | 135 // Try to OutputPicture() if we have both a ready surface and picture. |
138 void TryOutputSurface(); | 136 void TryOutputSurface(); |
139 | 137 |
140 // Called when a VASurface is no longer in use by the decoder or is not being | 138 // Called when a VASurface is no longer in use by the decoder or is not being |
141 // synced/waiting to be synced to a picture. Returns it to available surfaces | 139 // synced/waiting to be synced to a picture. Returns it to available surfaces |
142 // pool. | 140 // pool. |
143 void RecycleVASurfaceID(VASurfaceID va_surface_id); | 141 void RecycleVASurfaceID(VASurfaceID va_surface_id); |
144 | 142 |
145 // Initiate wait cycle for surfaces to be released before we release them | 143 // Initiate wait cycle for surfaces to be released before we release them |
146 // and allocate new ones, as requested by the decoder. | 144 // and allocate new ones, as requested by the decoder. |
147 void InitiateSurfaceSetChange(size_t num_pics, gfx::Size size); | 145 void InitiateSurfaceSetChange(size_t num_pics, gfx::Size size); |
148 // Check if the surfaces have been released or post ourselves for later. | 146 // Check if the surfaces have been released or post ourselves for later. |
149 void TryFinishSurfaceSetChange(); | 147 void TryFinishSurfaceSetChange(); |
150 | 148 |
151 // Client-provided X/GLX state. | 149 // Client-provided X/GLX state. |
152 Display* x_display_; | 150 // Display* x_display_; |
spang
2014/08/22 17:20:23
what's this commented out code?
Pawel Osciak
2014/08/25 01:13:23
Please clean up all commented-out code in the whol
| |
151 gfx::GLContext* gl_context_; | |
153 base::Callback<bool(void)> make_context_current_; | 152 base::Callback<bool(void)> make_context_current_; |
154 GLXFBConfig fb_config_; | 153 // GLXFBConfig fb_config_; |
155 | 154 |
156 // VAVDA state. | 155 // VAVDA state. |
157 enum State { | 156 enum State { |
158 // Initialize() not called yet or failed. | 157 // Initialize() not called yet or failed. |
159 kUninitialized, | 158 kUninitialized, |
160 // DecodeTask running. | 159 // DecodeTask running. |
161 kDecoding, | 160 kDecoding, |
162 // Resetting, waiting for decoder to finish current task and cleanup. | 161 // Resetting, waiting for decoder to finish current task and cleanup. |
163 kResetting, | 162 kResetting, |
164 // Flushing, waiting for decoder to finish current task and cleanup. | 163 // Flushing, waiting for decoder to finish current task and cleanup. |
(...skipping 24 matching lines...) Expand all Loading... | |
189 // Signalled when input buffers are queued onto the input_buffers_ queue. | 188 // Signalled when input buffers are queued onto the input_buffers_ queue. |
190 base::ConditionVariable input_ready_; | 189 base::ConditionVariable input_ready_; |
191 | 190 |
192 // Current input buffer at decoder. | 191 // Current input buffer at decoder. |
193 linked_ptr<InputBuffer> curr_input_buffer_; | 192 linked_ptr<InputBuffer> curr_input_buffer_; |
194 | 193 |
195 // Queue for incoming output buffers (texture ids). | 194 // Queue for incoming output buffers (texture ids). |
196 typedef std::queue<int32> OutputBuffers; | 195 typedef std::queue<int32> OutputBuffers; |
197 OutputBuffers output_buffers_; | 196 OutputBuffers output_buffers_; |
198 | 197 |
199 typedef std::map<int32, linked_ptr<TFPPicture> > TFPPictures; | 198 typedef std::map<int32, linked_ptr<VaapiWrapper::Picture> > Pictures; |
200 // All allocated TFPPictures, regardless of their current state. TFPPictures | 199 // All allocated Pictures, regardless of their current state. Pictures |
201 // are allocated once and destroyed at the end of decode. | 200 // are allocated once and destroyed at the end of decode. |
202 TFPPictures tfp_pictures_; | 201 Pictures pictures_; |
203 | 202 |
204 // Return a TFPPicture associated with given client-provided id. | 203 // Return a TFPPicture associated with given client-provided id. |
205 TFPPicture* TFPPictureById(int32 picture_buffer_id); | 204 VaapiWrapper::Picture* PictureById(int32 picture_buffer_id); |
206 | 205 |
207 // VA Surfaces no longer in use that can be passed back to the decoder for | 206 // VA Surfaces no longer in use that can be passed back to the decoder for |
208 // reuse, once it requests them. | 207 // reuse, once it requests them. |
209 std::list<VASurfaceID> available_va_surfaces_; | 208 std::list<VASurfaceID> available_va_surfaces_; |
210 // Signalled when output surfaces are queued onto the available_va_surfaces_ | 209 // Signalled when output surfaces are queued onto the available_va_surfaces_ |
211 // queue. | 210 // queue. |
212 base::ConditionVariable surfaces_available_; | 211 base::ConditionVariable surfaces_available_; |
213 | 212 |
214 // Pending output requests from the decoder. When it indicates that we should | 213 // Pending output requests from the decoder. When it indicates that we should |
215 // output a surface and we have an available TFPPicture (i.e. texture) ready | 214 // output a surface and we have an available Picture (i.e. texture) ready |
216 // to use, we'll execute the callback passing the TFPPicture. The callback | 215 // to use, we'll execute the callback passing the Picture. The callback |
217 // will put the contents of the surface into the picture and return it to | 216 // will put the contents of the surface into the picture and return it to |
218 // the client, releasing the surface as well. | 217 // the client, releasing the surface as well. |
219 // If we don't have any available TFPPictures at the time when the decoder | 218 // If we don't have any available Pictures at the time when the decoder |
220 // requests output, we'll store the request on pending_output_cbs_ queue for | 219 // requests output, we'll store the request on pending_output_cbs_ queue for |
221 // later and run it once the client gives us more textures | 220 // later and run it once the client gives us more textures |
222 // via ReusePictureBuffer(). | 221 // via ReusePictureBuffer(). |
223 typedef base::Callback<void(TFPPicture*)> OutputCB; | 222 typedef base::Callback<void(VaapiWrapper::Picture*)> OutputCB; |
224 std::queue<OutputCB> pending_output_cbs_; | 223 std::queue<OutputCB> pending_output_cbs_; |
225 | 224 |
226 // ChildThread's message loop | 225 // ChildThread's message loop |
227 base::MessageLoop* message_loop_; | 226 base::MessageLoop* message_loop_; |
228 | 227 |
229 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder | 228 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder |
230 // thread back to the ChildThread. Because the decoder thread is a member of | 229 // thread back to the ChildThread. Because the decoder thread is a member of |
231 // this class, any task running on the decoder thread is guaranteed that this | 230 // this class, any task running on the decoder thread is guaranteed that this |
232 // object is still alive. As a result, tasks posted from ChildThread to | 231 // object is still alive. As a result, tasks posted from ChildThread to |
233 // decoder thread should use base::Unretained(this), and tasks posted from the | 232 // decoder thread should use base::Unretained(this), and tasks posted from the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 | 269 |
271 // The WeakPtrFactory for |weak_this_|. | 270 // The WeakPtrFactory for |weak_this_|. |
272 base::WeakPtrFactory<VaapiVideoDecodeAccelerator> weak_this_factory_; | 271 base::WeakPtrFactory<VaapiVideoDecodeAccelerator> weak_this_factory_; |
273 | 272 |
274 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); | 273 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); |
275 }; | 274 }; |
276 | 275 |
277 } // namespace content | 276 } // namespace content |
278 | 277 |
279 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 278 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |