avcodec/wmv2: Split Wmv2Context into decoder and encoder context

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
release/5.1
Andreas Rheinhardt 3 years ago
parent 584f26db0d
commit cc90478967
  1. 6
      libavcodec/wmv2.c
  2. 26
      libavcodec/wmv2.h
  3. 64
      libavcodec/wmv2dec.c
  4. 29
      libavcodec/wmv2enc.c

@ -25,9 +25,9 @@
#include "wmv2.h" #include "wmv2.h"
av_cold void ff_wmv2_common_init(Wmv2Context *w) av_cold void ff_wmv2_common_init(MpegEncContext *s)
{ {
MpegEncContext *const s = &w->s; WMV2Context *const w = s->private_ctx;
ff_blockdsp_init(&s->bdsp, s->avctx); ff_blockdsp_init(&s->bdsp, s->avctx);
ff_wmv2dsp_init(&w->wdsp); ff_wmv2dsp_init(&w->wdsp);
@ -52,7 +52,7 @@ void ff_mspel_motion(MpegEncContext *s, uint8_t *dest_y,
uint8_t **ref_picture, op_pixels_func (*pix_op)[4], uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
int motion_x, int motion_y, int h) int motion_x, int motion_y, int h)
{ {
Wmv2Context *const w = (Wmv2Context *) s; WMV2Context *const w = s->private_ctx;
uint8_t *ptr; uint8_t *ptr;
int dxy, mx, my, src_x, src_y, v_edge_pos; int dxy, mx, my, src_x, src_y, v_edge_pos;
ptrdiff_t offset, linesize, uvlinesize; ptrdiff_t offset, linesize, uvlinesize;

@ -21,9 +21,6 @@
#ifndef AVCODEC_WMV2_H #ifndef AVCODEC_WMV2_H
#define AVCODEC_WMV2_H #define AVCODEC_WMV2_H
#include "libavutil/mem_internal.h"
#include "intrax8.h"
#include "mpegvideo.h" #include "mpegvideo.h"
#include "wmv2dsp.h" #include "wmv2dsp.h"
@ -33,29 +30,12 @@
#define SKIP_TYPE_COL 3 #define SKIP_TYPE_COL 3
typedef struct Wmv2Context { typedef struct WMV2Context {
MpegEncContext s;
IntraX8Context x8;
WMV2DSPContext wdsp; WMV2DSPContext wdsp;
int j_type_bit;
int j_type;
int abt_flag;
int abt_type;
int abt_type_table[6];
int per_mb_abt;
int per_block_abt;
int mspel_bit;
int cbp_table_index;
int top_left_mv_flag;
int per_mb_rl_bit;
int skip_type;
int hshift; int hshift;
} WMV2Context;
ScanTable abt_scantable[2]; void ff_wmv2_common_init(MpegEncContext *s);
DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64];
} Wmv2Context;
void ff_wmv2_common_init(Wmv2Context *w);
int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]); int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]);
int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number); int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number);

@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/mem_internal.h"
#include "avcodec.h" #include "avcodec.h"
#include "h263dec.h" #include "h263dec.h"
#include "internal.h" #include "internal.h"
@ -31,8 +33,28 @@
#include "wmv2.h" #include "wmv2.h"
#include "wmv2data.h" #include "wmv2data.h"
typedef struct WMV2DecContext {
static void wmv2_add_block(Wmv2Context *w, int16_t *block1, MpegEncContext s;
WMV2Context common;
IntraX8Context x8;
int j_type_bit;
int j_type;
int abt_flag;
int abt_type;
int abt_type_table[6];
int per_mb_abt;
int per_block_abt;
int mspel_bit;
int cbp_table_index;
int top_left_mv_flag;
int per_mb_rl_bit;
int skip_type;
ScanTable abt_scantable[2];
DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64];
} WMV2DecContext;
static void wmv2_add_block(WMV2DecContext *w, int16_t *block1,
uint8_t *dst, int stride, int n) uint8_t *dst, int stride, int n)
{ {
MpegEncContext *const s = &w->s; MpegEncContext *const s = &w->s;
@ -40,7 +62,7 @@ static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
if (s->block_last_index[n] >= 0) { if (s->block_last_index[n] >= 0) {
switch (w->abt_type_table[n]) { switch (w->abt_type_table[n]) {
case 0: case 0:
w->wdsp.idct_add(dst, stride, block1); w->common.wdsp.idct_add(dst, stride, block1);
break; break;
case 1: case 1:
ff_simple_idct84_add(dst, stride, block1); ff_simple_idct84_add(dst, stride, block1);
@ -61,7 +83,7 @@ static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64], void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64],
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr) uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr)
{ {
Wmv2Context *const w = (Wmv2Context *) s; WMV2DecContext *const w = (WMV2DecContext *) s;
wmv2_add_block(w, block1[0], dest_y, s->linesize, 0); wmv2_add_block(w, block1[0], dest_y, s->linesize, 0);
wmv2_add_block(w, block1[1], dest_y + 8, s->linesize, 1); wmv2_add_block(w, block1[1], dest_y + 8, s->linesize, 1);
@ -75,7 +97,7 @@ void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64],
wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5); wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5);
} }
static int parse_mb_skip(Wmv2Context *w) static int parse_mb_skip(WMV2DecContext *w)
{ {
int mb_x, mb_y; int mb_x, mb_y;
int coded_mb_count = 0; int coded_mb_count = 0;
@ -140,7 +162,7 @@ static int parse_mb_skip(Wmv2Context *w)
return 0; return 0;
} }
static int decode_ext_header(Wmv2Context *w) static int decode_ext_header(WMV2DecContext *w)
{ {
MpegEncContext *const s = &w->s; MpegEncContext *const s = &w->s;
GetBitContext gb; GetBitContext gb;
@ -180,7 +202,7 @@ static int decode_ext_header(Wmv2Context *w)
int ff_wmv2_decode_picture_header(MpegEncContext *s) int ff_wmv2_decode_picture_header(MpegEncContext *s)
{ {
Wmv2Context *const w = (Wmv2Context *) s; WMV2DecContext *const w = (WMV2DecContext *) s;
int code; int code;
if (s->picture_number == 0) if (s->picture_number == 0)
@ -215,7 +237,7 @@ int ff_wmv2_decode_picture_header(MpegEncContext *s)
int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
{ {
Wmv2Context *const w = (Wmv2Context *) s; WMV2DecContext *const w = (WMV2DecContext *) s;
if (s->pict_type == AV_PICTURE_TYPE_I) { if (s->pict_type == AV_PICTURE_TYPE_I) {
if (w->j_type_bit) if (w->j_type_bit)
@ -323,19 +345,19 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
return 0; return 0;
} }
static inline void wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr) static inline void wmv2_decode_motion(WMV2DecContext *w, int *mx_ptr, int *my_ptr)
{ {
MpegEncContext *const s = &w->s; MpegEncContext *const s = &w->s;
ff_msmpeg4_decode_motion(s, mx_ptr, my_ptr); ff_msmpeg4_decode_motion(s, mx_ptr, my_ptr);
if ((((*mx_ptr) | (*my_ptr)) & 1) && s->mspel) if ((((*mx_ptr) | (*my_ptr)) & 1) && s->mspel)
w->hshift = get_bits1(&s->gb); w->common.hshift = get_bits1(&s->gb);
else else
w->hshift = 0; w->common.hshift = 0;
} }
static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py) static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py)
{ {
MpegEncContext *const s = &w->s; MpegEncContext *const s = &w->s;
int xy, wrap, diff, type; int xy, wrap, diff, type;
@ -380,7 +402,7 @@ static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py)
return mot_val; return mot_val;
} }
static inline int wmv2_decode_inter_block(Wmv2Context *w, int16_t *block, static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block,
int n, int cbp) int n, int cbp)
{ {
MpegEncContext *const s = &w->s; MpegEncContext *const s = &w->s;
@ -422,7 +444,9 @@ static inline int wmv2_decode_inter_block(Wmv2Context *w, int16_t *block,
int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
{ {
Wmv2Context *const w = (Wmv2Context *) s; /* The following is only allowed because this encoder
* does not use slice threading. */
WMV2DecContext *const w = (WMV2DecContext *) s;
int cbp, code, i, ret; int cbp, code, i, ret;
uint8_t *coded_val; uint8_t *coded_val;
@ -440,7 +464,7 @@ int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[0][0][0] = 0; s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0; s->mv[0][0][1] = 0;
s->mb_skipped = 1; s->mb_skipped = 1;
w->hshift = 0; w->common.hshift = 0;
return 0; return 0;
} }
if (get_bits_left(&s->gb) <= 0) if (get_bits_left(&s->gb) <= 0)
@ -537,14 +561,16 @@ int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
static av_cold int wmv2_decode_init(AVCodecContext *avctx) static av_cold int wmv2_decode_init(AVCodecContext *avctx)
{ {
Wmv2Context *const w = avctx->priv_data; WMV2DecContext *const w = avctx->priv_data;
MpegEncContext *const s = &w->s; MpegEncContext *const s = &w->s;
int ret; int ret;
s->private_ctx = &w->common;
if ((ret = ff_msmpeg4_decode_init(avctx)) < 0) if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
return ret; return ret;
ff_wmv2_common_init(w); ff_wmv2_common_init(s);
ff_init_scantable(s->idsp.idct_permutation, &w->abt_scantable[0], ff_init_scantable(s->idsp.idct_permutation, &w->abt_scantable[0],
ff_wmv2_scantableA); ff_wmv2_scantableA);
ff_init_scantable(s->idsp.idct_permutation, &w->abt_scantable[1], ff_init_scantable(s->idsp.idct_permutation, &w->abt_scantable[1],
@ -557,7 +583,7 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx)
static av_cold int wmv2_decode_end(AVCodecContext *avctx) static av_cold int wmv2_decode_end(AVCodecContext *avctx)
{ {
Wmv2Context *w = avctx->priv_data; WMV2DecContext *const w = avctx->priv_data;
ff_intrax8_common_end(&w->x8); ff_intrax8_common_end(&w->x8);
return ff_h263_decode_end(avctx); return ff_h263_decode_end(avctx);
@ -568,7 +594,7 @@ const AVCodec ff_wmv2_decoder = {
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 8"), .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 8"),
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_WMV2, .id = AV_CODEC_ID_WMV2,
.priv_data_size = sizeof(Wmv2Context), .priv_data_size = sizeof(WMV2DecContext),
.init = wmv2_decode_init, .init = wmv2_decode_init,
.close = wmv2_decode_end, .close = wmv2_decode_end,
.decode = ff_h263_decode_frame, .decode = ff_h263_decode_frame,

@ -25,8 +25,21 @@
#include "msmpeg4data.h" #include "msmpeg4data.h"
#include "wmv2.h" #include "wmv2.h"
typedef struct WMV2EncContext {
static int encode_ext_header(Wmv2Context *w) MpegEncContext s;
WMV2Context common;
int j_type_bit;
int j_type;
int abt_flag;
int abt_type;
int per_mb_abt;
int mspel_bit;
int cbp_table_index;
int top_left_mv_flag;
int per_mb_rl_bit;
} WMV2EncContext;
static int encode_ext_header(WMV2EncContext *w)
{ {
MpegEncContext *const s = &w->s; MpegEncContext *const s = &w->s;
PutBitContext pb; PutBitContext pb;
@ -54,12 +67,14 @@ static int encode_ext_header(Wmv2Context *w)
static av_cold int wmv2_encode_init(AVCodecContext *avctx) static av_cold int wmv2_encode_init(AVCodecContext *avctx)
{ {
Wmv2Context *const w = avctx->priv_data; WMV2EncContext *const w = avctx->priv_data;
MpegEncContext *const s = &w->s;
s->private_ctx = &w->common;
if (ff_mpv_encode_init(avctx) < 0) if (ff_mpv_encode_init(avctx) < 0)
return -1; return -1;
ff_wmv2_common_init(w); ff_wmv2_common_init(&w->s);
avctx->extradata_size = 4; avctx->extradata_size = 4;
avctx->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); avctx->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
@ -73,7 +88,7 @@ static av_cold int wmv2_encode_init(AVCodecContext *avctx)
int ff_wmv2_encode_picture_header(MpegEncContext *s, int picture_number) int ff_wmv2_encode_picture_header(MpegEncContext *s, int picture_number)
{ {
Wmv2Context *const w = (Wmv2Context *) s; WMV2EncContext *const w = (WMV2EncContext *) s;
put_bits(&s->pb, 1, s->pict_type - 1); put_bits(&s->pb, 1, s->pict_type - 1);
if (s->pict_type == AV_PICTURE_TYPE_I) if (s->pict_type == AV_PICTURE_TYPE_I)
@ -147,7 +162,7 @@ int ff_wmv2_encode_picture_header(MpegEncContext *s, int picture_number)
void ff_wmv2_encode_mb(MpegEncContext *s, int16_t block[6][64], void ff_wmv2_encode_mb(MpegEncContext *s, int16_t block[6][64],
int motion_x, int motion_y) int motion_x, int motion_y)
{ {
Wmv2Context *const w = (Wmv2Context *) s; WMV2EncContext *const w = (WMV2EncContext *) s;
int cbp, coded_cbp, i; int cbp, coded_cbp, i;
int pred_x, pred_y; int pred_x, pred_y;
uint8_t *coded_block; uint8_t *coded_block;
@ -220,7 +235,7 @@ const AVCodec ff_wmv2_encoder = {
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_WMV2, .id = AV_CODEC_ID_WMV2,
.priv_class = &ff_mpv_enc_class, .priv_class = &ff_mpv_enc_class,
.priv_data_size = sizeof(Wmv2Context), .priv_data_size = sizeof(WMV2EncContext),
.init = wmv2_encode_init, .init = wmv2_encode_init,
.encode2 = ff_mpv_encode_picture, .encode2 = ff_mpv_encode_picture,
.close = ff_mpv_encode_end, .close = ff_mpv_encode_end,

Loading…
Cancel
Save