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() 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // an idle state, ready to resume if needed, discarding decoded but not yet | 113 // an idle state, ready to resume if needed, discarding decoded but not yet |
110 // outputted pictures (decoder keeps ownership of their associated picture | 114 // outputted pictures (decoder keeps ownership of their associated picture |
111 // buffers). Schedules a FinishReset afterwards. | 115 // buffers). Schedules a FinishReset afterwards. |
112 void ResetTask(); | 116 void ResetTask(); |
113 | 117 |
114 // Scheduled by ResetTask after it's done putting VAVDA into an idle state. | 118 // Scheduled by ResetTask after it's done putting VAVDA into an idle state. |
115 // Drops remaining input buffers and notifies the client that reset has been | 119 // Drops remaining input buffers and notifies the client that reset has been |
116 // finished. | 120 // finished. |
117 void FinishReset(); | 121 void FinishReset(); |
118 | 122 |
| 123 // Helper for Destroy(), doing all the actual work except for deleting self. |
| 124 void Cleanup(); |
| 125 |
119 // Client-provided X/GLX state. | 126 // Client-provided X/GLX state. |
120 Display* x_display_; | 127 Display* x_display_; |
121 GLXContext glx_context_; | 128 GLXContext glx_context_; |
122 base::Callback<bool(void)> make_context_current_; | 129 base::Callback<bool(void)> make_context_current_; |
123 | 130 |
124 // VAVDA state. | 131 // VAVDA state. |
125 enum State { | 132 enum State { |
126 // Initialize() not called yet or failed. | 133 // Initialize() not called yet or failed. |
127 kUninitialized, | 134 kUninitialized, |
128 // Initialize() succeeded, no initial decode and no pictures requested. | 135 // Initialize() succeeded, no initial decode and no pictures requested. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 174 |
168 // Queue for incoming input buffers. | 175 // Queue for incoming input buffers. |
169 typedef std::queue<int32> OutputBuffers; | 176 typedef std::queue<int32> OutputBuffers; |
170 OutputBuffers output_buffers_; | 177 OutputBuffers output_buffers_; |
171 // Signalled when output buffers are queued onto the output_buffers_ queue. | 178 // Signalled when output buffers are queued onto the output_buffers_ queue. |
172 base::ConditionVariable output_ready_; | 179 base::ConditionVariable output_ready_; |
173 | 180 |
174 // ChildThread's message loop | 181 // ChildThread's message loop |
175 MessageLoop* message_loop_; | 182 MessageLoop* message_loop_; |
176 | 183 |
| 184 // WeakPtr<> pointing to |this| for use in posting tasks from the decoder |
| 185 // thread back to the ChildThread. Because the decoder thread is a member of |
| 186 // this class, any task running on the decoder thread is guaranteed that this |
| 187 // object is still alive. As a result, tasks posted from ChildThread to |
| 188 // decoder thread should use base::Unretained(this), and tasks posted from the |
| 189 // decoder thread to the ChildThread should use |weak_this_|. |
| 190 base::WeakPtr<VaapiVideoDecodeAccelerator> weak_this_; |
| 191 |
177 // To expose client callbacks from VideoDecodeAccelerator. | 192 // To expose client callbacks from VideoDecodeAccelerator. |
178 // NOTE: all calls to these objects *MUST* be executed on message_loop_. | 193 // NOTE: all calls to these objects *MUST* be executed on message_loop_. |
179 base::WeakPtrFactory<Client> client_ptr_factory_; | 194 base::WeakPtrFactory<Client> client_ptr_factory_; |
180 base::WeakPtr<Client> client_; | 195 base::WeakPtr<Client> client_; |
181 | 196 |
182 base::Thread decoder_thread_; | 197 base::Thread decoder_thread_; |
183 content::VaapiH264Decoder decoder_; | 198 content::VaapiH264Decoder decoder_; |
184 | 199 |
185 // Callback passed to the decoder, which it will use to signal readiness | 200 // Callback passed to the decoder, which it will use to signal readiness |
186 // of an output picture to be displayed. | 201 // of an output picture to be displayed. |
187 void OutputPicCallback(int32 input_id, int32 output_id); | 202 void OutputPicCallback(int32 input_id, int32 output_id); |
188 | 203 |
189 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); | 204 DISALLOW_COPY_AND_ASSIGN(VaapiVideoDecodeAccelerator); |
190 }; | 205 }; |
191 | 206 |
192 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ | 207 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |