Chromium Code Reviews| 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 <queue> | |
| 9 | |
| 10 #include "base/memory/linked_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/message_loop/message_loop.h" | |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "base/threading/non_thread_safe.h" | |
| 15 #include "base/threading/thread.h" | |
| 16 #include "content/common/content_export.h" | |
| 17 #include "content/common/gpu/media/vaapi_jpeg_decoder.h" | |
| 18 #include "content/common/gpu/media/vaapi_wrapper.h" | |
| 19 #include "media/base/bitstream_buffer.h" | |
| 20 #include "media/video/jpeg_decode_accelerator.h" | |
| 21 #include "media/video/picture.h" | |
| 22 | |
| 23 namespace content { | |
| 24 | |
| 25 // Class to provide JPEG decode acceleration for Intel systems with hardware | |
| 26 // support for it, and on which libva is available. | |
| 27 // Decoding tasks are performed in a separate decoding thread. | |
| 28 // | |
| 29 // Threading/life-cycle: this object is created & destroyed on the GPU | |
| 30 // ChildThread. A few methods on it are called on the decoder thread which is | |
| 31 // stopped during |this->Destroy()|, so any tasks posted to the decoder thread | |
| 32 // can assume |*this| is still alive. See |weak_this_| below for more details. | |
| 33 class CONTENT_EXPORT VaapiJpegDecodeAccelerator | |
| 34 : public media::JpegDecodeAccelerator { | |
| 35 public: | |
| 36 VaapiJpegDecodeAccelerator( | |
| 37 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); | |
| 38 ~VaapiJpegDecodeAccelerator() override; | |
| 39 | |
| 40 // media::JpegDecodeAccelerator implementation. | |
| 41 bool Initialize(media::JpegDecodeAccelerator::Client* client) override; | |
| 42 void Decode(const media::BitstreamBuffer& bitstream_buffer, | |
| 43 const scoped_refptr<media::VideoFrame>& video_frame) override; | |
| 44 void Destroy() override; | |
| 45 | |
| 46 private: | |
| 47 // Notifies the client that an error has occurred and decoding cannot | |
| 48 // continue. | |
| 49 void NotifyError(int32_t bitstream_buffer_id, Error error); | |
| 50 | |
| 51 // Processes one decode request in the queue. | |
| 52 void DecodeTask(); | |
| 53 | |
| 54 // Helper for Destroy(), doing all the actual work except for deleting self. | |
| 55 void Cleanup(); | |
| 56 | |
| 57 // Puts contents of |va_surface| into given |video_frame|, releases the | |
| 58 // surface and passes the buffer id of the resulting picture to client for | |
| 59 // output. | |
| 60 bool OutputPicture(VASurfaceID va_surface_id, | |
| 61 int32_t input_buffer_id, | |
| 62 const scoped_refptr<media::VideoFrame>& video_frame); | |
| 63 | |
| 64 // VAVDA state. | |
| 65 enum State { | |
|
wuchengli
2015/05/13 15:04:07
remove
kcwu
2015/05/25 18:20:36
Done.
| |
| 66 // Initialize() not called yet or failed. | |
| 67 kUninitialized, | |
| 68 // Initialize() succeeded. | |
| 69 kInitialized, | |
| 70 }; | |
| 71 | |
| 72 // Protects |decode_requests_| and |initialized_|. | |
| 73 base::Lock lock_; | |
| 74 bool initialized_; | |
| 75 | |
| 76 // An input buffer and the corresponding output video frame awaiting | |
| 77 // consumption, provided by the client. | |
| 78 struct DecodeRequest { | |
| 79 DecodeRequest(const media::BitstreamBuffer& bitstream_buffer, | |
| 80 scoped_refptr<media::VideoFrame> video_frame); | |
| 81 ~DecodeRequest(); | |
| 82 | |
| 83 media::BitstreamBuffer bitstream_buffer; | |
| 84 scoped_refptr<media::VideoFrame> video_frame; | |
| 85 }; | |
| 86 | |
| 87 // Queue for incoming decode requests. | |
| 88 typedef std::queue<linked_ptr<DecodeRequest>> DecodeRequests; | |
| 89 DecodeRequests decode_requests_; | |
| 90 | |
| 91 // ChildThread's message loop | |
| 92 base::MessageLoop* message_loop_; | |
| 93 | |
| 94 // GPU IO message loop. | |
| 95 scoped_refptr<base::MessageLoopProxy> io_message_loop_; | |
| 96 | |
| 97 // To expose client callbacks from JpegDecodeAccelerator. | |
| 98 // NOTE: all calls to these objects *MUST* be executed on message_loop_. | |
|
wuchengli
2015/05/13 15:04:07
s/message_loop_/|message_loop_|/
kcwu
2015/05/25 18:20:35
Done.
| |
| 99 scoped_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; | |
| 100 base::WeakPtr<Client> client_; | |
| 101 | |
| 102 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder | |
| 103 // thread back to the ChildThread. Because the decoder thread is a member of | |
| 104 // this class, any task running on the decoder thread is guaranteed that this | |
| 105 // object is still alive. As a result, tasks posted from ChildThread to | |
| 106 // decoder thread should use base::Unretained(this), and tasks posted from the | |
| 107 // decoder thread to the ChildThread should use |weak_this_|. | |
| 108 base::WeakPtr<VaapiJpegDecodeAccelerator> weak_this_; | |
| 109 | |
| 110 scoped_ptr<VaapiWrapper> vaapi_wrapper_; | |
| 111 | |
| 112 // Comes after vaapi_wrapper_ to ensure its destructor is executed before | |
| 113 // vaapi_wrapper_ is destroyed. | |
|
wuchengli
2015/05/13 15:04:07
s/vaapi_wrapper_/|vaapi_wrapper_|/
kcwu
2015/05/25 18:20:36
Done.
| |
| 114 scoped_ptr<VaapiJpegDecoder> decoder_; | |
| 115 base::Thread decoder_thread_; | |
| 116 // Use this to post tasks to |decoder_thread_| instead of | |
| 117 // |decoder_thread_.message_loop()| because the latter will be NULL once | |
| 118 // |decoder_thread_.Stop()| returns. | |
| 119 scoped_refptr<base::MessageLoopProxy> decoder_thread_proxy_; | |
| 120 | |
| 121 VASurfaceID va_surface_; | |
| 122 gfx::Size last_coded_size_; | |
|
wuchengli
2015/05/13 15:04:07
Add variable comment for these two variables.
kcwu
2015/05/25 18:20:35
Done.
| |
| 123 | |
| 124 // The WeakPtrFactory for |weak_this_|. | |
| 125 base::WeakPtrFactory<VaapiJpegDecodeAccelerator> weak_this_factory_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(VaapiJpegDecodeAccelerator); | |
| 128 }; | |
| 129 | |
| 130 } // namespace content | |
| 131 | |
| 132 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_DECODE_ACCELERATOR_H_ | |
| OLD | NEW |