1 /*
2 * Copyright (c) 2017 Jun Zhao
3 * Copyright (c) 2017 Kaixuan Liu
4 *
5 * HW Acceleration API (video decoding) decode sample
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26 /**
27 * @file HW-accelerated decoding API usage.example
28 * @example hw_decode.c
29 *
30 * Perform HW-accelerated decoding with output frames from HW video
31 * surfaces.
32 */
33
34 #include <stdio.h>
35
43
47
49 {
50 int err = 0;
51
54 fprintf(stderr, "Failed to create specified HW device.\n");
55 return err;
56 }
58
59 return err;
60 }
61
64 {
66
69 return *p;
70 }
71
72 fprintf(stderr, "Failed to get HW surface format.\n");
74 }
75
77 {
83
86 fprintf(stderr, "Error during decoding\n");
88 }
89
90 while (1) {
92 fprintf(stderr, "Can not alloc frame\n");
95 }
96
101 return 0;
102 }
else if (
ret < 0) {
103 fprintf(stderr, "Error while decoding\n");
105 }
106
108 /* retrieve data from GPU to CPU */
110 fprintf(stderr, "Error transferring the data to system memory\n");
112 }
113 tmp_frame = sw_frame;
114 } else
116
121 fprintf(stderr, "Can not alloc buffer\n");
124 }
126 (
const uint8_t *
const *)tmp_frame->
data,
130 fprintf(stderr, "Can not copy image to buffer\n");
132 }
133
135 fprintf(stderr, "Failed to dump raw data.\n");
137 }
138
145 }
146 }
147
148 int main(
int argc,
char *argv[])
149 {
158
159 if (argc < 4) {
160 fprintf(stderr, "Usage: %s <device type> <input file> <output file>\n", argv[0]);
161 return -1;
162 }
163
166 fprintf(stderr, "Device type %s is not supported.\n", argv[1]);
167 fprintf(stderr, "Available device types:");
170 fprintf(stderr, "\n");
171 return -1;
172 }
173
175 if (!packet) {
176 fprintf(stderr, "Failed to allocate AVPacket\n");
177 return -1;
178 }
179
180 /* open the input file */
182 fprintf(stderr, "Cannot open input file '%s'\n", argv[2]);
183 return -1;
184 }
185
187 fprintf(stderr, "Cannot find input stream information.\n");
188 return -1;
189 }
190
191 /* find the video stream information */
194 fprintf(stderr, "Cannot find a video stream in the input file\n");
195 return -1;
196 }
198
202 fprintf(stderr, "Decoder %s does not support device type %s.\n",
204 return -1;
205 }
209 break;
210 }
211 }
212
215
218 return -1;
219
221
223 return -1;
224
226 fprintf(stderr,
"Failed to open codec for stream #%u\n",
video_stream);
227 return -1;
228 }
229
230 /* open the file to dump raw data */
232
233 /* actual decoding and dump the raw data */
236 break;
237
240
242 }
243
244 /* flush the decoder */
246
253
254 return 0;
255 }