Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-02-15 04:38:34 +0400
committerMichael Niedermayer <michaelni@gmx.at>2012-02-15 04:52:14 +0400
commitc980be9e3aafad57ec769cbb16c9ad6e640479cb (patch)
treea804c9e2517a2e8ec9e5f22890862cbb226a66da /libavcodec
parente7dbfa59f218ece7ec65f7ea0ff2950573dd2267 (diff)
parentdc4e57489fa0f9cf4faf4c85cc405d6db77d84db (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (21 commits) CDXL demuxer and decoder hls: Re-add legacy applehttp name to preserve interface compatibility. hlsproto: Rename the functions and context hlsproto: Encourage users to try the hls demuxer instead of the proto doc: Move the hls protocol section into the right place libavformat: Rename the applehttp protocol to hls hls: Rename the functions and context libavformat: Rename the applehttp demuxer to hls rtpdec: Support H263 in RFC 2190 format rv30: check block type validity ttadec: CRC checking movenc: Support muxing VC1 avconv: Don't split out inline sequence headers when stream copying VC1 rv34: handle size changes during frame multithreading rv40: prevent undefined signed overflow in rv40_loop_filter() rv34: use AVERROR return values in ff_rv34_decode_frame() rv34: use uint16_t for RV34DecContext.deblock_coefs librtmp: Add "lib" prefix to librtmp URLProtocol declarations. movenc: Use defines instead of hardcoded numbers for RTCP types smjpegdec: implement seeking ... Conflicts: Changelog doc/general.texi libavcodec/avcodec.h libavcodec/rv30.c libavcodec/tta.c libavcodec/version.h libavformat/Makefile libavformat/allformats.c libavformat/version.h libswscale/x86/swscale_mmx.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/Makefile1
-rw-r--r--libavcodec/allcodecs.c1
-rw-r--r--libavcodec/avcodec.h1
-rw-r--r--libavcodec/cdxl.c278
-rw-r--r--libavcodec/rv34.c158
-rw-r--r--libavcodec/rv34.h2
-rw-r--r--libavcodec/rv40.c5
-rw-r--r--libavcodec/tta.c33
-rw-r--r--libavcodec/version.h2
9 files changed, 409 insertions, 72 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index d14dac6010..49664078b3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -111,6 +111,7 @@ OBJS-$(CONFIG_C93_DECODER) += c93.o
OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdec.o cavsdsp.o \
mpeg12data.o mpegvideo.o
OBJS-$(CONFIG_CDGRAPHICS_DECODER) += cdgraphics.o
+OBJS-$(CONFIG_CDXL_DECODER) += cdxl.o
OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o
OBJS-$(CONFIG_CLJR_DECODER) += cljr.o
OBJS-$(CONFIG_CLJR_ENCODER) += cljr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index d18b3f03c7..54f67691aa 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -90,6 +90,7 @@ void avcodec_register_all(void)
REGISTER_DECODER (C93, c93);
REGISTER_DECODER (CAVS, cavs);
REGISTER_DECODER (CDGRAPHICS, cdgraphics);
+ REGISTER_DECODER (CDXL, cdxl);
REGISTER_DECODER (CINEPAK, cinepak);
REGISTER_ENCDEC (CLJR, cljr);
REGISTER_DECODER (CSCD, cscd);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3ea7a24534..c9e1e1dc46 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -246,6 +246,7 @@ enum CodecID {
CODEC_ID_DXTORY,
CODEC_ID_V410,
CODEC_ID_XWD,
+ CODEC_ID_CDXL,
CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'),
CODEC_ID_AVRP = MKBETAG('A','V','R','P'),
diff --git a/libavcodec/cdxl.c b/libavcodec/cdxl.c
new file mode 100644
index 0000000000..a53a001ea4
--- /dev/null
+++ b/libavcodec/cdxl.c
@@ -0,0 +1,278 @@
+/*
+ * CDXL video decoder
+ * Copyright (c) 2011-2012 Paul B Mahol
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/imgutils.h"
+#include "avcodec.h"
+#include "get_bits.h"
+
+typedef struct {
+ AVCodecContext *avctx;
+ AVFrame frame;
+ int bpp;
+ const uint8_t *palette;
+ int palette_size;
+ const uint8_t *video;
+ int video_size;
+ uint8_t *new_video;
+ int new_video_size;
+} CDXLVideoContext;
+
+static av_cold int cdxl_decode_init(AVCodecContext *avctx)
+{
+ CDXLVideoContext *c = avctx->priv_data;
+
+ avcodec_get_frame_defaults(&c->frame);
+ c->new_video_size = 0;
+ c->avctx = avctx;
+
+ return 0;
+}
+
+static void import_palette(CDXLVideoContext *c, uint32_t *new_palette)
+{
+ int i;
+
+ for (i = 0; i < c->palette_size / 2; i++) {
+ unsigned rgb = AV_RB16(&c->palette[i * 2]);
+ unsigned r = ((rgb >> 8) & 0xF) * 0x11;
+ unsigned g = ((rgb >> 4) & 0xF) * 0x11;
+ unsigned b = (rgb & 0xF) * 0x11;
+ AV_WN32(&new_palette[i], (r << 16) | (g << 8) | b);
+ }
+}
+
+static void bitplanar2chunky(CDXLVideoContext *c, int width,
+ int linesize, uint8_t *out)
+{
+ GetBitContext gb;
+ int x, y, plane;
+
+ init_get_bits(&gb, c->video, c->video_size * 8);
+ memset(out, 0, linesize * c->avctx->height);
+ for (plane = 0; plane < c->bpp; plane++)
+ for (y = 0; y < c->avctx->height; y++)
+ for (x = 0; x < width; x++)
+ out[linesize * y + x] |= get_bits1(&gb) << plane;
+}
+
+static void cdxl_decode_rgb(CDXLVideoContext *c)
+{
+ uint32_t *new_palette = (uint32_t *)c->frame.data[1];
+ int padded_width = FFALIGN(c->avctx->width, 16);
+
+ import_palette(c, new_palette);
+ bitplanar2chunky(c, padded_width, c->frame.linesize[0], c->frame.data[0]);
+}
+
+static void cdxl_decode_ham6(CDXLVideoContext *c)
+{
+ AVCodecContext *avctx = c->avctx;
+ uint32_t new_palette[16], r, g, b;
+ uint8_t *ptr, *out, index, op;
+ int x, y;
+
+ ptr = c->new_video;
+ out = c->frame.data[0];
+
+ import_palette(c, new_palette);
+ bitplanar2chunky(c, avctx->width, avctx->width, c->new_video);
+
+ for (y = 0; y < avctx->height; y++) {
+ r = new_palette[0] & 0xFF0000;
+ g = new_palette[0] & 0xFF00;
+ b = new_palette[0] & 0xFF;
+ for (x = 0; x < avctx->width; x++) {
+ index = *ptr++;
+ op = index >> 4;
+ index &= 15;
+ switch (op) {
+ case 0:
+ r = new_palette[index] & 0xFF0000;
+ g = new_palette[index] & 0xFF00;
+ b = new_palette[index] & 0xFF;
+ break;
+ case 1:
+ b = index * 0x11;
+ break;
+ case 2:
+ r = index * 0x11 << 16;
+ break;
+ case 3:
+ g = index * 0x11 << 8;
+ break;
+ }
+ AV_WN32(out + x * 3, r | g | b);
+ }
+ out += c->frame.linesize[0];
+ }
+}
+
+static void cdxl_decode_ham8(CDXLVideoContext *c)
+{
+ AVCodecContext *avctx = c->avctx;
+ uint32_t new_palette[64], r, g, b;
+ uint8_t *ptr, *out, index, op;
+ int x, y;
+
+ ptr = c->new_video;
+ out = c->frame.data[0];
+
+ import_palette(c, new_palette);
+ bitplanar2chunky(c, avctx->width, avctx->width, c->new_video);
+
+ for (y = 0; y < avctx->height; y++) {
+ r = new_palette[0] & 0xFF0000;
+ g = new_palette[0] & 0xFF00;
+ b = new_palette[0] & 0xFF;
+ for (x = 0; x < avctx->width; x++) {
+ index = *ptr++;
+ op = index >> 6;
+ index &= 63;
+ switch (op) {
+ case 0:
+ r = new_palette[index] & 0xFF0000;
+ g = new_palette[index] & 0xFF00;
+ b = new_palette[index] & 0xFF;
+ break;
+ case 1:
+ b = (index << 2) | (b & 3);
+ break;
+ case 2:
+ r = (index << 18) | (r & (3 << 16));
+ break;
+ case 3:
+ g = (index << 10) | (g & (3 << 8));
+ break;
+ }
+ AV_WN32(out + x * 3, r | g | b);
+ }
+ out += c->frame.linesize[0];
+ }
+}
+
+static int cdxl_decode_frame(AVCodecContext *avctx, void *data,
+ int *data_size, AVPacket *pkt)
+{
+ CDXLVideoContext *c = avctx->priv_data;
+ AVFrame * const p = &c->frame;
+ int ret, w, h, encoding, format, buf_size = pkt->size;
+ const uint8_t *buf = pkt->data;
+
+ if (buf_size < 32)
+ return AVERROR_INVALIDDATA;
+ encoding = buf[1] & 7;
+ format = buf[1] & 0xE0;
+ w = AV_RB16(&buf[14]);
+ h = AV_RB16(&buf[16]);
+ c->bpp = buf[19];
+ c->palette_size = AV_RB16(&buf[20]);
+ c->palette = buf + 32;
+ c->video = c->palette + c->palette_size;
+ c->video_size = buf_size - c->palette_size - 32;
+
+ if (c->palette_size > 512)
+ return AVERROR_INVALIDDATA;
+ if (buf_size < c->palette_size + 32)
+ return AVERROR_INVALIDDATA;
+ if (c->bpp < 1)
+ return AVERROR_INVALIDDATA;
+ if (c->bpp > 8) {
+ av_log_ask_for_sample(avctx, "unsupported pixel size: %d\n", c->bpp);
+ return AVERROR_PATCHWELCOME;
+ }
+ if (format) {
+ av_log_ask_for_sample(avctx, "unsupported pixel format: %d\n", format);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ if ((ret = av_image_check_size(w, h, 0, avctx)) < 0)
+ return ret;
+ if (w != avctx->width || h != avctx->height)
+ avcodec_set_dimensions(avctx, w, h);
+
+ if (encoding == 0) {
+ if (c->video_size < FFALIGN(avctx->width, 16) *
+ avctx->height * c->bpp / 8)
+ return AVERROR_INVALIDDATA;
+ avctx->pix_fmt = PIX_FMT_PAL8;
+ } else if (encoding == 1 && (c->bpp == 6 || c->bpp == 8)) {
+ if (c->palette_size != (1 << (c->bpp - 1)))
+ return AVERROR_INVALIDDATA;
+ if (c->video_size < avctx->width * avctx->height * c->bpp / 8)
+ return AVERROR_INVALIDDATA;
+ avctx->pix_fmt = PIX_FMT_BGR24;
+ } else {
+ av_log_ask_for_sample(avctx, "unsupported encoding %d and bpp %d\n",
+ encoding, c->bpp);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ if (p->data[0])
+ avctx->release_buffer(avctx, p);
+
+ p->reference = 0;
+ if ((ret = avctx->get_buffer(avctx, p)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return ret;
+ }
+ p->pict_type = AV_PICTURE_TYPE_I;
+
+ if (encoding) {
+ av_fast_padded_malloc(&c->new_video, &c->new_video_size,
+ h * w + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!c->new_video)
+ return AVERROR(ENOMEM);
+ if (c->bpp == 8)
+ cdxl_decode_ham8(c);
+ else
+ cdxl_decode_ham6(c);
+ } else {
+ cdxl_decode_rgb(c);
+ }
+ *data_size = sizeof(AVFrame);
+ *(AVFrame*)data = c->frame;
+
+ return buf_size;
+}
+
+static av_cold int cdxl_decode_end(AVCodecContext *avctx)
+{
+ CDXLVideoContext *c = avctx->priv_data;
+
+ av_free(c->new_video);
+ if (c->frame.data[0])
+ avctx->release_buffer(avctx, &c->frame);
+
+ return 0;
+}
+
+AVCodec ff_cdxl_decoder = {
+ .name = "cdxl",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_CDXL,
+ .priv_data_size = sizeof(CDXLVideoContext),
+ .init = cdxl_decode_init,
+ .close = cdxl_decode_end,
+ .decode = cdxl_decode_frame,
+ .capabilities = CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("Commodore CDXL video"),
+};
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index e09d5dcf14..52483e6e8b 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -711,8 +711,7 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type,
if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) {
/* wait for the referenced mb row to be finished */
- int mb_row = FFMIN(s->mb_height - 1,
- s->mb_y + ((yoff + my + 5 + 8 * height) >> 4));
+ int mb_row = s->mb_y + ((yoff + my + 5 + 8 * height) >> 4);
AVFrame *f = dir ? &s->next_picture_ptr->f : &s->last_picture_ptr->f;
ff_thread_await_progress(f, mb_row, 0);
}
@@ -1361,6 +1360,53 @@ static int check_slice_end(RV34DecContext *r, MpegEncContext *s)
return 0;
}
+
+static void rv34_decoder_free(RV34DecContext *r)
+{
+ av_freep(&r->intra_types_hist);
+ r->intra_types = NULL;
+ av_freep(&r->tmp_b_block_base);
+ av_freep(&r->mb_type);
+ av_freep(&r->cbp_luma);
+ av_freep(&r->cbp_chroma);
+ av_freep(&r->deblock_coefs);
+}
+
+
+static int rv34_decoder_alloc(RV34DecContext *r)
+{
+ r->intra_types_stride = r->s.mb_width * 4 + 4;
+
+ r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height *
+ sizeof(*r->cbp_chroma));
+ r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height *
+ sizeof(*r->cbp_luma));
+ r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height *
+ sizeof(*r->deblock_coefs));
+ r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 *
+ sizeof(*r->intra_types_hist));
+ r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height *
+ sizeof(*r->mb_type));
+
+ if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs &&
+ r->intra_types_hist && r->mb_type)) {
+ rv34_decoder_free(r);
+ return AVERROR(ENOMEM);
+ }
+
+ r->intra_types = r->intra_types_hist + r->intra_types_stride * 4;
+
+ return 0;
+}
+
+
+static int rv34_decoder_realloc(RV34DecContext *r)
+{
+ rv34_decoder_free(r);
+ return rv34_decoder_alloc(r);
+}
+
+
static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int buf_size)
{
MpegEncContext *s = &r->s;
@@ -1376,22 +1422,19 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int
}
if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) {
- if(s->width != r->si.width || s->height != r->si.height){
- av_log(s->avctx, AV_LOG_DEBUG, "Changing dimensions to %dx%d\n", r->si.width,r->si.height);
+ if (s->width != r->si.width || s->height != r->si.height) {
+ int err;
+
+ av_log(s->avctx, AV_LOG_WARNING, "Changing dimensions to %dx%d\n",
+ r->si.width, r->si.height);
MPV_common_end(s);
s->width = r->si.width;
s->height = r->si.height;
avcodec_set_dimensions(s->avctx, s->width, s->height);
- if(MPV_common_init(s) < 0)
- return -1;
- r->intra_types_stride = s->mb_width*4 + 4;
- r->intra_types_hist = av_realloc(r->intra_types_hist, r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist));
- r->intra_types = r->intra_types_hist + r->intra_types_stride * 4;
- r->mb_type = av_realloc(r->mb_type, r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type));
- r->cbp_luma = av_realloc(r->cbp_luma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma));
- r->cbp_chroma = av_realloc(r->cbp_chroma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma));
- r->deblock_coefs = av_realloc(r->deblock_coefs, r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs));
- av_freep(&r->tmp_b_block_base);
+ if ((err = MPV_common_init(s)) < 0)
+ return err;
+ if ((err = rv34_decoder_realloc(r)) < 0)
+ return err;
}
s->pict_type = r->si.type ? r->si.type : AV_PICTURE_TYPE_I;
if(MPV_frame_start(s, s->avctx) < 0)
@@ -1500,6 +1543,7 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
{
RV34DecContext *r = avctx->priv_data;
MpegEncContext *s = &r->s;
+ int ret;
MPV_decode_defaults(s);
s->avctx = avctx;
@@ -1516,8 +1560,8 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
avctx->has_b_frames = 1;
s->low_delay = 0;
- if (MPV_common_init(s) < 0)
- return -1;
+ if ((ret = MPV_common_init(s)) < 0)
+ return ret;
ff_h264_pred_init(&r->h, CODEC_ID_RV40, 8, 1);
@@ -1530,15 +1574,8 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
ff_rv40dsp_init(&r->rdsp, &r->s.dsp);
#endif
- r->intra_types_stride = 4*s->mb_stride + 4;
- r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist));
- r->intra_types = r->intra_types_hist + r->intra_types_stride * 4;
-
- r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type));
-
- r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma));
- r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma));
- r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs));
+ if ((ret = rv34_decoder_alloc(r)) < 0)
+ return ret;
if(!intra_vlcs[0].cbppattern[0].bits)
rv34_init_tables();
@@ -1548,40 +1585,17 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
int ff_rv34_decode_init_thread_copy(AVCodecContext *avctx)
{
+ int err;
RV34DecContext *r = avctx->priv_data;
r->s.avctx = avctx;
if (avctx->internal->is_copy) {
- r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height *
- sizeof(*r->cbp_chroma));
- r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height *
- sizeof(*r->cbp_luma));
- r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height *
- sizeof(*r->deblock_coefs));
- r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 *
- sizeof(*r->intra_types_hist));
- r->mb_type = av_malloc(r->s.mb_stride * r->s.mb_height *
- sizeof(*r->mb_type));
-
- if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs &&
- r->intra_types_hist && r->mb_type)) {
- av_freep(&r->cbp_chroma);
- av_freep(&r->cbp_luma);
- av_freep(&r->deblock_coefs);
- av_freep(&r->intra_types_hist);
- av_freep(&r->mb_type);
- r->intra_types = NULL;
- return AVERROR(ENOMEM);
- }
-
- r->intra_types = r->intra_types_hist + r->intra_types_stride * 4;
r->tmp_b_block_base = NULL;
-
- memset(r->mb_type, 0, r->s.mb_stride * r->s.mb_height *
- sizeof(*r->mb_type));
-
- MPV_common_init(&r->s);
+ if ((err = MPV_common_init(&r->s)) < 0)
+ return err;
+ if ((err = rv34_decoder_alloc(r)) < 0)
+ return err;
}
return 0;
}
@@ -1595,6 +1609,16 @@ int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecConte
if (dst == src || !s1->context_initialized)
return 0;
+ if (s->height != s1->height || s->width != s1->width) {
+ MPV_common_end(s);
+ s->height = s1->height;
+ s->width = s1->width;
+ if ((err = MPV_common_init(s)) < 0)
+ return err;
+ if ((err = rv34_decoder_realloc(r)) < 0)
+ return err;
+ }
+
if ((err = ff_mpeg_update_thread_context(dst, src)))
return err;
@@ -1656,15 +1680,19 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
if(get_slice_offset(avctx, slices_hdr, 0) < 0 ||
get_slice_offset(avctx, slices_hdr, 0) > buf_size){
av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, 0), (buf_size-get_slice_offset(avctx, slices_hdr, 0))*8);
if(r->parse_slice_header(r, &r->s.gb, &si) < 0 || si.start){
av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n");
- return -1;
+ return AVERROR_INVALIDDATA;
+ }
+ if ((!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) &&
+ si.type == AV_PICTURE_TYPE_B) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid decoder state: B-frame without "
+ "reference data.\n");
+ return AVERROR_INVALIDDATA;
}
- if ((!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) && si.type == AV_PICTURE_TYPE_B)
- return -1;
if( (avctx->skip_frame >= AVDISCARD_NONREF && si.type==AV_PICTURE_TYPE_B)
|| (avctx->skip_frame >= AVDISCARD_NONKEY && si.type!=AV_PICTURE_TYPE_I)
|| avctx->skip_frame >= AVDISCARD_ALL)
@@ -1712,11 +1740,12 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
if(last && s->current_picture_ptr){
if(r->loop_filter)
r->loop_filter(r, s->mb_height - 1);
- if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
- ff_thread_report_progress(&s->current_picture_ptr->f,
- s->mb_height - 1, 0);
ff_er_frame_end(s);
MPV_frame_end(s);
+
+ if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
+ ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);
+
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
*pict = *(AVFrame*)s->current_picture_ptr;
} else if (s->last_picture_ptr != NULL) {
@@ -1737,14 +1766,7 @@ av_cold int ff_rv34_decode_end(AVCodecContext *avctx)
RV34DecContext *r = avctx->priv_data;
MPV_common_end(&r->s);
-
- av_freep(&r->intra_types_hist);
- r->intra_types = NULL;
- av_freep(&r->tmp_b_block_base);
- av_freep(&r->mb_type);
- av_freep(&r->cbp_luma);
- av_freep(&r->cbp_chroma);
- av_freep(&r->deblock_coefs);
+ rv34_decoder_free(r);
return 0;
}
diff --git a/libavcodec/rv34.h b/libavcodec/rv34.h
index e9cac1ca2f..4207ab45dd 100644
--- a/libavcodec/rv34.h
+++ b/libavcodec/rv34.h
@@ -110,7 +110,7 @@ typedef struct RV34DecContext{
uint16_t *cbp_luma; ///< CBP values for luma subblocks
uint8_t *cbp_chroma; ///< CBP values for chroma subblocks
- int *deblock_coefs; ///< deblock coefficients for each macroblock
+ uint16_t *deblock_coefs; ///< deblock coefficients for each macroblock
/** 8x8 block available flags (for MV prediction) */
DECLARE_ALIGNED(8, uint32_t, avail_cache)[3*4];
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index 3bd1826b70..a0fa678ada 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -360,7 +360,7 @@ static void rv40_loop_filter(RV34DecContext *r, int row)
* in addition to the coded ones because because they lie at the edge of
* 8x8 block with different enough motion vectors
*/
- int mvmasks[4];
+ unsigned mvmasks[4];
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
@@ -376,7 +376,8 @@ static void rv40_loop_filter(RV34DecContext *r, int row)
int c_v_deblock[2], c_h_deblock[2];
int clip_left;
int avail[4];
- int y_to_deblock, c_to_deblock[2];
+ unsigned y_to_deblock;
+ int c_to_deblock[2];
q = s->current_picture_ptr->f.qscale_table[mb_pos];
alpha = rv40_alpha_tab[q];
diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index 3f5ab23b1e..2a4c2e859c 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -32,6 +32,7 @@
#include <limits.h>
#include "avcodec.h"
#include "get_bits.h"
+#include "libavutil/crc.h"
#define FORMAT_SIMPLE 1
#define FORMAT_ENCRYPTED 2
@@ -58,6 +59,7 @@ typedef struct TTAContext {
AVCodecContext *avctx;
AVFrame frame;
GetBitContext gb;
+ const AVCRC *crc_table;
int format, channels, bps, data_length;
int frame_length, last_frame_length, total_frames;
@@ -198,6 +200,20 @@ static const int64_t tta_channel_layouts[7] = {
AV_CH_LAYOUT_7POINT1_WIDE
};
+static int tta_check_crc(TTAContext *s, const uint8_t *buf, int buf_size)
+{
+ uint32_t crc, CRC;
+
+ CRC = AV_RL32(buf + buf_size);
+ crc = av_crc(s->crc_table, 0xFFFFFFFFU, buf, buf_size);
+ if (CRC != (crc ^ 0xFFFFFFFFU)) {
+ av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ return 0;
+}
+
static av_cold int tta_decode_init(AVCodecContext * avctx)
{
TTAContext *s = avctx->priv_data;
@@ -211,6 +227,12 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8);
if (show_bits_long(&s->gb, 32) == AV_RL32("TTA1"))
{
+ if (avctx->err_recognition & AV_EF_CRCCHECK) {
+ s->crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
+ if (tta_check_crc(s, avctx->extradata, 18))
+ return AVERROR_INVALIDDATA;
+ }
+
/* signature */
skip_bits_long(&s->gb, 32);
@@ -274,6 +296,12 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
s->data_length, s->frame_length, s->last_frame_length, s->total_frames);
// FIXME: seek table
+ if (get_bits_left(&s->gb) < 32 * s->total_frames + 32)
+ av_log(avctx, AV_LOG_WARNING, "Seek table missing or too small\n");
+ else if (avctx->err_recognition & AV_EF_CRCCHECK) {
+ if (tta_check_crc(s, avctx->extradata + 22, s->total_frames * 4))
+ return AVERROR_INVALIDDATA;
+ }
skip_bits_long(&s->gb, 32 * s->total_frames);
skip_bits_long(&s->gb, 32); // CRC32 of seektable
@@ -314,6 +342,11 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
int cur_chan = 0, framelen = s->frame_length;
int32_t *p;
+ if (avctx->err_recognition & AV_EF_CRCCHECK) {
+ if (buf_size < 4 || tta_check_crc(s, buf, buf_size - 4))
+ return AVERROR_INVALIDDATA;
+ }
+
init_get_bits(&s->gb, buf, buf_size*8);
// FIXME: seeking
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 6d82bdb49d..2bf7ed1db3 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@
#define AVCODEC_VERSION_H
#define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR 1
+#define LIBAVCODEC_VERSION_MINOR 2
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \