annotate libvpxdec.c @ 12530:63edd10ad4bc libavcodec tip

Try to fix crashes introduced by r25218 r25218 made assumptions about the existence of past reference frames that weren't necessarily true.
author darkshikari
date Tue, 28 Sep 2010 09:06:22 +0000
parents ffb3668ff7af
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11756
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
1 /*
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
2 * Copyright (c) 2010, Google, Inc.
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
3 *
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
4 * This file is part of FFmpeg.
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
5 *
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
10 *
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
14 * Lesser General Public License for more details.
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
15 *
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
19 */
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
20
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
21 /**
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
22 * @file
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
23 * VP8 decoder support via libvpx
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
24 */
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
25
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
26 #define VPX_CODEC_DISABLE_COMPAT 1
11758
6c1e78b8aba5 Headers for libvpx are installed into vpx subdirectory.
cehoyos
parents: 11756
diff changeset
27 #include <vpx/vpx_decoder.h>
6c1e78b8aba5 Headers for libvpx are installed into vpx subdirectory.
cehoyos
parents: 11756
diff changeset
28 #include <vpx/vp8dx.h>
11756
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
29
12375
98004cbdda4e libvpxdec: Fix "error: implicit declaration of function ¡Æav_check_image_size¡Ç".
alexc
parents: 12372
diff changeset
30 #include "libavcore/imgutils.h"
11756
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
31 #include "avcodec.h"
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
32
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
33 typedef struct VP8DecoderContext {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
34 struct vpx_codec_ctx decoder;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
35 } VP8Context;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
36
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
37 static av_cold int vp8_init(AVCodecContext *avctx)
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
38 {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
39 VP8Context *ctx = avctx->priv_data;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
40 const struct vpx_codec_iface *iface = &vpx_codec_vp8_dx_algo;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
41 struct vpx_codec_dec_cfg deccfg = {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
42 /* token partitions+1 would be a decent choice */
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
43 .threads = FFMIN(avctx->thread_count, 16)
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
44 };
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
45
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
46 av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
47 av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config());
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
48
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
49 if (vpx_codec_dec_init(&ctx->decoder, iface, &deccfg, 0) != VPX_CODEC_OK) {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
50 const char *error = vpx_codec_error(&ctx->decoder);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
51 av_log(avctx, AV_LOG_ERROR, "Failed to initialize decoder: %s\n",
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
52 error);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
53 return AVERROR(EINVAL);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
54 }
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
55
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
56 avctx->pix_fmt = PIX_FMT_YUV420P;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
57 return 0;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
58 }
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
59
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
60 static int vp8_decode(AVCodecContext *avctx,
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
61 void *data, int *data_size, AVPacket *avpkt)
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
62 {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
63 VP8Context *ctx = avctx->priv_data;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
64 AVFrame *picture = data;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
65 const void *iter = NULL;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
66 struct vpx_image *img;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
67
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
68 if (vpx_codec_decode(&ctx->decoder, avpkt->data, avpkt->size, NULL, 0) !=
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
69 VPX_CODEC_OK) {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
70 const char *error = vpx_codec_error(&ctx->decoder);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
71 const char *detail = vpx_codec_error_detail(&ctx->decoder);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
72
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
73 av_log(avctx, AV_LOG_ERROR, "Failed to decode frame: %s\n", error);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
74 if (detail)
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
75 av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n",
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
76 detail);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
77 return AVERROR_INVALIDDATA;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
78 }
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
79
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
80 if ((img = vpx_codec_get_frame(&ctx->decoder, &iter))) {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
81 if (img->fmt != VPX_IMG_FMT_I420) {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
82 av_log(avctx, AV_LOG_ERROR, "Unsupported output colorspace (%d)\n",
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
83 img->fmt);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
84 return AVERROR_INVALIDDATA;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
85 }
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
86
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
87 if ((int) img->d_w != avctx->width || (int) img->d_h != avctx->height) {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
88 av_log(avctx, AV_LOG_INFO, "dimension change! %dx%d -> %dx%d\n",
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
89 avctx->width, avctx->height, img->d_w, img->d_h);
12462
ffb3668ff7af Use new imgutils.h API names, fix deprecation warnings.
stefano
parents: 12375
diff changeset
90 if (av_image_check_size(img->d_w, img->d_h, 0, avctx))
11756
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
91 return AVERROR_INVALIDDATA;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
92 avcodec_set_dimensions(avctx, img->d_w, img->d_h);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
93 }
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
94 picture->data[0] = img->planes[0];
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
95 picture->data[1] = img->planes[1];
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
96 picture->data[2] = img->planes[2];
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
97 picture->data[3] = NULL;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
98 picture->linesize[0] = img->stride[0];
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
99 picture->linesize[1] = img->stride[1];
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
100 picture->linesize[2] = img->stride[2];
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
101 picture->linesize[3] = 0;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
102 *data_size = sizeof(AVPicture);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
103 }
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
104 return avpkt->size;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
105 }
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
106
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
107 static av_cold int vp8_free(AVCodecContext *avctx)
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
108 {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
109 VP8Context *ctx = avctx->priv_data;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
110 vpx_codec_destroy(&ctx->decoder);
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
111 return 0;
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
112 }
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
113
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
114 AVCodec libvpx_decoder = {
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
115 "libvpx",
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
116 AVMEDIA_TYPE_VIDEO,
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
117 CODEC_ID_VP8,
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
118 sizeof(VP8Context),
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
119 vp8_init,
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
120 NULL, /* encode */
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
121 vp8_free,
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
122 vp8_decode,
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
123 0, /* capabilities */
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
124 .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"),
cec5a6f0beec VP8 decoding via libvpx.
cehoyos
parents:
diff changeset
125 };