diff mbox series

[FFmpeg-devel,v2,25/69] avcodec/speedhqenc: Add SpeedHQEncContext and move slice_start to it

Message ID AM7PR03MB666035632BD7A42C14670F0B8F269@AM7PR03MB6660.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,v2,01/69] avcodec/avcodec: Avoid MpegEncContext in AVHWAccel.decode_mb | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 1, 2022, 1:06 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpegvideo.h  |  3 ---
 libavcodec/speedhqenc.c | 19 ++++++++++++++-----
 2 files changed, 14 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index c4ac7bc966..e31ad2ccff 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -419,9 +419,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 5b40011e40..2a8ddebb0a 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);
@@ -121,24 +127,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);
 }
 
@@ -271,7 +280,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,