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 * VP8 decoder support via libvpx
24 */
25
26 #define VPX_CODEC_DISABLE_COMPAT 1
27 #include <vpx/vpx_decoder.h>
28 #include <vpx/vp8dx.h>
29
36
37 typedef struct VP8DecoderContext {
40
42 const struct vpx_codec_iface *iface)
43 {
45 struct vpx_codec_dec_cfg deccfg = {
46 /* token partitions+1 would be a decent choice */
48 };
49
52
53 if (vpx_codec_dec_init(&ctx->
decoder, iface, &deccfg, 0) != VPX_CODEC_OK) {
54 const char *error = vpx_codec_error(&ctx->
decoder);
56 error);
58 }
59
60 return 0;
61 }
62
63 // returns 0 on success, AVERROR_INVALIDDATA otherwise
65 {
66 #if VPX_IMAGE_ABI_VERSION >= 3
70 };
71 #if VPX_IMAGE_ABI_VERSION >= 4
74 };
76 #endif
78 #endif
81 switch (img->fmt) {
82 case VPX_IMG_FMT_I420:
86 return 0;
87 #if CONFIG_LIBVPX_VP9_DECODER
88 case VPX_IMG_FMT_I422:
91 return 0;
92 #if VPX_IMAGE_ABI_VERSION >= 3
93 case VPX_IMG_FMT_I440:
96 return 0;
97 #endif
98 case VPX_IMG_FMT_I444:
100 #if VPX_IMAGE_ABI_VERSION >= 3
103 #else
105 #endif
106 return 0;
107 #ifdef VPX_IMG_FMT_HIGHBITDEPTH
108 case VPX_IMG_FMT_I42016:
110 if (img->bit_depth == 10) {
112 return 0;
113 } else if (img->bit_depth == 12) {
115 return 0;
116 } else {
118 }
119 case VPX_IMG_FMT_I42216:
121 if (img->bit_depth == 10) {
123 return 0;
124 } else if (img->bit_depth == 12) {
126 return 0;
127 } else {
129 }
130 #if VPX_IMAGE_ABI_VERSION >= 3
131 case VPX_IMG_FMT_I44016:
133 if (img->bit_depth == 10) {
135 return 0;
136 } else if (img->bit_depth == 12) {
138 return 0;
139 } else {
141 }
142 #endif
143 case VPX_IMG_FMT_I44416:
145 if (img->bit_depth == 10) {
146 #if VPX_IMAGE_ABI_VERSION >= 3
149 #else
151 #endif
152 return 0;
153 } else if (img->bit_depth == 12) {
154 #if VPX_IMAGE_ABI_VERSION >= 3
157 #else
159 #endif
160 return 0;
161 } else {
163 }
164 #endif
165 #endif
166 default:
168 }
169 }
170
173 {
176 const void *iter =
NULL;
177 struct vpx_image *
img;
178 int ret;
179
181 VPX_CODEC_OK) {
182 const char *error = vpx_codec_error(&ctx->
decoder);
183 const char *detail = vpx_codec_error_detail(&ctx->
decoder);
184
186 if (detail)
188 detail);
190 }
191
192 if ((img = vpx_codec_get_frame(&ctx->
decoder, &iter))) {
194 #ifdef VPX_IMG_FMT_HIGHBITDEPTH
196 img->fmt, img->bit_depth);
197 #else
199 img->fmt, 8);
200 #endif
201 return ret;
202 }
203
204 if ((
int) img->d_w != avctx->
width || (
int) img->d_h != avctx->
height) {
208 if (ret < 0)
209 return ret;
210 }
212 return ret;
214 img->stride, avctx->
pix_fmt, img->d_w, img->d_h);
215 *got_frame = 1;
216 }
218 }
219
221 {
223 vpx_codec_destroy(&ctx->
decoder);
224 return 0;
225 }
226
227 #if CONFIG_LIBVPX_VP8_DECODER
229 {
230 return vpx_init(avctx, &vpx_codec_vp8_dx_algo);
231 }
232
233 AVCodec ff_libvpx_vp8_decoder = {
243 };
244 #endif /* CONFIG_LIBVPX_VP8_DECODER */
245
246 #if CONFIG_LIBVPX_VP9_DECODER
248 {
249 return vpx_init(avctx, &vpx_codec_vp9_dx_algo);
250 }
251
252 AVCodec ff_libvpx_vp9_decoder = {
253 .
name =
"libvpx-vp9",
264 };
265 #endif /* CONFIG_LIBVPX_VP9_DECODER */
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
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.
struct vpx_codec_ctx decoder
static av_cold int init(AVCodecContext *avctx)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
enum AVColorRange color_range
MPEG vs JPEG YUV range.
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above ...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
planar GBR 4:4:4 36bpp, little-endian
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
AVColorSpace
YUV colorspace type.
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
static av_cold void init_static_data(void)
#define AV_LOG_VERBOSE
Detailed information.
AVColorRange
MPEG vs JPEG YUV range.
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
#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. ...
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
const char * name
Name of the codec implementation.
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)
static av_cold int vp8_free(AVCodecContext *avctx)
static const chunk_decoder decoder[8]
int width
picture width / height.
ITU-R BT2020 non-constant luminance system.
static av_cold int vpx_init(AVCodecContext *avctx, const struct vpx_codec_iface *iface)
static int vp8_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
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
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
av_cold void ff_vp9_init_static(AVCodec *codec)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_cold int vp9_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
enum AVColorSpace colorspace
YUV colorspace type.
static int set_pix_fmt(AVCodecContext *avctx, struct vpx_image *img)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
static av_cold int vp8_init(AVFormatContext *s, int st_index, PayloadContext *vp8)
static const AVProfile profiles[]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
common internal api header.
common internal and external API header
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const AVProfile ff_vp9_profiles[]
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
planar GBR 4:4:4 30bpp, little-endian