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

Showing the changes to libavcodec (4 of 4 files). Show all

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
71 * max run: 29/4171 * max run: 29/41
72 */72 */
73 73
74typedef struct Mpeg4EncContext {
75 MPVMainEncContext m;
76 /// number of bits to represent the fractional part of time
77 int time_increment_bits;
78} Mpeg4EncContext;
79
80static inline Mpeg4EncContext *mainctx_to_mpeg4(MPVMainEncContext *m)
81{
82 return (Mpeg4EncContext*)m;
83}
84
74/**85/**
75 * Return the number of bits that encoding the 8x8 block in block would need.86 * Return the number of bits that encoding the 8x8 block in block would need.
76 * @param[in] block_last_index last index in scantable order that refers to a non zero element in block.87 * @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
960 ff_mpeg4_stuffing(&s->pb);971 ff_mpeg4_stuffing(&s->pb);
961}972}
962 973
963static void mpeg4_encode_vol_header(MpegEncContext *s,974static void mpeg4_encode_vol_header(Mpeg4EncContext *const m4,
964 int vo_number,975 int vo_number,
965 int vol_number)976 int vol_number)
966{977{
978 MpegEncContext *const s = &m4->m.s;
967 int vo_ver_id, vo_type, aspect_ratio_info;979 int vo_ver_id, vo_type, aspect_ratio_info;
968 980
969 if (s->max_b_frames || s->quarter_sample) {981 if (s->max_b_frames || s->quarter_sample) {
@@ -1002,8 +1014,8 @@ static void mpeg4_encode_vol_header(MpegEncContext *s, · 32 unmodified lines
1002 put_bits(&s->pb, 1, 1); /* marker bit */1014 put_bits(&s->pb, 1, 1); /* marker bit */
1003 1015
1004 put_bits(&s->pb, 16, s->avctx->time_base.den);1016 put_bits(&s->pb, 16, s->avctx->time_base.den);
1005 if (s->time_increment_bits < 1)1017 if (m4->time_increment_bits < 1)
1006 s->time_increment_bits = 1;1018 m4->time_increment_bits = 1;
1007 put_bits(&s->pb, 1, 1); /* marker bit */1019 put_bits(&s->pb, 1, 1); /* marker bit */
1008 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */1020 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
1009 put_bits(&s->pb, 1, 1); /* marker bit */1021 put_bits(&s->pb, 1, 1); /* marker bit */
@@ -1050,8 +1062,10 @@ static void mpeg4_encode_vol_header(MpegEncContext *s, · 40 unmodified lines
1050}1062}
1051 1063
1052/* write MPEG-4 VOP header */1064/* write MPEG-4 VOP header */
1053int ff_mpeg4_encode_picture_header(MpegEncContext *s)1065int ff_mpeg4_encode_picture_header(MPVMainEncContext *const m)
1054{1066{
1067 Mpeg4EncContext *const m4 = mainctx_to_mpeg4(m);
1068 MpegEncContext *const s = &m->s;
1055 uint64_t time_incr;1069 uint64_t time_incr;
1056 int64_t time_div, time_mod;1070 int64_t time_div, time_mod;
1057 1071
@@ -1060,7 +1074,7 @@ int ff_mpeg4_encode_picture_header(MpegEncContext *s) · 2 unmodified lines
1060 if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy1074 if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy
1061 mpeg4_encode_visual_object_header(s);1075 mpeg4_encode_visual_object_header(s);
1062 if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || s->picture_number == 0) // HACK, the reference sw is buggy1076 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);
1064 }1078 }
1065 mpeg4_encode_gop_header(s);1079 mpeg4_encode_gop_header(s);
1066 }1080 }
@@ -1085,7 +1099,7 @@ int ff_mpeg4_encode_picture_header(MpegEncContext *s) · 18 unmodified lines
1085 put_bits(&s->pb, 1, 0);1099 put_bits(&s->pb, 1, 0);
1086 1100
1087 put_bits(&s->pb, 1, 1); /* marker */1101 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 */
1089 put_bits(&s->pb, 1, 1); /* marker */1103 put_bits(&s->pb, 1, 1); /* marker */
1090 put_bits(&s->pb, 1, 1); /* vop coded */1104 put_bits(&s->pb, 1, 1); /* vop coded */
1091 if (s->pict_type == AV_PICTURE_TYPE_P) {1105 if (s->pict_type == AV_PICTURE_TYPE_P) {
@@ -1276,7 +1290,8 @@ static av_cold void mpeg4_encode_init_static(void) · 184 unmodified lines
1276static av_cold int encode_init(AVCodecContext *avctx)1290static av_cold int encode_init(AVCodecContext *avctx)
1277{1291{
1278 static AVOnce init_static_once = AV_ONCE_INIT;1292 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;
1280 int ret;1295 int ret;
1281 1296
1282 if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) {1297 if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) {
@@ -1290,7 +1305,10 @@ static av_cold int encode_init(AVCodecContext *avctx) · 7 unmodified lines
1290 1305
1291 ff_thread_once(&init_static_once, mpeg4_encode_init_static);1306 ff_thread_once(&init_static_once, mpeg4_encode_init_static);
1292 1307
1308 m4->time_increment_bits = av_log2(avctx->time_base.den - 1) + 1;
1309
1293 s->fcode_tab = fcode_tab + MAX_MV;1310 s->fcode_tab = fcode_tab + MAX_MV;
1311
1294 s->min_qcoeff = -2048;1312 s->min_qcoeff = -2048;
1295 s->max_qcoeff = 2047;1313 s->max_qcoeff = 2047;
1296 s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len;1314 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
1309 init_put_bits(&s->pb, s->avctx->extradata, 1024);1327 init_put_bits(&s->pb, s->avctx->extradata, 1024);
1310 1328
1311 mpeg4_encode_visual_object_header(s);1329 mpeg4_encode_visual_object_header(s);
1312 mpeg4_encode_vol_header(s, 0, 0);1330 mpeg4_encode_vol_header(m4, 0, 0);
1313 1331
1314// ff_mpeg4_stuffing(&s->pb); ?1332// ff_mpeg4_stuffing(&s->pb); ?
1315 flush_put_bits(&s->pb);1333 flush_put_bits(&s->pb);
@@ -1395,7 +1413,7 @@ const FFCodec ff_mpeg4_encoder = { · 79 unmodified lines
1395 CODEC_LONG_NAME("MPEG-4 part 2"),1413 CODEC_LONG_NAME("MPEG-4 part 2"),
1396 .p.type = AVMEDIA_TYPE_VIDEO,1414 .p.type = AVMEDIA_TYPE_VIDEO,
1397 .p.id = AV_CODEC_ID_MPEG4,1415 .p.id = AV_CODEC_ID_MPEG4,
1398 .priv_data_size = sizeof(MPVMainEncContext),1416 .priv_data_size = sizeof(Mpeg4EncContext),
1399 .init = encode_init,1417 .init = encode_init,
1400 FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),1418 FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
1401 .close = ff_mpv_encode_end,1419 .close = ff_mpv_encode_end,
libavcodec/mpeg4videoenc.h+2−2
@@ -25,14 +25,14 @@ · 24 unmodified lines
25 25
26#include <stdint.h>26#include <stdint.h>
27 27
28#include "mpegvideo.h"28#include "mpegvideoenc.h"
29#include "put_bits.h"29#include "put_bits.h"
30 30
31void ff_mpeg4_encode_mb(MpegEncContext *s,31void ff_mpeg4_encode_mb(MpegEncContext *s,
32 int16_t block[6][64],32 int16_t block[6][64],
33 int motion_x, int motion_y);33 int motion_x, int motion_y);
34void ff_set_mpeg4_time(MpegEncContext *s);34void ff_set_mpeg4_time(MpegEncContext *s);
35int ff_mpeg4_encode_picture_header(MpegEncContext *s);35int ff_mpeg4_encode_picture_header(MPVMainEncContext *m);
36 36
37void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);37void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
38void ff_mpeg4_stuffing(PutBitContext *pbc);38void ff_mpeg4_stuffing(PutBitContext *pbc);
libavcodec/mpegvideo.h+0−2
@@ -362,8 +362,6 @@ typedef struct MpegEncContext { · 361 unmodified lines
362 /* MPEG-4 specific */362 /* MPEG-4 specific */
363 int studio_profile;363 int studio_profile;
364 int dct_precision;364 int dct_precision;
365 /// number of bits to represent the fractional part of time (encoder only)
366 int time_increment_bits;
367 int last_time_base;365 int last_time_base;
368 int time_base; ///< time in seconds of last I,P,S Frame366 int time_base; ///< time in seconds of last I,P,S Frame
369 int64_t time; ///< time of current frame367 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
746 (1 << 16) - 1);746 (1 << 16) - 1);
747 return AVERROR(EINVAL);747 return AVERROR(EINVAL);
748 }748 }
749 s->time_increment_bits = av_log2(avctx->time_base.den - 1) + 1;
750 749
751 switch (avctx->codec->id) {750 switch (avctx->codec->id) {
752#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER751#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER
@@ -3919,7 +3918,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) · 3166 unmodified lines
3919 ff_msmpeg4_encode_picture_header(s);3918 ff_msmpeg4_encode_picture_header(s);
3920#endif3919#endif
3921 else if (CONFIG_MPEG4_ENCODER && s->h263_pred) {3920 else if (CONFIG_MPEG4_ENCODER && s->h263_pred) {
3922 ret = ff_mpeg4_encode_picture_header(s);3921 ret = ff_mpeg4_encode_picture_header(m);
3923 if (ret < 0)3922 if (ret < 0)
3924 return ret;3923 return ret;
3925 } else if (CONFIG_RV10_ENCODER && s->codec_id == AV_CODEC_ID_RV10) {3924 } 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