1 /*
2 * DXVA2 HW acceleration.
3 *
4 * copyright (c) 2010 Laurent Aimar
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <assert.h>
24 #include <string.h>
25
28
32
34 {
35 return frame->
data[3];
36 }
37
40 {
42 unsigned i;
43
46 return i;
47
48 assert(0);
49 return 0;
50 }
51
54 DXVA2_DecodeBufferDesc *dsc,
56 unsigned mb_count)
57 {
58 void *dxva_data;
59 unsigned dxva_size;
60 int result;
62
63 hr = IDirectXVideoDecoder_GetBuffer(ctx->
decoder, type,
64 &dxva_data, &dxva_size);
67 type, hr);
68 return -1;
69 }
70 if (size <= dxva_size) {
71 memcpy(dxva_data, data, size);
72
73 memset(dsc, 0, sizeof(*dsc));
74 dsc->CompressedBufferType =
type;
76 dsc->NumMBsInBuffer = mb_count;
77
78 result = 0;
79 } else {
81 result = -1;
82 }
83
84 hr = IDirectXVideoDecoder_ReleaseBuffer(ctx->
decoder, type);
87 "Failed to release buffer type %u: 0x%lx\n",
88 type, hr);
89 result = -1;
90 }
91 return result;
92 }
93
95 const void *pp, unsigned pp_size,
96 const void *qm, unsigned qm_size,
98 DXVA2_DecodeBufferDesc *bs,
99 DXVA2_DecodeBufferDesc *slice))
100 {
102 unsigned buffer_count = 0;
103 DXVA2_DecodeBufferDesc
buffer[4];
104 DXVA2_DecodeExecuteParams exec = { 0 };
105 int result, runs = 0;
107
108 do {
109 hr = IDirectXVideoDecoder_BeginFrame(ctx->
decoder,
112 if (hr == E_PENDING)
114 } while (hr == E_PENDING && ++runs < 50);
115
118 return -1;
119 }
120
122 DXVA2_PictureParametersBufferType,
123 pp, pp_size, 0);
124 if (result) {
126 "Failed to add picture parameter buffer\n");
128 }
129 buffer_count++;
130
131 if (qm_size > 0) {
133 DXVA2_InverseQuantizationMatrixBufferType,
134 qm, qm_size, 0);
135 if (result) {
137 "Failed to add inverse quantization matrix buffer\n");
139 }
140 buffer_count++;
141 }
142
143 result = commit_bs_si(avctx,
144 &buffer[buffer_count + 0],
145 &buffer[buffer_count + 1]);
146 if (result) {
148 "Failed to add bitstream or slice control buffer\n");
150 }
151 buffer_count += 2;
152
153 /* TODO Film Grain when possible */
154
155 assert(buffer_count == 1 + (qm_size > 0) + 2);
156
157 exec.NumCompBuffers = buffer_count;
158 exec.pCompressedBuffers =
buffer;
159 exec.pExtensionData =
NULL;
160 hr = IDirectXVideoDecoder_Execute(ctx->
decoder, &exec);
163 result = -1;
164 }
165
167 hr = IDirectXVideoDecoder_EndFrame(ctx->
decoder,
NULL);
170 result = -1;
171 }
172
173 return result;
174 }