Commit 537d6aa3 authored by Mark Thompson's avatar Mark Thompson

vaapi_encode_mpeg2: Move common structure into context

parent 2c3ad16d
......@@ -28,6 +28,9 @@
#include "vaapi_encode.h"
typedef struct VAAPIEncodeMPEG2Context {
VAAPIEncodeContext common;
// Derived settings.
int mb_width;
int mb_height;
......@@ -35,15 +38,6 @@ typedef struct VAAPIEncodeMPEG2Context {
int quant_p;
int quant_b;
MPEG2RawSequenceHeader sequence_header;
MPEG2RawExtensionData sequence_extension;
MPEG2RawExtensionData sequence_display_extension;
MPEG2RawGroupOfPicturesHeader gop_header;
MPEG2RawPictureHeader picture_header;
MPEG2RawExtensionData picture_coding_extension;
int64_t last_i_frame;
unsigned int bit_rate;
unsigned int vbv_buffer_size;
......@@ -52,6 +46,17 @@ typedef struct VAAPIEncodeMPEG2Context {
unsigned int f_code_horizontal;
unsigned int f_code_vertical;
// Stream state.
int64_t last_i_frame;
// Writer structures.
MPEG2RawSequenceHeader sequence_header;
MPEG2RawExtensionData sequence_extension;
MPEG2RawExtensionData sequence_display_extension;
MPEG2RawGroupOfPicturesHeader gop_header;
MPEG2RawPictureHeader picture_header;
MPEG2RawExtensionData picture_coding_extension;
CodedBitstreamContext *cbc;
CodedBitstreamFragment current_fragment;
} VAAPIEncodeMPEG2Context;
......@@ -61,8 +66,7 @@ static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx,
char *data, size_t *data_len,
CodedBitstreamFragment *frag)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
int err;
err = ff_cbs_write_fragment_data(priv->cbc, frag);
......@@ -88,8 +92,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx,
CodedBitstreamFragment *frag,
int type, void *header)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
int err;
err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, type, header, NULL);
......@@ -105,8 +108,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx,
static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx,
char *data, size_t *data_len)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
CodedBitstreamFragment *frag = &priv->current_fragment;
int err;
......@@ -140,8 +142,7 @@ static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
char *data, size_t *data_len)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
CodedBitstreamFragment *frag = &priv->current_fragment;
int err;
......@@ -164,7 +165,7 @@ fail:
static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
MPEG2RawSequenceHeader *sh = &priv->sequence_header;
MPEG2RawSequenceExtension *se = &priv->sequence_extension.data.sequence;
MPEG2RawSequenceDisplayExtension *sde = &priv->sequence_display_extension.data.sequence_display;
......@@ -416,8 +417,7 @@ static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx,
VAAPIEncodePicture *pic)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
MPEG2RawPictureHeader *ph = &priv->picture_header;
MPEG2RawPictureCodingExtension *pce = &priv->picture_coding_extension.data.picture_coding;
VAEncPictureParameterBufferMPEG2 *vpic = pic->codec_picture_params;
......@@ -482,9 +482,8 @@ static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
VAAPIEncodeSlice *slice)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
VAEncSliceParameterBufferMPEG2 *vslice = slice->codec_slice_params;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
int qp;
vslice->macroblock_address = priv->mb_width * slice->index;
......@@ -515,7 +514,7 @@ static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx,
static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
int err;
err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MPEG2VIDEO, avctx);
......@@ -638,11 +637,9 @@ static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
if (priv)
ff_cbs_close(&priv->cbc);
ff_cbs_close(&priv->cbc);
return ff_vaapi_encode_close(avctx);
}
......@@ -665,7 +662,7 @@ AVCodec ff_mpeg2_vaapi_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 (VAAPI)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MPEG2VIDEO,
.priv_data_size = sizeof(VAAPIEncodeContext),
.priv_data_size = sizeof(VAAPIEncodeMPEG2Context),
.init = &vaapi_encode_mpeg2_init,
.encode2 = &ff_vaapi_encode2,
.close = &vaapi_encode_mpeg2_close,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment