diff mbox

[FFmpeg-devel,04/26] vaapi_encode_mpeg2: Move common structure into context

Message ID 20180422152921.32510-5-sw@jkqxz.net
State Superseded
Headers show

Commit Message

Mark Thompson April 22, 2018, 3:28 p.m. UTC
---
 libavcodec/vaapi_encode_mpeg2.c | 50 ++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 26 deletions(-)

Comments

Xiang, Haihao April 25, 2018, 7:43 a.m. UTC | #1
> ---

>  libavcodec/vaapi_encode_mpeg2.c | 50 ++++++++++++++++++++------------------

> ---

>  1 file changed, 24 insertions(+), 26 deletions(-)

> 

> diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c

> index 42df77ea49..5dd1f39cbc 100644

> --- a/libavcodec/vaapi_encode_mpeg2.c

> +++ b/libavcodec/vaapi_encode_mpeg2.c

> @@ -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,8 +637,7 @@ 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)


Is this check necessary?

>          ff_cbs_close(&priv->cbc);

> @@ -665,7 +663,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,
diff mbox

Patch

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index 42df77ea49..5dd1f39cbc 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -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,8 +637,7 @@  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);
@@ -665,7 +663,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,