1 /*
2 * Copyright (c) 2010, Google, Inc.
3 *
4 * This file is part of FFmpeg.
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 /**
22 * @file
23 * AV1 decoder support via libaom
24 */
25
26 #include <aom/aom_decoder.h>
27 #include <aom/aomdx.h>
28
31
35
39
41 const struct aom_codec_iface *iface)
42 {
44 struct aom_codec_dec_cfg deccfg = {
45 /* token partitions+1 would be a decent choice */
47 };
48
51
52 if (aom_codec_dec_init(&ctx->
decoder, iface, &deccfg, 0) != AOM_CODEC_OK) {
55 error);
57 }
58
59 return 0;
60 }
61
63 {
65 int i;
66
70 int x, y;
71
72 if (i) {
73 w = (w + img->x_chroma_shift) >> img->x_chroma_shift;
74 h = (h + img->y_chroma_shift) >> img->y_chroma_shift;
75 }
76
77 for (y = 0; y <
h; y++) {
78 uint16_t *
src = (uint16_t *)(img->planes[i] + y * img->stride[i]);
80 for (x = 0; x <
w; x++)
81 *dst++ = *src++;
82 }
83 }
84 }
85
86 // returns 0 on success, AVERROR_INVALIDDATA otherwise
88 {
91 };
96
97 switch (img->fmt) {
98 case AOM_IMG_FMT_I420:
99 case AOM_IMG_FMT_I42016:
100 if (img->bit_depth == 8) {
101 avctx->
pix_fmt = img->monochrome ?
104 return 0;
105 } else if (img->bit_depth == 10) {
106 avctx->
pix_fmt = img->monochrome ?
109 return 0;
110 } else if (img->bit_depth == 12) {
111 avctx->
pix_fmt = img->monochrome ?
114 return 0;
115 } else {
117 }
118 case AOM_IMG_FMT_I422:
119 case AOM_IMG_FMT_I42216:
120 if (img->bit_depth == 8) {
123 return 0;
124 } else if (img->bit_depth == 10) {
127 return 0;
128 } else if (img->bit_depth == 12) {
131 return 0;
132 } else {
134 }
135 case AOM_IMG_FMT_I444:
136 case AOM_IMG_FMT_I44416:
137 if (img->bit_depth == 8) {
140 return 0;
141 } else if (img->bit_depth == 10) {
144 return 0;
145 } else if (img->bit_depth == 12) {
148 return 0;
149 } else {
151 }
152
153 default:
155 }
156 }
157
160 {
163 const void *iter =
NULL;
164 struct aom_image *
img;
165 int ret;
166
168 AOM_CODEC_OK) {
170 const char *detail = aom_codec_error_detail(&ctx->
decoder);
171
173 if (detail)
175 detail);
177 }
178
179 if ((img = aom_codec_get_frame(&ctx->
decoder, &iter))) {
180 if (img->d_w > img->w || img->d_h > img->h) {
182 img->d_w, img->d_h, img->w, img->h);
184 }
185
188 img->fmt, img->bit_depth);
189 return ret;
190 }
191
192 if ((
int)img->d_w != avctx->
width || (
int)img->d_h != avctx->
height) {
196 if (ret < 0)
197 return ret;
198 }
200 return ret;
201 if ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) && img->bit_depth == 8)
203 else
205 img->stride, avctx->
pix_fmt, img->d_w, img->d_h);
206 *got_frame = 1;
207 }
209 }
210
212 {
214 aom_codec_destroy(&ctx->
decoder);
215 return 0;
216 }
217
219 {
220 return aom_init(avctx, &aom_codec_av1_dx_algo);
221 }
222
224 .
name =
"libaom-av1",
234 .wrapper_name = "libaom",
235 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static av_cold int aom_free(AVCodecContext *avctx)
ptrdiff_t const GLvoid * data
static av_cold int aom_init(AVCodecContext *avctx, const struct aom_codec_iface *iface)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
static av_cold int init(AVCodecContext *avctx)
static int aom_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_PIX_FMT_YUV420P12
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
struct aom_codec_ctx decoder
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY12
#define AV_LOG_VERBOSE
Detailed information.
AVColorRange
MPEG vs JPEG YUV range.
#define AV_PIX_FMT_YUV422P12
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
#define AV_PIX_FMT_YUV444P10
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
uint8_t nb_components
The number of components each pixel has, (1-4)
int width
picture width / height.
AVCodec ff_libaom_av1_decoder
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static void error(const char *err)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
the normal 2^n-1 "JPEG" YUV ranges
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define AV_LOG_INFO
Standard information.
static void image_copy_16_to_8(AVFrame *pic, struct aom_image *img)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
const AVProfile ff_av1_profiles[]
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_PIX_FMT_YUV420P10
static const AVProfile profiles[]
#define FF_PROFILE_AV1_PROFESSIONAL
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static int set_pix_fmt(AVCodecContext *avctx, struct aom_image *img)
#define FF_PROFILE_AV1_MAIN
static av_cold int av1_init(AVCodecContext *avctx)
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
common internal and external API header
#define AVERROR_EXTERNAL
Generic error in an external library.
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define FF_PROFILE_AV1_HIGH