1 /*
2 * This file is part of FFmpeg.
3 *
4 * Copyright (c) 2024 James Almer <jamrial@gmail.com>
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdint.h>
22
23 #include <LCEVC/lcevc_dec.h>
24
29
34
36 {
39 return LCEVC_I420_8;
41 return LCEVC_I420_10_LE;
43 return LCEVC_NV12_8;
45 return LCEVC_NV21_8;
47 return LCEVC_GRAY_8;
49 return LCEVC_GRAY_10_LE;
50 }
51
52 return LCEVC_ColorFormat_Unknown;
53 }
54
56 {
59 return LCEVC_ColorRange_Limited;
61 return LCEVC_ColorRange_Full;
62 }
63
64 return LCEVC_ColorRange_Unknown;
65 }
66
68 {
70 case LCEVC_ColorRange_Limited:
72 case LCEVC_ColorRange_Full:
74 }
75
77 }
78
80 LCEVC_PictureHandle *picture)
81 {
84 LCEVC_PictureDesc
desc;
89 LCEVC_ReturnCode res;
90
92 if (res != LCEVC_Success) {
95 }
96
100 }
101
110 desc.matrixCoefficients = (LCEVC_MatrixCoefficients)in->
colorspace;
111 desc.transferCharacteristics = (LCEVC_TransferCharacteristics)in->
color_trc;
114 "SAR %d:%d\n",
118
120 if (res != LCEVC_Success) {
123 }
124
125 return 0;
126 }
127
129 {
132 LCEVC_PictureHandle picture;
134 LCEVC_ReturnCode res;
136
140
141 if (sd) {
143 if (res == LCEVC_Again)
145 else if (res != LCEVC_Success) {
148 }
149 }
150
151 res = LCEVC_SendDecoderBase(lcevc->
decoder, in->
pts, picture, -1, in);
152 if (res != LCEVC_Success) {
154 LCEVC_FreePicture(lcevc->
decoder, picture);
156 }
157
158 return 0;
159 }
160
162 LCEVC_PictureHandle *picture)
163 {
166 LCEVC_PictureDesc
desc;
169 LCEVC_ReturnCode res;
170
171 res = LCEVC_DefaultPictureDesc(&
desc, fmt,
out->width,
out->height);
172 if (res != LCEVC_Success)
174
178 }
179
181 if (res != LCEVC_Success) {
182 av_log(
ctx,
AV_LOG_ERROR,
"LCEVC_AllocPictureExternal to allocate a buffer for an enhanced frame\n");
184 }
185
186 return 0;
187 }
188
190 {
194 LCEVC_PictureDesc
desc;
195 LCEVC_DecodeInformation
info;
196 LCEVC_PictureHandle picture;
197 LCEVC_ReturnCode res;
198
199 res = LCEVC_ReceiveDecoderPicture(lcevc->
decoder, &picture, &
info);
200 if (res == LCEVC_Again) {
206 return 0;
207 }
208 // this shouldn't be reachable, but instead of asserting, just error out
210 } else if (res != LCEVC_Success) {
213 }
214
217
219
220 res = LCEVC_GetPictureDesc(lcevc->
decoder, picture, &
desc);
221 LCEVC_FreePicture(lcevc->
decoder, picture);
222
224 out->crop_bottom =
desc.cropBottom;
225 out->crop_left =
desc.cropLeft;
226 out->crop_right =
desc.cropRight;
233 out->width = outlink->
w =
desc.width +
out->crop_left +
out->crop_right;
234 out->height = outlink->
h =
desc.height +
out->crop_top +
out->crop_bottom;
235
238 "SAR %d:%d, "
239 "hasEnhancement %d, enhanced %d\n",
241 out->crop_top,
out->crop_bottom,
out->crop_left,
out->crop_right,
242 out->sample_aspect_ratio.num,
out->sample_aspect_ratio.den,
243 info.hasEnhancement,
info.enhanced);
244
246 }
247
249 {
252 LCEVC_PictureHandle picture;
253 LCEVC_ReturnCode res;
255
259
260 res = LCEVC_SendDecoderPicture(lcevc->
decoder, picture);
261 if (res != LCEVC_Success) {
264 }
265
267 }
268
270 {
274
278
279 return 0;
280 }
281
283 {
285 LCEVC_PictureHandle picture;
286
287 while (LCEVC_ReceiveDecoderBase(lcevc->
decoder, &picture) == LCEVC_Success)
288 LCEVC_FreePicture(lcevc->
decoder, picture);
289 }
290
292 {
298
300
309 }
312 }
313
314 if (in) {
323
325 }
326
330 }
331
335
340 }
341
343
345 }
346
348 LCEVC_PictureHandle pic,
const LCEVC_DecodeInformation *
info,
349 const uint8_t *
data, uint32_t
size,
void *logctx)
350 {
351 if (event != LCEVC_Log) // shouldn't happen
352 return;
353
354 if (strlen(
data) !=
size)
// sanitize input
355 return;
356
358 }
359
361 {
363 LCEVC_AccelContextHandle
dummy = { 0 };
364 const int32_t event = LCEVC_Log;
365 LCEVC_ReturnCode res;
366
368 if (res != LCEVC_Success) {
371 }
372
373 res = LCEVC_ConfigureDecoderInt(lcevc->
decoder,
"log_level", 4);
374 if (res != LCEVC_Success) {
377 }
378 res = LCEVC_ConfigureDecoderIntArray(lcevc->
decoder,
"events", 1, &event);
379 if (res != LCEVC_Success) {
382 }
384 if (res != LCEVC_Success) {
387 }
388
389 res = LCEVC_InitializeDecoder(lcevc->
decoder);
390 if (res != LCEVC_Success) {
393 }
394
395 return 0;
396 }
397
399 {
401
402 LCEVC_DestroyDecoder(lcevc->
decoder);
403 }
404
406 {
410 },
411 };
412
418 };
419
430 };