-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
DXVA.h
152 lines (126 loc) · 4.59 KB
/
DXVA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright (C) 2005-2009 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "DllAvCodec.h"
#include "DVDCodecs/Video/DVDVideoCodecFFmpeg.h"
#include "guilib/D3DResource.h"
#include "threads/Event.h"
#include "DVDResource.h"
#include <dxva2api.h>
#include <deque>
#include <vector>
namespace DXVA {
class CProcessor;
class CDecoder
: public CDVDVideoCodecFFmpeg::IHardwareDecoder
, public ID3DResource
{
public:
CDecoder();
~CDecoder();
virtual bool Open (AVCodecContext* avctx, const enum PixelFormat);
virtual int Decode (AVCodecContext* avctx, AVFrame* frame);
virtual bool GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture);
virtual int Check (AVCodecContext* avctx);
virtual void Close();
virtual const std::string Name() { return "dxva2"; }
bool OpenProcessor();
bool OpenTarget(const GUID &guid);
bool OpenDecoder();
int GetBuffer(AVCodecContext *avctx, AVFrame *pic);
void RelBuffer(AVCodecContext *avctx, AVFrame *pic);
static bool Supports(enum PixelFormat fmt);
protected:
enum EDeviceState
{ DXVA_OPEN
, DXVA_RESET
, DXVA_LOST
} m_state;
virtual void OnCreateDevice() {}
virtual void OnDestroyDevice() { CSingleLock lock(m_section); m_state = DXVA_LOST; m_event.Reset(); }
virtual void OnLostDevice() { CSingleLock lock(m_section); m_state = DXVA_LOST; m_event.Reset(); }
virtual void OnResetDevice() { CSingleLock lock(m_section); m_state = DXVA_RESET; m_event.Set(); }
struct SVideoBuffer
{
SVideoBuffer();
~SVideoBuffer();
void Clear();
IDirect3DSurface9* surface;
bool used;
int age;
};
IDirectXVideoDecoderService* m_service;
IDirectXVideoDecoder* m_decoder;
HANDLE m_device;
GUID m_input;
DXVA2_VideoDesc m_format;
static const unsigned m_buffer_max = 32;
SVideoBuffer m_buffer[m_buffer_max];
unsigned m_buffer_count;
unsigned m_buffer_age;
int m_refs;
struct dxva_context* m_context;
CProcessor* m_processor;
CCriticalSection m_section;
CEvent m_event;
};
class CProcessor
: public ID3DResource
, public IDVDResourceCounted<CProcessor>
{
public:
CProcessor();
~CProcessor();
bool Open(UINT width, UINT height, unsigned int flags);
bool Open(const DXVA2_VideoDesc& dsc);
bool CreateSurfaces();
void Close();
void HoldSurface(IDirect3DSurface9* surface);
REFERENCE_TIME Add(IDirect3DSurface9* source);
bool ProcessPicture(DVDVideoPicture* picture);
bool Render(const RECT& src, const RECT& dst, IDirect3DSurface9* target, const REFERENCE_TIME time);
int Size() { return m_size; }
virtual void OnCreateDevice() {}
virtual void OnDestroyDevice() { CSingleLock lock(m_section); Close(); }
virtual void OnLostDevice() { CSingleLock lock(m_section); Close(); }
virtual void OnResetDevice() { CSingleLock lock(m_section); Close(); }
protected:
bool Open(UINT width, UINT height, unsigned int flags, D3DFORMAT format);
IDirectXVideoProcessorService* m_service;
IDirectXVideoProcessor* m_process;
GUID m_device;
DXVA2_VideoProcessorCaps m_caps;
DXVA2_VideoDesc m_desc;
DXVA2_ValueRange m_brightness;
DXVA2_ValueRange m_contrast;
DXVA2_ValueRange m_hue;
DXVA2_ValueRange m_saturation;
REFERENCE_TIME m_time;
unsigned m_size;
unsigned m_index;
typedef std::deque<DXVA2_VideoSample> SSamples;
SSamples m_sample;
CCriticalSection m_section;
std::vector<IDirect3DSurface9*> m_heldsurfaces;
LPDIRECT3DSURFACE9* m_surfaces;
unsigned m_surfaces_count;
};
};