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 MEDIA_GPU_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
9 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 9 #define MEDIA_GPU_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" | |
29 #include "content/common/gpu/media/gpu_video_decode_accelerator_helpers.h" | |
30 #include "content/common/gpu/media/shared_memory_region.h" | |
31 #include "content/common/gpu/media/vaapi_wrapper.h" | |
32 #include "media/base/bitstream_buffer.h" | 28 #include "media/base/bitstream_buffer.h" |
| 29 #include "media/gpu/gpu_video_decode_accelerator_helpers.h" |
| 30 #include "media/gpu/media_gpu_export.h" |
| 31 #include "media/gpu/shared_memory_region.h" |
| 32 #include "media/gpu/vaapi_wrapper.h" |
33 #include "media/video/picture.h" | 33 #include "media/video/picture.h" |
34 #include "media/video/video_decode_accelerator.h" | 34 #include "media/video/video_decode_accelerator.h" |
35 | 35 |
36 namespace gl { | 36 namespace gl { |
37 class GLImage; | 37 class GLImage; |
38 } | 38 } |
39 | 39 |
40 namespace content { | 40 namespace media { |
41 | 41 |
42 class AcceleratedVideoDecoder; | 42 class AcceleratedVideoDecoder; |
43 class VaapiPicture; | 43 class VaapiPicture; |
44 | 44 |
45 // Class to provide video decode acceleration for Intel systems with hardware | 45 // Class to provide video decode acceleration for Intel systems with hardware |
46 // support for it, and on which libva is available. | 46 // support for it, and on which libva is available. |
47 // Decoding tasks are performed in a separate decoding thread. | 47 // Decoding tasks are performed in a separate decoding thread. |
48 // | 48 // |
49 // Threading/life-cycle: this object is created & destroyed on the GPU | 49 // Threading/life-cycle: this object is created & destroyed on the GPU |
50 // 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 |
51 // 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 |
52 // 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. |
53 class CONTENT_EXPORT VaapiVideoDecodeAccelerator | 53 class MEDIA_GPU_EXPORT VaapiVideoDecodeAccelerator |
54 : public media::VideoDecodeAccelerator { | 54 : public media::VideoDecodeAccelerator { |
55 public: | 55 public: |
56 class VaapiDecodeSurface; | 56 class VaapiDecodeSurface; |
57 | 57 |
58 VaapiVideoDecodeAccelerator( | 58 VaapiVideoDecodeAccelerator( |
59 const MakeGLContextCurrentCallback& make_context_current_cb, | 59 const MakeGLContextCurrentCallback& make_context_current_cb, |
60 const BindGLImageCallback& bind_image_cb); | 60 const BindGLImageCallback& bind_image_cb); |
61 | 61 |
62 ~VaapiVideoDecodeAccelerator() override; | 62 ~VaapiVideoDecodeAccelerator() override; |
63 | 63 |
64 // media::VideoDecodeAccelerator implementation. | 64 // media::VideoDecodeAccelerator implementation. |
65 bool Initialize(const Config& config, Client* client) override; | 65 bool Initialize(const Config& config, Client* client) override; |
66 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; | 66 void Decode(const media::BitstreamBuffer& bitstream_buffer) override; |
67 void AssignPictureBuffers( | 67 void AssignPictureBuffers( |
68 const std::vector<media::PictureBuffer>& buffers) override; | 68 const std::vector<media::PictureBuffer>& buffers) override; |
69 void ReusePictureBuffer(int32_t picture_buffer_id) override; | 69 void ReusePictureBuffer(int32_t picture_buffer_id) override; |
70 void Flush() override; | 70 void Flush() override; |
71 void Reset() override; | 71 void Reset() override; |
72 void Destroy() override; | 72 void Destroy() override; |
73 bool TryToSetupDecodeOnSeparateThread( | 73 bool TryToSetupDecodeOnSeparateThread( |
74 const base::WeakPtr<Client>& decode_client, | 74 const base::WeakPtr<Client>& decode_client, |
75 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) | 75 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) |
76 override; | 76 override; |
77 | 77 |
78 static media::VideoDecodeAccelerator::SupportedProfiles | 78 static media::VideoDecodeAccelerator::SupportedProfiles |
79 GetSupportedProfiles(); | 79 GetSupportedProfiles(); |
80 | 80 |
81 private: | 81 private: |
82 class VaapiH264Accelerator; | 82 class VaapiH264Accelerator; |
83 class VaapiVP8Accelerator; | 83 class VaapiVP8Accelerator; |
84 class VaapiVP9Accelerator; | 84 class VaapiVP9Accelerator; |
85 | 85 |
86 // 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. |
87 void NotifyError(Error error); | 87 void NotifyError(Error error); |
88 | 88 |
89 // Map the received input buffer into this process' address space and | 89 // Map the received input buffer into this process' address space and |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // An input buffer awaiting consumption, provided by the client. | 207 // An input buffer awaiting consumption, provided by the client. |
208 struct InputBuffer { | 208 struct InputBuffer { |
209 InputBuffer(); | 209 InputBuffer(); |
210 ~InputBuffer(); | 210 ~InputBuffer(); |
211 | 211 |
212 int32_t id; | 212 int32_t id; |
213 std::unique_ptr<SharedMemoryRegion> shm; | 213 std::unique_ptr<SharedMemoryRegion> shm; |
214 }; | 214 }; |
215 | 215 |
216 // Queue for incoming input buffers. | 216 // Queue for incoming input buffers. |
217 typedef std::queue<linked_ptr<InputBuffer> > InputBuffers; | 217 typedef std::queue<linked_ptr<InputBuffer>> InputBuffers; |
218 InputBuffers input_buffers_; | 218 InputBuffers input_buffers_; |
219 // Signalled when input buffers are queued onto the input_buffers_ queue. | 219 // Signalled when input buffers are queued onto the input_buffers_ queue. |
220 base::ConditionVariable input_ready_; | 220 base::ConditionVariable input_ready_; |
221 | 221 |
222 // Current input buffer at decoder. | 222 // Current input buffer at decoder. |
223 linked_ptr<InputBuffer> curr_input_buffer_; | 223 linked_ptr<InputBuffer> curr_input_buffer_; |
224 | 224 |
225 // Queue for incoming output buffers (texture ids). | 225 // Queue for incoming output buffers (texture ids). |
226 typedef std::queue<int32_t> OutputBuffers; | 226 typedef std::queue<int32_t> OutputBuffers; |
227 OutputBuffers output_buffers_; | 227 OutputBuffers output_buffers_; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 309 |
310 // Callback to bind a GLImage to a given texture. | 310 // Callback to bind a GLImage to a given texture. |
311 BindGLImageCallback bind_image_cb_; | 311 BindGLImageCallback bind_image_cb_; |
312 | 312 |
313 // The WeakPtrFactory for |weak_this_|. | 313 // The WeakPtrFactory for |weak_this_|. |
314 base::WeakPtrFactory<VaapiVideoDecodeAccelerator> weak_this_factory_; | 314 base::WeakPtrFactory<VaapiVideoDecodeAccelerator> weak_this_factory_; |
315 | 315 |
316 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); | 316 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); |
317 }; | 317 }; |
318 | 318 |
319 } // namespace content | 319 } // namespace media |
320 | 320 |
321 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 321 #endif // MEDIA_GPU_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |