Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: content/common/gpu/media/dxva_video_decode_accelerator.h

Issue 765533005: Move the DXVA decoder off the GPU thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ 5 #ifndef CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ 6 #define CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_
7 7
8 #include <d3d9.h> 8 #include <d3d9.h>
9 // Work around bug in this header by disabling the relevant warning for it. 9 // Work around bug in this header by disabling the relevant warning for it.
10 // https://connect.microsoft.com/VisualStudio/feedback/details/911260/dxva2api-h -in-win8-sdk-triggers-c4201-with-w4 10 // https://connect.microsoft.com/VisualStudio/feedback/details/911260/dxva2api-h -in-win8-sdk-triggers-c4201-with-w4
11 #pragma warning(push) 11 #pragma warning(push)
12 #pragma warning(disable:4201) 12 #pragma warning(disable:4201)
13 #include <dxva2api.h> 13 #include <dxva2api.h>
14 #pragma warning(pop) 14 #pragma warning(pop)
15 #include <list> 15 #include <list>
16 #include <map> 16 #include <map>
17 #include <mfidl.h> 17 #include <mfidl.h>
18 #include <vector> 18 #include <vector>
19 19
20 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
21 #include "base/memory/linked_ptr.h" 21 #include "base/memory/linked_ptr.h"
22 #include "base/memory/weak_ptr.h" 22 #include "base/memory/weak_ptr.h"
23 #include "base/synchronization/lock.h"
23 #include "base/threading/non_thread_safe.h" 24 #include "base/threading/non_thread_safe.h"
25 #include "base/threading/thread.h"
24 #include "base/win/scoped_comptr.h" 26 #include "base/win/scoped_comptr.h"
25 #include "content/common/content_export.h" 27 #include "content/common/content_export.h"
26 #include "media/video/video_decode_accelerator.h" 28 #include "media/video/video_decode_accelerator.h"
27 29
28 interface IMFSample; 30 interface IMFSample;
29 interface IDirect3DSurface9; 31 interface IDirect3DSurface9;
30 32
31 namespace content { 33 namespace content {
32 34
33 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media 35 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media
(...skipping 27 matching lines...) Expand all
61 const std::vector<media::PictureBuffer>& buffers) override; 63 const std::vector<media::PictureBuffer>& buffers) override;
62 virtual void ReusePictureBuffer(int32 picture_buffer_id) override; 64 virtual void ReusePictureBuffer(int32 picture_buffer_id) override;
63 virtual void Flush() override; 65 virtual void Flush() override;
64 virtual void Reset() override; 66 virtual void Reset() override;
65 virtual void Destroy() override; 67 virtual void Destroy() override;
66 virtual bool CanDecodeOnIOThread() override; 68 virtual bool CanDecodeOnIOThread() override;
67 69
68 private: 70 private:
69 typedef void* EGLConfig; 71 typedef void* EGLConfig;
70 typedef void* EGLSurface; 72 typedef void* EGLSurface;
73
71 // Creates and initializes an instance of the D3D device and the 74 // Creates and initializes an instance of the D3D device and the
72 // corresponding device manager. The device manager instance is eventually 75 // corresponding device manager. The device manager instance is eventually
73 // passed to the IMFTransform interface implemented by the decoder. 76 // passed to the IMFTransform interface implemented by the decoder.
74 bool CreateD3DDevManager(); 77 bool CreateD3DDevManager();
75 78
76 // Creates, initializes and sets the media codec types for the decoder. 79 // Creates, initializes and sets the media codec types for the decoder.
77 bool InitDecoder(media::VideoCodecProfile profile); 80 bool InitDecoder(media::VideoCodecProfile profile);
78 81
79 // Validates whether the decoder supports hardware video acceleration. 82 // Validates whether the decoder supports hardware video acceleration.
80 bool CheckDecoderDxvaSupport(); 83 bool CheckDecoderDxvaSupport();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 154
152 struct DXVAPictureBuffer; 155 struct DXVAPictureBuffer;
153 typedef std::map<int32, linked_ptr<DXVAPictureBuffer> > OutputBuffers; 156 typedef std::map<int32, linked_ptr<DXVAPictureBuffer> > OutputBuffers;
154 157
155 // Tells the client to dismiss the stale picture buffers passed in. 158 // Tells the client to dismiss the stale picture buffers passed in.
156 void DismissStaleBuffers(); 159 void DismissStaleBuffers();
157 160
158 // Called after the client indicates we can recycle a stale picture buffer. 161 // Called after the client indicates we can recycle a stale picture buffer.
159 void DeferredDismissStaleBuffer(int32 picture_buffer_id); 162 void DeferredDismissStaleBuffer(int32 picture_buffer_id);
160 163
164 // Sets the state of the decoder. Called from the main thread and the decoder
165 // thread. The state is changed on the main thread.
166 void SetState(State state);
167
168 // Gets the state of the decoder. Can be called from the main thread and
169 // the decoder thread. Threadsafe.
DaleCurtis 2014/12/03 22:34:42 Thread safe?
170 State GetState() const;
171
172 // Worker function for the Decoder Reset functionality. Executes on the
173 // decoder thread and queues tasks on the main thread as needed.
174 void ResetHelper();
175
176 // Starts the thread used for decoding.
177 void StartDecoderThread();
178
179 // Returns if we have output samples waiting to be processed. We only
180 // allow one output sample to be present in the output queue at any given
181 // time.
182 bool OutputSamplesPresent();
183
161 // To expose client callbacks from VideoDecodeAccelerator. 184 // To expose client callbacks from VideoDecodeAccelerator.
162 media::VideoDecodeAccelerator::Client* client_; 185 media::VideoDecodeAccelerator::Client* client_;
163 186
164 base::win::ScopedComPtr<IMFTransform> decoder_; 187 base::win::ScopedComPtr<IMFTransform> decoder_;
165 188
166 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_; 189 base::win::ScopedComPtr<IDirect3D9Ex> d3d9_;
167 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_; 190 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_;
168 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; 191 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_;
169 base::win::ScopedComPtr<IDirect3DQuery9> query_; 192 base::win::ScopedComPtr<IDirect3DQuery9> query_;
170 // Ideally the reset token would be a stack variable which is used while 193 // Ideally the reset token would be a stack variable which is used while
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 PendingInputs pending_input_buffers_; 242 PendingInputs pending_input_buffers_;
220 243
221 // Callback to set the correct gl context. 244 // Callback to set the correct gl context.
222 base::Callback<bool(void)> make_context_current_; 245 base::Callback<bool(void)> make_context_current_;
223 246
224 // WeakPtrFactory for posting tasks back to |this|. 247 // WeakPtrFactory for posting tasks back to |this|.
225 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_; 248 base::WeakPtrFactory<DXVAVideoDecodeAccelerator> weak_this_factory_;
226 249
227 // Which codec we are decoding with hardware acceleration. 250 // Which codec we are decoding with hardware acceleration.
228 media::VideoCodec codec_; 251 media::VideoCodec codec_;
252 // Thread on which the decoder operations like passing input frames,
253 // getting output frames are performed. One instance of this thread
254 // is created per decoder instance.
255 base::Thread decoder_thread_;
256
257 // Task runner to be used for posting tasks to the decoder thread.
258 scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_;
259
260 // Task runner to be used for posting tasks to the main thread.
261 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
262
263 // Used to synchronize access between the decoder thread and the main thread.
264 // Currently only used to synchronize access to the pending output samples
265 // queue.
266 base::Lock decoder_lock_;
229 }; 267 };
230 268
231 } // namespace content 269 } // namespace content
232 270
233 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ 271 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698