OLD | NEW |
---|---|
(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 <vector> | |
13 | |
14 #include "base/task.h" | |
15 #include "base/threading/non_thread_safe.h" | |
16 #include "base/win/scoped_comptr.h" | |
17 #include "build/build_config.h" | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
What for?
ananta
2011/12/17 00:40:25
Removed.
| |
18 #include "media/video/video_decode_accelerator.h" | |
19 #include "third_party/angle/include/EGL/egl.h" | |
20 #include "third_party/angle/include/EGL/eglext.h" | |
21 | |
22 interface IMFSample; | |
23 interface IDirect3DSurface9; | |
24 | |
25 // Class to provide a DXVA 2.0 based accelerator using the Microsoft Media | |
26 // foundation APIs via the VideoDecodeAccelerator interface. | |
27 // This class lives on a single thread and DCHECKs that it is never accessed | |
28 // from any other. | |
29 class DXVAVideoDecodeAccelerator : public media::VideoDecodeAccelerator, | |
30 public base::NonThreadSafe { | |
31 public: | |
32 enum State { | |
33 kUninitialized, // un-initialized. | |
34 kNormal, // normal playing state. | |
35 kResetting, // upon received Reset(), before ResetDone() | |
36 kEosDrain, // upon input EOS received. | |
37 kStopped, // upon output EOS received. | |
38 }; | |
39 | |
40 // Does not take ownership of |client| which must outlive |*this|. | |
41 DXVAVideoDecodeAccelerator( | |
42 media::VideoDecodeAccelerator::Client* client, | |
43 base::ProcessHandle renderer_process); | |
44 virtual ~DXVAVideoDecodeAccelerator(); | |
45 | |
46 // media::VideoDecodeAccelerator implementation. | |
47 virtual bool Initialize(Profile profile) OVERRIDE; | |
48 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | |
49 virtual void AssignPictureBuffers( | |
50 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | |
51 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | |
52 virtual void Flush() OVERRIDE; | |
53 virtual void Reset() OVERRIDE; | |
54 virtual void Destroy() OVERRIDE; | |
55 | |
56 private: | |
57 // Creates and initializes an instance of the D3D device and the | |
58 // corresponding device manager. The device manager instance is eventually | |
59 // passed to the IMFTransform interface implemented by the H264 decoder. | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
s/H264/h.264/ here and elsewhere in the CL.
ananta
2011/12/17 00:40:25
Done.
| |
60 bool CreateD3DDevManager(); | |
61 | |
62 // Creates, initializes and sets the media types for the H264 decoder. | |
63 bool InitDecoder(); | |
64 | |
65 // Returns true if the H264 decoder supports hardware video acceleration. | |
66 bool CheckDecoderDxvaSupport(); | |
67 | |
68 // Returns information about the input and output streams. This includes | |
69 // alignment information, decoder support flags, minimum sample size, etc. | |
70 bool GetStreamsInfoAndBufferReqs(); | |
71 | |
72 // Registers the input and output media types on the H264 decoder. This | |
73 // includes the expected input and output formats. | |
74 bool SetDecoderMediaTypes(); | |
75 | |
76 // Registers the input media type for the H264 decoder. | |
77 bool SetDecoderInputMediaType(); | |
78 | |
79 // Registers the output media type for the H264 decoder. | |
80 bool SetDecoderOutputMediaType(const GUID& subtype); | |
81 | |
82 // Passes a command message to the decoder. This includes commands like | |
83 // start of stream, end of stream, flush, drain the decoder, etc. | |
84 bool SendMFTMessage(MFT_MESSAGE_TYPE msg, int32 param); | |
85 | |
86 // The bulk of the decoding happens here. This function handles errors, | |
87 // format changes and processes decoded output. | |
88 void DoDecode(); | |
89 | |
90 // Invoked when we have a valid decoded output sample. Retrieves the D3D | |
91 // surface and maintains a copy of it which is passed eventually to the | |
92 // client when we have a picture buffer to copy the surface contents to. | |
93 bool ProcessOutputSample(IMFSample* sample); | |
94 | |
95 // Copies the output sample data to the picture buffer provided by the | |
96 // client. | |
97 bool CopyOutputSampleDataToPictureBuffer(IDirect3DSurface9* dest_surface, | |
98 media::PictureBuffer picture_buffer, | |
99 int32 input_buffer_id); | |
100 // Processes pending output samples by copying them to available picture | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
precede with newline
ananta
2011/12/17 00:40:25
Done.
| |
101 // slots. | |
102 void ProcessPendingSamples(); | |
103 | |
104 // Clears local state maintained by the decoder. | |
105 void ClearState(); | |
106 | |
107 // Helper function to notify the accelerator client about the error. | |
108 void NotifyError(media::VideoDecodeAccelerator::Error error); | |
109 | |
110 // Helper function to read the bitmap from the D3D surface passed in. | |
111 bool GetBitmapFromSurface(IDirect3DSurface9* surface, | |
112 scoped_array<char>* bits); | |
113 | |
114 // To expose client callbacks from VideoDecodeAccelerator. | |
115 media::VideoDecodeAccelerator::Client* client_; | |
116 | |
117 base::win::ScopedComPtr<IDirect3DDevice9Ex> device_; | |
118 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; | |
119 base::win::ScopedComPtr<IMFTransform> decoder_; | |
120 | |
121 // Current state of the decoder. | |
122 State state_; | |
123 | |
124 MFT_INPUT_STREAM_INFO input_stream_info_; | |
125 MFT_OUTPUT_STREAM_INFO output_stream_info_; | |
126 | |
127 // Contains information about a decoded sample. | |
128 struct PendingSampleInfo { | |
129 PendingSampleInfo(int32 buffer_id, IDirect3DSurface9* surface); | |
130 | |
131 int32 input_buffer_id; | |
132 base::win::ScopedComPtr<IDirect3DSurface9> dest_surface; | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
This field makes it ~PendingSampleInfo() non-trivi
ananta
2011/12/17 00:40:25
Done.
| |
133 }; | |
134 | |
135 typedef std::vector<PendingSampleInfo> PendingOutputSamples; | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
Given the ways this is used a list<> makes more se
ananta
2011/12/17 00:40:25
Done.
| |
136 | |
137 // List of output samples for DXVAVideoDecodeAcceleratorrendering. | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
s/rr/r r/
ananta
2011/12/17 00:40:25
Done.
| |
138 PendingOutputSamples pending_output_samples_; | |
139 | |
140 // Maintains information about a DXVA picture buffer, i.e. whether it is | |
141 // available for rendering, the texture information, etc. | |
142 struct DXVAPictureBuffer { | |
143 DXVAPictureBuffer(bool is_available, const media::PictureBuffer& buffer); | |
144 DXVAPictureBuffer(); | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
Can you drop this ctor?
(I suspect you needed it o
ananta
2011/12/17 00:40:25
Done.
| |
145 | |
146 bool available; | |
147 media::PictureBuffer picture_buffer; | |
148 }; | |
149 | |
150 // This map maintains the picture buffers passed the client for decoding. | |
151 // The key is the picture buffer id. | |
152 typedef std::map<int32, DXVAPictureBuffer> OutputBuffers; | |
153 OutputBuffers output_picture_buffers_; | |
154 | |
155 // Set to true if we requested picture slots from the client. | |
156 bool pictures_requested_; | |
157 | |
158 // Contains the id of the last input buffer received from the client. | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
Can you drop this in favor of simply passing the b
ananta
2011/12/17 00:40:25
DoDecode also gets called from Flush which drains
Ami GONE FROM CHROMIUM
2011/12/19 22:53:44
Decode's synchronous implementation means Flush()
| |
159 int32 last_input_buffer_id_; | |
160 | |
161 // Handle to the renderer process. | |
162 base::ProcessHandle renderer_process_; | |
163 | |
164 uint32 dev_manager_reset_token_; | |
Ami GONE FROM CHROMIUM
2011/12/16 07:38:54
This needs a great big comment on it, if its only
ananta
2011/12/17 00:40:25
Added a comment for now. Will look into this along
| |
165 | |
166 scoped_ptr<ScopedRunnableMethodFactory< | |
167 media::VideoDecodeAccelerator::Client> > method_factory_; | |
168 | |
169 // Counter which holds the number of input packets before a successful | |
170 // decode. | |
171 int inputs_before_decode_; | |
172 }; | |
173 | |
174 #endif // CONTENT_COMMON_GPU_MEDIA_DXVA_VIDEO_DECODE_ACCELERATOR_H_ | |
175 | |
OLD | NEW |