1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

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@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-05-06 13:03:17 +02:00
parent 5d0e8fa4bb
commit a35917268d
10 changed files with 26 additions and 6 deletions

View File

@ -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 */

View File

@ -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 */

View File

@ -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);

View File

@ -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 */

View File

@ -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

View File

@ -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);

View File

@ -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 */

View File

@ -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);

View File

@ -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 */

View File

@ -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);