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 <stddef.h> | 11 #include <stddef.h> |
12 #include <stdint.h> | 12 #include <stdint.h> |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <queue> | 16 #include <queue> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/macros.h" | 21 #include "base/macros.h" |
22 #include "base/memory/linked_ptr.h" | 22 #include "base/memory/linked_ptr.h" |
23 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
24 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
25 #include "base/synchronization/condition_variable.h" | 25 #include "base/synchronization/condition_variable.h" |
26 #include "base/synchronization/lock.h" | 26 #include "base/synchronization/lock.h" |
27 #include "base/threading/thread.h" | 27 #include "base/threading/thread.h" |
28 #include "content/common/content_export.h" | 28 #include "content/common/content_export.h" |
| 29 #include "content/common/gpu/media/gpu_video_decode_accelerator_helpers.h" |
29 #include "content/common/gpu/media/shared_memory_region.h" | 30 #include "content/common/gpu/media/shared_memory_region.h" |
30 #include "content/common/gpu/media/vaapi_wrapper.h" | 31 #include "content/common/gpu/media/vaapi_wrapper.h" |
31 #include "media/base/bitstream_buffer.h" | 32 #include "media/base/bitstream_buffer.h" |
32 #include "media/video/picture.h" | 33 #include "media/video/picture.h" |
33 #include "media/video/video_decode_accelerator.h" | 34 #include "media/video/video_decode_accelerator.h" |
34 | 35 |
35 namespace gl { | 36 namespace gl { |
36 class GLImage; | 37 class GLImage; |
37 } | 38 } |
38 | 39 |
39 namespace content { | 40 namespace content { |
40 | 41 |
41 class AcceleratedVideoDecoder; | 42 class AcceleratedVideoDecoder; |
42 class VaapiPicture; | 43 class VaapiPicture; |
43 | 44 |
44 // Class to provide video decode acceleration for Intel systems with hardware | 45 // Class to provide video decode acceleration for Intel systems with hardware |
45 // support for it, and on which libva is available. | 46 // support for it, and on which libva is available. |
46 // Decoding tasks are performed in a separate decoding thread. | 47 // Decoding tasks are performed in a separate decoding thread. |
47 // | 48 // |
48 // Threading/life-cycle: this object is created & destroyed on the GPU | 49 // Threading/life-cycle: this object is created & destroyed on the GPU |
49 // ChildThread. A few methods on it are called on the decoder thread which is | 50 // ChildThread. A few methods on it are called on the decoder thread which is |
50 // stopped during |this->Destroy()|, so any tasks posted to the decoder thread | 51 // stopped during |this->Destroy()|, so any tasks posted to the decoder thread |
51 // can assume |*this| is still alive. See |weak_this_| below for more details. | 52 // can assume |*this| is still alive. See |weak_this_| below for more details. |
52 class CONTENT_EXPORT VaapiVideoDecodeAccelerator | 53 class CONTENT_EXPORT VaapiVideoDecodeAccelerator |
53 : public media::VideoDecodeAccelerator { | 54 : public media::VideoDecodeAccelerator { |
54 public: | 55 public: |
55 class VaapiDecodeSurface; | 56 class VaapiDecodeSurface; |
56 | 57 |
57 VaapiVideoDecodeAccelerator( | 58 VaapiVideoDecodeAccelerator( |
58 const MakeContextCurrentCallback& make_context_current, | 59 const MakeGLContextCurrentCallback& make_context_current_cb, |
59 const BindImageCallback& bind_image); | 60 const BindGLImageCallback& bind_image_cb); |
| 61 |
60 ~VaapiVideoDecodeAccelerator() override; | 62 ~VaapiVideoDecodeAccelerator() override; |
61 | 63 |
62 // media::VideoDecodeAccelerator implementation. | 64 // media::VideoDecodeAccelerator implementation. |
63 bool Initialize(const Config& config, Client* client) override; | 65 bool Initialize(const Config& config, Client* client) override; |
64 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 66 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
65 void AssignPictureBuffers( | 67 void AssignPictureBuffers( |
66 const std::vector<media::PictureBuffer>& buffers) override; | 68 const std::vector<media::PictureBuffer>& buffers) override; |
67 void ReusePictureBuffer(int32_t picture_buffer_id) override; | 69 void ReusePictureBuffer(int32_t picture_buffer_id) override; |
68 void Flush() override; | 70 void Flush() override; |
69 void Reset() override; | 71 void Reset() override; |
70 void Destroy() override; | 72 void Destroy() override; |
71 bool CanDecodeOnIOThread() override; | 73 bool TryToSetupDecodeOnSeparateThread( |
| 74 const base::WeakPtr<Client>& decode_client, |
| 75 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) |
| 76 override; |
72 | 77 |
73 static media::VideoDecodeAccelerator::SupportedProfiles | 78 static media::VideoDecodeAccelerator::SupportedProfiles |
74 GetSupportedProfiles(); | 79 GetSupportedProfiles(); |
75 | 80 |
76 private: | 81 private: |
77 class VaapiH264Accelerator; | 82 class VaapiH264Accelerator; |
78 class VaapiVP8Accelerator; | 83 class VaapiVP8Accelerator; |
79 class VaapiVP9Accelerator; | 84 class VaapiVP9Accelerator; |
80 | 85 |
81 // Notify the client that an error has occurred and decoding cannot continue. | 86 // Notify the client that an error has occurred and decoding cannot continue. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // On Intel, we don't have to explicitly maintain the ordering however, as the | 177 // On Intel, we don't have to explicitly maintain the ordering however, as the |
173 // driver will maintain ordering, as well as dependencies, and will process | 178 // driver will maintain ordering, as well as dependencies, and will process |
174 // each submitted command in order, and run each command only if its | 179 // each submitted command in order, and run each command only if its |
175 // dependencies are ready. | 180 // dependencies are ready. |
176 void SurfaceReady(const scoped_refptr<VaapiDecodeSurface>& dec_surface); | 181 void SurfaceReady(const scoped_refptr<VaapiDecodeSurface>& dec_surface); |
177 | 182 |
178 // Return a new VaapiDecodeSurface for decoding into, or nullptr if not | 183 // Return a new VaapiDecodeSurface for decoding into, or nullptr if not |
179 // available. | 184 // available. |
180 scoped_refptr<VaapiDecodeSurface> CreateSurface(); | 185 scoped_refptr<VaapiDecodeSurface> CreateSurface(); |
181 | 186 |
182 | |
183 // Client-provided GL state. | |
184 MakeContextCurrentCallback make_context_current_; | |
185 | |
186 // VAVDA state. | 187 // VAVDA state. |
187 enum State { | 188 enum State { |
188 // Initialize() not called yet or failed. | 189 // Initialize() not called yet or failed. |
189 kUninitialized, | 190 kUninitialized, |
190 // DecodeTask running. | 191 // DecodeTask running. |
191 kDecoding, | 192 kDecoding, |
192 // Resetting, waiting for decoder to finish current task and cleanup. | 193 // Resetting, waiting for decoder to finish current task and cleanup. |
193 kResetting, | 194 kResetting, |
194 // Flushing, waiting for decoder to finish current task and cleanup. | 195 // Flushing, waiting for decoder to finish current task and cleanup. |
195 kFlushing, | 196 kFlushing, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 bool finish_flush_pending_; | 297 bool finish_flush_pending_; |
297 | 298 |
298 // Decoder requested a new surface set and we are waiting for all the surfaces | 299 // Decoder requested a new surface set and we are waiting for all the surfaces |
299 // to be returned before we can free them. | 300 // to be returned before we can free them. |
300 bool awaiting_va_surfaces_recycle_; | 301 bool awaiting_va_surfaces_recycle_; |
301 | 302 |
302 // Last requested number/resolution of output picture buffers. | 303 // Last requested number/resolution of output picture buffers. |
303 size_t requested_num_pics_; | 304 size_t requested_num_pics_; |
304 gfx::Size requested_pic_size_; | 305 gfx::Size requested_pic_size_; |
305 | 306 |
306 // Binds the provided GLImage to a givenr client texture ID & texture target | 307 // Callback to make GL context current. |
307 // combination in GLES. | 308 MakeGLContextCurrentCallback make_context_current_cb_; |
308 BindImageCallback bind_image_; | 309 |
| 310 // Callback to bind a GLImage to a given texture. |
| 311 BindGLImageCallback bind_image_cb_; |
309 | 312 |
310 // The WeakPtrFactory for |weak_this_|. | 313 // The WeakPtrFactory for |weak_this_|. |
311 base::WeakPtrFactory<VaapiVideoDecodeAccelerator> weak_this_factory_; | 314 base::WeakPtrFactory<VaapiVideoDecodeAccelerator> weak_this_factory_; |
312 | 315 |
313 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); | 316 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); |
314 }; | 317 }; |
315 | 318 |
316 } // namespace content | 319 } // namespace content |
317 | 320 |
318 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 321 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |