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
35
36 typedef struct VP8DecoderContext {
39
41 const struct vpx_codec_iface *iface)
42 {
44 struct vpx_codec_dec_cfg deccfg = {
45 /* token partitions+1 would be a decent choice */
47 };
48
51
52 if (vpx_codec_dec_init(&ctx->
decoder, iface, &deccfg, 0) != VPX_CODEC_OK) {
53 const char *error = vpx_codec_error(&ctx->
decoder);
55 error);
57 }
58
59 return 0;
60 }
61
62 // returns 0 on success, AVERROR_INVALIDDATA otherwise
66 switch (img->fmt) {
67 case VPX_IMG_FMT_I420:
69 return 0;
70 #if CONFIG_LIBVPX_VP9_DECODER
71 case VPX_IMG_FMT_I422:
73 return 0;
74 case VPX_IMG_FMT_I444:
76 return 0;
77 #ifdef VPX_IMG_FMT_HIGHBITDEPTH
78 case VPX_IMG_FMT_I42016:
79 if (img->bit_depth == 10) {
81 return 0;
82 } else if (img->bit_depth == 12) {
84 return 0;
85 } else {
87 }
88 case VPX_IMG_FMT_I42216:
89 if (img->bit_depth == 10) {
91 return 0;
92 } else if (img->bit_depth == 12) {
94 return 0;
95 } else {
97 }
98 case VPX_IMG_FMT_I44416:
99 if (img->bit_depth == 10) {
101 return 0;
102 } else if (img->bit_depth == 12) {
104 return 0;
105 } else {
107 }
108 #endif
109 #endif
110 default:
112 }
113 }
114
117 {
120 const void *iter =
NULL;
121 struct vpx_image *
img;
123
125 VPX_CODEC_OK) {
126 const char *error = vpx_codec_error(&ctx->
decoder);
127 const char *detail = vpx_codec_error_detail(&ctx->
decoder);
128
130 if (detail)
132 detail);
134 }
135
136 if ((img = vpx_codec_get_frame(&ctx->
decoder, &iter))) {
138 #ifdef VPX_IMG_FMT_HIGHBITDEPTH
140 img->fmt, img->bit_depth);
141 #else
143 img->fmt, 8);
144 #endif
146 }
147
148 if ((
int) img->d_w != avctx->
width || (
int) img->d_h != avctx->
height) {
152 if (ret < 0)
154 }
158 img->stride, avctx->
pix_fmt, img->d_w, img->d_h);
159 *got_frame = 1;
160 }
162 }
163
165 {
167 vpx_codec_destroy(&ctx->
decoder);
168 return 0;
169 }
170
171 #if CONFIG_LIBVPX_VP8_DECODER
173 {
174 return vpx_init(avctx, &vpx_codec_vp8_dx_algo);
175 }
176
177 AVCodec ff_libvpx_vp8_decoder = {
187 };
188 #endif /* CONFIG_LIBVPX_VP8_DECODER */
189
190 #if CONFIG_LIBVPX_VP9_DECODER
192 {
193 return vpx_init(avctx, &vpx_codec_vp9_dx_algo);
194 }
195
196 AVCodec ff_libvpx_vp9_decoder = {
197 .
name =
"libvpx-vp9",
207 };
208 #endif /* CONFIG_LIBVPX_VP9_DECODER */