2001-07-22 16:18:56 +02:00
|
|
|
/*
|
2009-08-04 01:22:46 +02:00
|
|
|
* RV10/RV20 decoder
|
2009-01-19 16:46:40 +01:00
|
|
|
* Copyright (c) 2000,2001 Fabrice Bellard
|
2004-01-10 17:04:55 +01:00
|
|
|
* Copyright (c) 2002-2004 Michael Niedermayer
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-05-26 00:45:33 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 17:30:46 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2001-07-22 16:18:56 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2002-05-26 00:45:33 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2002-05-26 00:45:33 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 17:30:46 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 23:43:26 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-07-22 16:18:56 +02:00
|
|
|
*/
|
2003-03-06 12:32:04 +01:00
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2009-08-04 01:22:46 +02:00
|
|
|
* RV10/RV20 decoder
|
2003-03-06 12:32:04 +01:00
|
|
|
*/
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2014-03-13 12:13:33 +01:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2011-02-07 14:37:08 +01:00
|
|
|
#include "libavutil/imgutils.h"
|
2020-11-17 10:09:34 +01:00
|
|
|
#include "libavutil/thread.h"
|
2014-03-01 19:44:01 +01:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
#include "avcodec.h"
|
2013-03-06 18:31:14 +01:00
|
|
|
#include "error_resilience.h"
|
2014-03-01 19:44:01 +01:00
|
|
|
#include "h263.h"
|
2015-06-10 15:29:05 +02:00
|
|
|
#include "h263data.h"
|
2013-10-27 10:02:26 +01:00
|
|
|
#include "internal.h"
|
2014-06-20 15:05:45 +02:00
|
|
|
#include "mpeg_er.h"
|
2015-05-31 15:49:55 +02:00
|
|
|
#include "mpegutils.h"
|
2001-07-22 16:18:56 +02:00
|
|
|
#include "mpegvideo.h"
|
2010-01-31 13:27:05 +01:00
|
|
|
#include "mpeg4video.h"
|
2015-05-29 20:44:03 +02:00
|
|
|
#include "mpegvideodata.h"
|
2015-06-10 15:29:06 +02:00
|
|
|
#include "rv10.h"
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2011-08-04 21:00:12 +02:00
|
|
|
#define RV_GET_MAJOR_VER(x) ((x) >> 28)
|
|
|
|
#define RV_GET_MINOR_VER(x) (((x) >> 20) & 0xFF)
|
|
|
|
#define RV_GET_MICRO_VER(x) (((x) >> 12) & 0xFF)
|
|
|
|
|
2020-10-27 23:26:17 +01:00
|
|
|
#define MAX_VLC_ENTRIES 1023 // Note: Does not include the skip entries.
|
2020-10-28 10:48:09 +01:00
|
|
|
#define DC_VLC_BITS 9
|
2002-07-13 18:23:02 +02:00
|
|
|
|
2012-02-27 18:52:13 +01:00
|
|
|
typedef struct RVDecContext {
|
|
|
|
MpegEncContext m;
|
|
|
|
int sub_id;
|
2014-07-20 11:21:38 +02:00
|
|
|
int orig_width, orig_height;
|
2012-02-27 18:52:13 +01:00
|
|
|
} RVDecContext;
|
|
|
|
|
2020-10-27 23:26:17 +01:00
|
|
|
/* (run, length) encoded value for the symbols table. The actual symbols
|
2020-10-28 09:12:08 +01:00
|
|
|
* are run..run - length (mod 256).
|
2020-10-27 23:26:17 +01:00
|
|
|
* The last two entries in the following table apply to luma only.
|
|
|
|
* The skip values are not included in this list. */
|
|
|
|
static const uint8_t rv_sym_run_len[][2] = {
|
2020-10-28 09:12:08 +01:00
|
|
|
{ 0, 0 }, { 1, 0 }, { 255, 0 }, { 3, 1 }, { 254, 1 },
|
|
|
|
{ 7, 3 }, { 252, 3 }, { 15, 7 }, { 248, 7 }, { 31, 15 },
|
|
|
|
{ 240, 15 }, { 63, 31 }, { 224, 31 }, { 127, 63 }, { 192, 63 },
|
|
|
|
{ 255, 127 }, { 128, 127 }, { 127, 255 }, { 128, 255 },
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
|
|
|
|
2020-10-27 23:26:17 +01:00
|
|
|
/* entry[i] of the following tables gives
|
|
|
|
* the number of VLC codes of length i + 2. */
|
|
|
|
static const uint16_t rv_lum_len_count[15] = {
|
|
|
|
1, 0, 2, 4, 8, 16, 32, 0, 64, 0, 128, 0, 256, 0, 512,
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
|
|
|
|
2020-10-27 23:26:17 +01:00
|
|
|
static const uint16_t rv_chrom_len_count[15] = {
|
|
|
|
1, 2, 4, 0, 8, 0, 16, 0, 32, 0, 64, 0, 128, 0, 256,
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static VLC rv_dc_lum, rv_dc_chrom;
|
|
|
|
|
2012-02-15 12:54:05 +01:00
|
|
|
int ff_rv_decode_dc(MpegEncContext *s, int n)
|
2001-07-22 16:18:56 +02:00
|
|
|
{
|
|
|
|
int code;
|
|
|
|
|
|
|
|
if (n < 4) {
|
2002-07-13 18:23:02 +02:00
|
|
|
code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2);
|
2001-07-22 16:18:56 +02:00
|
|
|
} else {
|
2002-07-13 18:23:02 +02:00
|
|
|
code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2);
|
2001-07-22 16:18:56 +02:00
|
|
|
if (code < 0) {
|
2020-10-28 13:15:15 +01:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
|
|
|
|
return -1;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-28 09:12:08 +01:00
|
|
|
return code;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read RV 1.0 compatible frame header */
|
|
|
|
static int rv10_decode_picture_header(MpegEncContext *s)
|
|
|
|
{
|
2011-06-01 18:26:27 +02:00
|
|
|
int mb_count, pb_frame, marker, mb_xy;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2007-08-09 02:13:31 +02:00
|
|
|
marker = get_bits1(&s->gb);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2007-08-09 02:13:31 +02:00
|
|
|
if (get_bits1(&s->gb))
|
2011-04-28 01:40:44 +02:00
|
|
|
s->pict_type = AV_PICTURE_TYPE_P;
|
2001-07-22 16:18:56 +02:00
|
|
|
else
|
2011-04-28 01:40:44 +02:00
|
|
|
s->pict_type = AV_PICTURE_TYPE_I;
|
2013-04-09 20:06:44 +02:00
|
|
|
|
|
|
|
if (!marker)
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "marker missing\n");
|
|
|
|
|
2007-08-09 02:13:31 +02:00
|
|
|
pb_frame = get_bits1(&s->gb);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2015-03-16 09:57:36 +01:00
|
|
|
ff_dlog(s->avctx, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (pb_frame) {
|
2016-04-27 19:45:23 +02:00
|
|
|
avpriv_request_sample(s->avctx, "PB-frame");
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_PATCHWELCOME;
|
2002-08-28 14:23:12 +02:00
|
|
|
}
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
s->qscale = get_bits(&s->gb, 5);
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->qscale == 0) {
|
2013-04-09 20:11:09 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
2002-08-28 11:19:28 +02:00
|
|
|
}
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2011-04-28 01:40:44 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_I) {
|
2001-07-22 16:18:56 +02:00
|
|
|
if (s->rv10_version == 3) {
|
|
|
|
/* specific MPEG like DC coding not used */
|
|
|
|
s->last_dc[0] = get_bits(&s->gb, 8);
|
|
|
|
s->last_dc[1] = get_bits(&s->gb, 8);
|
|
|
|
s->last_dc[2] = get_bits(&s->gb, 8);
|
2015-03-16 09:57:36 +01:00
|
|
|
ff_dlog(s->avctx, "DC:%d %d %d\n", s->last_dc[0],
|
2009-07-28 14:50:32 +02:00
|
|
|
s->last_dc[1], s->last_dc[2]);
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if multiple packets per frame are sent, the position at which
|
2014-03-01 19:44:01 +01:00
|
|
|
* to display the macroblocks is coded here */
|
2004-12-06 18:21:17 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
mb_xy = s->mb_x + s->mb_y * s->mb_width;
|
|
|
|
if (show_bits(&s->gb, 12) == 0 || (mb_xy && mb_xy < s->mb_num)) {
|
|
|
|
s->mb_x = get_bits(&s->gb, 6); /* mb_x */
|
|
|
|
s->mb_y = get_bits(&s->gb, 6); /* mb_y */
|
2001-07-22 16:18:56 +02:00
|
|
|
mb_count = get_bits(&s->gb, 12);
|
|
|
|
} else {
|
2013-04-09 20:06:44 +02:00
|
|
|
s->mb_x = 0;
|
|
|
|
s->mb_y = 0;
|
2001-07-22 16:18:56 +02:00
|
|
|
mb_count = s->mb_width * s->mb_height;
|
|
|
|
}
|
2011-06-01 18:26:27 +02:00
|
|
|
skip_bits(&s->gb, 3); /* ignored */
|
2014-03-01 19:44:01 +01:00
|
|
|
s->f_code = 1;
|
2001-07-22 16:18:56 +02:00
|
|
|
s->unrestricted_mv = 1;
|
2002-08-28 23:47:28 +02:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
return mb_count;
|
|
|
|
}
|
|
|
|
|
2021-04-10 18:43:50 +02:00
|
|
|
static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
|
2003-11-30 15:35:35 +01:00
|
|
|
{
|
2012-02-27 18:52:13 +01:00
|
|
|
MpegEncContext *s = &rv->m;
|
2013-04-09 20:11:09 +02:00
|
|
|
int seq, mb_pos, i, ret;
|
2014-01-04 04:15:22 +01:00
|
|
|
int rpr_max;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
i = get_bits(&s->gb, 2);
|
|
|
|
switch (i) {
|
2014-03-01 19:44:01 +01:00
|
|
|
case 0:
|
|
|
|
s->pict_type = AV_PICTURE_TYPE_I;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
s->pict_type = AV_PICTURE_TYPE_I;
|
|
|
|
break; // hmm ...
|
|
|
|
case 2:
|
|
|
|
s->pict_type = AV_PICTURE_TYPE_P;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
s->pict_type = AV_PICTURE_TYPE_B;
|
|
|
|
break;
|
2005-12-17 19:14:38 +01:00
|
|
|
default:
|
2003-11-30 19:08:35 +01:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "unknown frame type\n");
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2003-11-30 19:08:35 +01:00
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2013-04-17 16:04:38 +02:00
|
|
|
if (s->low_delay && s->pict_type == AV_PICTURE_TYPE_B) {
|
2012-11-13 17:59:18 +01:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "low delay B\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-08-14 22:31:24 +02:00
|
|
|
if (!s->last_picture_ptr && s->pict_type == AV_PICTURE_TYPE_B) {
|
2013-04-09 20:11:09 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "early B-frame\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
2004-02-29 03:25:19 +01:00
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (get_bits1(&s->gb)) {
|
2011-08-04 21:00:12 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "reserved bit set\n");
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2003-11-30 15:35:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s->qscale = get_bits(&s->gb, 5);
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->qscale == 0) {
|
2013-04-09 20:11:09 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
2003-11-30 15:35:35 +01:00
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (RV_GET_MINOR_VER(rv->sub_id) >= 2)
|
2012-06-01 17:07:07 +02:00
|
|
|
s->loop_filter = get_bits1(&s->gb) && !s->avctx->lowres;
|
2004-12-06 23:44:03 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (RV_GET_MINOR_VER(rv->sub_id) <= 1)
|
2011-08-04 21:00:12 +02:00
|
|
|
seq = get_bits(&s->gb, 8) << 7;
|
|
|
|
else
|
|
|
|
seq = get_bits(&s->gb, 13) << 2;
|
|
|
|
|
2014-01-04 04:15:22 +01:00
|
|
|
rpr_max = s->avctx->extradata[1] & 7;
|
|
|
|
if (rpr_max) {
|
2011-08-04 21:00:12 +02:00
|
|
|
int f, new_w, new_h;
|
2014-01-04 04:15:22 +01:00
|
|
|
int rpr_bits = av_log2(rpr_max) + 1;
|
2004-12-13 12:41:59 +01:00
|
|
|
|
2011-08-04 21:00:12 +02:00
|
|
|
f = get_bits(&s->gb, rpr_bits);
|
2006-09-30 13:31:15 +02:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (f) {
|
2013-04-09 20:33:25 +02:00
|
|
|
if (s->avctx->extradata_size < 8 + 2 * f) {
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "Extradata too small.\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2014-03-01 19:44:01 +01:00
|
|
|
new_w = 4 * ((uint8_t *) s->avctx->extradata)[6 + 2 * f];
|
|
|
|
new_h = 4 * ((uint8_t *) s->avctx->extradata)[7 + 2 * f];
|
2013-04-09 20:06:44 +02:00
|
|
|
} else {
|
2014-07-20 11:21:38 +02:00
|
|
|
new_w = rv->orig_width;
|
|
|
|
new_h = rv->orig_height;
|
2006-09-30 13:31:15 +02:00
|
|
|
}
|
2021-04-04 21:30:33 +02:00
|
|
|
if (new_w != s->width || new_h != s->height || !s->context_initialized) {
|
2012-04-09 14:21:01 +02:00
|
|
|
AVRational old_aspect = s->avctx->sample_aspect_ratio;
|
2013-04-09 20:06:44 +02:00
|
|
|
av_log(s->avctx, AV_LOG_DEBUG,
|
|
|
|
"attempting to change resolution to %dx%d\n", new_w, new_h);
|
2013-11-22 19:30:33 +01:00
|
|
|
if (av_image_check_size(new_w, new_h, 0, s->avctx) < 0)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2021-04-10 18:43:50 +02:00
|
|
|
|
|
|
|
if (whole_size < (new_w + 15)/16 * ((new_h + 15)/16) / 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2014-08-10 17:25:12 +02:00
|
|
|
ff_mpv_common_end(s);
|
2012-04-09 14:21:01 +02:00
|
|
|
|
|
|
|
// attempt to keep aspect during typical resolution switches
|
|
|
|
if (!old_aspect.num)
|
|
|
|
old_aspect = (AVRational){1, 1};
|
2019-06-28 19:20:43 +02:00
|
|
|
if (2 * (int64_t)new_w * s->height == (int64_t)new_h * s->width)
|
2012-04-09 14:21:01 +02:00
|
|
|
s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1});
|
2019-06-28 19:20:43 +02:00
|
|
|
if ((int64_t)new_w * s->height == 2 * (int64_t)new_h * s->width)
|
2012-04-09 14:21:01 +02:00
|
|
|
s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2});
|
2013-11-01 15:34:49 +01:00
|
|
|
|
2013-10-27 10:02:26 +01:00
|
|
|
ret = ff_set_dimensions(s->avctx, new_w, new_h);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2009-11-23 20:22:19 +01:00
|
|
|
s->width = new_w;
|
|
|
|
s->height = new_h;
|
2014-08-10 17:25:12 +02:00
|
|
|
if ((ret = ff_mpv_common_init(s)) < 0)
|
2013-04-09 20:11:09 +02:00
|
|
|
return ret;
|
2006-09-30 13:31:15 +02:00
|
|
|
}
|
2005-04-25 00:08:31 +02:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
|
2014-01-04 04:15:22 +01:00
|
|
|
av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max);
|
2004-11-19 19:19:36 +01:00
|
|
|
}
|
2012-11-15 02:16:56 +01:00
|
|
|
}
|
|
|
|
if (av_image_check_size(s->width, s->height, 0, s->avctx) < 0)
|
2012-01-24 21:50:50 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2004-12-06 00:21:39 +01:00
|
|
|
|
2011-08-04 21:00:12 +02:00
|
|
|
mb_pos = ff_h263_decode_mba(s);
|
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
seq |= s->time & ~0x7FFF;
|
|
|
|
if (seq - s->time > 0x4000)
|
|
|
|
seq -= 0x8000;
|
|
|
|
if (seq - s->time < -0x4000)
|
|
|
|
seq += 0x8000;
|
|
|
|
|
|
|
|
if (seq != s->time) {
|
|
|
|
if (s->pict_type != AV_PICTURE_TYPE_B) {
|
|
|
|
s->time = seq;
|
|
|
|
s->pp_time = s->time - s->last_non_b_time;
|
|
|
|
s->last_non_b_time = s->time;
|
|
|
|
} else {
|
|
|
|
s->time = seq;
|
|
|
|
s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
|
2003-12-04 19:34:47 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-17 16:04:38 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B) {
|
|
|
|
if (s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0) {
|
|
|
|
av_log(s->avctx, AV_LOG_DEBUG,
|
2016-06-21 21:55:20 +02:00
|
|
|
"messed up order, possible from seeking? skipping current B-frame\n");
|
2013-03-06 03:10:18 +01:00
|
|
|
#define ERROR_SKIP_FRAME -123
|
|
|
|
return ERROR_SKIP_FRAME;
|
2013-01-07 21:16:23 +01:00
|
|
|
}
|
|
|
|
ff_mpeg4_init_direct_mv(s);
|
|
|
|
}
|
2012-09-25 17:19:34 +02:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
s->no_rounding = get_bits1(&s->gb);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B)
|
2014-03-01 19:44:01 +01:00
|
|
|
// binary decoder reads 3+2 bits here but they don't seem to be used
|
|
|
|
skip_bits(&s->gb, 5);
|
2011-08-04 21:00:12 +02:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
s->f_code = 1;
|
2003-11-30 15:35:35 +01:00
|
|
|
s->unrestricted_mv = 1;
|
2013-04-09 20:06:44 +02:00
|
|
|
s->h263_aic = s->pict_type == AV_PICTURE_TYPE_I;
|
|
|
|
s->modified_quant = 1;
|
2013-04-17 16:04:38 +02:00
|
|
|
if (!s->avctx->lowres)
|
|
|
|
s->loop_filter = 1;
|
2013-04-09 20:06:44 +02:00
|
|
|
|
|
|
|
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
|
2014-03-01 19:44:01 +01:00
|
|
|
av_log(s->avctx, AV_LOG_INFO,
|
|
|
|
"num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n",
|
|
|
|
seq, s->mb_x, s->mb_y, s->pict_type, s->qscale,
|
|
|
|
s->no_rounding);
|
2003-11-30 15:35:35 +01:00
|
|
|
}
|
|
|
|
|
2012-06-08 18:24:47 +02:00
|
|
|
av_assert0(s->pict_type != AV_PICTURE_TYPE_B || !s->low_delay);
|
2003-11-30 19:08:35 +01:00
|
|
|
|
2014-03-01 19:44:01 +01:00
|
|
|
return s->mb_width * s->mb_height - mb_pos;
|
2003-11-30 15:35:35 +01:00
|
|
|
}
|
|
|
|
|
2020-10-27 23:26:17 +01:00
|
|
|
static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15],
|
|
|
|
const uint8_t sym_rl[][2], int sym_rl_elems)
|
|
|
|
{
|
|
|
|
uint16_t syms[MAX_VLC_ENTRIES];
|
|
|
|
uint8_t lens[MAX_VLC_ENTRIES];
|
|
|
|
unsigned nb_syms = 0, nb_lens = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < sym_rl_elems; i++) {
|
|
|
|
unsigned cur_sym = sym_rl[i][0];
|
|
|
|
for (unsigned tmp = nb_syms + sym_rl[i][1]; nb_syms <= tmp; nb_syms++)
|
2020-10-28 09:12:08 +01:00
|
|
|
syms[nb_syms] = 0xFF & cur_sym--;
|
2020-10-27 23:26:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 15; i++)
|
|
|
|
for (unsigned tmp = nb_lens + len_count[i]; nb_lens < tmp; nb_lens++)
|
|
|
|
lens[nb_lens] = i + 2;
|
|
|
|
av_assert1(nb_lens == nb_syms);
|
|
|
|
ff_init_vlc_from_lengths(vlc, DC_VLC_BITS, nb_lens, lens, 1,
|
|
|
|
syms, 2, 2, 0, INIT_VLC_STATIC_OVERLONG, NULL);
|
|
|
|
}
|
|
|
|
|
2020-11-17 10:09:34 +01:00
|
|
|
static av_cold void rv10_init_static(void)
|
|
|
|
{
|
2020-10-28 10:48:09 +01:00
|
|
|
static VLC_TYPE table[1472 + 992][2];
|
2020-10-27 23:26:17 +01:00
|
|
|
|
|
|
|
rv_dc_lum.table = table;
|
2020-10-28 10:48:09 +01:00
|
|
|
rv_dc_lum.table_allocated = 1472;
|
2020-10-27 23:26:17 +01:00
|
|
|
rv10_build_vlc(&rv_dc_lum, rv_lum_len_count,
|
|
|
|
rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len));
|
2020-10-28 13:15:15 +01:00
|
|
|
for (int i = 0; i < 1 << (DC_VLC_BITS - 7 /* Length of skip prefix */); i++) {
|
|
|
|
/* All codes beginning with 0x7F have the same length and value.
|
|
|
|
* Modifying the table directly saves us the useless subtables. */
|
|
|
|
rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i][0] = 255;
|
|
|
|
rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i][1] = 18;
|
|
|
|
}
|
2020-10-28 10:48:09 +01:00
|
|
|
rv_dc_chrom.table = &table[1472];
|
|
|
|
rv_dc_chrom.table_allocated = 992;
|
2020-10-27 23:26:17 +01:00
|
|
|
rv10_build_vlc(&rv_dc_chrom, rv_chrom_len_count,
|
|
|
|
rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len) - 2);
|
2020-10-28 13:15:15 +01:00
|
|
|
for (int i = 0; i < 1 << (DC_VLC_BITS - 9 /* Length of skip prefix */); i++) {
|
|
|
|
/* Same as above. */
|
|
|
|
rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i][0] = 255;
|
|
|
|
rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i][1] = 18;
|
|
|
|
}
|
2020-11-17 10:09:34 +01:00
|
|
|
ff_h263_decode_init_vlc();
|
|
|
|
}
|
|
|
|
|
2008-03-21 04:11:20 +01:00
|
|
|
static av_cold int rv10_decode_init(AVCodecContext *avctx)
|
2001-07-22 16:18:56 +02:00
|
|
|
{
|
2020-11-17 10:09:34 +01:00
|
|
|
static AVOnce init_static_once = AV_ONCE_INIT;
|
2014-03-01 19:44:01 +01:00
|
|
|
RVDecContext *rv = avctx->priv_data;
|
2012-02-27 18:52:13 +01:00
|
|
|
MpegEncContext *s = &rv->m;
|
2013-04-09 20:11:09 +02:00
|
|
|
int major_ver, minor_ver, micro_ver, ret;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2008-12-16 00:01:54 +01:00
|
|
|
if (avctx->extradata_size < 8) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Extradata is too small.\n");
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2008-12-16 00:01:54 +01:00
|
|
|
}
|
2013-09-16 14:40:57 +02:00
|
|
|
if ((ret = av_image_check_size(avctx->coded_width,
|
|
|
|
avctx->coded_height, 0, avctx)) < 0)
|
|
|
|
return ret;
|
2008-12-16 00:01:54 +01:00
|
|
|
|
2014-09-05 16:57:57 +02:00
|
|
|
ff_mpv_decode_init(s, avctx);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2014-03-01 19:44:01 +01:00
|
|
|
s->out_format = FMT_H263;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2014-07-20 11:21:38 +02:00
|
|
|
rv->orig_width =
|
|
|
|
s->width = avctx->coded_width;
|
|
|
|
rv->orig_height =
|
|
|
|
s->height = avctx->coded_height;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2014-03-01 19:44:01 +01:00
|
|
|
s->h263_long_vectors = ((uint8_t *) avctx->extradata)[3] & 1;
|
|
|
|
rv->sub_id = AV_RB32((uint8_t *) avctx->extradata + 4);
|
2006-09-30 01:57:03 +02:00
|
|
|
|
2012-02-27 18:52:13 +01:00
|
|
|
major_ver = RV_GET_MAJOR_VER(rv->sub_id);
|
|
|
|
minor_ver = RV_GET_MINOR_VER(rv->sub_id);
|
|
|
|
micro_ver = RV_GET_MICRO_VER(rv->sub_id);
|
2011-08-04 21:00:12 +02:00
|
|
|
|
|
|
|
s->low_delay = 1;
|
|
|
|
switch (major_ver) {
|
|
|
|
case 1:
|
|
|
|
s->rv10_version = micro_ver ? 3 : 1;
|
2013-04-09 20:06:44 +02:00
|
|
|
s->obmc = micro_ver == 2;
|
2011-08-04 21:00:12 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (minor_ver >= 2) {
|
2013-04-09 20:06:44 +02:00
|
|
|
s->low_delay = 0;
|
2011-08-04 21:00:12 +02:00
|
|
|
s->avctx->has_b_frames = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-02-27 18:52:13 +01:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", rv->sub_id);
|
2013-03-13 21:18:34 +01:00
|
|
|
avpriv_request_sample(avctx, "RV1/2 version");
|
2011-08-04 21:00:12 +02:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (avctx->debug & FF_DEBUG_PICT_INFO) {
|
2014-03-22 18:43:40 +01:00
|
|
|
av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%"PRIX32"\n", rv->sub_id,
|
2014-03-09 01:05:37 +01:00
|
|
|
((uint32_t *) avctx->extradata)[0]);
|
2004-12-06 00:21:39 +01:00
|
|
|
}
|
2005-04-25 20:29:06 +02:00
|
|
|
|
2012-10-06 12:10:34 +02:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
|
2005-04-25 20:29:06 +02:00
|
|
|
|
2014-08-08 17:11:20 +02:00
|
|
|
ff_mpv_idct_init(s);
|
2014-08-10 17:25:12 +02:00
|
|
|
if ((ret = ff_mpv_common_init(s)) < 0)
|
2013-04-09 20:11:09 +02:00
|
|
|
return ret;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2013-11-05 08:11:47 +01:00
|
|
|
ff_h263dsp_init(&s->h263dsp);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2020-11-17 10:09:34 +01:00
|
|
|
/* init static VLCs */
|
|
|
|
ff_thread_once(&init_static_once, rv10_init_static);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-21 04:11:20 +01:00
|
|
|
static av_cold int rv10_decode_end(AVCodecContext *avctx)
|
2001-07-22 16:18:56 +02:00
|
|
|
{
|
|
|
|
MpegEncContext *s = avctx->priv_data;
|
|
|
|
|
2014-08-10 17:25:12 +02:00
|
|
|
ff_mpv_common_end(s);
|
2001-07-22 16:18:56 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-01 19:44:01 +01:00
|
|
|
static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
|
2019-10-09 09:08:38 +02:00
|
|
|
int buf_size, int buf_size2, int whole_size)
|
2001-07-22 16:18:56 +02:00
|
|
|
{
|
2014-03-01 19:44:01 +01:00
|
|
|
RVDecContext *rv = avctx->priv_data;
|
2012-02-27 18:52:13 +01:00
|
|
|
MpegEncContext *s = &rv->m;
|
2013-04-09 20:11:09 +02:00
|
|
|
int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2012-03-01 22:24:55 +01:00
|
|
|
active_bits_size = buf_size * 8;
|
|
|
|
init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8);
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->codec_id == AV_CODEC_ID_RV10)
|
2003-11-30 15:35:35 +01:00
|
|
|
mb_count = rv10_decode_picture_header(s);
|
|
|
|
else
|
2021-04-10 18:43:50 +02:00
|
|
|
mb_count = rv20_decode_picture_header(rv, whole_size);
|
2001-07-22 16:18:56 +02:00
|
|
|
if (mb_count < 0) {
|
2013-03-06 03:10:18 +01:00
|
|
|
if (mb_count != ERROR_SKIP_FRAME)
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n");
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
if (s->mb_x >= s->mb_width ||
|
|
|
|
s->mb_y >= s->mb_height) {
|
2003-11-03 14:26:22 +01:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", s->mb_x, s->mb_y);
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
mb_pos = s->mb_y * s->mb_width + s->mb_x;
|
2014-03-01 19:44:01 +01:00
|
|
|
left = s->mb_width * s->mb_height - mb_pos;
|
2001-07-22 16:18:56 +02:00
|
|
|
if (mb_count > left) {
|
2003-11-03 14:26:22 +01:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "COUNT ERROR\n");
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 09:08:38 +02:00
|
|
|
if (whole_size < s->mb_width * s->mb_height / 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2014-08-14 22:31:24 +02:00
|
|
|
if ((s->mb_x == 0 && s->mb_y == 0) || !s->current_picture_ptr) {
|
2014-03-01 19:44:01 +01:00
|
|
|
// FIXME write parser so we always have complete frames?
|
|
|
|
if (s->current_picture_ptr) {
|
2013-02-02 20:42:07 +01:00
|
|
|
ff_er_frame_end(&s->er);
|
2014-08-10 17:25:12 +02:00
|
|
|
ff_mpv_frame_end(s);
|
2013-04-09 20:06:44 +02:00
|
|
|
s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
|
2005-09-01 02:15:12 +02:00
|
|
|
}
|
2014-08-10 17:25:12 +02:00
|
|
|
if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
|
2013-04-09 20:11:09 +02:00
|
|
|
return ret;
|
2013-02-02 20:42:07 +01:00
|
|
|
ff_mpeg_er_frame_start(s);
|
2011-09-18 00:17:44 +02:00
|
|
|
} else {
|
2014-03-31 19:46:29 +02:00
|
|
|
if (s->current_picture_ptr->f->pict_type != s->pict_type) {
|
2011-09-18 00:03:08 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n");
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2011-09-18 00:03:08 +02:00
|
|
|
}
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
|
2011-09-18 00:17:44 +02:00
|
|
|
|
2015-03-16 09:57:36 +01:00
|
|
|
ff_dlog(avctx, "qscale=%d\n", s->qscale);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
/* default quantization values */
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->codec_id == AV_CODEC_ID_RV10) {
|
|
|
|
if (s->mb_y == 0)
|
|
|
|
s->first_slice_line = 1;
|
|
|
|
} else {
|
|
|
|
s->first_slice_line = 1;
|
|
|
|
s->resync_mb_x = s->mb_x;
|
2003-11-30 15:35:35 +01:00
|
|
|
}
|
2013-04-09 20:06:44 +02:00
|
|
|
start_mb_x = s->mb_x;
|
|
|
|
s->resync_mb_y = s->mb_y;
|
|
|
|
if (s->h263_aic) {
|
2014-03-01 19:44:01 +01:00
|
|
|
s->y_dc_scale_table =
|
|
|
|
s->c_dc_scale_table = ff_aic_dc_scale_table;
|
2013-04-09 20:06:44 +02:00
|
|
|
} else {
|
2014-03-01 19:44:01 +01:00
|
|
|
s->y_dc_scale_table =
|
|
|
|
s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
|
2003-11-30 15:35:35 +01:00
|
|
|
}
|
2003-12-01 16:23:14 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->modified_quant)
|
|
|
|
s->chroma_qscale_table = ff_h263_chroma_qscale_table;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2003-12-03 17:47:17 +01:00
|
|
|
ff_set_qscale(s, s->qscale);
|
2003-12-01 16:23:14 +01:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
s->rv10_first_dc_coded[0] = 0;
|
|
|
|
s->rv10_first_dc_coded[1] = 0;
|
|
|
|
s->rv10_first_dc_coded[2] = 0;
|
2013-04-09 20:06:44 +02:00
|
|
|
s->block_wrap[0] =
|
|
|
|
s->block_wrap[1] =
|
|
|
|
s->block_wrap[2] =
|
|
|
|
s->block_wrap[3] = s->b8_stride;
|
|
|
|
s->block_wrap[4] =
|
|
|
|
s->block_wrap[5] = s->mb_stride;
|
2002-10-13 15:16:04 +02:00
|
|
|
ff_init_block_index(s);
|
2004-02-09 16:23:35 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
/* decode each macroblock */
|
|
|
|
for (s->mb_num_left = mb_count; s->mb_num_left > 0; s->mb_num_left--) {
|
2003-11-30 15:35:35 +01:00
|
|
|
int ret;
|
2002-10-13 15:16:04 +02:00
|
|
|
ff_update_block_index(s);
|
2015-04-26 16:29:23 +02:00
|
|
|
ff_tlog(avctx, "**mb x=%d y=%d\n", s->mb_x, s->mb_y);
|
2004-02-09 16:23:35 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
s->mv_dir = MV_DIR_FORWARD;
|
2005-12-17 19:14:38 +01:00
|
|
|
s->mv_type = MV_TYPE_16X16;
|
2013-04-09 20:06:44 +02:00
|
|
|
ret = ff_h263_decode_mb(s, s->block);
|
2003-11-30 15:35:35 +01:00
|
|
|
|
2012-03-01 22:24:55 +01:00
|
|
|
// Repeat the slice end check from ff_h263_decode_mb with our active
|
|
|
|
// bitstream size
|
2019-06-16 12:52:30 +02:00
|
|
|
if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&s->gb)) {
|
2012-03-01 22:24:55 +01:00
|
|
|
int v = show_bits(&s->gb, 16);
|
|
|
|
|
|
|
|
if (get_bits_count(&s->gb) + 16 > active_bits_size)
|
|
|
|
v >>= get_bits_count(&s->gb) + 16 - active_bits_size;
|
|
|
|
|
|
|
|
if (!v)
|
|
|
|
ret = SLICE_END;
|
|
|
|
}
|
|
|
|
if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&s->gb) &&
|
|
|
|
8 * buf_size2 >= get_bits_count(&s->gb)) {
|
|
|
|
active_bits_size = buf_size2 * 8;
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
|
|
|
|
8 * buf_size, active_bits_size);
|
2013-04-09 20:06:44 +02:00
|
|
|
ret = SLICE_OK;
|
2009-12-01 22:10:37 +01:00
|
|
|
}
|
|
|
|
|
2012-03-01 22:24:55 +01:00
|
|
|
if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) {
|
2014-03-01 19:44:01 +01:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x,
|
|
|
|
s->mb_y);
|
2013-04-09 20:11:09 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->pict_type != AV_PICTURE_TYPE_B)
|
2004-01-18 03:59:01 +01:00
|
|
|
ff_h263_update_motion_val(s);
|
2017-06-18 20:15:05 +02:00
|
|
|
ff_mpv_reconstruct_mb(s, s->block);
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->loop_filter)
|
2003-12-01 16:23:14 +01:00
|
|
|
ff_h263_loop_filter(s);
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
if (++s->mb_x == s->mb_width) {
|
|
|
|
s->mb_x = 0;
|
|
|
|
s->mb_y++;
|
2002-10-13 15:16:04 +02:00
|
|
|
ff_init_block_index(s);
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->mb_x == s->resync_mb_x)
|
|
|
|
s->first_slice_line = 0;
|
|
|
|
if (ret == SLICE_END)
|
|
|
|
break;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
|
2014-03-01 19:44:01 +01:00
|
|
|
ff_er_add_slice(&s->er, start_mb_x, s->resync_mb_y, s->mb_x - 1, s->mb_y,
|
2013-04-09 20:06:44 +02:00
|
|
|
ER_MB_END);
|
2005-09-01 02:15:12 +02:00
|
|
|
|
2012-03-01 22:24:55 +01:00
|
|
|
return active_bits_size;
|
2002-10-01 21:29:10 +02:00
|
|
|
}
|
|
|
|
|
2008-02-01 15:08:35 +01:00
|
|
|
static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
|
2007-10-21 19:22:37 +02:00
|
|
|
{
|
2013-04-09 20:06:44 +02:00
|
|
|
if (avctx->slice_count)
|
|
|
|
return avctx->slice_offset[n];
|
|
|
|
else
|
|
|
|
return AV_RL32(buf + n * 8);
|
2007-10-21 19:22:37 +02:00
|
|
|
}
|
|
|
|
|
2014-03-01 19:44:01 +01:00
|
|
|
static int rv10_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
2009-04-07 17:59:50 +02:00
|
|
|
AVPacket *avpkt)
|
2002-10-01 21:29:10 +02:00
|
|
|
{
|
2009-04-07 17:59:50 +02:00
|
|
|
const uint8_t *buf = avpkt->data;
|
2013-04-09 20:06:44 +02:00
|
|
|
int buf_size = avpkt->size;
|
2014-03-01 19:44:01 +01:00
|
|
|
MpegEncContext *s = avctx->priv_data;
|
|
|
|
AVFrame *pict = data;
|
2012-11-21 21:34:46 +01:00
|
|
|
int i, ret;
|
2007-10-21 19:22:37 +02:00
|
|
|
int slice_count;
|
2008-02-01 15:08:35 +01:00
|
|
|
const uint8_t *slices_hdr = NULL;
|
2002-10-01 21:29:10 +02:00
|
|
|
|
2015-03-16 09:57:36 +01:00
|
|
|
ff_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
|
2002-10-01 21:29:10 +02:00
|
|
|
|
|
|
|
/* no supplementary picture */
|
|
|
|
if (buf_size == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2004-01-18 03:59:01 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (!avctx->slice_count) {
|
2007-10-21 19:22:37 +02:00
|
|
|
slice_count = (*buf++) + 1;
|
2012-03-01 23:07:22 +01:00
|
|
|
buf_size--;
|
2013-02-03 08:42:02 +01:00
|
|
|
|
|
|
|
if (!slice_count || buf_size <= 8 * slice_count) {
|
2014-03-01 19:44:01 +01:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid slice count: %d.\n",
|
|
|
|
slice_count);
|
2013-02-03 08:42:02 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2007-10-21 19:22:37 +02:00
|
|
|
slices_hdr = buf + 4;
|
2013-04-09 20:06:44 +02:00
|
|
|
buf += 8 * slice_count;
|
|
|
|
buf_size -= 8 * slice_count;
|
|
|
|
} else
|
2007-10-21 19:22:37 +02:00
|
|
|
slice_count = avctx->slice_count;
|
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
for (i = 0; i < slice_count; i++) {
|
2012-01-23 20:57:04 +01:00
|
|
|
unsigned offset = get_slice_offset(avctx, slices_hdr, i);
|
2009-12-01 22:10:37 +01:00
|
|
|
int size, size2;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2012-01-23 20:57:04 +01:00
|
|
|
if (offset >= buf_size)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (i + 1 == slice_count)
|
|
|
|
size = buf_size - offset;
|
2007-10-21 19:23:07 +02:00
|
|
|
else
|
2013-04-09 20:06:44 +02:00
|
|
|
size = get_slice_offset(avctx, slices_hdr, i + 1) - offset;
|
2002-10-01 21:29:10 +02:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (i + 2 >= slice_count)
|
|
|
|
size2 = buf_size - offset;
|
2009-12-01 22:10:37 +01:00
|
|
|
else
|
2013-04-09 20:06:44 +02:00
|
|
|
size2 = get_slice_offset(avctx, slices_hdr, i + 2) - offset;
|
2009-12-01 22:10:37 +01:00
|
|
|
|
2012-01-23 20:57:04 +01:00
|
|
|
if (size <= 0 || size2 <= 0 ||
|
|
|
|
offset + FFMAX(size, size2) > buf_size)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2019-10-09 09:08:38 +02:00
|
|
|
if ((ret = rv10_decode_packet(avctx, buf + offset, size, size2, buf_size)) < 0)
|
2014-03-01 19:44:00 +01:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (ret > 8 * size)
|
2009-12-01 22:10:37 +01:00
|
|
|
i++;
|
2007-10-21 19:23:07 +02:00
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2014-08-14 22:31:25 +02:00
|
|
|
if (s->current_picture_ptr && s->mb_y >= s->mb_height) {
|
2013-02-02 20:42:07 +01:00
|
|
|
ff_er_frame_end(&s->er);
|
2014-08-10 17:25:12 +02:00
|
|
|
ff_mpv_frame_end(s);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2011-04-28 01:40:44 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
|
2014-03-31 19:46:29 +02:00
|
|
|
if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
|
2012-11-21 21:34:46 +01:00
|
|
|
return ret;
|
2013-03-12 11:23:07 +01:00
|
|
|
ff_print_debug_info(s, s->current_picture_ptr, pict);
|
2013-03-15 14:33:24 +01:00
|
|
|
ff_mpv_export_qp_table(s, pict, s->current_picture_ptr, FF_QSCALE_TYPE_MPEG1);
|
2014-08-14 22:31:25 +02:00
|
|
|
} else if (s->last_picture_ptr) {
|
2014-03-31 19:46:29 +02:00
|
|
|
if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0)
|
2012-11-21 21:34:46 +01:00
|
|
|
return ret;
|
2013-03-12 11:23:07 +01:00
|
|
|
ff_print_debug_info(s, s->last_picture_ptr, pict);
|
2013-03-15 14:33:24 +01:00
|
|
|
ff_mpv_export_qp_table(s, pict,s->last_picture_ptr, FF_QSCALE_TYPE_MPEG1);
|
2003-12-04 19:34:47 +01:00
|
|
|
}
|
2006-03-10 21:40:52 +01:00
|
|
|
|
2013-04-09 20:06:44 +02:00
|
|
|
if (s->last_picture_ptr || s->low_delay) {
|
2012-11-13 19:35:22 +01:00
|
|
|
*got_frame = 1;
|
2006-03-10 21:40:52 +01:00
|
|
|
}
|
2013-04-09 20:06:44 +02:00
|
|
|
|
|
|
|
// so we can detect if frame_end was not called (find some nicer solution...)
|
|
|
|
s->current_picture_ptr = NULL;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2002-10-01 21:29:10 +02:00
|
|
|
|
2012-03-01 23:07:22 +01:00
|
|
|
return avpkt->size;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
|
2021-02-25 10:50:26 +01:00
|
|
|
const AVCodec ff_rv10_decoder = {
|
2011-07-17 12:54:31 +02:00
|
|
|
.name = "rv10",
|
2013-10-03 22:57:53 +02:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("RealVideo 1.0"),
|
2011-07-17 12:54:31 +02:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 11:11:04 +02:00
|
|
|
.id = AV_CODEC_ID_RV10,
|
2012-02-27 18:52:13 +01:00
|
|
|
.priv_data_size = sizeof(RVDecContext),
|
2011-07-17 12:54:31 +02:00
|
|
|
.init = rv10_decode_init,
|
|
|
|
.close = rv10_decode_end,
|
|
|
|
.decode = rv10_decode_frame,
|
2015-07-07 02:41:27 +02:00
|
|
|
.capabilities = AV_CODEC_CAP_DR1,
|
2012-05-25 12:35:42 +02:00
|
|
|
.max_lowres = 3,
|
2014-03-17 18:03:47 +01:00
|
|
|
.pix_fmts = (const enum AVPixelFormat[]) {
|
|
|
|
AV_PIX_FMT_YUV420P,
|
|
|
|
AV_PIX_FMT_NONE
|
|
|
|
},
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
2003-11-30 15:35:35 +01:00
|
|
|
|
2021-02-25 10:50:26 +01:00
|
|
|
const AVCodec ff_rv20_decoder = {
|
2011-07-17 12:54:31 +02:00
|
|
|
.name = "rv20",
|
2013-10-03 22:57:53 +02:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
|
2011-07-17 12:54:31 +02:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 11:11:04 +02:00
|
|
|
.id = AV_CODEC_ID_RV20,
|
2012-02-27 18:52:13 +01:00
|
|
|
.priv_data_size = sizeof(RVDecContext),
|
2011-07-17 12:54:31 +02:00
|
|
|
.init = rv10_decode_init,
|
|
|
|
.close = rv10_decode_end,
|
|
|
|
.decode = rv10_decode_frame,
|
2015-07-07 02:41:27 +02:00
|
|
|
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
|
2012-04-06 18:19:39 +02:00
|
|
|
.flush = ff_mpeg_flush,
|
2012-05-25 12:35:42 +02:00
|
|
|
.max_lowres = 3,
|
2014-03-17 18:03:47 +01:00
|
|
|
.pix_fmts = (const enum AVPixelFormat[]) {
|
|
|
|
AV_PIX_FMT_YUV420P,
|
|
|
|
AV_PIX_FMT_NONE
|
|
|
|
},
|
2003-11-30 15:35:35 +01:00
|
|
|
};
|