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
24
26 {
27 return picture->
f.
data[3];
28 }
29
32 {
34 unsigned i;
35
38 return i;
39
40 assert(0);
41 return 0;
42 }
43
46 DXVA2_DecodeBufferDesc *dsc,
47 unsigned type,
const void *
data,
unsigned size,
48 unsigned mb_count)
49 {
50 void *dxva_data;
51 unsigned dxva_size;
52 int result;
53
55 &dxva_data, &dxva_size))) {
57 return -1;
58 }
59 if (size <= dxva_size) {
60 memcpy(dxva_data, data, size);
61
62 memset(dsc, 0, sizeof(*dsc));
63 dsc->CompressedBufferType = type;
65 dsc->NumMBsInBuffer = mb_count;
66
67 result = 0;
68 } else {
70 result = -1;
71 }
72 if (
FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->
decoder, type))) {
74 result = -1;
75 }
76 return result;
77 }
78
80 const void *pp, unsigned pp_size,
81 const void *qm, unsigned qm_size,
83 DXVA2_DecodeBufferDesc *bs,
84 DXVA2_DecodeBufferDesc *slice))
85 {
87 unsigned buffer_count = 0;
88 DXVA2_DecodeBufferDesc
buffer[4];
89 DXVA2_DecodeExecuteParams exec = { 0 };
90 int result;
91
94 NULL))) {
96 return -1;
97 }
98
100 DXVA2_PictureParametersBufferType,
101 pp, pp_size, 0);
102 if (result) {
104 "Failed to add picture parameter buffer\n");
106 }
107 buffer_count++;
108
109 if (qm_size > 0) {
111 DXVA2_InverseQuantizationMatrixBufferType,
112 qm, qm_size, 0);
113 if (result) {
115 "Failed to add inverse quantization matrix buffer\n");
117 }
118 buffer_count++;
119 }
120
121 result = commit_bs_si(avctx,
122 &buffer[buffer_count + 0],
123 &buffer[buffer_count + 1]);
124 if (result) {
126 "Failed to add bitstream or slice control buffer\n");
128 }
129 buffer_count += 2;
130
131 /* TODO Film Grain when possible */
132
133 assert(buffer_count == 1 + (qm_size > 0) + 2);
134
135 exec.NumCompBuffers = buffer_count;
136 exec.pCompressedBuffers =
buffer;
137 exec.pExtensionData = NULL;
138 if (
FAILED(IDirectXVideoDecoder_Execute(ctx->
decoder, &exec))) {
140 result = -1;
141 }
142
144 if (
FAILED(IDirectXVideoDecoder_EndFrame(ctx->
decoder, NULL))) {
146 result = -1;
147 }
148
149 return result;
150 }