History

avcodec/mpeg4videoenc: Add Mpeg4EncContext and move time_increment_bits

It is only ever used by the main encoder thread.

Andreas Rheinhardt committed 1 year ago

Commit fca1ac21 parent e8a8a134 files · +30 −15Browse files

Unified · Split

4 files
  1. libavcodec/mpeg4videoenc.c +27 −9
  2. libavcodec/mpeg4videoenc.h +2 −2
  3. libavcodec/mpegvideo.h +0 −2
  4. libavcodec/mpegvideo_enc.c +1 −2
libavcodec/mpeg4videoenc.c+27−9
@@ -71,6 +71,17 @@ static uint8_t uni_mpeg4_inter_rl_len[64 * 64 * 2 * 2]; · 70 unmodified lines
7171 * max run: 29/41
7272 */
7373
74+typedef struct Mpeg4EncContext {
75+ MPVMainEncContext m;
76+ /// number of bits to represent the fractional part of time
77+ int time_increment_bits;
78+} Mpeg4EncContext;
79+
80+static inline Mpeg4EncContext *mainctx_to_mpeg4(MPVMainEncContext *m)
81+{
82+ return (Mpeg4EncContext*)m;
83+}
84+
7485 /**
7586 * Return the number of bits that encoding the 8x8 block in block would need.
7687 * @param[in] block_last_index last index in scantable order that refers to a non zero element in block.
@@ -960,10 +971,11 @@ static void mpeg4_encode_visual_object_header(MpegEncContext *s) · 883 unmodified lines
960971 ff_mpeg4_stuffing(&s->pb);
961972 }
962973
963−static void mpeg4_encode_vol_header(MpegEncContext *s,
974+static void mpeg4_encode_vol_header(Mpeg4EncContext *const m4,
964975 int vo_number,
965976 int vol_number)
966977 {
978+ MpegEncContext *const s = &m4->m.s;
967979 int vo_ver_id, vo_type, aspect_ratio_info;
968980
969981 if (s->max_b_frames || s->quarter_sample) {
@@ -1002,8 +1014,8 @@ static void mpeg4_encode_vol_header(MpegEncContext *s, · 32 unmodified lines
10021014 put_bits(&s->pb, 1, 1); /* marker bit */
10031015
10041016 put_bits(&s->pb, 16, s->avctx->time_base.den);
1005− if (s->time_increment_bits < 1)
1006− s->time_increment_bits = 1;
1017+ if (m4->time_increment_bits < 1)
1018+ m4->time_increment_bits = 1;
10071019 put_bits(&s->pb, 1, 1); /* marker bit */
10081020 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
10091021 put_bits(&s->pb, 1, 1); /* marker bit */
@@ -1050,8 +1062,10 @@ static void mpeg4_encode_vol_header(MpegEncContext *s, · 40 unmodified lines
10501062 }
10511063
10521064 /* write MPEG-4 VOP header */
1053−int ff_mpeg4_encode_picture_header(MpegEncContext *s)
1065+int ff_mpeg4_encode_picture_header(MPVMainEncContext *const m)
10541066 {
1067+ Mpeg4EncContext *const m4 = mainctx_to_mpeg4(m);
1068+ MpegEncContext *const s = &m->s;
10551069 uint64_t time_incr;
10561070 int64_t time_div, time_mod;
10571071
@@ -1060,7 +1074,7 @@ int ff_mpeg4_encode_picture_header(MpegEncContext *s) · 2 unmodified lines
10601074 if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy
10611075 mpeg4_encode_visual_object_header(s);
10621076 if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || s->picture_number == 0) // HACK, the reference sw is buggy
1063− mpeg4_encode_vol_header(s, 0, 0);
1077+ mpeg4_encode_vol_header(m4, 0, 0);
10641078 }
10651079 mpeg4_encode_gop_header(s);
10661080 }
@@ -1085,7 +1099,7 @@ int ff_mpeg4_encode_picture_header(MpegEncContext *s) · 18 unmodified lines
10851099 put_bits(&s->pb, 1, 0);
10861100
10871101 put_bits(&s->pb, 1, 1); /* marker */
1088− put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */
1102+ put_bits(&s->pb, m4->time_increment_bits, time_mod); /* time increment */
10891103 put_bits(&s->pb, 1, 1); /* marker */
10901104 put_bits(&s->pb, 1, 1); /* vop coded */
10911105 if (s->pict_type == AV_PICTURE_TYPE_P) {
@@ -1276,7 +1290,8 @@ static av_cold void mpeg4_encode_init_static(void) · 184 unmodified lines
12761290 static av_cold int encode_init(AVCodecContext *avctx)
12771291 {
12781292 static AVOnce init_static_once = AV_ONCE_INIT;
1279− MpegEncContext *s = avctx->priv_data;
1293+ Mpeg4EncContext *const m4 = avctx->priv_data;
1294+ MpegEncContext *const s = &m4->m.s;
12801295 int ret;
12811296
12821297 if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) {
@@ -1290,7 +1305,10 @@ static av_cold int encode_init(AVCodecContext *avctx) · 7 unmodified lines
12901305
12911306 ff_thread_once(&init_static_once, mpeg4_encode_init_static);
12921307
1308+ m4->time_increment_bits = av_log2(avctx->time_base.den - 1) + 1;
1309+
12931310 s->fcode_tab = fcode_tab + MAX_MV;
1311+
12941312 s->min_qcoeff = -2048;
12951313 s->max_qcoeff = 2047;
12961314 s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len;
@@ -1309,7 +1327,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 12 unmodified lines
13091327 init_put_bits(&s->pb, s->avctx->extradata, 1024);
13101328
13111329 mpeg4_encode_visual_object_header(s);
1312− mpeg4_encode_vol_header(s, 0, 0);
1330+ mpeg4_encode_vol_header(m4, 0, 0);
13131331
13141332 // ff_mpeg4_stuffing(&s->pb); ?
13151333 flush_put_bits(&s->pb);
@@ -1395,7 +1413,7 @@ const FFCodec ff_mpeg4_encoder = { · 79 unmodified lines
13951413 CODEC_LONG_NAME("MPEG-4 part 2"),
13961414 .p.type = AVMEDIA_TYPE_VIDEO,
13971415 .p.id = AV_CODEC_ID_MPEG4,
1398− .priv_data_size = sizeof(MPVMainEncContext),
1416+ .priv_data_size = sizeof(Mpeg4EncContext),
13991417 .init = encode_init,
14001418 FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
14011419 .close = ff_mpv_encode_end,
libavcodec/mpeg4videoenc.h+2−2
@@ -25,14 +25,14 @@ · 24 unmodified lines
2525
2626 #include <stdint.h>
2727
28−#include "mpegvideo.h"
28+#include "mpegvideoenc.h"
2929 #include "put_bits.h"
3030
3131 void ff_mpeg4_encode_mb(MpegEncContext *s,
3232 int16_t block[6][64],
3333 int motion_x, int motion_y);
3434 void ff_set_mpeg4_time(MpegEncContext *s);
35−int ff_mpeg4_encode_picture_header(MpegEncContext *s);
35+int ff_mpeg4_encode_picture_header(MPVMainEncContext *m);
3636
3737 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
3838 void ff_mpeg4_stuffing(PutBitContext *pbc);
libavcodec/mpegvideo.h+0−2
@@ -362,8 +362,6 @@ typedef struct MpegEncContext { · 361 unmodified lines
362362 /* MPEG-4 specific */
363363 int studio_profile;
364364 int dct_precision;
365− /// number of bits to represent the fractional part of time (encoder only)
366− int time_increment_bits;
367365 int last_time_base;
368366 int time_base; ///< time in seconds of last I,P,S Frame
369367 int64_t time; ///< time of current frame
libavcodec/mpegvideo_enc.c+1−2
@@ -746,7 +746,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 745 unmodified lines
746746 (1 << 16) - 1);
747747 return AVERROR(EINVAL);
748748 }
749− s->time_increment_bits = av_log2(avctx->time_base.den - 1) + 1;
750749
751750 switch (avctx->codec->id) {
752751 #if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER
@@ -3919,7 +3918,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) · 3166 unmodified lines
39193918 ff_msmpeg4_encode_picture_header(s);
39203919 #endif
39213920 else if (CONFIG_MPEG4_ENCODER && s->h263_pred) {
3922− ret = ff_mpeg4_encode_picture_header(s);
3921+ ret = ff_mpeg4_encode_picture_header(m);
39233922 if (ret < 0)
39243923 return ret;
39253924 } else if (CONFIG_RV10_ENCODER && s->codec_id == AV_CODEC_ID_RV10) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t