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 CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
9 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 9 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
26 #include "content/common/content_export.h" | 26 #include "content/common/content_export.h" |
27 #include "content/common/gpu/media/vaapi_h264_decoder.h" | 27 #include "content/common/gpu/media/vaapi_h264_decoder.h" |
28 #include "media/base/bitstream_buffer.h" | 28 #include "media/base/bitstream_buffer.h" |
29 #include "media/video/picture.h" | 29 #include "media/video/picture.h" |
30 #include "media/video/video_decode_accelerator.h" | 30 #include "media/video/video_decode_accelerator.h" |
31 | 31 |
32 // Class to provide video decode acceleration for Intel systems with hardware | 32 // Class to provide video decode acceleration for Intel systems with hardware |
33 // support for it, and on which libva is available. | 33 // support for it, and on which libva is available. |
34 // Decoding tasks are performed in a separate decoding thread. | 34 // Decoding tasks are performed in a separate decoding thread. |
| 35 // |
| 36 // Threading/life-cycle: this object is created & destroyed on the GPU |
| 37 // ChildThread. A few methods on it are called on the decoder thread which is |
| 38 // stopped during |this->Destroy()|, so any tasks posted to the decoder thread |
| 39 // can assume |*this| is still alive. See |weak_this_| below for more details. |
35 class CONTENT_EXPORT VaapiVideoDecodeAccelerator : | 40 class CONTENT_EXPORT VaapiVideoDecodeAccelerator : |
36 public media::VideoDecodeAccelerator { | 41 public media::VideoDecodeAccelerator { |
37 public: | 42 public: |
38 VaapiVideoDecodeAccelerator( | 43 VaapiVideoDecodeAccelerator( |
39 Client* client, | 44 Client* client, |
40 const base::Callback<bool(void)>& make_context_current); | 45 const base::Callback<bool(void)>& make_context_current); |
| 46 virtual ~VaapiVideoDecodeAccelerator(); |
41 | 47 |
42 // media::VideoDecodeAccelerator implementation. | 48 // media::VideoDecodeAccelerator implementation. |
43 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; | 49 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; |
44 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | 50 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
45 virtual void AssignPictureBuffers( | 51 virtual void AssignPictureBuffers( |
46 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | 52 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; |
47 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | 53 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
48 virtual void Flush() OVERRIDE; | 54 virtual void Flush() OVERRIDE; |
49 virtual void Reset() OVERRIDE; | 55 virtual void Reset() OVERRIDE; |
50 virtual void Destroy() OVERRIDE; | 56 virtual void Destroy(scoped_ptr<VideoDecodeAccelerator> self) OVERRIDE; |
51 | 57 |
52 // Used by user of this class to pass X/GLX state. | 58 // Used by user of this class to pass X/GLX state. |
53 void SetGlxState(Display* x_display, GLXContext glx_context); | 59 void SetGlxState(Display* x_display, GLXContext glx_context); |
54 | 60 |
55 private: | 61 private: |
56 virtual ~VaapiVideoDecodeAccelerator(); | |
57 | |
58 // Ensure data has been synced with the output texture and notify | 62 // Ensure data has been synced with the output texture and notify |
59 // the client it is ready for displaying. | 63 // the client it is ready for displaying. |
60 void SyncAndNotifyPictureReady(int32 input_id, int32 output_id); | 64 void SyncAndNotifyPictureReady(int32 input_id, int32 output_id); |
61 | 65 |
62 // Notify the client that an error has occurred and decoding cannot continue. | 66 // Notify the client that an error has occurred and decoding cannot continue. |
63 void NotifyError(Error error); | 67 void NotifyError(Error error); |
64 | 68 |
65 // Map the received input buffer into this process' address space and | 69 // Map the received input buffer into this process' address space and |
66 // queue it for decode. | 70 // queue it for decode. |
67 void MapAndQueueNewInputBuffer( | 71 void MapAndQueueNewInputBuffer( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 171 |
168 // Queue for incoming input buffers. | 172 // Queue for incoming input buffers. |
169 typedef std::queue<int32> OutputBuffers; | 173 typedef std::queue<int32> OutputBuffers; |
170 OutputBuffers output_buffers_; | 174 OutputBuffers output_buffers_; |
171 // Signalled when output buffers are queued onto the output_buffers_ queue. | 175 // Signalled when output buffers are queued onto the output_buffers_ queue. |
172 base::ConditionVariable output_ready_; | 176 base::ConditionVariable output_ready_; |
173 | 177 |
174 // ChildThread's message loop | 178 // ChildThread's message loop |
175 MessageLoop* message_loop_; | 179 MessageLoop* message_loop_; |
176 | 180 |
| 181 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder |
| 182 // thread back to the ChildThread. Because the decoder thread is a member of |
| 183 // this class, any task running on the decoder thread is guaranteed that this |
| 184 // object is still alive. As a result, tasks posted from ChildThread to |
| 185 // decoder thread should use base::Unretained(this), and tasks posted from the |
| 186 // decoder thread to the ChildThread should use |weak_this_|. |
| 187 base::WeakPtr<VaapiVideoDecodeAccelerator> weak_this_; |
| 188 |
177 // To expose client callbacks from VideoDecodeAccelerator. | 189 // To expose client callbacks from VideoDecodeAccelerator. |
178 // NOTE: all calls to these objects *MUST* be executed on message_loop_. | 190 // NOTE: all calls to these objects *MUST* be executed on message_loop_. |
179 base::WeakPtrFactory<Client> client_ptr_factory_; | 191 base::WeakPtrFactory<Client> client_ptr_factory_; |
180 base::WeakPtr<Client> client_; | 192 base::WeakPtr<Client> client_; |
181 | 193 |
182 base::Thread decoder_thread_; | 194 base::Thread decoder_thread_; |
183 content::VaapiH264Decoder decoder_; | 195 content::VaapiH264Decoder decoder_; |
184 | 196 |
185 // Callback passed to the decoder, which it will use to signal readiness | 197 // Callback passed to the decoder, which it will use to signal readiness |
186 // of an output picture to be displayed. | 198 // of an output picture to be displayed. |
187 void OutputPicCallback(int32 input_id, int32 output_id); | 199 void OutputPicCallback(int32 input_id, int32 output_id); |
188 | 200 |
189 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); | 201 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); |
190 }; | 202 }; |
191 | 203 |
192 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 204 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |