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 scoped_ptr<base::SharedMemory> shm, |
| 48 const scoped_refptr<media::VideoFrame>& video_frame); |
| 49 ~DecodeRequest(); |
| 50 |
| 51 media::BitstreamBuffer bitstream_buffer; |
| 52 scoped_ptr<base::SharedMemory> shm; |
| 53 scoped_refptr<media::VideoFrame> video_frame; |
| 54 }; |
| 55 |
| 56 // Notifies the client that an error has occurred and decoding cannot |
| 57 // continue. |
| 58 void NotifyError(int32_t bitstream_buffer_id, Error error); |
| 59 void NotifyErrorFromDecoderThread(int32_t bitstream_buffer_id, Error error); |
| 60 void VideoFrameReady(int32_t bitstream_buffer_id); |
| 61 |
| 62 // Processes one decode |request|. |
| 63 void DecodeTask(const scoped_ptr<DecodeRequest>& request); |
| 64 |
| 65 // Puts contents of |va_surface| into given |video_frame|, releases the |
| 66 // surface and passes the |input_buffer_id| of the resulting picture to |
| 67 // client for output. |
| 68 bool OutputPicture(VASurfaceID va_surface_id, |
| 69 int32_t input_buffer_id, |
| 70 const scoped_refptr<media::VideoFrame>& video_frame); |
| 71 |
| 72 // ChildThread's task runner. |
| 73 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 74 |
| 75 // GPU IO task runner. |
| 76 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 77 |
| 78 // The client of this class. |
| 79 Client* client_; |
| 80 |
| 81 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder |
| 82 // thread back to the ChildThread. Because the decoder thread is a member of |
| 83 // this class, any task running on the decoder thread is guaranteed that this |
| 84 // object is still alive. As a result, tasks posted from ChildThread to |
| 85 // decoder thread should use base::Unretained(this), and tasks posted from the |
| 86 // decoder thread to the ChildThread should use |weak_this_|. |
| 87 base::WeakPtr<VaapiJpegDecodeAccelerator> weak_this_; |
| 88 |
| 89 scoped_ptr<VaapiWrapper> vaapi_wrapper_; |
| 90 |
| 91 // Comes after vaapi_wrapper_ to ensure its destructor is executed before |
| 92 // |vaapi_wrapper_| is destroyed. |
| 93 scoped_ptr<VaapiJpegDecoder> decoder_; |
| 94 base::Thread decoder_thread_; |
| 95 // Use this to post tasks to |decoder_thread_| instead of |
| 96 // |decoder_thread_.task_runner()| because the latter will be NULL once |
| 97 // |decoder_thread_.Stop()| returns. |
| 98 scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; |
| 99 |
| 100 // The current VA surface for decoding. |
| 101 VASurfaceID va_surface_id_; |
| 102 // The coded size associated with |va_surface_id_|. |
| 103 gfx::Size coded_size_; |
| 104 |
| 105 // The WeakPtrFactory for |weak_this_|. |
| 106 base::WeakPtrFactory<VaapiJpegDecodeAccelerator> weak_this_factory_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecodeAccelerator); |
| 109 }; |
| 110 |
| 111 } // namespace content |
| 112 |
| 113 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ |
OLD | NEW |