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

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

Issue 8510039: Initial implementation of the DXVA 2.0 H.264 hardware decoder for pepper for Windows. The decodin... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_DXVA_VIDEO_DECODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_
7
8 #include <d3d9.h>
9 #include <dxva2api.h>
10 #include <map>
11 #include <mfidl.h>
12 #include <list>
13
14 #include "base/threading/non_thread_safe.h"
15 #include "base/win/scoped_comptr.h"
16 #include "media/video/video_decode_accelerator.h"
17 #include "third_party/angle/include/EGL/egl.h"
18 #include "third_party/angle/include/EGL/eglext.h"
19
20 interface IMFSample;
21 interface IDirect3DSurface9;
22
23 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media
24 // foundation APIs via the VideoDecodeAccelerator interface.
25 // This class lives on a single thread and DCHECKs that it is never accessed
26 // from any other.
27 class DXVAVideoDecodeAccelerator : public media::VideoDecodeAccelerator,
28 public base::NonThreadSafe {
29 public:
30 enum State {
31 kUninitialized, // un-initialized.
32 kNormal, // normal playing state.
33 kResetting, // upon received Reset(), before ResetDone()
34 kEosDrain, // upon input EOS received.
35 kStopped, // upon output EOS received.
36 };
37
38 // Does not take ownership of |client| which must outlive |*this|.
39 DXVAVideoDecodeAccelerator(
40 media::VideoDecodeAccelerator::Client* client,
41 base::ProcessHandle renderer_process);
42 virtual ~DXVAVideoDecodeAccelerator();
43
44 // media::VideoDecodeAccelerator implementation.
45 virtual bool Initialize(Profile) OVERRIDE;
46 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE;
47 virtual void AssignPictureBuffers(
48 const std::vector<media::PictureBuffer>& buffers) OVERRIDE;
49 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE;
50 virtual void Flush() OVERRIDE;
51 virtual void Reset() OVERRIDE;
52 virtual void Destroy() OVERRIDE;
53
54 private:
55 // Creates and initializes an instance of the D3D device and the
56 // corresponding device manager. The device manager instance is eventually
57 // passed to the IMFTransform interface implemented by the h.264 decoder.
58 bool CreateD3DDevManager();
59
60 // Creates, initializes and sets the media types for the h.264 decoder.
61 bool InitDecoder();
62
63 // Validates if the h.264 decoder supports hardware video acceleration.
Ami GONE FROM CHROMIUM 2011/12/21 00:39:15 s/if/whether/
ananta 2011/12/21 02:59:58 Done.
64 bool CheckDecoderDxvaSupport();
65
66 // Returns information about the input and output streams. This includes
67 // alignment information, decoder support flags, minimum sample size, etc.
68 bool GetStreamsInfoAndBufferReqs();
69
70 // Registers the input and output media types on the h.264 decoder. This
71 // includes the expected input and output formats.
72 bool SetDecoderMediaTypes();
73
74 // Registers the input media type for the h.264 decoder.
75 bool SetDecoderInputMediaType();
76
77 // Registers the output media type for the h.264 decoder.
78 bool SetDecoderOutputMediaType(const GUID& subtype);
79
80 // Passes a command message to the decoder. This includes commands like
81 // start of stream, end of stream, flush, drain the decoder, etc.
82 bool SendMFTMessage(MFT_MESSAGE_TYPE msg, int32 param);
83
84 // The bulk of the decoding happens here. This function handles errors,
85 // format changes and processes decoded output.
86 void DoDecode();
87
88 // Invoked when we have a valid decoded output sample. Retrieves the D3D
89 // surface and maintains a copy of it which is passed eventually to the
90 // client when we have a picture buffer to copy the surface contents to.
91 bool ProcessOutputSample(IMFSample* sample);
92
93 // Copies the output sample data to the picture buffer provided by the
94 // client.
95 bool CopyOutputSampleDataToPictureBuffer(IDirect3DSurface9* dest_surface,
96 media::PictureBuffer picture_buffer,
97 int32 input_buffer_id);
98
99 // Processes pending output samples by copying them to available picture
100 // slots.
101 void ProcessPendingSamples();
102
103 // Clears local state maintained by the decoder.
104 void ClearState();
105
106 // Helper function to notify the accelerator client about the error.
107 void StopOnError(media::VideoDecodeAccelerator::Error error);
108
109 // Transitions the decoder to the uninitialized state. The decoder will stop
110 // accepting requests in this state.
111 void Invalidate();
112
113 // Helper function to read the bitmap from the D3D surface passed in.
114 bool GetBitmapFromSurface(IDirect3DSurface9* surface,
115 scoped_array<char>* bits);
116
117 // Notifies the client that the input buffer identifed by input_buffer_id has
118 // been processed.
119 void NotifyInputBufferRead(int input_buffer_id);
120
121 // Notifies the client that initialize was completed.
122 void NotifyInitializeDone();
123
124 // Notifies the client that the decoder was flushed.
125 void NotifyFlushDone();
126
127 // Notifies the client that the decoder was reset.
128 void NotifyResetDone();
129
130 // Requests picture buffers from the client.
131 void RequestPictureBuffers(int width, int height);
132
133 // Notifies the client about the availability of a picture.
134 void NotifyPictureReady(const media::Picture& picture);
135
136 // To expose client callbacks from VideoDecodeAccelerator.
137 media::VideoDecodeAccelerator::Client* client_;
138
139 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_;
140 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_;
141 base::win::ScopedComPtr<IMFTransform> decoder_;
142
143 // Current state of the decoder.
144 State state_;
145
146 MFT_INPUT_STREAM_INFO input_stream_info_;
147 MFT_OUTPUT_STREAM_INFO output_stream_info_;
148
149 // Contains information about a decoded sample.
150 struct PendingSampleInfo {
151 PendingSampleInfo(int32 buffer_id, IDirect3DSurface9* surface);
152 ~PendingSampleInfo();
153
154 int32 input_buffer_id;
155 base::win::ScopedComPtr<IDirect3DSurface9> dest_surface;
156 };
157
158 typedef std::list<PendingSampleInfo> PendingOutputSamples;
159
160 // List of decoded output samples.
161 PendingOutputSamples pending_output_samples_;
162
163 // Maintains information about a DXVA picture buffer, i.e. whether it is
164 // available for rendering, the texture information, etc.
165 struct DXVAPictureBuffer {
166 DXVAPictureBuffer(const media::PictureBuffer& buffer);
167
168 bool available;
169 media::PictureBuffer picture_buffer;
170 };
171
172 // This map maintains the picture buffers passed the client for decoding.
173 // The key is the picture buffer id.
174 typedef std::map<int32, DXVAPictureBuffer> OutputBuffers;
175 OutputBuffers output_picture_buffers_;
176
177 // Set to true if we requested picture slots from the client.
178 bool pictures_requested_;
179
180 // Contains the id of the last input buffer received from the client.
181 int32 last_input_buffer_id_;
182
183 // Handle to the renderer process.
184 base::ProcessHandle renderer_process_;
185
186 // Ideally the reset token would be a stack variable which is used while
187 // creating the device manager. However it seems that the device manager
188 // holds onto the token and attempts to access it if the underlying device
189 // changes.
190 // TODO(ananta): This needs to be verified.
191 uint32 dev_manager_reset_token_;
192
193 // Counter which holds the number of input packets before a successful
194 // decode.
195 int inputs_before_decode_;
196 };
197
198 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_
199
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698