[FFmpeg-devel] [PATCH 20/21] avcodec/speedhqenc: Add SpeedHQEncContext and move slice_start to it

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Jan 25 19:41:47 EET 2022


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/mpegvideo.h  |  3 ---
 libavcodec/speedhqenc.c | 19 ++++++++++++++-----
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index e5a4cc9b81..9243edefce 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -425,9 +425,6 @@ typedef struct MpegEncContext {
     int inter_intra_pred;
     int mspel;
 
-    /* SpeedHQ specific */
-    int slice_start;
-
     /* decompression specific */
     GetBitContext gb;
 
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 967774931c..9a03876fbf 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -54,6 +54,12 @@ static uint32_t speedhq_chr_dc_uni[512];
 
 static uint8_t uni_speedhq_ac_vlc_len[64 * 64 * 2];
 
+typedef struct SpeedHQEncContext {
+    MpegEncContext m;
+
+    int slice_start;
+} SpeedHQEncContext;
+
 static av_cold void speedhq_init_static_data(void)
 {
     ff_rl_init(&ff_rl_speedhq, speedhq_static_rl_table_store);
@@ -123,24 +129,27 @@ av_cold int ff_speedhq_encode_init(MpegEncContext *s)
 
 void ff_speedhq_encode_picture_header(MpegEncContext *s)
 {
+    SpeedHQEncContext *ctx = (SpeedHQEncContext*)s;
+
     put_bits_le(&s->pb, 8, 100 - s->qscale * 2);  /* FIXME why doubled */
     put_bits_le(&s->pb, 24, 4);  /* no second field */
 
+    ctx->slice_start = 4;
     /* length of first slice, will be filled out later */
-    s->slice_start = 4;
     put_bits_le(&s->pb, 24, 0);
 }
 
 void ff_speedhq_end_slice(MpegEncContext *s)
 {
+    SpeedHQEncContext *ctx = (SpeedHQEncContext*)s;
     int slice_len;
 
     flush_put_bits_le(&s->pb);
-    slice_len = s->pb.buf_ptr - (s->pb.buf + s->slice_start);
-    AV_WL24(s->pb.buf + s->slice_start, slice_len);
+    slice_len = put_bytes_output(&s->pb) - ctx->slice_start;
+    AV_WL24(s->pb.buf + ctx->slice_start, slice_len);
 
     /* length of next slice, will be filled out later */
-    s->slice_start = s->pb.buf_ptr - s->pb.buf;
+    ctx->slice_start = put_bytes_output(&s->pb);
     put_bits_le(&s->pb, 24, 0);
 }
 
@@ -273,7 +282,7 @@ const AVCodec ff_speedhq_encoder = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_SPEEDHQ,
     .priv_class     = &ff_mpv_enc_class,
-    .priv_data_size = sizeof(MpegEncContext),
+    .priv_data_size = sizeof(SpeedHQEncContext),
     .init           = ff_mpv_encode_init,
     .encode2        = ff_mpv_encode_picture,
     .close          = ff_mpv_encode_end,
-- 
2.32.0



More information about the ffmpeg-devel mailing list