summaryrefslogtreecommitdiff
path: root/libavcodec/h261dec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-01-27 22:49:52 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-02-13 15:18:24 +0100
commitd5e87df9029b5b14da95d48d5ffa63f58d2cc527 (patch)
tree3db5986b7645fadd2f680491decd5765faa63f5e /libavcodec/h261dec.c
parent725e2300af90eb005ecdde915ba59ee3a0dc5a7a (diff)
downloadffmpeg-d5e87df9029b5b14da95d48d5ffa63f58d2cc527.tar.gz
avcodec/h261: Separate decode and encode contexts
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/h261dec.c')
-rw-r--r--libavcodec/h261dec.c59
1 files changed, 37 insertions, 22 deletions
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 2fd8d94df1..17f1067b15 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -47,6 +47,19 @@ static VLC h261_mtype_vlc;
static VLC h261_mv_vlc;
static VLC h261_cbp_vlc;
+typedef struct H261DecContext {
+ MpegEncContext s;
+
+ H261Context common;
+
+ int current_mba;
+ int mba_diff;
+ int current_mv_x;
+ int current_mv_y;
+ int gob_number;
+ int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
+} H261DecContext;
+
static av_cold void h261_decode_init_static(void)
{
INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
@@ -67,9 +80,10 @@ static av_cold void h261_decode_init_static(void)
static av_cold int h261_decode_init(AVCodecContext *avctx)
{
static AVOnce init_static_once = AV_ONCE_INIT;
- H261Context *h = avctx->priv_data;
+ H261DecContext *const h = avctx->priv_data;
MpegEncContext *const s = &h->s;
+ s->private_ctx = &h->common;
// set defaults
ff_mpv_decode_init(s, avctx);
@@ -89,7 +103,7 @@ static av_cold int h261_decode_init(AVCodecContext *avctx)
* Decode the group of blocks header or slice header.
* @return <0 if an error occurred
*/
-static int h261_decode_gob_header(H261Context *h)
+static int h261_decode_gob_header(H261DecContext *h)
{
unsigned int val;
MpegEncContext *const s = &h->s;
@@ -143,7 +157,7 @@ static int h261_decode_gob_header(H261Context *h)
* Decode the group of blocks / video packet header.
* @return <0 if no resync found
*/
-static int h261_resync(H261Context *h)
+static int h261_resync(H261DecContext *h)
{
MpegEncContext *const s = &h->s;
int left, ret;
@@ -184,7 +198,7 @@ static int h261_resync(H261Context *h)
* Decode skipped macroblocks.
* @return 0
*/
-static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
+static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2)
{
MpegEncContext *const s = &h->s;
int i;
@@ -209,7 +223,7 @@ static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
s->mb_skipped = 1;
- h->mtype &= ~MB_TYPE_H261_FIL;
+ h->common.mtype &= ~MB_TYPE_H261_FIL;
if (s->current_picture.motion_val[0]) {
int b_stride = 2*s->mb_width + 1;
@@ -254,7 +268,7 @@ static int decode_mv_component(GetBitContext *gb, int v)
* Decode a macroblock.
* @return <0 if an error occurred
*/
-static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
+static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded)
{
MpegEncContext *const s = &h->s;
int level, i, j, run;
@@ -346,9 +360,10 @@ static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
return 0;
}
-static int h261_decode_mb(H261Context *h)
+static int h261_decode_mb(H261DecContext *h)
{
MpegEncContext *const s = &h->s;
+ H261Context *const com = &h->common;
int i, cbp, xy;
cbp = 63;
@@ -386,23 +401,23 @@ static int h261_decode_mb(H261Context *h)
ff_update_block_index(s);
// Read mtype
- h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
- if (h->mtype < 0) {
+ com->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
+ if (com->mtype < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
- h->mtype);
+ com->mtype);
return SLICE_ERROR;
}
- av_assert0(h->mtype < FF_ARRAY_ELEMS(ff_h261_mtype_map));
- h->mtype = ff_h261_mtype_map[h->mtype];
+ av_assert0(com->mtype < FF_ARRAY_ELEMS(ff_h261_mtype_map));
+ com->mtype = ff_h261_mtype_map[com->mtype];
// Read mquant
- if (IS_QUANT(h->mtype))
+ if (IS_QUANT(com->mtype))
ff_set_qscale(s, get_bits(&s->gb, 5));
- s->mb_intra = IS_INTRA4x4(h->mtype);
+ s->mb_intra = IS_INTRA4x4(com->mtype);
// Read mv
- if (IS_16X16(h->mtype)) {
+ if (IS_16X16(com->mtype)) {
/* Motion vector data is included for all MC macroblocks. MVD is
* obtained from the macroblock vector by subtracting the vector
* of the preceding macroblock. For this calculation the vector
@@ -425,7 +440,7 @@ static int h261_decode_mb(H261Context *h)
}
// Read cbp
- if (HAS_CBP(h->mtype))
+ if (HAS_CBP(com->mtype))
cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 1) + 1;
if (s->mb_intra) {
@@ -449,7 +464,7 @@ static int h261_decode_mb(H261Context *h)
intra:
/* decode each block */
- if (s->mb_intra || HAS_CBP(h->mtype)) {
+ if (s->mb_intra || HAS_CBP(com->mtype)) {
s->bdsp.clear_blocks(s->block[0]);
for (i = 0; i < 6; i++) {
if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0)
@@ -470,7 +485,7 @@ intra:
* Decode the H.261 picture header.
* @return <0 if no startcode found
*/
-static int h261_decode_picture_header(H261Context *h)
+static int h261_decode_picture_header(H261DecContext *h)
{
MpegEncContext *const s = &h->s;
int format, i;
@@ -534,7 +549,7 @@ static int h261_decode_picture_header(H261Context *h)
return 0;
}
-static int h261_decode_gob(H261Context *h)
+static int h261_decode_gob(H261DecContext *h)
{
MpegEncContext *const s = &h->s;
@@ -580,9 +595,9 @@ static int get_consumed_bytes(MpegEncContext *s, int buf_size)
static int h261_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
+ H261DecContext *const h = avctx->priv_data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
- H261Context *h = avctx->priv_data;
MpegEncContext *s = &h->s;
int ret;
AVFrame *pict = data;
@@ -657,7 +672,7 @@ retry:
static av_cold int h261_decode_end(AVCodecContext *avctx)
{
- H261Context *h = avctx->priv_data;
+ H261DecContext *const h = avctx->priv_data;
MpegEncContext *s = &h->s;
ff_mpv_common_end(s);
@@ -669,7 +684,7 @@ const AVCodec ff_h261_decoder = {
.long_name = NULL_IF_CONFIG_SMALL("H.261"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_H261,
- .priv_data_size = sizeof(H261Context),
+ .priv_data_size = sizeof(H261DecContext),
.init = h261_decode_init,
.close = h261_decode_end,
.decode = h261_decode_frame,