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.
Unified · Split
| @@ -46,7 +46,6 @@ · 45 unmodified lines | |||
| 46 | #include "mpeg12vlc.h" | 46 | #include "mpeg12vlc.h" |
| 47 | #include "mpegutils.h" | 47 | #include "mpegutils.h" |
| 48 | #include "mpegvideo.h" | 48 | #include "mpegvideo.h" |
| 49 | #include "mpegvideodata.h" | ||
| 50 | #include "mpegvideoenc.h" | 49 | #include "mpegvideoenc.h" |
| 51 | #include "profiles.h" | 50 | #include "profiles.h" |
| 52 | #include "rl.h" | 51 | #include "rl.h" |
| @@ -1000,36 +999,6 @@ static av_cold void mpeg12_encode_init_static(void) · 947 unmodified lines | |||
| 1000 | fcode_tab[mv + MAX_MV] = f_code; | 999 | fcode_tab[mv + MAX_MV] = f_code; |
| 1001 | } | 1000 | } |
| 1002 | 1001 | ||
| 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 | |||
| 1033 | static av_cold int find_frame_rate_index(AVCodecContext *avctx, MPEG12EncContext *mpeg12) | 1002 | static av_cold int find_frame_rate_index(AVCodecContext *avctx, MPEG12EncContext *mpeg12) |
| 1034 | { | 1003 | { |
| 1035 | AVRational bestq = (AVRational) {0, 0}; | 1004 | AVRational bestq = (AVRational) {0, 0}; |
| @@ -1070,7 +1039,10 @@ static av_cold int find_frame_rate_index(AVCodecContext *avctx, MPEG12EncContext · 34 unmodified lines | |||
| 1070 | 1039 | ||
| 1071 | static av_cold int encode_init(AVCodecContext *avctx) | 1040 | static av_cold int encode_init(AVCodecContext *avctx) |
| 1072 | { | 1041 | { |
| 1042 | static AVOnce init_static_once = AV_ONCE_INIT; | ||
| 1073 | MPEG12EncContext *const mpeg12 = avctx->priv_data; | 1043 | MPEG12EncContext *const mpeg12 = avctx->priv_data; |
| 1044 | MPVMainEncContext *const m = &mpeg12->mpeg; | ||
| 1045 | MpegEncContext *const s = &m->s; | ||
| 1074 | int ret; | 1046 | int ret; |
| 1075 | int max_size = avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 16383 : 4095; | 1047 | int max_size = avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 16383 : 4095; |
| 1076 | 1048 | ||
| @@ -1093,7 +1065,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 16 unmodified lines | |||
| 1093 | } | 1065 | } |
| 1094 | } | 1066 | } |
| 1095 | 1067 | ||
| 1096 | if (mpeg12->mpeg.s.q_scale_type == 1) { | 1068 | if (s->q_scale_type == 1) { |
| 1097 | if (avctx->qmax > 28) { | 1069 | if (avctx->qmax > 28) { |
| 1098 | av_log(avctx, AV_LOG_ERROR, | 1070 | av_log(avctx, AV_LOG_ERROR, |
| 1099 | "non linear quant only supports qmax <= 28 currently\n"); | 1071 | "non linear quant only supports qmax <= 28 currently\n"); |
| @@ -1132,6 +1104,26 @@ static av_cold int encode_init(AVCodecContext *avctx) · 32 unmodified lines | |||
| 1132 | } | 1104 | } |
| 1133 | } | 1105 | } |
| 1134 | 1106 | ||
| 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 | |||
| 1135 | ret = ff_mpv_encode_init(avctx); | 1127 | ret = ff_mpv_encode_init(avctx); |
| 1136 | if (ret < 0) | 1128 | if (ret < 0) |
| 1137 | return ret; | 1129 | return ret; |
| @@ -1176,6 +1168,8 @@ static av_cold int encode_init(AVCodecContext *avctx) · 38 unmodified lines | |||
| 1176 | mpeg12->timecode_frame_start = 0; // default is -1 | 1168 | mpeg12->timecode_frame_start = 0; // default is -1 |
| 1177 | } | 1169 | } |
| 1178 | 1170 | ||
| 1171 | ff_thread_once(&init_static_once, mpeg12_encode_init_static); | ||
| 1172 | |||
| 1179 | return 0; | 1173 | return 0; |
| 1180 | } | 1174 | } |
| 1181 | 1175 | ||
| @@ -25,11 +25,18 @@ · 24 unmodified lines | |||
| 25 | #include <stdint.h> | 25 | #include <stdint.h> |
| 26 | 26 | ||
| 27 | #include "mpegvideo.h" | 27 | #include "mpegvideo.h" |
| 28 | #include "mpegvideodata.h" | ||
| 28 | 29 | ||
| 29 | void ff_mpeg1_encode_picture_header(MpegEncContext *s); | 30 | void ff_mpeg1_encode_picture_header(MpegEncContext *s); |
| 30 | void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], | 31 | void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], |
| 31 | int motion_x, int motion_y); | 32 | int motion_x, int motion_y); |
| 32 | void ff_mpeg1_encode_init(MpegEncContext *s); | ||
| 33 | void ff_mpeg1_encode_slice_header(MpegEncContext *s); | 33 | void ff_mpeg1_encode_slice_header(MpegEncContext *s); |
| 34 | 34 | ||
| 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 | |||
| 35 | #endif /* AVCODEC_MPEG12ENC_H */ | 42 | #endif /* AVCODEC_MPEG12ENC_H */ |