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_DVX_VIDEO_DECODE_ACCELERATOR_H_ | |
6 #define CONTENT_COMMON_GPU_MEDIA_DVX_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/message_loop.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 behind VideoDecodeAccelerator | |
24 // 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: | |
29 typedef enum { | |
30 kUninitialized, // un-initialized. | |
31 kNormal, // normal playing state. | |
32 kResetting, // upon received Reset(), before ResetDone() | |
33 kEosDrain, // upon input EOS received. | |
34 kStopped, // upon output EOS received. | |
35 } State; | |
36 | |
37 // Does not take ownership of |client| which must outlive |*this|. | |
38 explicit DXVAVideoDecodeAccelerator( | |
apatrick_chromium
2011/12/13 02:00:13
nit: explicit is redundant
| |
39 media::VideoDecodeAccelerator::Client* client, | |
40 base::ProcessHandle renderer_process); | |
41 virtual ~DXVAVideoDecodeAccelerator(); | |
42 | |
43 // media::VideoDecodeAccelerator implementation. | |
44 bool Initialize(Profile profile) OVERRIDE; | |
45 void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | |
46 virtual void AssignPictureBuffers( | |
47 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | |
48 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | |
49 void Flush() OVERRIDE; | |
50 void Reset() OVERRIDE; | |
51 void Destroy() OVERRIDE; | |
52 | |
53 private: | |
54 bool CreateD3DDevManager(); | |
55 bool InitDecoder(); | |
56 bool CheckDecoderDxvaSupport(); | |
57 bool SetDecoderMediaTypes(); | |
58 bool SetDecoderInputMediaType(); | |
59 bool SetDecoderOutputMediaType(const GUID& subtype); | |
60 bool SendMFTMessage(MFT_MESSAGE_TYPE msg, int32 param); | |
61 bool GetStreamsInfoAndBufferReqs(); | |
62 bool DoDecode(); | |
63 bool ProcessOutputSample(IMFSample* sample); | |
64 bool CopyOutputSampleDataToPictureBuffer(IDirect3DSurface9* dest_surface, | |
65 media::PictureBuffer buffer, | |
66 int32 input_buffer_id); | |
67 void ProcessPendingSamples(); | |
68 | |
69 private: | |
70 MessageLoop* message_loop_; | |
apatrick_chromium
2011/12/13 02:00:13
MessageLoopProxy might be safer here if there is a
ananta
2011/12/13 02:51:18
Done.
| |
71 // To expose client callbacks from VideoDecodeAccelerator. | |
72 // NOTE: all calls to this object *MUST* be executed in message_loop_. | |
73 media::VideoDecodeAccelerator::Client* client_; | |
74 | |
75 base::win::ScopedComPtr<IDirect3D9> d3d9_; | |
76 base::win::ScopedComPtr<IDirect3DDevice9> device_; | |
77 base::win::ScopedComPtr<IDirect3DDeviceManager9> device_manager_; | |
78 base::win::ScopedComPtr<IMFTransform> decoder_; | |
79 | |
80 UINT32 surface_width_; | |
81 UINT32 surface_height_; | |
82 | |
83 // Current state of the decoder. | |
84 State state_; | |
85 | |
86 MFT_INPUT_STREAM_INFO input_stream_info_; | |
87 MFT_OUTPUT_STREAM_INFO output_stream_info_; | |
88 | |
89 // Contains information about a decoded sample. | |
90 struct PendingSampleInfo { | |
91 base::win::ScopedComPtr<IDirect3DSurface9> surface; | |
92 int32 input_buffer_id; | |
93 }; | |
94 | |
95 typedef std::vector<PendingSampleInfo> | |
96 PendingOutputSamples; | |
97 | |
98 // List of output samples for rendering. | |
99 PendingOutputSamples pending_output_samples_; | |
100 | |
101 // Maintains information about a DXVA picture buffer, i.e. whether it is | |
102 // available for rendering, the texture information, etc. | |
103 struct DXVAPictureBuffer { | |
104 DXVAPictureBuffer() | |
105 : picture_buffer(0, gfx::Size(), 0) { | |
106 available = false; | |
107 } | |
108 bool available; | |
109 media::PictureBuffer picture_buffer; | |
110 }; | |
111 | |
112 typedef std::map<int32, DXVAPictureBuffer> OutputBuffers; | |
113 OutputBuffers available_pictures_; | |
114 | |
115 // Set to true if we requested picture slots from the plugin. | |
116 bool pictures_requested_; | |
117 | |
118 // Contains the list of input buffer ids which map to frame time from the | |
119 // plugin. | |
120 std::vector<int32> input_buffer_frame_times_; | |
121 | |
122 // Handle to the renderer process. | |
123 base::ProcessHandle renderer_process_; | |
124 | |
125 #if !defined(NDEBUG) | |
126 uint32 decode_start_time_; | |
127 int inputs_before_decode_; | |
128 #endif // !defined(NDEBUG) | |
129 }; | |
130 | |
131 #endif // CONTENT_COMMON_GPU_MEDIA_DVX_VIDEO_DECODE_ACCELERATOR_H_ | |
132 | |
OLD | NEW |