[FFmpeg-cvslog] avcodec/mpegvideo encs: Add put_bits_assume_flushed() to encode_header
Andreas Rheinhardt
git at videolan.org
Wed May 21 13:47:55 EEST 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue May 6 13:03:17 2025 +0200| [a35917268dfe4abf1c0cdae1401b6b4d96a13f08] | committer: Andreas Rheinhardt
avcodec/mpegvideo encs: Add put_bits_assume_flushed() to encode_header
This allows the compiler to remove the implicit "Do I need to output
the PutBitContext buffer here?" checks.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a35917268dfe4abf1c0cdae1401b6b4d96a13f08
---
libavcodec/flvenc.c | 3 ++-
libavcodec/h261enc.c | 3 ++-
libavcodec/ituh263enc.c | 5 +++--
libavcodec/mpeg12enc.c | 5 +++++
libavcodec/mpeg4videoenc.c | 3 +++
libavcodec/msmpeg4enc.c | 3 ++-
libavcodec/rv10enc.c | 2 +-
libavcodec/rv20enc.c | 2 ++
libavcodec/speedhqenc.c | 3 +++
libavcodec/wmv2enc.c | 3 +++
10 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index df1a650222..8f07c3c778 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -22,13 +22,14 @@
#include "flvenc.h"
#include "mpegvideo.h"
#include "mpegvideoenc.h"
+#include "put_bits.h"
int ff_flv_encode_picture_header(MPVMainEncContext *const m)
{
MPVEncContext *const s = &m->s;
int format;
- align_put_bits(&s->pb);
+ put_bits_assume_flushed(&s->pb);
put_bits(&s->pb, 17, 1);
/* 0: H.263 escape codes 1: 11-bit escape codes */
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 70f5f2b09c..c217fb6233 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -35,6 +35,7 @@
#include "h261.h"
#include "h261enc.h"
#include "mpegvideoenc.h"
+#include "put_bits.h"
#define H261_MAX_RUN 26
#define H261_MAX_LEVEL 15
@@ -72,7 +73,7 @@ static int h261_encode_picture_header(MPVMainEncContext *const m)
MPVEncContext *const s = &h->s.s;
int temp_ref;
- align_put_bits(&s->pb);
+ put_bits_assume_flushed(&s->pb);
put_bits(&s->pb, 20, 0x10); /* PSC */
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 8be7ee4636..b9d903a220 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -46,6 +46,7 @@
#include "mathops.h"
#include "mpegutils.h"
#include "internal.h"
+#include "put_bits.h"
/**
* Table of number of bits a motion vector component needs.
@@ -230,6 +231,8 @@ static int h263_encode_picture_header(MPVMainEncContext *const m)
int best_error= INT_MAX;
int custom_pcf;
+ put_bits_assume_flushed(&s->pb);
+
if(s->c.h263_plus){
for(i=0; i<2; i++){
int div, error;
@@ -247,8 +250,6 @@ static int h263_encode_picture_header(MPVMainEncContext *const m)
coded_frame_rate= 1800000;
coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
- align_put_bits(&s->pb);
-
put_bits(&s->pb, 22, 0x20); /* PSC */
temp_ref= s->c.picture_number * (int64_t)coded_frame_rate * s->c.avctx->time_base.num / //FIXME use timestamp
(coded_frame_rate_base * (int64_t)s->c.avctx->time_base.den);
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 231740bcc8..d4791e8b33 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -49,6 +49,7 @@
#include "mpegvideo.h"
#include "mpegvideoenc.h"
#include "profiles.h"
+#include "put_bits.h"
#include "rl.h"
#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER
@@ -155,6 +156,8 @@ static void mpeg1_encode_sequence_header(MPEG12EncContext *mpeg12)
AVRational aspect_ratio = s->c.avctx->sample_aspect_ratio;
int aspect_ratio_info;
+ put_bits_assume_flushed(&s->pb);
+
if (!(s->c.cur_pic.ptr->f->flags & AV_FRAME_FLAG_KEY))
return;
@@ -339,6 +342,8 @@ static int mpeg1_encode_picture_header(MPVMainEncContext *const m)
MPVEncContext *const s = &m->s;
const AVFrameSideData *side_data;
+ put_bits_assume_flushed(&s->pb);
+
mpeg1_encode_sequence_header(mpeg12);
/* MPEG-1 picture header */
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 01d5076547..cf4a1dfa63 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -35,6 +35,7 @@
#include "mpeg4videoenc.h"
#include "mpegvideoenc.h"
#include "profiles.h"
+#include "put_bits.h"
#include "version.h"
/**
@@ -1070,6 +1071,8 @@ static int mpeg4_encode_picture_header(MPVMainEncContext *const m)
uint64_t time_incr;
int64_t time_div, time_mod;
+ put_bits_assume_flushed(&s->pb);
+
if (s->c.pict_type == AV_PICTURE_TYPE_I) {
if (!(s->c.avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) {
if (s->c.avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 795db6e4de..3449328b3c 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -221,7 +221,8 @@ static int msmpeg4_encode_picture_header(MPVMainEncContext *const m)
find_best_tables(ms);
- align_put_bits(&s->pb);
+ put_bits_assume_flushed(&s->pb);
+
put_bits(&s->pb, 2, s->c.pict_type - 1);
put_bits(&s->pb, 5, s->c.qscale);
diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c
index 984fe3379d..534b93fd81 100644
--- a/libavcodec/rv10enc.c
+++ b/libavcodec/rv10enc.c
@@ -36,7 +36,7 @@ int ff_rv10_encode_picture_header(MPVMainEncContext *const m)
MPVEncContext *const s = &m->s;
int full_frame= 0;
- align_put_bits(&s->pb);
+ put_bits_assume_flushed(&s->pb);
put_bits(&s->pb, 1, 1); /* marker */
diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c
index ce0d435dcb..4a3cef038c 100644
--- a/libavcodec/rv20enc.c
+++ b/libavcodec/rv20enc.c
@@ -38,6 +38,8 @@ int ff_rv20_encode_picture_header(MPVMainEncContext *const m)
{
MPVEncContext *const s = &m->s;
+ put_bits_assume_flushed(&s->pb);
+
put_bits(&s->pb, 2, s->c.pict_type); //I 0 vs. 1 ?
put_bits(&s->pb, 1, 0); /* unknown bit */
put_bits(&s->pb, 5, s->c.qscale);
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index a3bcf67e11..23ab86e8e2 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -37,6 +37,7 @@
#include "mpegvideo.h"
#include "mpegvideodata.h"
#include "mpegvideoenc.h"
+#include "put_bits.h"
#include "rl.h"
#include "speedhq.h"
#include "speedhqenc.h"
@@ -101,6 +102,8 @@ static int speedhq_encode_picture_header(MPVMainEncContext *const m)
SpeedHQEncContext *const ctx = (SpeedHQEncContext*)m;
MPVEncContext *const s = &m->s;
+ put_bits_assume_flushed(&s->pb);
+
put_bits_le(&s->pb, 8, 100 - s->c.qscale * 2); /* FIXME why doubled */
put_bits_le(&s->pb, 24, 4); /* no second field */
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index f9fd918dbf..592d1060d3 100644
--- a/libavcodec/wmv2enc.c
+++ b/libavcodec/wmv2enc.c
@@ -28,6 +28,7 @@
#include "msmpeg4enc.h"
#include "msmpeg4data.h"
#include "msmpeg4_vc1_data.h"
+#include "put_bits.h"
#include "wmv2.h"
#define WMV2_EXTRADATA_SIZE 4
@@ -78,6 +79,8 @@ static int wmv2_encode_picture_header(MPVMainEncContext *const m)
MSMPEG4EncContext *const ms = &w->msmpeg4;
MPVEncContext *const s = &m->s;
+ put_bits_assume_flushed(&s->pb);
+
put_bits(&s->pb, 1, s->c.pict_type - 1);
if (s->c.pict_type == AV_PICTURE_TYPE_I)
put_bits(&s->pb, 7, 0);
More information about the ffmpeg-cvslog
mailing list