History

avcodec/mpeg12enc: Merge ff_mpeg1_encode_init() into ordinary init

Everything except setting the dc_scale_tables can be done before calling ff_mpv_encode_init(); setting the dc_scale_tables unfortunately still has to be performed via a (now inlined) callback performed by ff_mpv_encode_init() as it relies on intra_dc_precision having been sanitized.

Andreas Rheinhardt committed 1 year ago

Commit 6ecdbcc1 parent 34557b12 files · +34 −33Browse files

Unified · Split

2 files
  1. libavcodec/mpeg12enc.c +26 −32
  2. libavcodec/mpeg12enc.h +8 −1
libavcodec/mpeg12enc.c+26−32
@@ -46,7 +46,6 @@ · 45 unmodified lines
4646 #include "mpeg12vlc.h"
4747 #include "mpegutils.h"
4848 #include "mpegvideo.h"
49−#include "mpegvideodata.h"
5049 #include "mpegvideoenc.h"
5150 #include "profiles.h"
5251 #include "rl.h"
@@ -1000,36 +999,6 @@ static av_cold void mpeg12_encode_init_static(void) · 947 unmodified lines
1000999 fcode_tab[mv + MAX_MV] = f_code;
10011000 }
10021001
1003−av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
1004−{
1005− static AVOnce init_static_once = AV_ONCE_INIT;
1006−
1007− s->y_dc_scale_table =
1008− s->c_dc_scale_table = ff_mpeg12_dc_scale_table[s->intra_dc_precision];
1009−
1010− s->me.mv_penalty = mv_penalty;
1011− s->fcode_tab = fcode_tab + MAX_MV;
1012− if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
1013− s->min_qcoeff = -255;
1014− s->max_qcoeff = 255;
1015− } else {
1016− s->min_qcoeff = -2047;
1017− s->max_qcoeff = 2047;
1018− s->mpeg_quant = 1;
1019− }
1020− if (s->intra_vlc_format) {
1021− s->intra_ac_vlc_length =
1022− s->intra_ac_vlc_last_length = uni_mpeg2_ac_vlc_len;
1023− } else {
1024− s->intra_ac_vlc_length =
1025− s->intra_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;
1026− }
1027− s->inter_ac_vlc_length =
1028− s->inter_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;
1029−
1030− ff_thread_once(&init_static_once, mpeg12_encode_init_static);
1031−}
1032−
10331002 static av_cold int find_frame_rate_index(AVCodecContext *avctx, MPEG12EncContext *mpeg12)
10341003 {
10351004 AVRational bestq = (AVRational) {0, 0};
@@ -1070,7 +1039,10 @@ static av_cold int find_frame_rate_index(AVCodecContext *avctx, MPEG12EncContext · 34 unmodified lines
10701039
10711040 static av_cold int encode_init(AVCodecContext *avctx)
10721041 {
1042+ static AVOnce init_static_once = AV_ONCE_INIT;
10731043 MPEG12EncContext *const mpeg12 = avctx->priv_data;
1044+ MPVMainEncContext *const m = &mpeg12->mpeg;
1045+ MpegEncContext *const s = &m->s;
10741046 int ret;
10751047 int max_size = avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 16383 : 4095;
10761048
@@ -1093,7 +1065,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 16 unmodified lines
10931065 }
10941066 }
10951067
1096− if (mpeg12->mpeg.s.q_scale_type == 1) {
1068+ if (s->q_scale_type == 1) {
10971069 if (avctx->qmax > 28) {
10981070 av_log(avctx, AV_LOG_ERROR,
10991071 "non linear quant only supports qmax <= 28 currently\n");
@@ -1132,6 +1104,26 @@ static av_cold int encode_init(AVCodecContext *avctx) · 32 unmodified lines
11321104 }
11331105 }
11341106
1107+ s->me.mv_penalty = mv_penalty;
1108+ s->fcode_tab = fcode_tab + MAX_MV;
1109+ if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
1110+ s->min_qcoeff = -255;
1111+ s->max_qcoeff = 255;
1112+ } else {
1113+ s->min_qcoeff = -2047;
1114+ s->max_qcoeff = 2047;
1115+ s->mpeg_quant = 1;
1116+ }
1117+ if (s->intra_vlc_format) {
1118+ s->intra_ac_vlc_length =
1119+ s->intra_ac_vlc_last_length = uni_mpeg2_ac_vlc_len;
1120+ } else {
1121+ s->intra_ac_vlc_length =
1122+ s->intra_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;
1123+ }
1124+ s->inter_ac_vlc_length =
1125+ s->inter_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;
1126+
11351127 ret = ff_mpv_encode_init(avctx);
11361128 if (ret < 0)
11371129 return ret;
@@ -1176,6 +1168,8 @@ static av_cold int encode_init(AVCodecContext *avctx) · 38 unmodified lines
11761168 mpeg12->timecode_frame_start = 0; // default is -1
11771169 }
11781170
1171+ ff_thread_once(&init_static_once, mpeg12_encode_init_static);
1172+
11791173 return 0;
11801174 }
11811175
libavcodec/mpeg12enc.h+8−1
@@ -25,11 +25,18 @@ · 24 unmodified lines
2525 #include <stdint.h>
2626
2727 #include "mpegvideo.h"
28+#include "mpegvideodata.h"
2829
2930 void ff_mpeg1_encode_picture_header(MpegEncContext *s);
3031 void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64],
3132 int motion_x, int motion_y);
32−void ff_mpeg1_encode_init(MpegEncContext *s);
3333 void ff_mpeg1_encode_slice_header(MpegEncContext *s);
3434
35+// Must not be called before intra_dc_precision has been sanitized in ff_mpv_encode_init()
36+static inline void ff_mpeg1_encode_init(MpegEncContext *s)
37+{
38+ s->y_dc_scale_table =
39+ s->c_dc_scale_table = ff_mpeg12_dc_scale_table[s->intra_dc_precision];
40+}
41+
3542 #endif /* AVCODEC_MPEG12ENC_H */

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