diff --git a/configure b/configure index 817c9cfac7..449a46ecae 100755 --- a/configure +++ b/configure @@ -268,6 +268,7 @@ Advanced options (experts only): disable buffer boundary checking in bitreaders (faster, but may crash) --enable-memalign-hack emulate memalign, interferes with memory debuggers + --enable-lto use link-time optimization Optimization options (experts only): --disable-asm disable all assembler optimizations @@ -1418,6 +1419,7 @@ CONFIG_EXTRA=" huffman lgplv3 lpc + mpegaudio mpegaudiodsp mpegvideo mpegvideoenc @@ -1439,6 +1441,7 @@ CMDLINE_SELECT=" debug extra_warnings logging + lto optimizations stripping " @@ -1563,6 +1566,7 @@ log2_deps="!msvcrt" dct_select="rdft" mdct_select="fft" rdft_select="fft" +mpegaudio_select="mpegaudiodsp" mpegaudiodsp_select="dct" mpegvideoenc_select="mpegvideo" @@ -1632,16 +1636,16 @@ loco_decoder_select="golomb" mdec_decoder_select="error_resilience mpegvideo" mjpeg_encoder_select="aandcttables mpegvideoenc" mlp_decoder_select="mlp_parser" -mp1_decoder_select="mpegaudiodsp" -mp1float_decoder_select="mpegaudiodsp" -mp2_decoder_select="mpegaudiodsp" -mp2float_decoder_select="mpegaudiodsp" -mp3_decoder_select="mpegaudiodsp" -mp3adu_decoder_select="mpegaudiodsp" -mp3adufloat_decoder_select="mpegaudiodsp" -mp3float_decoder_select="mpegaudiodsp" -mp3on4_decoder_select="mpegaudiodsp" -mp3on4float_decoder_select="mpegaudiodsp" +mp1_decoder_select="mpegaudio" +mp1float_decoder_select="mpegaudio" +mp2_decoder_select="mpegaudio" +mp2float_decoder_select="mpegaudio" +mp3_decoder_select="mpegaudio" +mp3adu_decoder_select="mpegaudio" +mp3adufloat_decoder_select="mpegaudio" +mp3float_decoder_select="mpegaudio" +mp3on4_decoder_select="mpegaudio" +mp3on4float_decoder_select="mpegaudio" mpc7_decoder_select="mpegaudiodsp" mpc8_decoder_select="mpegaudiodsp" mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder" @@ -3847,17 +3851,32 @@ void ff_foo(void) {} EOF fi -if [ -n "$optflags" ]; then - add_cflags $optflags -elif enabled small; then - add_cflags $cflags_size -elif enabled optimizations; then - add_cflags $cflags_speed -else - add_cflags $cflags_noopt +if [ -z "$optflags" ]; then + if enabled small; then + optflags=$cflags_size + elif enabled optimizations; then + optflags=$cflags_speed + else + optflags=$cflags_noopt + fi fi -check_cflags -fno-math-errno -check_cflags -fno-signed-zeros + +check_optflags(){ + check_cflags "$@" + enabled lto && check_ldflags "$@" +} + + +if enabled lto; then + test "$cc_type" != "$ld_type" && die "LTO requires same compiler and linker" + check_cflags -flto + check_ldflags -flto $cpuflags +fi + +check_optflags $optflags +check_optflags -fno-math-errno +check_optflags -fno-signed-zeros + check_cc -mno-red-zone <oformat->priv_class && oc->priv_data) - av_opt_set(oc->priv_data, "resend_headers", "1", 0); + av_opt_set(oc->priv_data, "resend_headers", "1", 0); /* mpegts specific */ if (write_header) { if ((err = avformat_write_header(oc, NULL)) < 0) @@ -201,7 +202,7 @@ static int segment_end(AVFormatContext *s, int write_trailer) AVFormatContext *oc = seg->avf; int ret = 0; - av_write_frame(oc, NULL); /* Flush any buffered data */ + av_write_frame(oc, NULL); /* Flush any buffered data (fragmented mp4) */ if (write_trailer) ret = av_write_trailer(oc); @@ -288,6 +289,26 @@ end: return ret; } +static int open_null_ctx(AVIOContext **ctx) +{ + int buf_size = 32768; + uint8_t *buf = av_malloc(buf_size); + if (!buf) + return AVERROR(ENOMEM); + *ctx = avio_alloc_context(buf, buf_size, AVIO_FLAG_WRITE, NULL, NULL, NULL, NULL); + if (!*ctx) { + av_free(buf); + return AVERROR(ENOMEM); + } + return 0; +} + +static void close_null_ctx(AVIOContext *pb) +{ + av_free(pb->buffer); + av_free(pb); +} + static int seg_write_header(AVFormatContext *s) { SegmentContext *seg = s->priv_data; @@ -295,6 +316,8 @@ static int seg_write_header(AVFormatContext *s) int ret, i; seg->segment_count = 0; + if (!seg->write_header_trailer) + seg->individual_header_trailer = 0; if (seg->time_str && seg->times_str) { av_log(s, AV_LOG_ERROR, @@ -379,15 +402,27 @@ static int seg_write_header(AVFormatContext *s) } seg->segment_count++; - if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, - &s->interrupt_callback, NULL)) < 0) - goto fail; + if (seg->write_header_trailer) { + if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, + &s->interrupt_callback, NULL)) < 0) + goto fail; + } else { + if ((ret = open_null_ctx(&oc->pb)) < 0) + goto fail; + } if ((ret = avformat_write_header(oc, NULL)) < 0) { avio_close(oc->pb); goto fail; } + if (!seg->write_header_trailer) { + close_null_ctx(oc->pb); + if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, + &s->interrupt_callback, NULL)) < 0) + goto fail; + } + fail: if (ret) { if (seg->list) @@ -454,7 +489,15 @@ static int seg_write_trailer(struct AVFormatContext *s) { SegmentContext *seg = s->priv_data; AVFormatContext *oc = seg->avf; - int ret = segment_end(s, 1); + int ret; + if (!seg->write_header_trailer) { + ret = segment_end(s, 0); + open_null_ctx(&oc->pb); + av_write_trailer(oc); + close_null_ctx(oc->pb); + } else { + ret = segment_end(s, 1); + } if (seg->list) segment_list_close(s); @@ -486,6 +529,7 @@ static const AVOption options[] = { { "segment_times", "set segment split time points", OFFSET(times_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E }, { "segment_wrap", "set number after which the index wraps", OFFSET(segment_idx_wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E }, { "individual_header_trailer", "write header/trailer to each segment", OFFSET(individual_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E }, + { "write_header_trailer", "write a header to the first segment and a trailer to the last one", OFFSET(write_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E }, { NULL }, }; diff --git a/libavutil/x86/cpu.c b/libavutil/x86/cpu.c index 994e30dfe1..cd2f0092fa 100644 --- a/libavutil/x86/cpu.c +++ b/libavutil/x86/cpu.c @@ -86,6 +86,26 @@ #endif /* HAVE_INLINE_ASM */ +#if ARCH_X86_64 + +#define cpuid_test() 1 + +#elif HAVE_INLINE_ASM || HAVE_RWEFLAGS + +static int cpuid_test(void) +{ + x86_reg a, c; + + /* Check if CPUID is supported by attempting to toggle the ID bit in + * the EFLAGS register. */ + get_eflags(a); + set_eflags(a ^ 0x200000); + get_eflags(c); + + return a != c; +} +#endif + /* Function to test if multimedia instructions are supported... */ int ff_get_cpu_flags_x86(void) { @@ -95,23 +115,10 @@ int ff_get_cpu_flags_x86(void) int family = 0, model = 0; union { int i[3]; char c[12]; } vendor; -#if ARCH_X86_32 - x86_reg a, c; - - /* Check if CPUID is supported by attempting to toggle the ID bit in - * the EFLAGS register. */ - get_eflags(a); - set_eflags(a ^ 0x200000); - get_eflags(c); - - if (a == c) + if (!cpuid_test()) return 0; /* CPUID not supported */ -#endif - cpuid(0, max_std_level, ebx, ecx, edx); - vendor.i[0] = ebx; - vendor.i[1] = edx; - vendor.i[2] = ecx; + cpuid(0, max_std_level, vendor.i[0], vendor.i[2], vendor.i[1]); if (max_std_level >= 1) { cpuid(1, eax, ebx, ecx, std_caps);