From b4d44a45f9aa43bd2e5bddde33e3b37802607b0a Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 1 Jan 2012 14:21:50 +0100 Subject: [PATCH 01/13] threads: introduce CODEC_CAP_AUTO_THREADS and add it to libx264 Some external codecs have their own code to determine the best number of threads. This number is not necessary the number of cpu cores. Thread_count will be only 0 if the codec has CODEC_CAP_AUTO_THREADS. --- libavcodec/avcodec.h | 4 ++++ libavcodec/libx264.c | 2 +- libavcodec/pthread.c | 3 +++ libavcodec/version.h | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 4f24f729ac..b139a8a9ea 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -777,6 +777,10 @@ typedef struct RcOverride{ * Codec supports changed parameters at any point. */ #define CODEC_CAP_PARAM_CHANGE 0x4000 +/** + * Codec supports avctx->thread_count == 0 (auto). + */ +#define CODEC_CAP_AUTO_THREADS 0x8000 //The following defines may change, don't expect compatibility if you use them. #define MB_TYPE_INTRA4x4 0x0001 diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index c52580860b..9b347951fd 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -592,7 +592,7 @@ AVCodec ff_libx264_encoder = { .init = X264_init, .encode = X264_frame, .close = X264_close, - .capabilities = CODEC_CAP_DELAY, + .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS, .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), .priv_class = &class, .defaults = x264_defaults, diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 400abf4f6c..54a0eb3ab7 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -982,6 +982,9 @@ static void validate_thread_parameters(AVCodecContext *avctx) } else if (avctx->codec->capabilities & CODEC_CAP_SLICE_THREADS && avctx->thread_type & FF_THREAD_SLICE) { avctx->active_thread_type = FF_THREAD_SLICE; + } else if (!(avctx->codec->capabilities & CODEC_CAP_AUTO_THREADS)) { + avctx->thread_count = 1; + avctx->active_thread_type = 0; } } diff --git a/libavcodec/version.h b/libavcodec/version.h index e6226cb224..1317ef0ddc 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -22,7 +22,7 @@ #define LIBAVCODEC_VERSION_MAJOR 53 #define LIBAVCODEC_VERSION_MINOR 32 -#define LIBAVCODEC_VERSION_MICRO 1 +#define LIBAVCODEC_VERSION_MICRO 2 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ From b6064d9a5970c3aed9284a272bdb288e3eb00990 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 1 Jan 2012 14:17:32 +0100 Subject: [PATCH 02/13] threads: set thread_count to 1 when thread support is disabled --- libavcodec/utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index a88d1a7229..c845a310cd 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -710,6 +710,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD goto free_and_end; } } + if (!HAVE_THREADS && !(codec->capabilities & CODEC_CAP_AUTO_THREADS)) + avctx->thread_count = 1; if (avctx->codec->max_lowres < avctx->lowres) { av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n", From 60d626650a123532af9bbc63cc5344b470b1633d Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 1 Jan 2012 16:32:25 +0100 Subject: [PATCH 03/13] fate: use rgb24 as output format for dfa tests Palette is as supposed in native endianness. Converting the pal8 output to rgb24 is thus necessary for identical CRCs on big and little endian systems. --- tests/fate/dfa.mak | 22 +++++++------- tests/ref/fate/dfa1 | 50 +++++++++++++++--------------- tests/ref/fate/dfa10 | 16 +++++----- tests/ref/fate/dfa11 | 18 +++++------ tests/ref/fate/dfa2 | 34 ++++++++++----------- tests/ref/fate/dfa3 | 20 ++++++------ tests/ref/fate/dfa4 | 26 ++++++++-------- tests/ref/fate/dfa5 | 30 +++++++++--------- tests/ref/fate/dfa6 | 24 +++++++-------- tests/ref/fate/dfa7 | 24 +++++++-------- tests/ref/fate/dfa8 | 72 ++++++++++++++++++++++---------------------- tests/ref/fate/dfa9 | 12 ++++---- 12 files changed, 174 insertions(+), 174 deletions(-) diff --git a/tests/fate/dfa.mak b/tests/fate/dfa.mak index 1d6bce7fff..6220c070ef 100644 --- a/tests/fate/dfa.mak +++ b/tests/fate/dfa.mak @@ -1,35 +1,35 @@ FATE_DFA += fate-dfa1 -fate-dfa1: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0000.dfa +fate-dfa1: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0000.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa2 -fate-dfa2: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0001.dfa +fate-dfa2: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0001.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa3 -fate-dfa3: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0002.dfa +fate-dfa3: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0002.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa4 -fate-dfa4: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0003.dfa +fate-dfa4: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0003.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa5 -fate-dfa5: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0004.dfa +fate-dfa5: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0004.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa6 -fate-dfa6: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0005.dfa +fate-dfa6: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0005.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa7 -fate-dfa7: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0006.dfa +fate-dfa7: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0006.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa8 -fate-dfa8: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0007.dfa +fate-dfa8: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0007.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa9 -fate-dfa9: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0008.dfa +fate-dfa9: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0008.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa10 -fate-dfa10: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0009.dfa +fate-dfa10: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0009.dfa -pix_fmt rgb24 FATE_DFA += fate-dfa11 -fate-dfa11: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0010.dfa +fate-dfa11: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0010.dfa -pix_fmt rgb24 FATE_TESTS += $(FATE_DFA) fate-dfa: $(FATE_DFA) diff --git a/tests/ref/fate/dfa1 b/tests/ref/fate/dfa1 index c268367f79..43c973706d 100644 --- a/tests/ref/fate/dfa1 +++ b/tests/ref/fate/dfa1 @@ -1,25 +1,25 @@ -0, 0, 308224, 0x4eb64db1 -0, 11520, 308224, 0xbdc5595e -0, 23040, 308224, 0x795032b7 -0, 34560, 308224, 0xc808f69e -0, 46080, 308224, 0x8b4376ba -0, 57600, 308224, 0xdfd3be4c -0, 69120, 308224, 0xc2edda1b -0, 80640, 308224, 0x7dd38e7b -0, 92160, 308224, 0x79c08795 -0, 103680, 308224, 0x30e924b1 -0, 115200, 308224, 0xbda01fbb -0, 126720, 308224, 0x7c78d952 -0, 138240, 308224, 0xd4e425f7 -0, 149760, 308224, 0xd0ec4cdf -0, 161280, 308224, 0x8062992a -0, 172800, 308224, 0xd6cbd611 -0, 184320, 308224, 0x1083fe8e -0, 195840, 308224, 0x4efc3e39 -0, 207360, 308224, 0x5d67a998 -0, 218880, 308224, 0xe0ffbc9c -0, 230400, 308224, 0x8e2cc5e0 -0, 241920, 308224, 0x5ad7269f -0, 253440, 308224, 0x6830aad2 -0, 264960, 308224, 0xc8fee524 -0, 276480, 308224, 0xc89e7654 +0, 0, 921600, 0x2e2b3ca4 +0, 11520, 921600, 0x0ff7a368 +0, 23040, 921600, 0xf5f0dc50 +0, 34560, 921600, 0x56cb0c9d +0, 46080, 921600, 0xb253228f +0, 57600, 921600, 0xefd3419e +0, 69120, 921600, 0x708c0ce7 +0, 80640, 921600, 0x0b3a7f6d +0, 92160, 921600, 0x72db4eac +0, 103680, 921600, 0x94328111 +0, 115200, 921600, 0x95f7b2f0 +0, 126720, 921600, 0xdc3c9655 +0, 138240, 921600, 0xfe03dec6 +0, 149760, 921600, 0x2551dffb +0, 161280, 921600, 0xe8b37d9e +0, 172800, 921600, 0xad93508b +0, 184320, 921600, 0x5a1c4890 +0, 195840, 921600, 0x6f972fb4 +0, 207360, 921600, 0xa1d5ff95 +0, 218880, 921600, 0x7bc5d07c +0, 230400, 921600, 0xc0311e4e +0, 241920, 921600, 0x5b02cc48 +0, 253440, 921600, 0x8db4d5fa +0, 264960, 921600, 0x31aae769 +0, 276480, 921600, 0xab62b9a7 diff --git a/tests/ref/fate/dfa10 b/tests/ref/fate/dfa10 index c03df64650..720704aa01 100644 --- a/tests/ref/fate/dfa10 +++ b/tests/ref/fate/dfa10 @@ -1,8 +1,8 @@ -0, 0, 65024, 0x0a87d009 -0, 6390, 65024, 0x9191399b -0, 12780, 65024, 0x36c8c351 -0, 19170, 65024, 0xc1004a53 -0, 25560, 65024, 0x479625f8 -0, 31950, 65024, 0xdfab5170 -0, 38340, 65024, 0x2fae5741 -0, 44730, 65024, 0x98cea283 +0, 0, 192000, 0xbabcbd55 +0, 6390, 192000, 0xf00a5683 +0, 12780, 192000, 0xcce90589 +0, 19170, 192000, 0x8545631f +0, 25560, 192000, 0xd3ab654c +0, 31950, 192000, 0x5e0dda12 +0, 38340, 192000, 0x7e94b053 +0, 44730, 192000, 0x8027e68b diff --git a/tests/ref/fate/dfa11 b/tests/ref/fate/dfa11 index 22f7740293..f01fd13ac3 100644 --- a/tests/ref/fate/dfa11 +++ b/tests/ref/fate/dfa11 @@ -1,9 +1,9 @@ -0, 0, 65024, 0xc17b6232 -0, 6390, 65024, 0x6687b1aa -0, 12780, 65024, 0x7a046b14 -0, 19170, 65024, 0x25734b71 -0, 25560, 65024, 0x0bd3519d -0, 31950, 65024, 0x3c84ca25 -0, 38340, 65024, 0x269ba3c7 -0, 44730, 65024, 0xe4e17223 -0, 51120, 65024, 0x4d71b7bc +0, 0, 192000, 0x8b8bd8de +0, 6390, 192000, 0xdac26ec2 +0, 12780, 192000, 0x0fc01c28 +0, 19170, 192000, 0x1251eef7 +0, 25560, 192000, 0x89eced0e +0, 31950, 192000, 0x4943d821 +0, 38340, 192000, 0x49258ec9 +0, 44730, 192000, 0x9afd5881 +0, 51120, 192000, 0xb322b901 diff --git a/tests/ref/fate/dfa2 b/tests/ref/fate/dfa2 index a1c91cec60..98af733117 100644 --- a/tests/ref/fate/dfa2 +++ b/tests/ref/fate/dfa2 @@ -1,17 +1,17 @@ -0, 0, 308224, 0x53d98b6d -0, 6390, 308224, 0xcc319665 -0, 12780, 308224, 0x7edb8714 -0, 19170, 308224, 0x8b489159 -0, 25560, 308224, 0x535b8230 -0, 31950, 308224, 0x5db4851e -0, 38340, 308224, 0x29e09995 -0, 44730, 308224, 0x0d1e9546 -0, 51120, 308224, 0xceab7712 -0, 57510, 308224, 0x013f7ac8 -0, 63900, 308224, 0xb701543a -0, 70290, 308224, 0x919b39f3 -0, 76680, 308224, 0x714629a3 -0, 83070, 308224, 0x0e6af89b -0, 89460, 308224, 0x99f7f7e5 -0, 95850, 308224, 0x68d0e08f -0, 102240, 308224, 0x9f08d802 +0, 0, 921600, 0x713f2da1 +0, 6390, 921600, 0x9e772ec9 +0, 12780, 921600, 0x9420310f +0, 19170, 921600, 0xd68f294f +0, 25560, 921600, 0xe25a1bcf +0, 31950, 921600, 0x32f903ec +0, 38340, 921600, 0xdb290b1c +0, 44730, 921600, 0x0b0d1b0f +0, 51120, 921600, 0x58430921 +0, 57510, 921600, 0xe65dd39e +0, 63900, 921600, 0x146b3068 +0, 70290, 921600, 0x6e1e7f78 +0, 76680, 921600, 0x0166e01c +0, 83070, 921600, 0x83b86b56 +0, 89460, 921600, 0xd52a1697 +0, 95850, 921600, 0x5b38adc8 +0, 102240, 921600, 0x457f6cea diff --git a/tests/ref/fate/dfa3 b/tests/ref/fate/dfa3 index 4d92322953..0452f2b311 100644 --- a/tests/ref/fate/dfa3 +++ b/tests/ref/fate/dfa3 @@ -1,10 +1,10 @@ -0, 0, 65024, 0xb65d6443 -0, 9000, 65024, 0x433eb164 -0, 18000, 65024, 0x3ff19134 -0, 27000, 65024, 0x515e185f -0, 36000, 65024, 0x2236fb61 -0, 45000, 65024, 0xcc00194e -0, 54000, 65024, 0xc3618ddb -0, 63000, 65024, 0xe28a1ca4 -0, 72000, 65024, 0xfe584bb4 -0, 81000, 65024, 0xd41e54d8 +0, 0, 192000, 0x10380cf0 +0, 9000, 192000, 0x1d74af4c +0, 18000, 192000, 0xd665492d +0, 27000, 192000, 0xbf544565 +0, 36000, 192000, 0xf8a33b00 +0, 45000, 192000, 0x7d08bbad +0, 54000, 192000, 0x10685a90 +0, 63000, 192000, 0x0a1a9ef6 +0, 72000, 192000, 0x3e967980 +0, 81000, 192000, 0x9849f751 diff --git a/tests/ref/fate/dfa4 b/tests/ref/fate/dfa4 index 5dedf1504e..f19061b966 100644 --- a/tests/ref/fate/dfa4 +++ b/tests/ref/fate/dfa4 @@ -1,13 +1,13 @@ -0, 0, 308224, 0xcbf38c88 -0, 12780, 308224, 0x13ca020e -0, 25560, 308224, 0x3d6fba11 -0, 38340, 308224, 0xfd4d9025 -0, 51120, 308224, 0x56536094 -0, 63900, 308224, 0x56536094 -0, 76680, 308224, 0x56536094 -0, 89460, 308224, 0x56536094 -0, 102240, 308224, 0x56536094 -0, 115020, 308224, 0x56536094 -0, 127800, 308224, 0x4f4aaf8f -0, 140580, 308224, 0x07f9ae83 -0, 153360, 308224, 0xd0a068eb +0, 0, 921600, 0xe6309638 +0, 12780, 921600, 0xa99a7665 +0, 25560, 921600, 0x172ccfbb +0, 38340, 921600, 0xcf676571 +0, 51120, 921600, 0x6a5077f2 +0, 63900, 921600, 0x6a5077f2 +0, 76680, 921600, 0x6a5077f2 +0, 89460, 921600, 0x6a5077f2 +0, 102240, 921600, 0x6a5077f2 +0, 115020, 921600, 0x6a5077f2 +0, 127800, 921600, 0xb83db404 +0, 140580, 921600, 0x997ceb90 +0, 153360, 921600, 0xd707157c diff --git a/tests/ref/fate/dfa5 b/tests/ref/fate/dfa5 index 1485d3b9b9..65aa1bc838 100644 --- a/tests/ref/fate/dfa5 +++ b/tests/ref/fate/dfa5 @@ -1,15 +1,15 @@ -0, 0, 65024, 0x773b2585 -0, 9000, 65024, 0x33c76718 -0, 18000, 65024, 0x0016a365 -0, 27000, 65024, 0x3d6b811d -0, 36000, 65024, 0x53d35d3e -0, 45000, 65024, 0xd3195adc -0, 54000, 65024, 0x904e9492 -0, 63000, 65024, 0x4b905b93 -0, 72000, 65024, 0x97a24d60 -0, 81000, 65024, 0x5738bbd2 -0, 90000, 65024, 0x60c9213f -0, 99000, 65024, 0x2f2966c2 -0, 108000, 65024, 0x5d82ba0e -0, 117000, 65024, 0x3e18fd53 -0, 126000, 65024, 0xf199519d +0, 0, 192000, 0xc0941c10 +0, 9000, 192000, 0xe2fe3ae5 +0, 18000, 192000, 0x4a352d98 +0, 27000, 192000, 0x7b78e0bb +0, 36000, 192000, 0x855c6675 +0, 45000, 192000, 0xf443dad6 +0, 54000, 192000, 0xe7e2a2e1 +0, 63000, 192000, 0xa9009c58 +0, 72000, 192000, 0x551855ab +0, 81000, 192000, 0x253908c7 +0, 90000, 192000, 0x616213c4 +0, 99000, 192000, 0xa381c3b1 +0, 108000, 192000, 0xa2d64152 +0, 117000, 192000, 0x34ed0f72 +0, 126000, 192000, 0x05be63b4 diff --git a/tests/ref/fate/dfa6 b/tests/ref/fate/dfa6 index b9f943c434..92fe427eb5 100644 --- a/tests/ref/fate/dfa6 +++ b/tests/ref/fate/dfa6 @@ -1,12 +1,12 @@ -0, 0, 65024, 0x78ca2f73 -0, 6390, 65024, 0x7993cfbb -0, 12780, 65024, 0xe43b2c7d -0, 19170, 65024, 0x1b2e754a -0, 25560, 65024, 0xe543704d -0, 31950, 65024, 0x298c7243 -0, 38340, 65024, 0x521720ff -0, 44730, 65024, 0xc49498ab -0, 51120, 65024, 0x00fc4739 -0, 57510, 65024, 0xff03e8d4 -0, 63900, 65024, 0x79c09db5 -0, 70290, 65024, 0xee66fd09 +0, 0, 192000, 0x69f6a5f6 +0, 6390, 192000, 0xc741d0a6 +0, 12780, 192000, 0xba31e7a4 +0, 19170, 192000, 0x7dc45080 +0, 25560, 192000, 0x1c91dad5 +0, 31950, 192000, 0x564b69b1 +0, 38340, 192000, 0xdd9d9ae8 +0, 44730, 192000, 0x605c05e1 +0, 51120, 192000, 0xa5341ddb +0, 57510, 192000, 0x1ebff8ba +0, 63900, 192000, 0x240df237 +0, 70290, 192000, 0xac641867 diff --git a/tests/ref/fate/dfa7 b/tests/ref/fate/dfa7 index 87bf67622c..c9612f0f5d 100644 --- a/tests/ref/fate/dfa7 +++ b/tests/ref/fate/dfa7 @@ -1,12 +1,12 @@ -0, 0, 3648, 0x29484c3c -0, 6390, 3648, 0xa16855bb -0, 12780, 3648, 0x538353d6 -0, 19170, 3648, 0x735b4dfb -0, 25560, 3648, 0x15874bf8 -0, 31950, 3648, 0x96f558fc -0, 38340, 3648, 0xd5715d7e -0, 44730, 3648, 0x33ab5529 -0, 51120, 3648, 0xe7434c9b -0, 57510, 3648, 0x5f2e52a7 -0, 63900, 3648, 0xd32a4b54 -0, 70290, 3648, 0xd3b8547a +0, 0, 7866, 0xa0056fdb +0, 6390, 7866, 0xed906c7a +0, 12780, 7866, 0x1c6e6f7d +0, 19170, 7866, 0xa2c460f7 +0, 25560, 7866, 0xcf2166d4 +0, 31950, 7866, 0xea545432 +0, 38340, 7866, 0x604a5a9e +0, 44730, 7866, 0xbbc95c89 +0, 51120, 7866, 0x80b16b5b +0, 57510, 7866, 0x9a1660ae +0, 63900, 7866, 0x6f886b10 +0, 70290, 7866, 0xad8b5c99 diff --git a/tests/ref/fate/dfa8 b/tests/ref/fate/dfa8 index 6f5d3ecfa6..ade21de822 100644 --- a/tests/ref/fate/dfa8 +++ b/tests/ref/fate/dfa8 @@ -1,36 +1,36 @@ -0, 0, 45932, 0xa55439fb -0, 6390, 45932, 0x071f423f -0, 12780, 45932, 0xf0aac5a9 -0, 19170, 45932, 0x9f3b803b -0, 25560, 45932, 0xeb68e802 -0, 31950, 45932, 0xfa3a994d -0, 38340, 45932, 0x0ed46f09 -0, 44730, 45932, 0x2374f44c -0, 51120, 45932, 0x2dde0a6e -0, 57510, 45932, 0x941e579f -0, 63900, 45932, 0x44ef4c63 -0, 70290, 45932, 0x743aa480 -0, 76680, 45932, 0x4eeb6204 -0, 83070, 45932, 0x60eb012c -0, 89460, 45932, 0x35f34724 -0, 95850, 45932, 0xc7565c42 -0, 102240, 45932, 0x9dc310c3 -0, 108630, 45932, 0x0afac80a -0, 115020, 45932, 0x720112f1 -0, 121410, 45932, 0x59d35a12 -0, 127800, 45932, 0xeadb11c1 -0, 134190, 45932, 0x8a2fb50a -0, 140580, 45932, 0xe730d603 -0, 146970, 45932, 0x8fb0b733 -0, 153360, 45932, 0x644bfddd -0, 159750, 45932, 0x7bec84af -0, 166140, 45932, 0x89892d60 -0, 172530, 45932, 0x9c74e8d4 -0, 178920, 45932, 0x81429e13 -0, 185310, 45932, 0xab80509d -0, 191700, 45932, 0x30914ddc -0, 198090, 45932, 0x925f64c0 -0, 204480, 45932, 0x6e3454bf -0, 210870, 45932, 0x32b072c4 -0, 217260, 45932, 0xae5049a4 -0, 223650, 45932, 0xde749c5a +0, 0, 134724, 0x2ab217de +0, 6390, 134724, 0xbf240f9a +0, 12780, 134724, 0x020a6010 +0, 19170, 134724, 0x9a5f9374 +0, 25560, 134724, 0x1e93a7e9 +0, 31950, 134724, 0x9e4a4c55 +0, 38340, 134724, 0x8f9d1bab +0, 44730, 134724, 0xb26ac45b +0, 51120, 134724, 0xc08706d2 +0, 57510, 134724, 0x0806b031 +0, 63900, 134724, 0x234dbb33 +0, 70290, 134724, 0xe4cbfb2f +0, 76680, 134724, 0xf603f3fd +0, 83070, 134724, 0x205669d1 +0, 89460, 134724, 0x7ddbb5e3 +0, 95850, 134724, 0x8dfbb45a +0, 102240, 134724, 0x9632f681 +0, 108630, 134724, 0x259e462c +0, 115020, 134724, 0x14f2bac1 +0, 121410, 134724, 0xac3de7ed +0, 127800, 134724, 0x6b8af396 +0, 134190, 134724, 0xd1e4bc1c +0, 140580, 134724, 0x716d1c73 +0, 146970, 134724, 0x610956c8 +0, 153360, 134724, 0x89ff8e86 +0, 159750, 134724, 0xc3ea6b6f +0, 166140, 134724, 0x886688ef +0, 172530, 134724, 0xe60fc8c1 +0, 178920, 134724, 0x22bd3131 +0, 185310, 134724, 0xb1d74561 +0, 191700, 134724, 0x61b069bc +0, 198090, 134724, 0x50b665c1 +0, 204480, 134724, 0x027e5144 +0, 210870, 134724, 0xfe0c31b4 +0, 217260, 134724, 0x1e7a1f2d +0, 223650, 134724, 0x48bff03d diff --git a/tests/ref/fate/dfa9 b/tests/ref/fate/dfa9 index f1de996a60..b33152a982 100644 --- a/tests/ref/fate/dfa9 +++ b/tests/ref/fate/dfa9 @@ -1,6 +1,6 @@ -0, 0, 77076, 0xd202cc47 -0, 6390, 77076, 0x7cceaf30 -0, 12780, 77076, 0x2baa1d52 -0, 19170, 77076, 0x89b1787a -0, 25560, 77076, 0x252af096 -0, 31950, 77076, 0xc77cff33 +0, 0, 228150, 0x188c6d9b +0, 6390, 228150, 0x658dbf2f +0, 12780, 228150, 0xc09a4b2e +0, 19170, 228150, 0x8777bc7d +0, 25560, 228150, 0xa388f0ce +0, 31950, 228150, 0x4e06666e From da7c65f0ce2a9c5609cdecbca4336821a92a7aa8 Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Sun, 1 Jan 2012 17:51:26 +0530 Subject: [PATCH 04/13] avplay: K&R cleanup Signed-off-by: Anton Khirnov --- avplay.c | 546 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 275 insertions(+), 271 deletions(-) diff --git a/avplay.c b/avplay.c index 6a79e87730..6dbf140135 100644 --- a/avplay.c +++ b/avplay.c @@ -80,7 +80,7 @@ const int program_birth_year = 2003; #define AUDIO_DIFF_AVG_NB 20 /* NOTE: the size must be big enough to compensate the hardware audio buffersize size */ -#define SAMPLE_ARRAY_SIZE (2*65536) +#define SAMPLE_ARRAY_SIZE (2 * 65536) static int sws_flags = SWS_BICUBIC; @@ -97,9 +97,9 @@ typedef struct PacketQueue { #define SUBPICTURE_QUEUE_SIZE 4 typedef struct VideoPicture { - double pts; ///mutex); - for(pkt = q->first_pkt; pkt != NULL; pkt = pkt1) { + for (pkt = q->first_pkt; pkt != NULL; pkt = pkt1) { pkt1 = pkt->next; av_free_packet(&pkt->pkt); av_freep(&pkt); @@ -323,7 +323,7 @@ static int packet_queue_put(PacketQueue *q, AVPacket *pkt) AVPacketList *pkt1; /* duplicate the packet */ - if (pkt!=&flush_pkt && av_dup_packet(pkt) < 0) + if (pkt != &flush_pkt && av_dup_packet(pkt) < 0) return -1; pkt1 = av_malloc(sizeof(AVPacketList)); @@ -369,7 +369,7 @@ static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block) SDL_LockMutex(q->mutex); - for(;;) { + for (;;) { if (q->abort_request) { ret = -1; break; @@ -451,8 +451,8 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, dstx = av_clip(rect->x, 0, imgw - dstw); dsty = av_clip(rect->y, 0, imgh - dsth); lum = dst->data[0] + dsty * dst->linesize[0]; - cb = dst->data[1] + (dsty >> 1) * dst->linesize[1]; - cr = dst->data[2] + (dsty >> 1) * dst->linesize[2]; + cb = dst->data[1] + (dsty >> 1) * dst->linesize[1]; + cr = dst->data[2] + (dsty >> 1) * dst->linesize[2]; width2 = ((dstw + 1) >> 1) + (dstx & ~dstw & 1); skip2 = dstx >> 1; @@ -476,7 +476,7 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, lum++; p += BPP; } - for(w = dstw - (dstx & 1); w >= 2; w -= 2) { + for (w = dstw - (dstx & 1); w >= 2; w -= 2) { YUVA_IN(y, u, v, a, p, pal); u1 = u; v1 = v; @@ -508,7 +508,7 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, cb += dst->linesize[1] - width2 - skip2; cr += dst->linesize[2] - width2 - skip2; } - for(h = dsth - (dsty & 1); h >= 2; h -= 2) { + for (h = dsth - (dsty & 1); h >= 2; h -= 2) { lum += dstx; cb += skip2; cr += skip2; @@ -533,7 +533,7 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, p += -wrap3 + BPP; lum += -wrap + 1; } - for(w = dstw - (dstx & 1); w >= 2; w -= 2) { + for (w = dstw - (dstx & 1); w >= 2; w -= 2) { YUVA_IN(y, u, v, a, p, pal); u1 = u; v1 = v; @@ -609,7 +609,7 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, lum++; p += BPP; } - for(w = dstw - (dstx & 1); w >= 2; w -= 2) { + for (w = dstw - (dstx & 1); w >= 2; w -= 2) { YUVA_IN(y, u, v, a, p, pal); u1 = u; v1 = v; @@ -742,15 +742,15 @@ static void video_audio_display(VideoState *s) int16_t time_diff; int rdft_bits, nb_freq; - for(rdft_bits=1; (1<height; rdft_bits++) + for (rdft_bits = 1; (1 << rdft_bits) < 2 * s->height; rdft_bits++) ; - nb_freq= 1<<(rdft_bits-1); + nb_freq = 1 << (rdft_bits - 1); /* compute display index : center on currently output samples */ channels = s->audio_st->codec->channels; nb_display_channels = channels; if (!s->paused) { - int data_used= s->show_audio==1 ? s->width : (2*nb_freq); + int data_used = s->show_audio == 1 ? s->width : (2 * nb_freq); n = 2 * channels; delay = audio_write_get_buf_size(s); delay /= n; @@ -762,23 +762,23 @@ static void video_audio_display(VideoState *s) delay -= (time_diff * s->audio_st->codec->sample_rate) / 1000000; } - delay += 2*data_used; + delay += 2 * data_used; if (delay < data_used) delay = data_used; i_start= x = compute_mod(s->sample_array_index - delay * channels, SAMPLE_ARRAY_SIZE); - if(s->show_audio==1){ - h= INT_MIN; - for(i=0; i<1000; i+=channels){ - int idx= (SAMPLE_ARRAY_SIZE + x - i) % SAMPLE_ARRAY_SIZE; - int a= s->sample_array[idx]; - int b= s->sample_array[(idx + 4*channels)%SAMPLE_ARRAY_SIZE]; - int c= s->sample_array[(idx + 5*channels)%SAMPLE_ARRAY_SIZE]; - int d= s->sample_array[(idx + 9*channels)%SAMPLE_ARRAY_SIZE]; - int score= a-d; - if(hshow_audio == 1) { + h = INT_MIN; + for (i = 0; i < 1000; i += channels) { + int idx = (SAMPLE_ARRAY_SIZE + x - i) % SAMPLE_ARRAY_SIZE; + int a = s->sample_array[idx]; + int b = s->sample_array[(idx + 4 * channels) % SAMPLE_ARRAY_SIZE]; + int c = s->sample_array[(idx + 5 * channels) % SAMPLE_ARRAY_SIZE]; + int d = s->sample_array[(idx + 9 * channels) % SAMPLE_ARRAY_SIZE]; + int score = a - d; + if (h < score && (b ^ c) < 0) { + h = score; + i_start = idx; } } } @@ -789,7 +789,7 @@ static void video_audio_display(VideoState *s) } bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); - if(s->show_audio==1){ + if (s->show_audio == 1) { fill_rectangle(screen, s->xleft, s->ytop, s->width, s->height, bgcolor); @@ -800,10 +800,10 @@ static void video_audio_display(VideoState *s) h = s->height / nb_display_channels; /* graph height / 2 */ h2 = (h * 9) / 20; - for(ch = 0;ch < nb_display_channels; ch++) { + for (ch = 0; ch < nb_display_channels; ch++) { i = i_start + ch; y1 = s->ytop + ch * h + (h / 2); /* position of center line */ - for(x = 0; x < s->width; x++) { + for (x = 0; x < s->width; x++) { y = (s->sample_array[i] * h2) >> 15; if (y < 0) { y = -y; @@ -822,45 +822,45 @@ static void video_audio_display(VideoState *s) fgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff); - for(ch = 1;ch < nb_display_channels; ch++) { + for (ch = 1; ch < nb_display_channels; ch++) { y = s->ytop + ch * h; fill_rectangle(screen, s->xleft, y, s->width, 1, fgcolor); } SDL_UpdateRect(screen, s->xleft, s->ytop, s->width, s->height); - }else{ + } else { nb_display_channels= FFMIN(nb_display_channels, 2); - if(rdft_bits != s->rdft_bits){ + if (rdft_bits != s->rdft_bits) { av_rdft_end(s->rdft); av_free(s->rdft_data); s->rdft = av_rdft_init(rdft_bits, DFT_R2C); - s->rdft_bits= rdft_bits; - s->rdft_data= av_malloc(4*nb_freq*sizeof(*s->rdft_data)); + s->rdft_bits = rdft_bits; + s->rdft_data = av_malloc(4 * nb_freq * sizeof(*s->rdft_data)); } { FFTSample *data[2]; - for(ch = 0;ch < nb_display_channels; ch++) { - data[ch] = s->rdft_data + 2*nb_freq*ch; + for (ch = 0; ch < nb_display_channels; ch++) { + data[ch] = s->rdft_data + 2 * nb_freq * ch; i = i_start + ch; - for(x = 0; x < 2*nb_freq; x++) { - double w= (x-nb_freq)*(1.0/nb_freq); - data[ch][x]= s->sample_array[i]*(1.0-w*w); + for (x = 0; x < 2 * nb_freq; x++) { + double w = (x-nb_freq) * (1.0 / nb_freq); + data[ch][x] = s->sample_array[i] * (1.0 - w * w); i += channels; if (i >= SAMPLE_ARRAY_SIZE) i -= SAMPLE_ARRAY_SIZE; } av_rdft_calc(s->rdft, data[ch]); } - //least efficient way to do this, we should of course directly access it but its more than fast enough - for(y=0; yheight; y++){ - double w= 1/sqrt(nb_freq); - int a= sqrt(w*sqrt(data[0][2*y+0]*data[0][2*y+0] + data[0][2*y+1]*data[0][2*y+1])); - int b= (nb_display_channels == 2 ) ? sqrt(w*sqrt(data[1][2*y+0]*data[1][2*y+0] - + data[1][2*y+1]*data[1][2*y+1])) : a; - a= FFMIN(a,255); - b= FFMIN(b,255); - fgcolor = SDL_MapRGB(screen->format, a, b, (a+b)/2); + // least efficient way to do this, we should of course directly access it but its more than fast enough + for (y = 0; y < s->height; y++) { + double w = 1 / sqrt(nb_freq); + int a = sqrt(w * sqrt(data[0][2 * y + 0] * data[0][2 * y + 0] + data[0][2 * y + 1] * data[0][2 * y + 1])); + int b = (nb_display_channels == 2 ) ? sqrt(w * sqrt(data[1][2 * y + 0] * data[1][2 * y + 0] + + data[1][2 * y + 1] * data[1][2 * y + 1])) : a; + a = FFMIN(a, 255); + b = FFMIN(b, 255); + fgcolor = SDL_MapRGB(screen->format, a, b, (a + b) / 2); fill_rectangle(screen, s->xpos, s->height-y, 1, 1, @@ -869,30 +869,31 @@ static void video_audio_display(VideoState *s) } SDL_UpdateRect(screen, s->xpos, s->ytop, 1, s->height); s->xpos++; - if(s->xpos >= s->width) + if (s->xpos >= s->width) s->xpos= s->xleft; } } -static int video_open(VideoState *is){ - int flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL; +static int video_open(VideoState *is) +{ + int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; int w,h; - if(is_full_screen) flags |= SDL_FULLSCREEN; - else flags |= SDL_RESIZABLE; + if (is_full_screen) flags |= SDL_FULLSCREEN; + else flags |= SDL_RESIZABLE; if (is_full_screen && fs_screen_width) { w = fs_screen_width; h = fs_screen_height; - } else if(!is_full_screen && screen_width){ + } else if (!is_full_screen && screen_width) { w = screen_width; h = screen_height; #if CONFIG_AVFILTER - }else if (is->out_video_filter && is->out_video_filter->inputs[0]){ + } else if (is->out_video_filter && is->out_video_filter->inputs[0]) { w = is->out_video_filter->inputs[0]->w; h = is->out_video_filter->inputs[0]->h; #else - }else if (is->video_st && is->video_st->codec->width){ + } else if (is->video_st && is->video_st->codec->width) { w = is->video_st->codec->width; h = is->video_st->codec->height; #endif @@ -900,7 +901,7 @@ static int video_open(VideoState *is){ w = 640; h = 480; } - if(screen && is->width == screen->w && screen->w == w + if (screen && is->width == screen->w && screen->w == w && is->height== screen->h && screen->h == h) return 0; @@ -918,7 +919,7 @@ static int video_open(VideoState *is){ window_title = input_filename; SDL_WM_SetCaption(window_title, window_title); - is->width = screen->w; + is->width = screen->w; is->height = screen->h; return 0; @@ -927,7 +928,7 @@ static int video_open(VideoState *is){ /* display the current picture, if any */ static void video_display(VideoState *is) { - if(!screen) + if (!screen) video_open(cur_stream); if (is->audio_st && is->show_audio) video_audio_display(is); @@ -938,15 +939,15 @@ static void video_display(VideoState *is) static int refresh_thread(void *opaque) { VideoState *is= opaque; - while(!is->abort_request){ + while (!is->abort_request) { SDL_Event event; event.type = FF_REFRESH_EVENT; event.user.data1 = opaque; - if(!is->refresh){ - is->refresh=1; + if (!is->refresh) { + is->refresh = 1; SDL_PushEvent(&event); } - usleep(is->audio_st && is->show_audio ? rdftspeed*1000 : 5000); //FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly + usleep(is->audio_st && is->show_audio ? rdftspeed * 1000 : 5000); // FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly } return 0; } @@ -961,7 +962,7 @@ static double get_audio_clock(VideoState *is) bytes_per_sec = 0; if (is->audio_st) { bytes_per_sec = is->audio_st->codec->sample_rate * - 2 * is->audio_st->codec->channels; + 2 * is->audio_st->codec->channels; } if (bytes_per_sec) pts -= (double)hw_buf_size / bytes_per_sec; @@ -1025,7 +1026,7 @@ static void stream_pause(VideoState *is) { if (is->paused) { is->frame_timer += av_gettime() / 1000000.0 + is->video_current_pts_drift - is->video_current_pts; - if(is->read_pause_return != AVERROR(ENOSYS)){ + if (is->read_pause_return != AVERROR(ENOSYS)) { is->video_current_pts = is->video_current_pts_drift + av_gettime() / 1000000.0; } is->video_current_pts_drift = is->video_current_pts - av_gettime() / 1000000.0; @@ -1084,29 +1085,29 @@ static void video_refresh_timer(void *opaque) if (is->video_st) { retry: if (is->pictq_size == 0) { - //nothing to do, no picture to display in the que + // nothing to do, no picture to display in the que } else { - double time= av_gettime()/1000000.0; + double time = av_gettime() / 1000000.0; double next_target; /* dequeue the picture */ vp = &is->pictq[is->pictq_rindex]; - if(time < vp->target_clock) + if (time < vp->target_clock) return; /* update current video pts */ is->video_current_pts = vp->pts; is->video_current_pts_drift = is->video_current_pts - time; is->video_current_pos = vp->pos; - if(is->pictq_size > 1){ - VideoPicture *nextvp= &is->pictq[(is->pictq_rindex+1)%VIDEO_PICTURE_QUEUE_SIZE]; + if (is->pictq_size > 1) { + VideoPicture *nextvp = &is->pictq[(is->pictq_rindex + 1) % VIDEO_PICTURE_QUEUE_SIZE]; assert(nextvp->target_clock >= vp->target_clock); next_target= nextvp->target_clock; - }else{ - next_target= vp->target_clock + is->video_clock - vp->pts; //FIXME pass durations cleanly + } else { + next_target = vp->target_clock + is->video_clock - vp->pts; // FIXME pass durations cleanly } - if(framedrop && time > next_target){ + if (framedrop && time > next_target) { is->skip_frames *= 1.0 + FRAME_SKIP_FACTOR; - if(is->pictq_size > 1 || time > next_target + 0.5){ + if (is->pictq_size > 1 || time > next_target + 0.5) { /* update queue size and signal for next picture */ if (++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE) is->pictq_rindex = 0; @@ -1119,7 +1120,7 @@ retry: } } - if(is->subtitle_st) { + if (is->subtitle_st) { if (is->subtitle_stream_changed) { SDL_LockMutex(is->subpq_mutex); @@ -1207,7 +1208,8 @@ retry: if (is->audio_st && is->video_st) av_diff = get_audio_clock(is) - get_video_clock(is); printf("%7.2f A-V:%7.3f s:%3.1f aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64"/%"PRId64" \r", - get_master_clock(is), av_diff, FFMAX(is->skip_frames-1, 0), aqsize / 1024, vqsize / 1024, sqsize, is->pts_ctx.num_faulty_dts, is->pts_ctx.num_faulty_pts); + get_master_clock(is), av_diff, FFMAX(is->skip_frames - 1, 0), aqsize / 1024, + vqsize / 1024, sqsize, is->pts_ctx.num_faulty_dts, is->pts_ctx.num_faulty_pts); fflush(stdout); last_time = cur_time; } @@ -1224,7 +1226,7 @@ static void stream_close(VideoState *is) SDL_WaitThread(is->refresh_tid, NULL); /* free all pictures */ - for(i=0;ipictq[i]; #if CONFIG_AVFILTER if (vp->picref) { @@ -1325,8 +1327,8 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t /* wait until we have space to put a new picture */ SDL_LockMutex(is->pictq_mutex); - if(is->pictq_size>=VIDEO_PICTURE_QUEUE_SIZE && !is->refresh) - is->skip_frames= FFMAX(1.0 - FRAME_SKIP_FACTOR, is->skip_frames * (1.0-FRAME_SKIP_FACTOR)); + if (is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE && !is->refresh) + is->skip_frames = FFMAX(1.0 - FRAME_SKIP_FACTOR, is->skip_frames * (1.0 - FRAME_SKIP_FACTOR)); while (is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE && !is->videoq.abort_request) { @@ -1374,7 +1376,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t if (vp->bmp) { AVPicture pict; #if CONFIG_AVFILTER - if(vp->picref) + if (vp->picref) avfilter_unref_buffer(vp->picref); vp->picref = src_frame->opaque; #endif @@ -1382,7 +1384,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t /* get a pointer on the bitmap */ SDL_LockYUVOverlay (vp->bmp); - memset(&pict,0,sizeof(AVPicture)); + memset(&pict, 0, sizeof(AVPicture)); pict.data[0] = vp->bmp->pixels[0]; pict.data[1] = vp->bmp->pixels[2]; pict.data[2] = vp->bmp->pixels[1]; @@ -1400,7 +1402,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t pict_src.linesize[1] = src_frame->linesize[1]; pict_src.linesize[2] = src_frame->linesize[2]; - //FIXME use direct rendering + // FIXME use direct rendering av_picture_copy(&pict, &pict_src, vp->pix_fmt, vp->width, vp->height); #else @@ -1425,7 +1427,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t if (++is->pictq_windex == VIDEO_PICTURE_QUEUE_SIZE) is->pictq_windex = 0; SDL_LockMutex(is->pictq_mutex); - vp->target_clock= compute_target_time(vp->pts, is); + vp->target_clock = compute_target_time(vp->pts, is); is->pictq_size++; SDL_UnlockMutex(is->pictq_mutex); @@ -1470,7 +1472,7 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke avcodec_flush_buffers(is->video_st->codec); SDL_LockMutex(is->pictq_mutex); - //Make sure there are no long delay timers (ideally we should just flush the que but thats harder) + // Make sure there are no long delay timers (ideally we should just flush the que but thats harder) for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) { is->pictq[i].target_clock= 0; } @@ -1505,7 +1507,7 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke } is->skip_frames_index += 1; - if(is->skip_frames_index >= is->skip_frames){ + if (is->skip_frames_index >= is->skip_frames) { is->skip_frames_index -= FFMAX(is->skip_frames, 1.0); return 1; } @@ -1533,12 +1535,12 @@ static int input_get_buffer(AVCodecContext *codec, AVFrame *pic) if (codec->codec->capabilities & CODEC_CAP_NEG_LINESIZES) perms |= AV_PERM_NEG_LINESIZES; - if(pic->buffer_hints & FF_BUFFER_HINTS_VALID) { - if(pic->buffer_hints & FF_BUFFER_HINTS_READABLE) perms |= AV_PERM_READ; - if(pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) perms |= AV_PERM_PRESERVE; - if(pic->buffer_hints & FF_BUFFER_HINTS_REUSABLE) perms |= AV_PERM_REUSE2; + if (pic->buffer_hints & FF_BUFFER_HINTS_VALID) { + if (pic->buffer_hints & FF_BUFFER_HINTS_READABLE) perms |= AV_PERM_READ; + if (pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) perms |= AV_PERM_PRESERVE; + if (pic->buffer_hints & FF_BUFFER_HINTS_REUSABLE) perms |= AV_PERM_REUSE2; } - if(pic->reference) perms |= AV_PERM_READ | AV_PERM_PRESERVE; + if (pic->reference) perms |= AV_PERM_READ | AV_PERM_PRESERVE; w = codec->width; h = codec->height; @@ -1547,13 +1549,13 @@ static int input_get_buffer(AVCodecContext *codec, AVFrame *pic) w += edge << 1; h += edge << 1; - if(!(ref = avfilter_get_video_buffer(ctx->outputs[0], perms, w, h))) + if (!(ref = avfilter_get_video_buffer(ctx->outputs[0], perms, w, h))) return -1; - pixel_size = av_pix_fmt_descriptors[ref->format].comp[0].step_minus1+1; + pixel_size = av_pix_fmt_descriptors[ref->format].comp[0].step_minus1 + 1; ref->video->w = codec->width; ref->video->h = codec->height; - for(i = 0; i < 4; i ++) { + for (i = 0; i < 4; i ++) { unsigned hshift = (i == 1 || i == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_w : 0; unsigned vshift = (i == 1 || i == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_h : 0; @@ -1566,8 +1568,8 @@ static int input_get_buffer(AVCodecContext *codec, AVFrame *pic) pic->opaque = ref; pic->type = FF_BUFFER_TYPE_USER; pic->reordered_opaque = codec->reordered_opaque; - if(codec->pkt) pic->pkt_pts = codec->pkt->pts; - else pic->pkt_pts = AV_NOPTS_VALUE; + if (codec->pkt) pic->pkt_pts = codec->pkt->pts; + else pic->pkt_pts = AV_NOPTS_VALUE; return 0; } @@ -1593,8 +1595,8 @@ static int input_reget_buffer(AVCodecContext *codec, AVFrame *pic) } pic->reordered_opaque = codec->reordered_opaque; - if(codec->pkt) pic->pkt_pts = codec->pkt->pts; - else pic->pkt_pts = AV_NOPTS_VALUE; + if (codec->pkt) pic->pkt_pts = codec->pkt->pts; + else pic->pkt_pts = AV_NOPTS_VALUE; return 0; } @@ -1602,12 +1604,12 @@ static int input_init(AVFilterContext *ctx, const char *args, void *opaque) { FilterPriv *priv = ctx->priv; AVCodecContext *codec; - if(!opaque) return -1; + if (!opaque) return -1; priv->is = opaque; codec = priv->is->video_st->codec; codec->opaque = ctx; - if(codec->codec->capabilities & CODEC_CAP_DR1) { + if (codec->codec->capabilities & CODEC_CAP_DR1) { priv->use_dr1 = 1; codec->get_buffer = input_get_buffer; codec->release_buffer = input_release_buffer; @@ -1639,7 +1641,7 @@ static int input_request_frame(AVFilterLink *link) if (ret < 0) return -1; - if(priv->use_dr1) { + if (priv->use_dr1) { picref = avfilter_ref_buffer(priv->frame->opaque, ~0); } else { picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, link->w, link->h); @@ -1717,7 +1719,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c NULL, &ffsink_ctx, graph)) < 0) return ret; - if(vfilters) { + if (vfilters) { AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut)); AVFilterInOut *inputs = av_malloc(sizeof(AVFilterInOut)); @@ -1752,7 +1754,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c static int video_thread(void *arg) { VideoState *is = arg; - AVFrame *frame= avcodec_alloc_frame(); + AVFrame *frame = avcodec_alloc_frame(); int64_t pts_int; double pts; int ret; @@ -1769,7 +1771,7 @@ static int video_thread(void *arg) filt_out = is->out_video_filter; #endif - for(;;) { + for (;;) { #if !CONFIG_AVFILTER AVPacket pkt; #else @@ -1810,12 +1812,13 @@ static int video_thread(void *arg) ret = get_video_frame(is, frame, &pts_int, &pkt); #endif - if (ret < 0) goto the_end; + if (ret < 0) + goto the_end; if (!ret) continue; - pts = pts_int*av_q2d(is->video_st->time_base); + pts = pts_int * av_q2d(is->video_st->time_base); #if CONFIG_AVFILTER ret = output_picture2(is, frame, pts, pos); @@ -1848,14 +1851,14 @@ static int subtitle_thread(void *arg) int i, j; int r, g, b, y, u, v, a; - for(;;) { + for (;;) { while (is->paused && !is->subtitleq.abort_request) { SDL_Delay(10); } if (packet_queue_get(&is->subtitleq, pkt, 1) < 0) break; - if(pkt->data == flush_pkt.data){ + if (pkt->data == flush_pkt.data) { avcodec_flush_buffers(is->subtitle_st->codec); continue; } @@ -1875,7 +1878,7 @@ static int subtitle_thread(void *arg) this packet, if any */ pts = 0; if (pkt->pts != AV_NOPTS_VALUE) - pts = av_q2d(is->subtitle_st->time_base)*pkt->pts; + pts = av_q2d(is->subtitle_st->time_base) * pkt->pts; avcodec_decode_subtitle2(is->subtitle_st->codec, &sp->sub, &got_subtitle, pkt); @@ -1994,7 +1997,7 @@ static int synchronize_audio(VideoState *is, short *samples, /* too big difference : may be initial PTS errors, so reset A-V filter */ is->audio_diff_avg_count = 0; - is->audio_diff_cum = 0; + is->audio_diff_cum = 0; } } @@ -2006,13 +2009,13 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) { AVPacket *pkt_temp = &is->audio_pkt_temp; AVPacket *pkt = &is->audio_pkt; - AVCodecContext *dec= is->audio_st->codec; + AVCodecContext *dec = is->audio_st->codec; int n, len1, data_size, got_frame; double pts; int new_packet = 0; int flush_complete = 0; - for(;;) { + for (;;) { /* NOTE: the audio packet can contain several frames */ while (pkt_temp->size > 0 || (!pkt_temp->data && new_packet)) { if (!is->frame) { @@ -2059,25 +2062,25 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr) } if (is->reformat_ctx) { - const void *ibuf[6]= { is->frame->data[0] }; + const void *ibuf[6] = { is->frame->data[0] }; void *obuf[6]; - int istride[6]= {av_get_bytes_per_sample(dec->sample_fmt)}; - int ostride[6]= {2}; + int istride[6] = { av_get_bytes_per_sample(dec->sample_fmt) }; + int ostride[6] = { 2 }; int len= data_size/istride[0]; obuf[0] = av_realloc(is->audio_buf1, FFALIGN(len * ostride[0], 32)); if (!obuf[0]) { return AVERROR(ENOMEM); } is->audio_buf1 = obuf[0]; - if (av_audio_convert(is->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) { + if (av_audio_convert(is->reformat_ctx, obuf, ostride, ibuf, istride, len) < 0) { printf("av_audio_convert() failed\n"); break; } is->audio_buf = is->audio_buf1; /* FIXME: existing code assume that data_size equals framesize*channels*2 remove this legacy cruft */ - data_size= len*2; - }else{ + data_size = len * 2; + } else { is->audio_buf = is->frame->data[0]; } @@ -2176,19 +2179,20 @@ static int stream_component_open(VideoState *is, int stream_index) opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index]); codec = avcodec_find_decoder(avctx->codec_id); - avctx->debug_mv = debug_mv; - avctx->debug = debug; - avctx->workaround_bugs = workaround_bugs; - avctx->lowres = lowres; - if(lowres) avctx->flags |= CODEC_FLAG_EMU_EDGE; - avctx->idct_algo= idct; - if(fast) avctx->flags2 |= CODEC_FLAG2_FAST; - avctx->skip_frame= skip_frame; - avctx->skip_idct= skip_idct; - avctx->skip_loop_filter= skip_loop_filter; - avctx->error_recognition= error_recognition; - avctx->error_concealment= error_concealment; - avctx->thread_count= thread_count; + avctx->debug_mv = debug_mv; + avctx->debug = debug; + avctx->workaround_bugs = workaround_bugs; + avctx->lowres = lowres; + avctx->idct_algo = idct; + avctx->skip_frame = skip_frame; + avctx->skip_idct = skip_idct; + avctx->skip_loop_filter = skip_loop_filter; + avctx->error_recognition = error_recognition; + avctx->error_concealment = error_concealment; + avctx->thread_count = thread_count; + + if (lowres) avctx->flags |= CODEC_FLAG_EMU_EDGE; + if (fast) avctx->flags2 |= CODEC_FLAG2_FAST; if (!codec || avcodec_open2(avctx, codec, &opts) < 0) @@ -2212,19 +2216,19 @@ static int stream_component_open(VideoState *is, int stream_index) return -1; } is->audio_hw_buf_size = spec.size; - is->audio_src_fmt= AV_SAMPLE_FMT_S16; + is->audio_src_fmt = AV_SAMPLE_FMT_S16; } ic->streams[stream_index]->discard = AVDISCARD_DEFAULT; - switch(avctx->codec_type) { + switch (avctx->codec_type) { case AVMEDIA_TYPE_AUDIO: is->audio_stream = stream_index; is->audio_st = ic->streams[stream_index]; - is->audio_buf_size = 0; + is->audio_buf_size = 0; is->audio_buf_index = 0; /* init averaging filter */ - is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB); + is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB); is->audio_diff_avg_count = 0; /* since we do not have a precise anough audio fifo fullness, we correct audio sync only if larger than this threshold */ @@ -2263,7 +2267,7 @@ static void stream_component_close(VideoState *is, int stream_index) return; avctx = ic->streams[stream_index]->codec; - switch(avctx->codec_type) { + switch (avctx->codec_type) { case AVMEDIA_TYPE_AUDIO: packet_queue_abort(&is->audioq); @@ -2319,7 +2323,7 @@ static void stream_component_close(VideoState *is, int stream_index) ic->streams[stream_index]->discard = AVDISCARD_ALL; avcodec_close(avctx); - switch(avctx->codec_type) { + switch (avctx->codec_type) { case AVMEDIA_TYPE_AUDIO: is->audio_st = NULL; is->audio_stream = -1; @@ -2354,7 +2358,7 @@ static int decode_thread(void *arg) int err, i, ret; int st_index[AVMEDIA_TYPE_NB]; AVPacket pkt1, *pkt = &pkt1; - int eof=0; + int eof = 0; int pkt_in_play_range = 0; AVDictionaryEntry *t; AVDictionary **opts; @@ -2382,7 +2386,7 @@ static int decode_thread(void *arg) } is->ic = ic; - if(genpts) + if (genpts) ic->flags |= AVFMT_FLAG_GENPTS; opts = setup_find_stream_info_opts(ic, codec_opts); @@ -2398,11 +2402,11 @@ static int decode_thread(void *arg) av_dict_free(&opts[i]); av_freep(&opts); - if(ic->pb) - ic->pb->eof_reached= 0; //FIXME hack, avplay maybe should not use url_feof() to test for the end + if (ic->pb) + ic->pb->eof_reached = 0; // FIXME hack, avplay maybe should not use url_feof() to test for the end - if(seek_by_bytes<0) - seek_by_bytes= !!(ic->iformat->flags & AVFMT_TS_DISCONT); + if (seek_by_bytes < 0) + seek_by_bytes = !!(ic->iformat->flags & AVFMT_TS_DISCONT); /* if seeking requested, we execute it */ if (start_time != AV_NOPTS_VALUE) { @@ -2448,12 +2452,12 @@ static int decode_thread(void *arg) stream_component_open(is, st_index[AVMEDIA_TYPE_AUDIO]); } - ret=-1; + ret = -1; if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) { - ret= stream_component_open(is, st_index[AVMEDIA_TYPE_VIDEO]); + ret = stream_component_open(is, st_index[AVMEDIA_TYPE_VIDEO]); } is->refresh_tid = SDL_CreateThread(refresh_thread, is); - if(ret<0) { + if (ret < 0) { if (!display_disable) is->show_audio = 2; } @@ -2468,13 +2472,13 @@ static int decode_thread(void *arg) goto fail; } - for(;;) { + for (;;) { if (is->abort_request) break; if (is->paused != is->last_paused) { is->last_paused = is->paused; if (is->paused) - is->read_pause_return= av_read_pause(ic); + is->read_pause_return = av_read_pause(ic); else av_read_play(ic); } @@ -2487,16 +2491,16 @@ static int decode_thread(void *arg) } #endif if (is->seek_req) { - int64_t seek_target= is->seek_pos; - int64_t seek_min= is->seek_rel > 0 ? seek_target - is->seek_rel + 2: INT64_MIN; - int64_t seek_max= is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX; -//FIXME the +-2 is due to rounding being not done in the correct direction in generation + int64_t seek_target = is->seek_pos; + int64_t seek_min = is->seek_rel > 0 ? seek_target - is->seek_rel + 2: INT64_MIN; + int64_t seek_max = is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX; +// FIXME the +-2 is due to rounding being not done in the correct direction in generation // of the seek_pos/seek_rel variables ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags); if (ret < 0) { fprintf(stderr, "%s: error while seeking\n", is->ic->filename); - }else{ + } else { if (is->audio_stream >= 0) { packet_queue_flush(&is->audioq); packet_queue_put(&is->audioq, &flush_pkt); @@ -2511,24 +2515,24 @@ static int decode_thread(void *arg) } } is->seek_req = 0; - eof= 0; + eof = 0; } /* if the queue are full, no need to read more */ if ( is->audioq.size + is->videoq.size + is->subtitleq.size > MAX_QUEUE_SIZE - || ( (is->audioq .size > MIN_AUDIOQ_SIZE || is->audio_stream<0) - && (is->videoq .nb_packets > MIN_FRAMES || is->video_stream<0) - && (is->subtitleq.nb_packets > MIN_FRAMES || is->subtitle_stream<0))) { + || ( (is->audioq .size > MIN_AUDIOQ_SIZE || is->audio_stream < 0) + && (is->videoq .nb_packets > MIN_FRAMES || is->video_stream < 0) + && (is->subtitleq.nb_packets > MIN_FRAMES || is->subtitle_stream < 0))) { /* wait 10 ms */ SDL_Delay(10); continue; } - if(eof) { - if(is->video_stream >= 0){ + if (eof) { + if (is->video_stream >= 0) { av_init_packet(pkt); - pkt->data=NULL; - pkt->size=0; - pkt->stream_index= is->video_stream; + pkt->data = NULL; + pkt->size = 0; + pkt->stream_index = is->video_stream; packet_queue_put(&is->videoq, pkt); } if (is->audio_stream >= 0 && @@ -2540,11 +2544,11 @@ static int decode_thread(void *arg) packet_queue_put(&is->audioq, pkt); } SDL_Delay(10); - if(is->audioq.size + is->videoq.size + is->subtitleq.size ==0){ - if(loop!=1 && (!loop || --loop)){ + if (is->audioq.size + is->videoq.size + is->subtitleq.size == 0) { + if (loop != 1 && (!loop || --loop)) { stream_seek(cur_stream, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0); - }else if(autoexit){ - ret=AVERROR_EOF; + } else if (autoexit) { + ret = AVERROR_EOF; goto fail; } } @@ -2553,7 +2557,7 @@ static int decode_thread(void *arg) ret = av_read_frame(ic, pkt); if (ret < 0) { if (ret == AVERROR_EOF || (ic->pb && ic->pb->eof_reached)) - eof=1; + eof = 1; if (ic->pb && ic->pb->error) break; SDL_Delay(100); /* wait for user event */ @@ -2563,8 +2567,8 @@ static int decode_thread(void *arg) pkt_in_play_range = duration == AV_NOPTS_VALUE || (pkt->pts - ic->streams[pkt->stream_index]->start_time) * av_q2d(ic->streams[pkt->stream_index]->time_base) - - (double)(start_time != AV_NOPTS_VALUE ? start_time : 0)/1000000 - <= ((double)duration/1000000); + (double)(start_time != AV_NOPTS_VALUE ? start_time : 0) / 1000000 + <= ((double)duration / 1000000); if (pkt->stream_index == is->audio_stream && pkt_in_play_range) { packet_queue_put(&is->audioq, pkt); } else if (pkt->stream_index == is->video_stream && pkt_in_play_range) { @@ -2616,18 +2620,18 @@ static VideoState *stream_open(const char *filename, AVInputFormat *iformat) return NULL; av_strlcpy(is->filename, filename, sizeof(is->filename)); is->iformat = iformat; - is->ytop = 0; - is->xleft = 0; + is->ytop = 0; + is->xleft = 0; /* start video display */ is->pictq_mutex = SDL_CreateMutex(); - is->pictq_cond = SDL_CreateCond(); + is->pictq_cond = SDL_CreateCond(); is->subpq_mutex = SDL_CreateMutex(); - is->subpq_cond = SDL_CreateCond(); + is->subpq_cond = SDL_CreateCond(); is->av_sync_type = av_sync_type; - is->parse_tid = SDL_CreateThread(decode_thread, is); + is->parse_tid = SDL_CreateThread(decode_thread, is); if (!is->parse_tid) { av_free(is); return NULL; @@ -2650,7 +2654,7 @@ static void stream_cycle_channel(VideoState *is, int codec_type) if (start_index < (codec_type == AVMEDIA_TYPE_SUBTITLE ? -1 : 0)) return; stream_index = start_index; - for(;;) { + for (;;) { if (++stream_index >= is->ic->nb_streams) { if (codec_type == AVMEDIA_TYPE_SUBTITLE) @@ -2665,7 +2669,7 @@ static void stream_cycle_channel(VideoState *is, int codec_type) st = ic->streams[stream_index]; if (st->codec->codec_type == codec_type) { /* check that parameters are OK */ - switch(codec_type) { + switch (codec_type) { case AVMEDIA_TYPE_AUDIO: if (st->codec->sample_rate != 0 && st->codec->channels != 0) @@ -2720,8 +2724,8 @@ static void toggle_audio_display(void) int bgcolor = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); cur_stream->show_audio = (cur_stream->show_audio + 1) % 3; fill_rectangle(screen, - cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height, - bgcolor); + cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height, + bgcolor); SDL_UpdateRect(screen, cur_stream->xleft, cur_stream->ytop, cur_stream->width, cur_stream->height); } } @@ -2732,16 +2736,16 @@ static void event_loop(void) SDL_Event event; double incr, pos, frac; - for(;;) { + for (;;) { double x; SDL_WaitEvent(&event); - switch(event.type) { + switch (event.type) { case SDL_KEYDOWN: if (exit_on_keydown) { do_exit(); break; } - switch(event.key.keysym.sym) { + switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_q: do_exit(); @@ -2753,7 +2757,7 @@ static void event_loop(void) case SDLK_SPACE: toggle_pause(); break; - case SDLK_s: //S: Step to next frame + case SDLK_s: // S: Step to next frame step_to_next_frame(); break; case SDLK_a: @@ -2785,11 +2789,11 @@ static void event_loop(void) do_seek: if (cur_stream) { if (seek_by_bytes) { - if (cur_stream->video_stream >= 0 && cur_stream->video_current_pos>=0){ - pos= cur_stream->video_current_pos; - }else if(cur_stream->audio_stream >= 0 && cur_stream->audio_pkt.pos>=0){ - pos= cur_stream->audio_pkt.pos; - }else + if (cur_stream->video_stream >= 0 && cur_stream->video_current_pos >= 0) { + pos = cur_stream->video_current_pos; + } else if (cur_stream->audio_stream >= 0 && cur_stream->audio_pkt.pos >= 0) { + pos = cur_stream->audio_pkt.pos; + } else pos = avio_tell(cur_stream->ic->pb); if (cur_stream->ic->bit_rate) incr *= cur_stream->ic->bit_rate / 8.0; @@ -2814,33 +2818,33 @@ static void event_loop(void) break; } case SDL_MOUSEMOTION: - if(event.type ==SDL_MOUSEBUTTONDOWN){ - x= event.button.x; - }else{ - if(event.motion.state != SDL_PRESSED) + if (event.type == SDL_MOUSEBUTTONDOWN) { + x = event.button.x; + } else { + if (event.motion.state != SDL_PRESSED) break; - x= event.motion.x; + x = event.motion.x; } if (cur_stream) { - if(seek_by_bytes || cur_stream->ic->duration<=0){ - uint64_t size= avio_size(cur_stream->ic->pb); + if (seek_by_bytes || cur_stream->ic->duration <= 0) { + uint64_t size = avio_size(cur_stream->ic->pb); stream_seek(cur_stream, size*x/cur_stream->width, 0, 1); - }else{ + } else { int64_t ts; int ns, hh, mm, ss; int tns, thh, tmm, tss; - tns = cur_stream->ic->duration/1000000LL; - thh = tns/3600; - tmm = (tns%3600)/60; - tss = (tns%60); - frac = x/cur_stream->width; - ns = frac*tns; - hh = ns/3600; - mm = (ns%3600)/60; - ss = (ns%60); + tns = cur_stream->ic->duration / 1000000LL; + thh = tns / 3600; + tmm = (tns % 3600) / 60; + tss = (tns % 60); + frac = x / cur_stream->width; + ns = frac * tns; + hh = ns / 3600; + mm = (ns % 3600) / 60; + ss = (ns % 60); fprintf(stderr, "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100, hh, mm, ss, thh, tmm, tss); - ts = frac*cur_stream->ic->duration; + ts = frac * cur_stream->ic->duration; if (cur_stream->ic->start_time != AV_NOPTS_VALUE) ts += cur_stream->ic->start_time; stream_seek(cur_stream, ts, 0, 0); @@ -2851,8 +2855,8 @@ static void event_loop(void) if (cur_stream) { screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); - screen_width = cur_stream->width = event.resize.w; - screen_height= cur_stream->height= event.resize.h; + screen_width = cur_stream->width = event.resize.w; + screen_height = cur_stream->height = event.resize.h; } break; case SDL_QUIT: @@ -2865,7 +2869,7 @@ static void event_loop(void) break; case FF_REFRESH_EVENT: video_refresh_timer(event.user.data1); - cur_stream->refresh=0; + cur_stream->refresh = 0; break; default: break; @@ -2951,7 +2955,7 @@ static int opt_vismv(const char *opt, const char *arg) static int opt_thread_count(const char *opt, const char *arg) { - thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); + thread_count = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); #if !HAVE_THREADS fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n"); #endif @@ -2960,49 +2964,49 @@ static int opt_thread_count(const char *opt, const char *arg) static const OptionDef options[] = { #include "cmdutils_common_opts.h" - { "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" }, - { "y", HAS_ARG, {(void*)opt_height}, "force displayed height", "height" }, - { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, - { "fs", OPT_BOOL, {(void*)&is_full_screen}, "force full screen" }, - { "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" }, - { "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" }, - { "ast", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_stream[AVMEDIA_TYPE_AUDIO]}, "select desired audio stream", "stream_number" }, - { "vst", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_stream[AVMEDIA_TYPE_VIDEO]}, "select desired video stream", "stream_number" }, - { "sst", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_stream[AVMEDIA_TYPE_SUBTITLE]}, "select desired subtitle stream", "stream_number" }, - { "ss", HAS_ARG, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" }, - { "t", HAS_ARG, {(void*)&opt_duration}, "play \"duration\" seconds of audio/video", "duration" }, - { "bytes", OPT_INT | HAS_ARG, {(void*)&seek_by_bytes}, "seek by bytes 0=off 1=on -1=auto", "val" }, - { "nodisp", OPT_BOOL, {(void*)&display_disable}, "disable graphical display" }, - { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" }, - { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format", "format" }, - { "stats", OPT_BOOL | OPT_EXPERT, {(void*)&show_status}, "show status", "" }, - { "debug", HAS_ARG | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" }, - { "bug", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&workaround_bugs}, "workaround bugs", "" }, - { "vismv", HAS_ARG | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" }, - { "fast", OPT_BOOL | OPT_EXPERT, {(void*)&fast}, "non spec compliant optimizations", "" }, - { "genpts", OPT_BOOL | OPT_EXPERT, {(void*)&genpts}, "generate pts", "" }, - { "drp", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&decoder_reorder_pts}, "let decoder reorder pts 0=off 1=on -1=auto", ""}, - { "lowres", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&lowres}, "", "" }, - { "skiploop", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&skip_loop_filter}, "", "" }, - { "skipframe", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&skip_frame}, "", "" }, - { "skipidct", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&skip_idct}, "", "" }, - { "idct", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&idct}, "set idct algo", "algo" }, - { "er", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_recognition}, "set error detection threshold (0-4)", "threshold" }, - { "ec", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_concealment}, "set error concealment options", "bit_mask" }, - { "sync", HAS_ARG | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" }, - { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" }, - { "autoexit", OPT_BOOL | OPT_EXPERT, {(void*)&autoexit}, "exit at the end", "" }, - { "exitonkeydown", OPT_BOOL | OPT_EXPERT, {(void*)&exit_on_keydown}, "exit on key down", "" }, - { "exitonmousedown", OPT_BOOL | OPT_EXPERT, {(void*)&exit_on_mousedown}, "exit on mouse down", "" }, - { "loop", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&loop}, "set number of times the playback shall be looped", "loop count" }, - { "framedrop", OPT_BOOL | OPT_EXPERT, {(void*)&framedrop}, "drop frames when cpu is too slow", "" }, - { "window_title", OPT_STRING | HAS_ARG, {(void*)&window_title}, "set window title", "window title" }, + { "x", HAS_ARG, { (void*)opt_width }, "force displayed width", "width" }, + { "y", HAS_ARG, { (void*)opt_height }, "force displayed height", "height" }, + { "s", HAS_ARG | OPT_VIDEO, { (void*)opt_frame_size }, "set frame size (WxH or abbreviation)", "size" }, + { "fs", OPT_BOOL, { (void*)&is_full_screen }, "force full screen" }, + { "an", OPT_BOOL, { (void*)&audio_disable }, "disable audio" }, + { "vn", OPT_BOOL, { (void*)&video_disable }, "disable video" }, + { "ast", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&wanted_stream[AVMEDIA_TYPE_AUDIO] }, "select desired audio stream", "stream_number" }, + { "vst", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&wanted_stream[AVMEDIA_TYPE_VIDEO] }, "select desired video stream", "stream_number" }, + { "sst", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&wanted_stream[AVMEDIA_TYPE_SUBTITLE] }, "select desired subtitle stream", "stream_number" }, + { "ss", HAS_ARG, { (void*)&opt_seek }, "seek to a given position in seconds", "pos" }, + { "t", HAS_ARG, { (void*)&opt_duration }, "play \"duration\" seconds of audio/video", "duration" }, + { "bytes", OPT_INT | HAS_ARG, { (void*)&seek_by_bytes }, "seek by bytes 0=off 1=on -1=auto", "val" }, + { "nodisp", OPT_BOOL, { (void*)&display_disable }, "disable graphical display" }, + { "f", HAS_ARG, { (void*)opt_format }, "force format", "fmt" }, + { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { (void*)opt_frame_pix_fmt }, "set pixel format", "format" }, + { "stats", OPT_BOOL | OPT_EXPERT, { (void*)&show_status }, "show status", "" }, + { "debug", HAS_ARG | OPT_EXPERT, { (void*)opt_debug }, "print specific debug info", "" }, + { "bug", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&workaround_bugs }, "workaround bugs", "" }, + { "vismv", HAS_ARG | OPT_EXPERT, { (void*)opt_vismv }, "visualize motion vectors", "" }, + { "fast", OPT_BOOL | OPT_EXPERT, { (void*)&fast }, "non spec compliant optimizations", "" }, + { "genpts", OPT_BOOL | OPT_EXPERT, { (void*)&genpts }, "generate pts", "" }, + { "drp", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&decoder_reorder_pts }, "let decoder reorder pts 0=off 1=on -1=auto", ""}, + { "lowres", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&lowres }, "", "" }, + { "skiploop", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&skip_loop_filter }, "", "" }, + { "skipframe", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&skip_frame }, "", "" }, + { "skipidct", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&skip_idct }, "", "" }, + { "idct", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&idct }, "set idct algo", "algo" }, + { "er", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&error_recognition }, "set error detection threshold (0-4)", "threshold" }, + { "ec", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&error_concealment }, "set error concealment options", "bit_mask" }, + { "sync", HAS_ARG | OPT_EXPERT, { (void*)opt_sync }, "set audio-video sync. type (type=audio/video/ext)", "type" }, + { "threads", HAS_ARG | OPT_EXPERT, { (void*)opt_thread_count }, "thread count", "count" }, + { "autoexit", OPT_BOOL | OPT_EXPERT, { (void*)&autoexit }, "exit at the end", "" }, + { "exitonkeydown", OPT_BOOL | OPT_EXPERT, { (void*)&exit_on_keydown }, "exit on key down", "" }, + { "exitonmousedown", OPT_BOOL | OPT_EXPERT, { (void*)&exit_on_mousedown }, "exit on mouse down", "" }, + { "loop", OPT_INT | HAS_ARG | OPT_EXPERT, { (void*)&loop }, "set number of times the playback shall be looped", "loop count" }, + { "framedrop", OPT_BOOL | OPT_EXPERT, { (void*)&framedrop }, "drop frames when cpu is too slow", "" }, + { "window_title", OPT_STRING | HAS_ARG, { (void*)&window_title }, "set window title", "window title" }, #if CONFIG_AVFILTER - { "vf", OPT_STRING | HAS_ARG, {(void*)&vfilters}, "video filters", "filter list" }, + { "vf", OPT_STRING | HAS_ARG, { (void*)&vfilters }, "video filters", "filter list" }, #endif - { "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, {(void*)&rdftspeed}, "rdft speed", "msecs" }, - { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, - { "i", 0, {NULL}, "avconv compatibility dummy option", ""}, + { "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, { (void*)&rdftspeed }, "rdft speed", "msecs" }, + { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, { (void*)opt_default }, "generic catch all option", "" }, + { "i", 0, { NULL }, "avconv compatibility dummy option", ""}, { NULL, }, }; @@ -3111,7 +3115,7 @@ int main(int argc, char **argv) SDL_EventState(SDL_USEREVENT, SDL_IGNORE); av_init_packet(&flush_pkt); - flush_pkt.data= "FLUSH"; + flush_pkt.data = "FLUSH"; cur_stream = stream_open(input_filename, file_iformat); From b12d21733975f9001eecb480fc28e5e4473b1327 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 1 Jan 2012 17:35:16 +0100 Subject: [PATCH 05/13] threads: limit the number of automatic threads to MAX_AUTO_THREADS The extra thread added in {frame_}*thread_init was not taken into account. Explicitly sets thread_count to 1 if only one CPU core was detected. Also fixes two typos in comments. --- libavcodec/pthread.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 54a0eb3ab7..58c5fcd638 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -186,7 +186,7 @@ static int get_logical_cpus(AVCodecContext *avctx) nb_cpus = sysconf(_SC_NPROCESSORS_ONLN); #endif av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus); - return FFMIN(nb_cpus, MAX_AUTO_THREADS); + return nb_cpus; } @@ -296,9 +296,11 @@ static int thread_init(AVCodecContext *avctx) if (!thread_count) { int nb_cpus = get_logical_cpus(avctx); - // use number of cores + 1 as thread count if there is motre than one + // use number of cores + 1 as thread count if there is more than one if (nb_cpus > 1) - thread_count = avctx->thread_count = nb_cpus + 1; + thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS); + else + thread_count = avctx->thread_count = 1; } if (thread_count <= 1) { @@ -767,9 +769,11 @@ static int frame_thread_init(AVCodecContext *avctx) if (!thread_count) { int nb_cpus = get_logical_cpus(avctx); - // use number of cores + 1 as thread count if there is motre than one + // use number of cores + 1 as thread count if there is more than one if (nb_cpus > 1) - thread_count = avctx->thread_count = nb_cpus + 1; + thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS); + else + thread_count = avctx->thread_count = 1; } if (thread_count <= 1) { From 1135a0714613b91642fc1c2c4b0d807250a55f5c Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 1 Jan 2012 17:56:28 +0100 Subject: [PATCH 06/13] avconv: free bitstream filters --- avconv.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/avconv.c b/avconv.c index f3e6e288ba..3fa164ff43 100644 --- a/avconv.c +++ b/avconv.c @@ -667,6 +667,15 @@ void exit_program(int ret) avformat_free_context(s); av_dict_free(&output_files[i].opts); } + for (i = 0; i < nb_output_streams; i++) { + AVBitStreamFilterContext *bsfc = output_streams[i].bitstream_filters; + while (bsfc) { + AVBitStreamFilterContext *next = bsfc->next; + av_bitstream_filter_close(bsfc); + bsfc = next; + } + output_streams[i].bitstream_filters = NULL; + } for (i = 0; i < nb_input_files; i++) { avformat_close_input(&input_files[i].ctx); } From d3a5c2698676c68e529f79d8bf9954793b97fc4e Mon Sep 17 00:00:00 2001 From: Piotr Bandurski Date: Wed, 28 Dec 2011 00:50:25 -0500 Subject: [PATCH 07/13] rawdec: Support more QT 1bpp rawvideo files. Signed-off-by: Anton Khirnov --- libavcodec/rawdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c index 9989a36d13..dcbe23c500 100644 --- a/libavcodec/rawdec.c +++ b/libavcodec/rawdec.c @@ -59,6 +59,7 @@ static const PixelFormatTag pix_fmt_bps_mov[] = { { PIX_FMT_RGB555BE, 16 }, { PIX_FMT_RGB24, 24 }, { PIX_FMT_ARGB, 32 }, + { PIX_FMT_MONOWHITE,33 }, { PIX_FMT_NONE, 0 }, }; From 28b4af8e38204261df2f22faae6f0a70cacb3565 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Wed, 28 Dec 2011 00:50:28 -0500 Subject: [PATCH 08/13] rawdec: propagate pict_type information to the output frame Signed-off-by: Anton Khirnov --- libavcodec/rawdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c index dcbe23c500..427d109a2b 100644 --- a/libavcodec/rawdec.c +++ b/libavcodec/rawdec.c @@ -123,6 +123,7 @@ static int raw_decode(AVCodecContext *avctx, AVFrame * frame = (AVFrame *) data; AVPicture * picture = (AVPicture *) data; + frame->pict_type = avctx->coded_frame->pict_type; frame->interlaced_frame = avctx->coded_frame->interlaced_frame; frame->top_field_first = avctx->coded_frame->top_field_first; frame->reordered_opaque = avctx->reordered_opaque; From 835af79b052c25d7c7ac33dd6d1dd2f52ab13276 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Wed, 28 Dec 2011 00:50:31 -0500 Subject: [PATCH 09/13] Detect 'yuv2' as rawvideo also in avi. Signed-off-by: Anton Khirnov --- libavformat/riff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/riff.c b/libavformat/riff.c index 1d226abb40..8489bc7ae6 100644 --- a/libavformat/riff.c +++ b/libavformat/riff.c @@ -172,6 +172,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_RAWVIDEO, MKTAG('2', 'V', 'u', '1') }, { CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') }, { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') }, + { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', '2') }, { CODEC_ID_RAWVIDEO, MKTAG('P', '4', '2', '2') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '2') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '6') }, From c914038d381df57a9b22fb98f8083d6bea2e4856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 28 Dec 2011 00:50:32 -0500 Subject: [PATCH 10/13] rawdec: Set start_time to 0 for raw audio files. None of the raw audio files have timestamps, thus setting start_time to 0 should be reasonable. Signed-off-by: Anton Khirnov --- libavformat/rawdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 589cdd5db9..3e2dd05940 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -129,6 +129,7 @@ int ff_raw_audio_read_header(AVFormatContext *s, st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = s->iformat->value; st->need_parsing = AVSTREAM_PARSE_FULL; + st->start_time = 0; /* the parameters will be extracted from the compressed bitstream */ return 0; From 87d9874864105d53ba8578c8879d5de1e0f38795 Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Sat, 31 Dec 2011 18:00:22 +0530 Subject: [PATCH 11/13] bgmc: K&R cleanup Signed-off-by: Anton Khirnov --- libavcodec/bgmc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/bgmc.c b/libavcodec/bgmc.c index b8aaa8d14a..b17c3b1f72 100644 --- a/libavcodec/bgmc.c +++ b/libavcodec/bgmc.c @@ -474,7 +474,8 @@ int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status) av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); return AVERROR(ENOMEM); } else { - // initialize lut_status buffer to a value never used to compare against + // initialize lut_status buffer to a value never used to compare + // against memset(*cf_lut_status, -1, sizeof(*cf_lut_status) * LUT_BUFF); } @@ -494,7 +495,7 @@ void ff_bgmc_end(uint8_t **cf_lut, int **cf_lut_status) /** Initialize decoding and reads the first value */ void ff_bgmc_decode_init(GetBitContext *gb, - unsigned int *h, unsigned int *l, unsigned int *v) + unsigned int *h, unsigned int *l, unsigned int *v) { *h = TOP_VALUE; *l = 0; @@ -513,9 +514,9 @@ void ff_bgmc_decode_end(GetBitContext *gb) /** Read and decode a block Gilbert-Moore coded symbol */ void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, - int delta, unsigned int sx, - unsigned int *h, unsigned int *l, unsigned int *v, - uint8_t *cf_lut, int *cf_lut_status) + int delta, unsigned int sx, + unsigned int *h, unsigned int *l, unsigned int *v, + uint8_t *cf_lut, int *cf_lut_status) { unsigned int i; uint8_t *lut = bgmc_lut_getp(cf_lut, cf_lut_status, delta); @@ -567,4 +568,3 @@ void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, *l = low; *v = value; } - From f7e30cc13b4463dab22e203a8ce0021bbc98876e Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Sun, 1 Jan 2012 22:07:54 +0530 Subject: [PATCH 12/13] bfi: K&R cosmetics Signed-off-by: Anton Khirnov --- libavcodec/bfi.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libavcodec/bfi.c b/libavcodec/bfi.c index 3c66226041..cfe7bdc738 100644 --- a/libavcodec/bfi.c +++ b/libavcodec/bfi.c @@ -36,7 +36,7 @@ typedef struct BFIContext { uint8_t *dst; } BFIContext; -static av_cold int bfi_decode_init(AVCodecContext * avctx) +static av_cold int bfi_decode_init(AVCodecContext *avctx) { BFIContext *bfi = avctx->priv_data; avctx->pix_fmt = PIX_FMT_PAL8; @@ -44,7 +44,7 @@ static av_cold int bfi_decode_init(AVCodecContext * avctx) return 0; } -static int bfi_decode_frame(AVCodecContext * avctx, void *data, +static int bfi_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data, *buf_end = avpkt->data + avpkt->size; @@ -71,11 +71,11 @@ static int bfi_decode_frame(AVCodecContext * avctx, void *data, bfi->frame.pict_type = AV_PICTURE_TYPE_I; bfi->frame.key_frame = 1; /* Setting the palette */ - if(avctx->extradata_size>768) { + if (avctx->extradata_size > 768) { av_log(NULL, AV_LOG_ERROR, "Palette is too large.\n"); return -1; } - pal = (uint32_t *) bfi->frame.data[1]; + pal = (uint32_t *)bfi->frame.data[1]; for (i = 0; i < avctx->extradata_size / 3; i++) { int shift = 16; *pal = 0; @@ -91,16 +91,17 @@ static int bfi_decode_frame(AVCodecContext * avctx, void *data, bfi->frame.key_frame = 0; } - buf += 4; //Unpacked size, not required. + buf += 4; // Unpacked size, not required. while (dst != frame_end) { - static const uint8_t lentab[4]={0,2,0,1}; - unsigned int byte = *buf++, av_uninit(offset); - unsigned int code = byte >> 6; + static const uint8_t lentab[4] = { 0, 2, 0, 1 }; + unsigned int byte = *buf++, av_uninit(offset); + unsigned int code = byte >> 6; unsigned int length = byte & ~0xC0; if (buf >= buf_end) { - av_log(avctx, AV_LOG_ERROR, "Input resolution larger than actual frame.\n"); + av_log(avctx, AV_LOG_ERROR, + "Input resolution larger than actual frame.\n"); return -1; } @@ -120,7 +121,7 @@ static int bfi_decode_frame(AVCodecContext * avctx, void *data, } /* Do boundary check */ - if (dst + (length< frame_end) + if (dst + (length << lentab[code]) > frame_end) break; switch (code) { @@ -167,7 +168,7 @@ static int bfi_decode_frame(AVCodecContext * avctx, void *data, dst += bfi->frame.linesize[0]; } *data_size = sizeof(AVFrame); - *(AVFrame *) data = bfi->frame; + *(AVFrame *)data = bfi->frame; return buf_size; } From f15f02c204e5fe355e084923c34dda1c6c3a66ec Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 1 Jan 2012 21:51:26 +0100 Subject: [PATCH 13/13] avconv: make -frames work for all types of streams, not just video. --- avconv.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/avconv.c b/avconv.c index 3fa164ff43..159c7b5406 100644 --- a/avconv.c +++ b/avconv.c @@ -855,8 +855,10 @@ get_sync_ipts(const OutputStream *ost) return (double)(ist->pts - of->start_time) / AV_TIME_BASE; } -static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc) +static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) { + AVBitStreamFilterContext *bsfc = ost->bitstream_filters; + AVCodecContext *avctx = ost->st->codec; int ret; while (bsfc) { @@ -886,6 +888,7 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx print_error("av_interleaved_write_frame()", ret); exit_program(1); } + ost->frame_number++; } static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_t size) @@ -1100,7 +1103,7 @@ need_realloc: if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) pkt.pts = av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); pkt.flags |= AV_PKT_FLAG_KEY; - write_frame(s, &pkt, enc, ost->bitstream_filters); + write_frame(s, &pkt, ost); ost->sync_opts += enc->frame_size; } @@ -1135,7 +1138,7 @@ need_realloc: if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) pkt.pts = av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); pkt.flags |= AV_PKT_FLAG_KEY; - write_frame(s, &pkt, enc, ost->bitstream_filters); + write_frame(s, &pkt, ost); } } @@ -1237,7 +1240,7 @@ static void do_subtitle_out(AVFormatContext *s, else pkt.pts += 90 * sub->end_display_time; } - write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); + write_frame(s, &pkt, ost); } } @@ -1378,7 +1381,7 @@ static void do_video_out(AVFormatContext *s, pkt.pts = av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base); pkt.flags |= AV_PKT_FLAG_KEY; - write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); + write_frame(s, &pkt, ost); } else { AVFrame big_picture; @@ -1426,7 +1429,7 @@ static void do_video_out(AVFormatContext *s, if (enc->coded_frame->key_frame) pkt.flags |= AV_PKT_FLAG_KEY; - write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); + write_frame(s, &pkt, ost); *frame_size = ret; video_size += ret; // fprintf(stderr,"\nFrame: %3d size: %5d type: %d", @@ -1438,7 +1441,6 @@ static void do_video_out(AVFormatContext *s, } } ost->sync_opts++; - ost->frame_number++; } } @@ -1687,7 +1689,7 @@ static void flush_encoders(OutputStream *ost_table, int nb_ostreams) pkt.size = ret; if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) pkt.pts = av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); - write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters); + write_frame(os, &pkt, ost); } } } @@ -1763,9 +1765,8 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p opkt.size = pkt->size; } - write_frame(of->ctx, &opkt, ost->st->codec, ost->bitstream_filters); + write_frame(of->ctx, &opkt, ost); ost->st->codec->frame_number++; - ost->frame_number++; av_free_packet(&opkt); }