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