OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ |
| 7 |
| 8 #include "base/memory/linked_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/synchronization/lock.h" |
| 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "base/threading/thread.h" |
| 14 #include "content/common/content_export.h" |
| 15 #include "content/common/gpu/media/vaapi_jpeg_decoder.h" |
| 16 #include "content/common/gpu/media/vaapi_wrapper.h" |
| 17 #include "media/base/bitstream_buffer.h" |
| 18 #include "media/video/jpeg_decode_accelerator.h" |
| 19 |
| 20 namespace content { |
| 21 |
| 22 // Class to provide JPEG decode acceleration for Intel systems with hardware |
| 23 // support for it, and on which libva is available. |
| 24 // Decoding tasks are performed in a separate decoding thread. |
| 25 // |
| 26 // Threading/life-cycle: this object is created & destroyed on the GPU |
| 27 // ChildThread. A few methods on it are called on the decoder thread which is |
| 28 // stopped during |this->Destroy()|, so any tasks posted to the decoder thread |
| 29 // can assume |*this| is still alive. See |weak_this_| below for more details. |
| 30 class CONTENT_EXPORT VaapiJpegDecodeAccelerator |
| 31 : public media::JpegDecodeAccelerator { |
| 32 public: |
| 33 VaapiJpegDecodeAccelerator( |
| 34 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 35 ~VaapiJpegDecodeAccelerator() override; |
| 36 |
| 37 // media::JpegDecodeAccelerator implementation. |
| 38 bool Initialize(media::JpegDecodeAccelerator::Client* client) override; |
| 39 void Decode(const media::BitstreamBuffer& bitstream_buffer, |
| 40 const scoped_refptr<media::VideoFrame>& video_frame) override; |
| 41 |
| 42 private: |
| 43 // An input buffer and the corresponding output video frame awaiting |
| 44 // consumption, provided by the client. |
| 45 struct DecodeRequest { |
| 46 DecodeRequest(const media::BitstreamBuffer& bitstream_buffer, |
| 47 const scoped_refptr<media::VideoFrame>& video_frame); |
| 48 ~DecodeRequest(); |
| 49 |
| 50 media::BitstreamBuffer bitstream_buffer; |
| 51 scoped_refptr<media::VideoFrame> video_frame; |
| 52 }; |
| 53 |
| 54 // Notifies the client that an error has occurred and decoding cannot |
| 55 // continue. |
| 56 void NotifyError(int32_t bitstream_buffer_id, Error error); |
| 57 void NotifyErrorFromDecoderThread(int32_t bitstream_buffer_id, Error error); |
| 58 void VideoFrameReady(int32_t bitstream_buffer_id); |
| 59 |
| 60 // Processes one decode |request|. |
| 61 void DecodeTask(const scoped_ptr<DecodeRequest>& request); |
| 62 |
| 63 // Puts contents of |va_surface| into given |video_frame|, releases the |
| 64 // surface and passes the |input_buffer_id| of the resulting picture to |
| 65 // client for output. |
| 66 bool OutputPicture(VASurfaceID va_surface_id, |
| 67 int32_t input_buffer_id, |
| 68 const scoped_refptr<media::VideoFrame>& video_frame); |
| 69 |
| 70 // ChildThread's task runner. |
| 71 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 72 |
| 73 // GPU IO task runner. |
| 74 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 75 |
| 76 // The client of this class. |
| 77 Client* client_; |
| 78 |
| 79 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder |
| 80 // thread back to the ChildThread. Because the decoder thread is a member of |
| 81 // this class, any task running on the decoder thread is guaranteed that this |
| 82 // object is still alive. As a result, tasks posted from ChildThread to |
| 83 // decoder thread should use base::Unretained(this), and tasks posted from the |
| 84 // decoder thread to the ChildThread should use |weak_this_|. |
| 85 base::WeakPtr<VaapiJpegDecodeAccelerator> weak_this_; |
| 86 |
| 87 scoped_ptr<VaapiWrapper> vaapi_wrapper_; |
| 88 |
| 89 // Comes after vaapi_wrapper_ to ensure its destructor is executed before |
| 90 // |vaapi_wrapper_| is destroyed. |
| 91 scoped_ptr<VaapiJpegDecoder> decoder_; |
| 92 base::Thread decoder_thread_; |
| 93 // Use this to post tasks to |decoder_thread_| instead of |
| 94 // |decoder_thread_.task_runner()| because the latter will be NULL once |
| 95 // |decoder_thread_.Stop()| returns. |
| 96 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; |
| 97 |
| 98 // The current VA surface for decoding. |
| 99 VASurfaceID va_surface_id_; |
| 100 // The coded size associated with |va_surface_id_|. |
| 101 gfx::Size coded_size_; |
| 102 |
| 103 // The WeakPtrFactory for |weak_this_|. |
| 104 base::WeakPtrFactory<VaapiJpegDecodeAccelerator> weak_this_factory_; |
| 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecodeAccelerator); |
| 107 }; |
| 108 |
| 109 } // namespace content |
| 110 |
| 111 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ |
OLD | NEW |