Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/svq1enc: Move PutBitContext from context to stack
Date: Tue, 11 Oct 2022 15:18:48 +0200
Message-ID: <AS8P250MB07447E798A2A8560130380888F239@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AS8P250MB07447D47B896E0C97810EADC8F239@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>

This is more natural, because said context is only used
for the duration of one call to svq1_encode_frame().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/svq1enc.c | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 67a6de5cc0..75adbe7ea0 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -56,7 +56,6 @@ typedef struct SVQ1EncContext {
     HpelDSPContext hdsp;
     AVFrame *current_picture;
     AVFrame *last_picture;
-    PutBitContext pb;
 
     /* Some compression statistics */
     enum AVPictureType pict_type;
@@ -93,38 +92,38 @@ typedef struct SVQ1EncContext {
     SVQ1EncDSPContext svq1encdsp;
 } SVQ1EncContext;
 
-static void svq1_write_header(SVQ1EncContext *s, int frame_type)
+static void svq1_write_header(SVQ1EncContext *s, PutBitContext *pb, int frame_type)
 {
     int i;
 
     /* frame code */
-    put_bits(&s->pb, 22, 0x20);
+    put_bits(pb, 22, 0x20);
 
     /* temporal reference (sure hope this is a "don't care") */
-    put_bits(&s->pb, 8, 0x00);
+    put_bits(pb, 8, 0x00);
 
     /* frame type */
-    put_bits(&s->pb, 2, frame_type - 1);
+    put_bits(pb, 2, frame_type - 1);
 
     if (frame_type == AV_PICTURE_TYPE_I) {
         /* no checksum since frame code is 0x20 */
         /* no embedded string either */
         /* output 5 unknown bits (2 + 2 + 1) */
-        put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */
+        put_bits(pb, 5, 2); /* 2 needed by quicktime decoder */
 
         i = ff_match_2uint16((void*)ff_svq1_frame_size_table,
                              FF_ARRAY_ELEMS(ff_svq1_frame_size_table),
                              s->frame_width, s->frame_height);
-        put_bits(&s->pb, 3, i);
+        put_bits(pb, 3, i);
 
         if (i == 7) {
-            put_bits(&s->pb, 12, s->frame_width);
-            put_bits(&s->pb, 12, s->frame_height);
+            put_bits(pb, 12, s->frame_width);
+            put_bits(pb, 12, s->frame_height);
         }
     }
 
     /* no checksum or extra data (next 2 bits get 0) */
-    put_bits(&s->pb, 2, 0);
+    put_bits(pb, 2, 0);
 }
 
 #define QUALITY_THRESHOLD    100
@@ -298,6 +297,7 @@ static void init_block_index(MpegEncContext *s){
 }
 
 static int svq1_encode_plane(SVQ1EncContext *s, int plane,
+                             PutBitContext *pb,
                              const unsigned char *src_plane,
                              unsigned char *ref_plane,
                              unsigned char *decoded_plane,
@@ -425,7 +425,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
             int score[4]     = { 0, 0, 0, 0 }, best;
             uint8_t *temp    = s->scratchbuf;
 
-            if (put_bytes_left(&s->pb, 0) < 3000) { // FIXME: check size
+            if (put_bytes_left(pb, 0) < 3000) { // FIXME: check size
                 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
                 return -1;
             }
@@ -496,7 +496,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
                     if (score[2] < score[best] && mx == 0 && my == 0) {
                         best = 2;
                         s->hdsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
-                        put_bits(&s->pb, SVQ1_BLOCK_SKIP_LEN, SVQ1_BLOCK_SKIP_CODE);
+                        put_bits(pb, SVQ1_BLOCK_SKIP_LEN, SVQ1_BLOCK_SKIP_CODE);
                     }
                 }
 
@@ -521,7 +521,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
 
             if (best != 2)
             for (i = 5; i >= 0; i--)
-                ff_copy_bits(&s->pb, reorder_buffer[best][i],
+                ff_copy_bits(pb, reorder_buffer[best][i],
                                  count[best][i]);
             if (best == 0)
                 s->hdsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
@@ -630,6 +630,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                              const AVFrame *pict, int *got_packet)
 {
     SVQ1EncContext *const s = avctx->priv_data;
+    PutBitContext pb;
     int i, ret;
 
     ret = ff_alloc_packet(avctx, pkt, s->y_block_width * s->y_block_height *
@@ -660,8 +661,6 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
     FFSWAP(AVFrame*, s->current_picture, s->last_picture);
 
-    init_put_bits(&s->pb, pkt->data, pkt->size);
-
     if (avctx->gop_size && (avctx->frame_number % avctx->gop_size))
         s->pict_type = AV_PICTURE_TYPE_P;
     else
@@ -670,9 +669,10 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
     ff_side_data_set_encoder_stats(pkt, pict->quality, NULL, 0, s->pict_type);
 
-    svq1_write_header(s, s->pict_type);
+    init_put_bits(&pb, pkt->data, pkt->size);
+    svq1_write_header(s, &pb, s->pict_type);
     for (i = 0; i < 3; i++) {
-        int ret = svq1_encode_plane(s, i,
+        int ret = svq1_encode_plane(s, i, &pb,
                               pict->data[i],
                               s->last_picture->data[i],
                               s->current_picture->data[i],
@@ -692,13 +692,13 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         }
     }
 
-    // align_put_bits(&s->pb);
-    while (put_bits_count(&s->pb) & 31)
-        put_bits(&s->pb, 1, 0);
+    // align_put_bits(&pb);
+    while (put_bits_count(&pb) & 31)
+        put_bits(&pb, 1, 0);
 
-    flush_put_bits(&s->pb);
+    flush_put_bits(&pb);
 
-    pkt->size = put_bytes_output(&s->pb);
+    pkt->size = put_bytes_output(&pb);
     if (s->pict_type == AV_PICTURE_TYPE_I)
         pkt->flags |= AV_PKT_FLAG_KEY;
     *got_packet = 1;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-10-11 13:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-11 13:13 [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 2/4] avcodec/svq1enc: Add SVQ1EncDSPContext, make codec context private Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 3/4] avcodec/svq1: Set hidden visibility Andreas Rheinhardt
2022-10-11 13:18 ` Andreas Rheinhardt [this message]
2022-10-13 17:25 ` [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AS8P250MB07447E798A2A8560130380888F239@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git