From b1bf8c7887395b08a68072c80f11b0c53d8e785a Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 24 May 2011 15:14:36 -0400 Subject: [PATCH 01/27] ac3enc: Move AC-3 AVOptions array to a separate file to make it easier to use only selected options for the different AC-3 encoder types. --- libavcodec/ac3enc.c | 61 ++++--------------------- libavcodec/ac3enc_opts_template.c | 75 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 libavcodec/ac3enc_opts_template.c diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index ec3ffb30e4..78e97b522f 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -247,63 +247,20 @@ static const float extmixlev_options[EXTMIXLEV_NUM_OPTIONS] = { #define OFFSET(param) offsetof(AC3EncodeContext, options.param) #define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) -static const AVOption options[] = { -/* Metadata Options */ -{"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM}, -/* downmix levels */ -{"center_mixlev", "Center Mix Level", OFFSET(center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_4POINT5DB }, 0.0, 1.0, AC3ENC_PARAM}, -{"surround_mixlev", "Surround Mix Level", OFFSET(surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_6DB }, 0.0, 1.0, AC3ENC_PARAM}, -/* audio production information */ -{"mixing_level", "Mixing Level", OFFSET(mixing_level), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 111, AC3ENC_PARAM}, -{"room_type", "Room Type", OFFSET(room_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "room_type"}, - {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, - {"large", "Large Room", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, - {"small", "Small Room", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, -/* other metadata options */ -{"copyright", "Copyright Bit", OFFSET(copyright), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM}, -{"dialnorm", "Dialogue Level (dB)", OFFSET(dialogue_level), FF_OPT_TYPE_INT, {.dbl = -31 }, -31, -1, AC3ENC_PARAM}, -{"dsur_mode", "Dolby Surround Mode", OFFSET(dolby_surround_mode), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 2, AC3ENC_PARAM, "dsur_mode"}, - {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, - {"on", "Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, - {"off", "Not Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, -{"original", "Original Bit Stream", OFFSET(original), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM}, -/* extended bitstream information */ -{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dmix_mode"}, - {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, - {"ltrt", "Lt/Rt Downmix Preferred", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, - {"loro", "Lo/Ro Downmix Preferred", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, -{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, -{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, -{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, -{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, -{"dsurex_mode", "Dolby Surround EX Mode", OFFSET(dolby_surround_ex_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dsurex_mode"}, - {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, - {"on", "Dolby Surround EX Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, - {"off", "Not Dolby Surround EX Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, -{"dheadphone_mode", "Dolby Headphone Mode", OFFSET(dolby_headphone_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dheadphone_mode"}, - {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, - {"on", "Dolby Headphone Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, - {"off", "Not Dolby Headphone Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, -{"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 1, AC3ENC_PARAM, "ad_conv_type"}, - {"standard", "Standard (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"}, - {"hdcd", "HDCD", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"}, -/* Other Encoding Options */ -{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM}, -#if CONFIG_AC3ENC_FLOAT -{"channel_coupling", "Channel Coupling", OFFSET(channel_coupling), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM, "channel_coupling"}, - {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "channel_coupling"}, -{"cpl_start_band", "Coupling Start Band", OFFSET(cpl_start), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 15, AC3ENC_PARAM, "cpl_start_band"}, - {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"}, -#endif -{NULL} -}; + +#define AC3ENC_TYPE_AC3_FIXED 0 +#define AC3ENC_TYPE_AC3 1 #if CONFIG_AC3ENC_FLOAT +#define AC3ENC_TYPE AC3ENC_TYPE_AC3 +#include "ac3enc_opts_template.c" static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name, - options, LIBAVUTIL_VERSION_INT }; + ac3_options, LIBAVUTIL_VERSION_INT }; #else +#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED +#include "ac3enc_opts_template.c" static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name, - options, LIBAVUTIL_VERSION_INT }; + ac3fixed_options, LIBAVUTIL_VERSION_INT }; #endif diff --git a/libavcodec/ac3enc_opts_template.c b/libavcodec/ac3enc_opts_template.c new file mode 100644 index 0000000000..e9c15f2758 --- /dev/null +++ b/libavcodec/ac3enc_opts_template.c @@ -0,0 +1,75 @@ +/* + * AC-3 encoder options + * Copyright (c) 2010 Justin Ruggles + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED +static const AVOption ac3fixed_options[] = { +#elif AC3ENC_TYPE == AC3ENC_TYPE_AC3 +static const AVOption ac3_options[] = { +#endif +/* Metadata Options */ +{"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM}, +/* downmix levels */ +{"center_mixlev", "Center Mix Level", OFFSET(center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_4POINT5DB }, 0.0, 1.0, AC3ENC_PARAM}, +{"surround_mixlev", "Surround Mix Level", OFFSET(surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_6DB }, 0.0, 1.0, AC3ENC_PARAM}, +/* audio production information */ +{"mixing_level", "Mixing Level", OFFSET(mixing_level), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 111, AC3ENC_PARAM}, +{"room_type", "Room Type", OFFSET(room_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "room_type"}, + {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, + {"large", "Large Room", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, + {"small", "Small Room", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, +/* other metadata options */ +{"copyright", "Copyright Bit", OFFSET(copyright), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM}, +{"dialnorm", "Dialogue Level (dB)", OFFSET(dialogue_level), FF_OPT_TYPE_INT, {.dbl = -31 }, -31, -1, AC3ENC_PARAM}, +{"dsur_mode", "Dolby Surround Mode", OFFSET(dolby_surround_mode), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 2, AC3ENC_PARAM, "dsur_mode"}, + {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, + {"on", "Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, + {"off", "Not Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, +{"original", "Original Bit Stream", OFFSET(original), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM}, +/* extended bitstream information */ +{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dmix_mode"}, + {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, + {"ltrt", "Lt/Rt Downmix Preferred", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, + {"loro", "Lo/Ro Downmix Preferred", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, +{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, +{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, +{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, +{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, +{"dsurex_mode", "Dolby Surround EX Mode", OFFSET(dolby_surround_ex_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dsurex_mode"}, + {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, + {"on", "Dolby Surround EX Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, + {"off", "Not Dolby Surround EX Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, +{"dheadphone_mode", "Dolby Headphone Mode", OFFSET(dolby_headphone_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dheadphone_mode"}, + {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, + {"on", "Dolby Headphone Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, + {"off", "Not Dolby Headphone Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, +{"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 1, AC3ENC_PARAM, "ad_conv_type"}, + {"standard", "Standard (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"}, + {"hdcd", "HDCD", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"}, +/* Other Encoding Options */ +{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM}, +#if AC3ENC_TYPE != AC3ENC_TYPE_AC3_FIXED +{"channel_coupling", "Channel Coupling", OFFSET(channel_coupling), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM, "channel_coupling"}, + {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "channel_coupling"}, +{"cpl_start_band", "Coupling Start Band", OFFSET(cpl_start), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 15, AC3ENC_PARAM, "cpl_start_band"}, + {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"}, +#endif +{NULL} +}; From aa47c35dff263f19f64f10a93ea9e4da4e395ede Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 24 May 2011 15:20:56 -0400 Subject: [PATCH 02/27] ac3enc: add support for E-AC-3 encoding. This adds basic stream format support and allows for arbitrary bit rates rather than just those supported in AC-3. --- Changelog | 2 + configure | 1 + doc/general.texi | 2 +- libavcodec/Makefile | 1 + libavcodec/ac3enc.c | 300 +++++++++++++++++++++++++++--- libavcodec/ac3enc_float.c | 18 ++ libavcodec/ac3enc_opts_template.c | 6 + libavcodec/allcodecs.c | 2 +- libavcodec/version.h | 2 +- 9 files changed, 309 insertions(+), 25 deletions(-) diff --git a/Changelog b/Changelog index b05755503c..da948c6d73 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,8 @@ releases are sorted from youngest to oldest. version : +- E-AC-3 audio encoder + version 0.7_beta2: diff --git a/configure b/configure index 46593882df..b535920cb2 100755 --- a/configure +++ b/configure @@ -1261,6 +1261,7 @@ dca_decoder_select="mdct" dnxhd_encoder_select="aandct" dxa_decoder_select="zlib" eac3_decoder_select="ac3_decoder" +eac3_encoder_select="mdct ac3dsp" eamad_decoder_select="aandct" eatgq_decoder_select="aandct" eatqi_decoder_select="aandct" diff --git a/doc/general.texi b/doc/general.texi index 23a789572d..775bf5d03f 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -614,7 +614,7 @@ following image formats are supported: @tab Used in Origin's Wing Commander IV AVI files. @item DSP Group TrueSpeech @tab @tab X @item DV audio @tab @tab X -@item Enhanced AC-3 @tab @tab X +@item Enhanced AC-3 @tab X @tab X @item FLAC (Free Lossless Audio Codec) @tab X @tab IX @item GSM @tab E @tab X @tab encoding supported through external library libgsm diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 81981d76b6..ca5839f2af 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -124,6 +124,7 @@ OBJS-$(CONFIG_DVVIDEO_DECODER) += dv.o dvdata.o OBJS-$(CONFIG_DVVIDEO_ENCODER) += dv.o dvdata.o OBJS-$(CONFIG_DXA_DECODER) += dxa.o OBJS-$(CONFIG_EAC3_DECODER) += eac3dec.o eac3dec_data.o +OBJS-$(CONFIG_EAC3_ENCODER) += ac3enc_float.o ac3tab.o ac3.o kbdwin.o OBJS-$(CONFIG_EACMV_DECODER) += eacmv.o OBJS-$(CONFIG_EAMAD_DECODER) += eamad.o eaidct.o mpeg12.o \ mpeg12data.o mpegvideo.o \ diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 78e97b522f..07ceda0446 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -147,6 +147,7 @@ typedef struct AC3EncodeContext { AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info + int eac3; ///< indicates if this is E-AC-3 vs. AC-3 int bitstream_id; ///< bitstream id (bsid) int bitstream_mode; ///< bitstream mode (bsmod) @@ -157,8 +158,8 @@ typedef struct AC3EncodeContext { int frame_size; ///< current frame size in bytes int frame_size_code; ///< frame size code (frmsizecod) uint16_t crc_inv[2]; - int bits_written; ///< bit count (used to avg. bitrate) - int samples_written; ///< sample count (used to avg. bitrate) + int64_t bits_written; ///< bit count (used to avg. bitrate) + int64_t samples_written; ///< sample count (used to avg. bitrate) int fbw_channels; ///< number of full-bandwidth channels (nfchans) int channels; ///< total number of channels (nchans) @@ -247,15 +248,20 @@ static const float extmixlev_options[EXTMIXLEV_NUM_OPTIONS] = { #define OFFSET(param) offsetof(AC3EncodeContext, options.param) #define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) - #define AC3ENC_TYPE_AC3_FIXED 0 #define AC3ENC_TYPE_AC3 1 +#define AC3ENC_TYPE_EAC3 2 #if CONFIG_AC3ENC_FLOAT #define AC3ENC_TYPE AC3ENC_TYPE_AC3 #include "ac3enc_opts_template.c" static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name, ac3_options, LIBAVUTIL_VERSION_INT }; +#undef AC3ENC_TYPE +#define AC3ENC_TYPE AC3ENC_TYPE_EAC3 +#include "ac3enc_opts_template.c" +static AVClass eac3enc_class = { "E-AC-3 Encoder", av_default_item_name, + eac3_options, LIBAVUTIL_VERSION_INT }; #else #define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED #include "ac3enc_opts_template.c" @@ -387,7 +393,7 @@ static const int8_t ac3_coupling_start_tab[6][3][19] = { /** * Adjust the frame size to make the average bit rate match the target bit rate. - * This is only needed for 11025, 22050, and 44100 sample rates. + * This is only needed for 11025, 22050, and 44100 sample rates or any E-AC-3. */ static void adjust_frame_size(AC3EncodeContext *s) { @@ -734,6 +740,35 @@ static void apply_channel_coupling(AC3EncodeContext *s) } } } + + if (s->eac3) { + /* set first cpl coords */ + int first_cpl_coords[AC3_MAX_CHANNELS]; + for (ch = 1; ch <= s->fbw_channels; ch++) + first_cpl_coords[ch] = 1; + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { + AC3Block *block = &s->blocks[blk]; + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (block->channel_in_cpl[ch]) { + if (first_cpl_coords[ch]) { + block->new_cpl_coords = 2; + first_cpl_coords[ch] = 0; + } + } else { + first_cpl_coords[ch] = 1; + } + } + } + + /* set first cpl leak */ + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { + AC3Block *block = &s->blocks[blk]; + if (block->cpl_in_use) { + block->new_cpl_leak = 2; + break; + } + } + } #endif /* CONFIG_AC3ENC_FLOAT */ } @@ -1151,23 +1186,50 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) * no delta bit allocation * no skipped data * no auxilliary data + * no E-AC-3 metadata */ /* header */ - frame_bits = 65; - frame_bits += frame_bits_inc[s->channel_mode]; + frame_bits = 16; /* sync info */ + if (s->eac3) { + /* bitstream info header */ + frame_bits += 35; + frame_bits += 1 + 1 + 1; + /* audio frame header */ + frame_bits += 2; + frame_bits += 10; + /* exponent strategy */ + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) + frame_bits += 2 * s->fbw_channels + s->lfe_on; + /* converter exponent strategy */ + frame_bits += s->fbw_channels * 5; + /* snr offsets */ + frame_bits += 10; + /* block start info */ + frame_bits++; + } else { + frame_bits += 49; + frame_bits += frame_bits_inc[s->channel_mode]; + } /* audio blocks */ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { + if (!s->eac3) { /* block switch flags */ frame_bits += s->fbw_channels; /* dither flags */ frame_bits += s->fbw_channels; + } /* dynamic range */ frame_bits++; + /* spectral extension */ + if (s->eac3) + frame_bits++; + + if (!s->eac3) { /* exponent strategy */ frame_bits += 2 * s->fbw_channels; if (s->lfe_on) @@ -1177,12 +1239,19 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) frame_bits++; if (!blk) frame_bits += 2 + 2 + 2 + 2 + 3; + } + /* converter snr offset */ + if (s->eac3) + frame_bits++; + + if (!s->eac3) { /* delta bit allocation */ frame_bits++; /* skipped data */ frame_bits++; + } } /* auxiliary data */ @@ -1207,7 +1276,7 @@ static void bit_alloc_init(AC3EncodeContext *s) s->slow_decay_code = 2; s->fast_decay_code = 1; s->slow_gain_code = 1; - s->db_per_bit_code = 3; + s->db_per_bit_code = s->eac3 ? 2 : 3; s->floor_code = 7; for (ch = 0; ch <= s->channels; ch++) s->fast_gain_code[ch] = 4; @@ -1242,6 +1311,21 @@ static void count_frame_bits(AC3EncodeContext *s) int frame_bits = 0; /* header */ + if (s->eac3) { + /* coupling */ + if (s->channel_mode > AC3_CHMODE_MONO) { + frame_bits++; + for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) { + AC3Block *block = &s->blocks[blk]; + frame_bits++; + if (block->new_cpl_strategy) + frame_bits++; + } + } + /* coupling exponent strategy */ + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) + frame_bits += 2 * s->blocks[blk].cpl_in_use; + } else { if (opt->audio_production_info) frame_bits += 7; if (s->bitstream_id == 6) { @@ -1250,20 +1334,29 @@ static void count_frame_bits(AC3EncodeContext *s) if (opt->extended_bsi_2) frame_bits += 14; } + } /* audio blocks */ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; /* coupling strategy */ + if (!s->eac3) frame_bits++; if (block->new_cpl_strategy) { + if (!s->eac3) frame_bits++; if (block->cpl_in_use) { + if (s->eac3) + frame_bits++; + if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO) frame_bits += s->fbw_channels; if (s->channel_mode == AC3_CHMODE_STEREO) frame_bits++; frame_bits += 4 + 4; + if (s->eac3) + frame_bits++; + else frame_bits += s->num_cpl_subbands - 1; } } @@ -1272,6 +1365,7 @@ static void count_frame_bits(AC3EncodeContext *s) if (block->cpl_in_use) { for (ch = 1; ch <= s->fbw_channels; ch++) { if (block->channel_in_cpl[ch]) { + if (!s->eac3 || block->new_cpl_coords != 2) frame_bits++; if (block->new_cpl_coords) { frame_bits += 2; @@ -1283,6 +1377,7 @@ static void count_frame_bits(AC3EncodeContext *s) /* stereo rematrixing */ if (s->channel_mode == AC3_CHMODE_STEREO) { + if (!s->eac3 || blk > 0) frame_bits++; if (s->blocks[blk].new_rematrixing_strategy) frame_bits += block->num_rematrixing_bands; @@ -1298,16 +1393,19 @@ static void count_frame_bits(AC3EncodeContext *s) } /* coupling exponent strategy */ - if (block->cpl_in_use) + if (!s->eac3 && block->cpl_in_use) frame_bits += 2; /* snr offsets and fast gain codes */ + if (!s->eac3) { frame_bits++; if (block->new_snr_offsets) frame_bits += 6 + (s->channels + block->cpl_in_use) * (4 + 3); + } /* coupling leak info */ if (block->cpl_in_use) { + if (!s->eac3 || block->new_cpl_leak != 2) frame_bits++; if (block->new_cpl_leak) frame_bits += 3 + 3; @@ -1736,7 +1834,7 @@ static void quantize_mantissas(AC3EncodeContext *s) /** * Write the AC-3 frame header to the output bitstream. */ -static void output_frame_header(AC3EncodeContext *s) +static void ac3_output_frame_header(AC3EncodeContext *s) { AC3EncOptions *opt = &s->options; @@ -1789,6 +1887,79 @@ static void output_frame_header(AC3EncodeContext *s) } +/** + * Write the E-AC-3 frame header to the output bitstream. + */ +static void eac3_output_frame_header(AC3EncodeContext *s) +{ + int blk, ch; + AC3EncOptions *opt = &s->options; + + put_bits(&s->pb, 16, 0x0b77); /* sync word */ + + /* BSI header */ + put_bits(&s->pb, 2, 0); /* stream type = independent */ + put_bits(&s->pb, 3, 0); /* substream id = 0 */ + put_bits(&s->pb, 11, (s->frame_size / 2) - 1); /* frame size */ + if (s->bit_alloc.sr_shift) { + put_bits(&s->pb, 2, 0x3); /* fscod2 */ + put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */ + } else { + put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */ + put_bits(&s->pb, 2, 0x3); /* number of blocks = 6 */ + } + put_bits(&s->pb, 3, s->channel_mode); /* audio coding mode */ + put_bits(&s->pb, 1, s->lfe_on); /* LFE channel indicator */ + put_bits(&s->pb, 5, s->bitstream_id); /* bitstream id (EAC3=16) */ + put_bits(&s->pb, 5, -opt->dialogue_level); /* dialogue normalization level */ + put_bits(&s->pb, 1, 0); /* no compression gain */ + put_bits(&s->pb, 1, 0); /* no mixing metadata */ + /* TODO: mixing metadata */ + put_bits(&s->pb, 1, 0); /* no info metadata */ + /* TODO: info metadata */ + put_bits(&s->pb, 1, 0); /* no additional bit stream info */ + + /* frame header */ + put_bits(&s->pb, 1, 1); /* exponent strategy syntax = each block */ + put_bits(&s->pb, 1, 0); /* aht enabled = no */ + put_bits(&s->pb, 2, 0); /* snr offset strategy = 1 */ + put_bits(&s->pb, 1, 0); /* transient pre-noise processing enabled = no */ + put_bits(&s->pb, 1, 0); /* block switch syntax enabled = no */ + put_bits(&s->pb, 1, 0); /* dither flag syntax enabled = no */ + put_bits(&s->pb, 1, 0); /* bit allocation model syntax enabled = no */ + put_bits(&s->pb, 1, 0); /* fast gain codes enabled = no */ + put_bits(&s->pb, 1, 0); /* dba syntax enabled = no */ + put_bits(&s->pb, 1, 0); /* skip field syntax enabled = no */ + put_bits(&s->pb, 1, 0); /* spx enabled = no */ + /* coupling strategy use flags */ + if (s->channel_mode > AC3_CHMODE_MONO) { + put_bits(&s->pb, 1, s->blocks[0].cpl_in_use); + for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) { + AC3Block *block = &s->blocks[blk]; + put_bits(&s->pb, 1, block->new_cpl_strategy); + if (block->new_cpl_strategy) + put_bits(&s->pb, 1, block->cpl_in_use); + } + } + /* exponent strategy */ + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) + for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) + put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); + if (s->lfe_on) { + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) + put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); + } + /* E-AC-3 to AC-3 converter exponent strategy (unfortunately not optional...) */ + for (ch = 1; ch <= s->fbw_channels; ch++) + put_bits(&s->pb, 5, 0); + /* snr offsets */ + put_bits(&s->pb, 6, s->coarse_snr_offset); + put_bits(&s->pb, 4, s->fine_snr_offset[1]); + /* block start info */ + put_bits(&s->pb, 1, 0); +} + + /** * Write one audio block to the output bitstream. */ @@ -1799,32 +1970,51 @@ static void output_audio_block(AC3EncodeContext *s, int blk) AC3Block *block = &s->blocks[blk]; /* block switching */ + if (!s->eac3) { for (ch = 0; ch < s->fbw_channels; ch++) put_bits(&s->pb, 1, 0); + } /* dither flags */ + if (!s->eac3) { for (ch = 0; ch < s->fbw_channels; ch++) put_bits(&s->pb, 1, 1); + } /* dynamic range codes */ put_bits(&s->pb, 1, 0); + /* spectral extension */ + if (s->eac3) + put_bits(&s->pb, 1, 0); + /* channel coupling */ + if (!s->eac3) put_bits(&s->pb, 1, block->new_cpl_strategy); if (block->new_cpl_strategy) { + if (!s->eac3) put_bits(&s->pb, 1, block->cpl_in_use); if (block->cpl_in_use) { int start_sub, end_sub; + if (s->eac3) + put_bits(&s->pb, 1, 0); /* enhanced coupling */ + if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO) { for (ch = 1; ch <= s->fbw_channels; ch++) put_bits(&s->pb, 1, block->channel_in_cpl[ch]); + } if (s->channel_mode == AC3_CHMODE_STEREO) put_bits(&s->pb, 1, 0); /* phase flags in use */ start_sub = (s->start_freq[CPL_CH] - 37) / 12; end_sub = (s->cpl_end_freq - 37) / 12; put_bits(&s->pb, 4, start_sub); put_bits(&s->pb, 4, end_sub - 3); + /* coupling band structure */ + if (s->eac3) { + put_bits(&s->pb, 1, 0); /* use default */ + } else { for (bnd = start_sub+1; bnd < end_sub; bnd++) put_bits(&s->pb, 1, ff_eac3_default_cpl_band_struct[bnd]); + } } } @@ -1832,6 +2022,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk) if (block->cpl_in_use) { for (ch = 1; ch <= s->fbw_channels; ch++) { if (block->channel_in_cpl[ch]) { + if (!s->eac3 || block->new_cpl_coords != 2) put_bits(&s->pb, 1, block->new_cpl_coords); if (block->new_cpl_coords) { put_bits(&s->pb, 2, block->cpl_master_exp[ch]); @@ -1846,6 +2037,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* stereo rematrixing */ if (s->channel_mode == AC3_CHMODE_STEREO) { + if (!s->eac3 || blk > 0) put_bits(&s->pb, 1, block->new_rematrixing_strategy); if (block->new_rematrixing_strategy) { /* rematrixing flags */ @@ -1855,10 +2047,12 @@ static void output_audio_block(AC3EncodeContext *s, int blk) } /* exponent strategy */ + if (!s->eac3) { for (ch = !block->cpl_in_use; ch <= s->fbw_channels; ch++) put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); if (s->lfe_on) put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); + } /* bandwidth */ for (ch = 1; ch <= s->fbw_channels; ch++) { @@ -1888,6 +2082,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk) } /* bit allocation info */ + if (!s->eac3) { baie = (blk == 0); put_bits(&s->pb, 1, baie); if (baie) { @@ -1897,8 +2092,10 @@ static void output_audio_block(AC3EncodeContext *s, int blk) put_bits(&s->pb, 2, s->db_per_bit_code); put_bits(&s->pb, 3, s->floor_code); } + } /* snr offset */ + if (!s->eac3) { put_bits(&s->pb, 1, block->new_snr_offsets); if (block->new_snr_offsets) { put_bits(&s->pb, 6, s->coarse_snr_offset); @@ -1907,9 +2104,13 @@ static void output_audio_block(AC3EncodeContext *s, int blk) put_bits(&s->pb, 3, s->fast_gain_code[ch]); } } + } else { + put_bits(&s->pb, 1, 0); /* no converter snr offset */ + } /* coupling leak */ if (block->cpl_in_use) { + if (!s->eac3 || block->new_cpl_leak != 2) put_bits(&s->pb, 1, block->new_cpl_leak); if (block->new_cpl_leak) { put_bits(&s->pb, 3, s->bit_alloc.cpl_fast_leak); @@ -1917,8 +2118,10 @@ static void output_audio_block(AC3EncodeContext *s, int blk) } } + if (!s->eac3) { put_bits(&s->pb, 1, 0); /* no delta bit allocation */ put_bits(&s->pb, 1, 0); /* no data to skip */ + } /* mantissas */ got_cpl = !block->cpl_in_use; @@ -2007,6 +2210,10 @@ static void output_frame_end(AC3EncodeContext *s) if (pad_bytes > 0) memset(put_bits_ptr(&s->pb), 0, pad_bytes); + if (s->eac3) { + /* compute crc2 */ + crc2_partial = av_crc(crc_ctx, 0, frame + 2, s->frame_size - 5); + } else { /* compute crc1 */ /* this is not so easy because it is at the beginning of the data... */ crc1 = av_bswap16(av_crc(crc_ctx, 0, frame + 4, frame_size_58 - 4)); @@ -2017,6 +2224,7 @@ static void output_frame_end(AC3EncodeContext *s) /* compute crc2 */ crc2_partial = av_crc(crc_ctx, 0, frame + frame_size_58, s->frame_size - frame_size_58 - 3); + } crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1); /* ensure crc2 does not match sync word by flipping crcrsv bit if needed */ if (crc2 == 0x770B) { @@ -2037,7 +2245,10 @@ static void output_frame(AC3EncodeContext *s, unsigned char *frame) init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE); - output_frame_header(s); + if (s->eac3) + eac3_output_frame_header(s); + else + ac3_output_frame_header(s); for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) output_audio_block(s, blk); @@ -2058,6 +2269,7 @@ static void dprint_options(AVCodecContext *avctx) case 8: av_strlcpy(strbuf, "AC-3 (standard)", 32); break; case 9: av_strlcpy(strbuf, "AC-3 (dnet half-rate)", 32); break; case 10: av_strlcpy(strbuf, "AC-3 (dnet quater-rate", 32); break; + case 16: av_strlcpy(strbuf, "E-AC-3 (enhanced)", 32); break; default: snprintf(strbuf, 32, "ERROR"); } av_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id); @@ -2318,13 +2530,13 @@ static int ac3_encode_frame(AVCodecContext *avctx, unsigned char *frame, const SampleType *samples = data; int ret; - if (s->options.allow_per_frame_metadata) { + if (!s->eac3 && s->options.allow_per_frame_metadata) { ret = validate_metadata(avctx); if (ret) return ret; } - if (s->bit_alloc.sr_code == 1) + if (s->bit_alloc.sr_code == 1 || s->eac3) adjust_frame_size(s); deinterleave_input_samples(s, samples); @@ -2450,7 +2662,7 @@ static av_cold int set_channel_info(AC3EncodeContext *s, int channels, static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) { - int i, ret; + int i, ret, max_sr; /* validate channel layout */ if (!avctx->channel_layout) { @@ -2465,20 +2677,59 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) } /* validate sample rate */ - for (i = 0; i < 9; i++) { - if ((ff_ac3_sample_rate_tab[i / 3] >> (i % 3)) == avctx->sample_rate) + /* note: max_sr could be changed from 2 to 5 for E-AC-3 once we find a + decoder that supports half sample rate so we can validate that + the generated files are correct. */ + max_sr = s->eac3 ? 2 : 8; + for (i = 0; i <= max_sr; i++) { + if ((ff_ac3_sample_rate_tab[i % 3] >> (i / 3)) == avctx->sample_rate) break; } - if (i == 9) { + if (i > max_sr) { av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); return AVERROR(EINVAL); } s->sample_rate = avctx->sample_rate; - s->bit_alloc.sr_shift = i % 3; - s->bit_alloc.sr_code = i / 3; - s->bitstream_id = 8 + s->bit_alloc.sr_shift; + s->bit_alloc.sr_shift = i / 3; + s->bit_alloc.sr_code = i % 3; + s->bitstream_id = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift; /* validate bit rate */ + if (s->eac3) { + int max_br, min_br, wpf, min_br_dist, min_br_code; + + /* calculate min/max bitrate */ + max_br = 2048 * s->sample_rate / AC3_FRAME_SIZE * 16; + min_br = ((s->sample_rate + (AC3_FRAME_SIZE-1)) / AC3_FRAME_SIZE) * 16; + if (avctx->bit_rate < min_br || avctx->bit_rate > max_br) { + av_log(avctx, AV_LOG_ERROR, "invalid bit rate. must be %d to %d " + "for this sample rate\n", min_br, max_br); + return AVERROR(EINVAL); + } + + /* calculate words-per-frame for the selected bitrate */ + wpf = (avctx->bit_rate / 16) * AC3_FRAME_SIZE / s->sample_rate; + av_assert1(wpf > 0 && wpf <= 2048); + + /* find the closest AC-3 bitrate code to the selected bitrate. + this is needed for lookup tables for bandwidth and coupling + parameter selection */ + min_br_code = -1; + min_br_dist = INT_MAX; + for (i = 0; i < 19; i++) { + int br_dist = abs(ff_ac3_bitrate_tab[i] * 1000 - avctx->bit_rate); + if (br_dist < min_br_dist) { + min_br_dist = br_dist; + min_br_code = i; + } + } + + /* make sure the minimum frame size is below the average frame size */ + s->frame_size_code = min_br_code << 1; + while (wpf > 1 && wpf * s->sample_rate / AC3_FRAME_SIZE * 16 > avctx->bit_rate) + wpf--; + s->frame_size_min = 2 * wpf; + } else { for (i = 0; i < 19; i++) { if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate) break; @@ -2487,8 +2738,11 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n"); return AVERROR(EINVAL); } - s->bit_rate = avctx->bit_rate; s->frame_size_code = i << 1; + s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code]; + } + s->bit_rate = avctx->bit_rate; + s->frame_size = s->frame_size_min; /* validate cutoff */ if (avctx->cutoff < 0) { @@ -2511,9 +2765,11 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) return AVERROR(EINVAL); } + if (!s->eac3) { ret = validate_metadata(avctx); if (ret) return ret; + } s->rematrixing_enabled = s->options.stereo_rematrixing && (s->channel_mode == AC3_CHMODE_STEREO); @@ -2713,6 +2969,8 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx) AC3EncodeContext *s = avctx->priv_data; int ret, frame_size_58; + s->eac3 = avctx->codec_id == CODEC_ID_EAC3; + avctx->frame_size = AC3_FRAME_SIZE; ff_ac3_common_init(); @@ -2725,10 +2983,8 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx) if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE) s->bitstream_mode = 0x7; - s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code]; s->bits_written = 0; s->samples_written = 0; - s->frame_size = s->frame_size_min; /* calculate crc_inv for both possible frame sizes */ frame_size_58 = (( s->frame_size >> 2) + ( s->frame_size >> 4)) << 1; diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c index 4f61440b52..012c31de5d 100644 --- a/libavcodec/ac3enc_float.c +++ b/libavcodec/ac3enc_float.c @@ -100,6 +100,7 @@ static void scale_coefficients(AC3EncodeContext *s) } +#if CONFIG_AC3_ENCODER AVCodec ff_ac3_encoder = { "ac3", AVMEDIA_TYPE_AUDIO, @@ -114,3 +115,20 @@ AVCodec ff_ac3_encoder = { .priv_class = &ac3enc_class, .channel_layouts = ac3_channel_layouts, }; +#endif + +#if CONFIG_EAC3_ENCODER +AVCodec ff_eac3_encoder = { + .name = "eac3", + .type = AVMEDIA_TYPE_AUDIO, + .id = CODEC_ID_EAC3, + .priv_data_size = sizeof(AC3EncodeContext), + .init = ac3_encode_init, + .encode = ac3_encode_frame, + .close = ac3_encode_close, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"), + .priv_class = &eac3enc_class, + .channel_layouts = ac3_channel_layouts, +}; +#endif diff --git a/libavcodec/ac3enc_opts_template.c b/libavcodec/ac3enc_opts_template.c index e9c15f2758..699c1b5982 100644 --- a/libavcodec/ac3enc_opts_template.c +++ b/libavcodec/ac3enc_opts_template.c @@ -23,7 +23,10 @@ static const AVOption ac3fixed_options[] = { #elif AC3ENC_TYPE == AC3ENC_TYPE_AC3 static const AVOption ac3_options[] = { +#else /* AC3ENC_TYPE_EAC3 */ +static const AVOption eac3_options[] = { #endif +#if AC3ENC_TYPE != AC3ENC_TYPE_EAC3 /* Metadata Options */ {"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM}, /* downmix levels */ @@ -37,7 +40,9 @@ static const AVOption ac3_options[] = { {"small", "Small Room", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, /* other metadata options */ {"copyright", "Copyright Bit", OFFSET(copyright), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM}, +#endif {"dialnorm", "Dialogue Level (dB)", OFFSET(dialogue_level), FF_OPT_TYPE_INT, {.dbl = -31 }, -31, -1, AC3ENC_PARAM}, +#if AC3ENC_TYPE != AC3ENC_TYPE_EAC3 {"dsur_mode", "Dolby Surround Mode", OFFSET(dolby_surround_mode), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 2, AC3ENC_PARAM, "dsur_mode"}, {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, {"on", "Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, @@ -63,6 +68,7 @@ static const AVOption ac3_options[] = { {"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 1, AC3ENC_PARAM, "ad_conv_type"}, {"standard", "Standard (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"}, {"hdcd", "HDCD", 0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"}, +#endif /* Other Encoding Options */ {"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM}, #if AC3ENC_TYPE != AC3ENC_TYPE_AC3_FIXED diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index f063369dfd..71b6094089 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -241,7 +241,7 @@ void avcodec_register_all(void) REGISTER_DECODER (COOK, cook); REGISTER_DECODER (DCA, dca); REGISTER_DECODER (DSICINAUDIO, dsicinaudio); - REGISTER_DECODER (EAC3, eac3); + REGISTER_ENCDEC (EAC3, eac3); REGISTER_ENCDEC (FLAC, flac); REGISTER_DECODER (GSM, gsm); REGISTER_DECODER (GSM_MS, gsm_ms); diff --git a/libavcodec/version.h b/libavcodec/version.h index 0def0d1ff9..894188b093 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -21,7 +21,7 @@ #define AVCODEC_VERSION_H #define LIBAVCODEC_VERSION_MAJOR 53 -#define LIBAVCODEC_VERSION_MINOR 4 +#define LIBAVCODEC_VERSION_MINOR 5 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ From 1a950da6a2d981d53f61d42f3a078888b00db091 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 24 May 2011 19:38:30 -0400 Subject: [PATCH 03/27] cosmetics: indentation and alignment after previous commit --- libavcodec/ac3enc.c | 174 ++++++++++++++++++++++---------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 07ceda0446..5285874caa 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -1215,11 +1215,11 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) /* audio blocks */ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { if (!s->eac3) { - /* block switch flags */ - frame_bits += s->fbw_channels; + /* block switch flags */ + frame_bits += s->fbw_channels; - /* dither flags */ - frame_bits += s->fbw_channels; + /* dither flags */ + frame_bits += s->fbw_channels; } /* dynamic range */ @@ -1230,15 +1230,15 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) frame_bits++; if (!s->eac3) { - /* exponent strategy */ - frame_bits += 2 * s->fbw_channels; - if (s->lfe_on) - frame_bits++; + /* exponent strategy */ + frame_bits += 2 * s->fbw_channels; + if (s->lfe_on) + frame_bits++; - /* bit allocation params */ - frame_bits++; - if (!blk) - frame_bits += 2 + 2 + 2 + 2 + 3; + /* bit allocation params */ + frame_bits++; + if (!blk) + frame_bits += 2 + 2 + 2 + 2 + 3; } /* converter snr offset */ @@ -1246,11 +1246,11 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) frame_bits++; if (!s->eac3) { - /* delta bit allocation */ - frame_bits++; + /* delta bit allocation */ + frame_bits++; - /* skipped data */ - frame_bits++; + /* skipped data */ + frame_bits++; } } @@ -1326,14 +1326,14 @@ static void count_frame_bits(AC3EncodeContext *s) for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) frame_bits += 2 * s->blocks[blk].cpl_in_use; } else { - if (opt->audio_production_info) - frame_bits += 7; - if (s->bitstream_id == 6) { - if (opt->extended_bsi_1) - frame_bits += 14; - if (opt->extended_bsi_2) - frame_bits += 14; - } + if (opt->audio_production_info) + frame_bits += 7; + if (s->bitstream_id == 6) { + if (opt->extended_bsi_1) + frame_bits += 14; + if (opt->extended_bsi_2) + frame_bits += 14; + } } /* audio blocks */ @@ -1342,22 +1342,22 @@ static void count_frame_bits(AC3EncodeContext *s) /* coupling strategy */ if (!s->eac3) - frame_bits++; + frame_bits++; if (block->new_cpl_strategy) { if (!s->eac3) - frame_bits++; + frame_bits++; if (block->cpl_in_use) { if (s->eac3) frame_bits++; if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO) - frame_bits += s->fbw_channels; + frame_bits += s->fbw_channels; if (s->channel_mode == AC3_CHMODE_STEREO) frame_bits++; frame_bits += 4 + 4; if (s->eac3) frame_bits++; else - frame_bits += s->num_cpl_subbands - 1; + frame_bits += s->num_cpl_subbands - 1; } } @@ -1366,7 +1366,7 @@ static void count_frame_bits(AC3EncodeContext *s) for (ch = 1; ch <= s->fbw_channels; ch++) { if (block->channel_in_cpl[ch]) { if (!s->eac3 || block->new_cpl_coords != 2) - frame_bits++; + frame_bits++; if (block->new_cpl_coords) { frame_bits += 2; frame_bits += (4 + 4) * s->num_cpl_bands; @@ -1378,7 +1378,7 @@ static void count_frame_bits(AC3EncodeContext *s) /* stereo rematrixing */ if (s->channel_mode == AC3_CHMODE_STEREO) { if (!s->eac3 || blk > 0) - frame_bits++; + frame_bits++; if (s->blocks[blk].new_rematrixing_strategy) frame_bits += block->num_rematrixing_bands; } @@ -1398,15 +1398,15 @@ static void count_frame_bits(AC3EncodeContext *s) /* snr offsets and fast gain codes */ if (!s->eac3) { - frame_bits++; - if (block->new_snr_offsets) - frame_bits += 6 + (s->channels + block->cpl_in_use) * (4 + 3); + frame_bits++; + if (block->new_snr_offsets) + frame_bits += 6 + (s->channels + block->cpl_in_use) * (4 + 3); } /* coupling leak info */ if (block->cpl_in_use) { if (!s->eac3 || block->new_cpl_leak != 2) - frame_bits++; + frame_bits++; if (block->new_cpl_leak) frame_bits += 3 + 3; } @@ -1971,14 +1971,14 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* block switching */ if (!s->eac3) { - for (ch = 0; ch < s->fbw_channels; ch++) - put_bits(&s->pb, 1, 0); + for (ch = 0; ch < s->fbw_channels; ch++) + put_bits(&s->pb, 1, 0); } /* dither flags */ if (!s->eac3) { - for (ch = 0; ch < s->fbw_channels; ch++) - put_bits(&s->pb, 1, 1); + for (ch = 0; ch < s->fbw_channels; ch++) + put_bits(&s->pb, 1, 1); } /* dynamic range codes */ @@ -1990,17 +1990,17 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* channel coupling */ if (!s->eac3) - put_bits(&s->pb, 1, block->new_cpl_strategy); + put_bits(&s->pb, 1, block->new_cpl_strategy); if (block->new_cpl_strategy) { if (!s->eac3) - put_bits(&s->pb, 1, block->cpl_in_use); + put_bits(&s->pb, 1, block->cpl_in_use); if (block->cpl_in_use) { int start_sub, end_sub; if (s->eac3) put_bits(&s->pb, 1, 0); /* enhanced coupling */ if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO) { - for (ch = 1; ch <= s->fbw_channels; ch++) - put_bits(&s->pb, 1, block->channel_in_cpl[ch]); + for (ch = 1; ch <= s->fbw_channels; ch++) + put_bits(&s->pb, 1, block->channel_in_cpl[ch]); } if (s->channel_mode == AC3_CHMODE_STEREO) put_bits(&s->pb, 1, 0); /* phase flags in use */ @@ -2012,8 +2012,8 @@ static void output_audio_block(AC3EncodeContext *s, int blk) if (s->eac3) { put_bits(&s->pb, 1, 0); /* use default */ } else { - for (bnd = start_sub+1; bnd < end_sub; bnd++) - put_bits(&s->pb, 1, ff_eac3_default_cpl_band_struct[bnd]); + for (bnd = start_sub+1; bnd < end_sub; bnd++) + put_bits(&s->pb, 1, ff_eac3_default_cpl_band_struct[bnd]); } } } @@ -2023,7 +2023,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk) for (ch = 1; ch <= s->fbw_channels; ch++) { if (block->channel_in_cpl[ch]) { if (!s->eac3 || block->new_cpl_coords != 2) - put_bits(&s->pb, 1, block->new_cpl_coords); + put_bits(&s->pb, 1, block->new_cpl_coords); if (block->new_cpl_coords) { put_bits(&s->pb, 2, block->cpl_master_exp[ch]); for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { @@ -2038,7 +2038,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* stereo rematrixing */ if (s->channel_mode == AC3_CHMODE_STEREO) { if (!s->eac3 || blk > 0) - put_bits(&s->pb, 1, block->new_rematrixing_strategy); + put_bits(&s->pb, 1, block->new_rematrixing_strategy); if (block->new_rematrixing_strategy) { /* rematrixing flags */ for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++) @@ -2048,10 +2048,10 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* exponent strategy */ if (!s->eac3) { - for (ch = !block->cpl_in_use; ch <= s->fbw_channels; ch++) - put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); - if (s->lfe_on) - put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); + for (ch = !block->cpl_in_use; ch <= s->fbw_channels; ch++) + put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); + if (s->lfe_on) + put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); } /* bandwidth */ @@ -2083,27 +2083,27 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* bit allocation info */ if (!s->eac3) { - baie = (blk == 0); - put_bits(&s->pb, 1, baie); - if (baie) { - put_bits(&s->pb, 2, s->slow_decay_code); - put_bits(&s->pb, 2, s->fast_decay_code); - put_bits(&s->pb, 2, s->slow_gain_code); - put_bits(&s->pb, 2, s->db_per_bit_code); - put_bits(&s->pb, 3, s->floor_code); - } + baie = (blk == 0); + put_bits(&s->pb, 1, baie); + if (baie) { + put_bits(&s->pb, 2, s->slow_decay_code); + put_bits(&s->pb, 2, s->fast_decay_code); + put_bits(&s->pb, 2, s->slow_gain_code); + put_bits(&s->pb, 2, s->db_per_bit_code); + put_bits(&s->pb, 3, s->floor_code); + } } /* snr offset */ if (!s->eac3) { - put_bits(&s->pb, 1, block->new_snr_offsets); - if (block->new_snr_offsets) { - put_bits(&s->pb, 6, s->coarse_snr_offset); - for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { - put_bits(&s->pb, 4, s->fine_snr_offset[ch]); - put_bits(&s->pb, 3, s->fast_gain_code[ch]); + put_bits(&s->pb, 1, block->new_snr_offsets); + if (block->new_snr_offsets) { + put_bits(&s->pb, 6, s->coarse_snr_offset); + for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { + put_bits(&s->pb, 4, s->fine_snr_offset[ch]); + put_bits(&s->pb, 3, s->fast_gain_code[ch]); + } } - } } else { put_bits(&s->pb, 1, 0); /* no converter snr offset */ } @@ -2111,7 +2111,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk) /* coupling leak */ if (block->cpl_in_use) { if (!s->eac3 || block->new_cpl_leak != 2) - put_bits(&s->pb, 1, block->new_cpl_leak); + put_bits(&s->pb, 1, block->new_cpl_leak); if (block->new_cpl_leak) { put_bits(&s->pb, 3, s->bit_alloc.cpl_fast_leak); put_bits(&s->pb, 3, s->bit_alloc.cpl_slow_leak); @@ -2119,8 +2119,8 @@ static void output_audio_block(AC3EncodeContext *s, int blk) } if (!s->eac3) { - put_bits(&s->pb, 1, 0); /* no delta bit allocation */ - put_bits(&s->pb, 1, 0); /* no data to skip */ + put_bits(&s->pb, 1, 0); /* no delta bit allocation */ + put_bits(&s->pb, 1, 0); /* no data to skip */ } /* mantissas */ @@ -2265,11 +2265,11 @@ static void dprint_options(AVCodecContext *avctx) char strbuf[32]; switch (s->bitstream_id) { - case 6: av_strlcpy(strbuf, "AC-3 (alt syntax)", 32); break; - case 8: av_strlcpy(strbuf, "AC-3 (standard)", 32); break; - case 9: av_strlcpy(strbuf, "AC-3 (dnet half-rate)", 32); break; - case 10: av_strlcpy(strbuf, "AC-3 (dnet quater-rate", 32); break; - case 16: av_strlcpy(strbuf, "E-AC-3 (enhanced)", 32); break; + case 6: av_strlcpy(strbuf, "AC-3 (alt syntax)", 32); break; + case 8: av_strlcpy(strbuf, "AC-3 (standard)", 32); break; + case 9: av_strlcpy(strbuf, "AC-3 (dnet half-rate)", 32); break; + case 10: av_strlcpy(strbuf, "AC-3 (dnet quater-rate)", 32); break; + case 16: av_strlcpy(strbuf, "E-AC-3 (enhanced)", 32); break; default: snprintf(strbuf, 32, "ERROR"); } av_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id); @@ -2730,16 +2730,16 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) wpf--; s->frame_size_min = 2 * wpf; } else { - for (i = 0; i < 19; i++) { - if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate) - break; - } - if (i == 19) { - av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n"); - return AVERROR(EINVAL); - } - s->frame_size_code = i << 1; - s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code]; + for (i = 0; i < 19; i++) { + if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate) + break; + } + if (i == 19) { + av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n"); + return AVERROR(EINVAL); + } + s->frame_size_code = i << 1; + s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code]; } s->bit_rate = avctx->bit_rate; s->frame_size = s->frame_size_min; @@ -2766,9 +2766,9 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) } if (!s->eac3) { - ret = validate_metadata(avctx); - if (ret) - return ret; + ret = validate_metadata(avctx); + if (ret) + return ret; } s->rematrixing_enabled = s->options.stereo_rematrixing && From 2e0e1e712aa263d919ebb842567977195dfa4774 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 09:02:11 +0200 Subject: [PATCH 04/27] libdc1394: add a pixel_format private option. --- libavdevice/libdc1394.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index 4462262c93..f4340f570c 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -25,6 +25,7 @@ #include "libavutil/log.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" +#include "libavutil/pixdesc.h" #if HAVE_LIBDC1394_2 #include @@ -61,6 +62,7 @@ typedef struct dc1394_data { int current_frame; int fps; char *video_size; /**< String describing video size, set by a private option. */ + char *pixel_format; /**< Set by a private option. */ AVPacket packet; } dc1394_data; @@ -99,6 +101,7 @@ static const AVOption options[] = { { "channel", "", offsetof(dc1394_data, channel), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, #endif { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC }, + { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "uyvy422"}, 0, 0, DEC }, { NULL }, }; @@ -117,11 +120,17 @@ static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, AVStream* vst; struct dc1394_frame_format *fmt; struct dc1394_frame_rate *fps; - enum PixelFormat pix_fmt = ap->pix_fmt == PIX_FMT_NONE ? PIX_FMT_UYVY422 : ap->pix_fmt; /* defaults */ + enum PixelFormat pix_fmt; int width, height; int frame_rate = !ap->time_base.num ? 30000 : av_rescale(1000, ap->time_base.den, ap->time_base.num); int ret = 0; + if ((pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == PIX_FMT_NONE) { + av_log(c, AV_LOG_ERROR, "No such pixel format: %s.\n", dc1394->pixel_format); + ret = AVERROR(EINVAL); + goto out; + } + if ((ret = av_parse_video_size(&width, &height, dc1394->video_size)) < 0) { av_log(c, AV_LOG_ERROR, "Couldn't parse video size.\n"); goto out; @@ -131,6 +140,8 @@ static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, width = ap->width; if (ap->height > 0) height = ap->height; + if (ap->pix_fmt) + pix_fmt = ap->pix_fmt; #endif for (fmt = dc1394_frame_formats; fmt->width; fmt++) @@ -177,6 +188,7 @@ static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, *select_fmt = fmt; out: av_freep(&dc1394->video_size); + av_freep(&dc1394->pixel_format); return ret; } From d576bbf3eb0eb2a421f0c3efb2b78a47a1826cf5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 09:02:11 +0200 Subject: [PATCH 05/27] v4l2: add a pixel_format private option. --- libavdevice/v4l2.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index f5baf08b42..e0186f8031 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -47,6 +47,7 @@ #include "libavutil/log.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" +#include "libavutil/pixdesc.h" static const int desired_video_buffers = 256; @@ -71,6 +72,7 @@ struct video_data { char *standard; int channel; char *video_size; /**< String describing video size, set by a private option. */ + char *pixel_format; /**< Set by a private option. */ }; struct buff_data { @@ -544,12 +546,12 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) } static uint32_t device_try_init(AVFormatContext *s1, - const AVFormatParameters *ap, + enum PixelFormat pix_fmt, int *width, int *height, enum CodecID *codec_id) { - uint32_t desired_format = fmt_ff2v4l(ap->pix_fmt, s1->video_codec_id); + uint32_t desired_format = fmt_ff2v4l(pix_fmt, s1->video_codec_id); if (desired_format == 0 || device_init(s1, width, height, desired_format) < 0) { @@ -582,6 +584,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) int res = 0; uint32_t desired_format, capabilities; enum CodecID codec_id; + enum PixelFormat pix_fmt = PIX_FMT_NONE; st = av_new_stream(s1, 0); if (!st) { @@ -594,11 +597,18 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n"); goto out; } + if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == PIX_FMT_NONE) { + av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format); + res = AVERROR(EINVAL); + goto out; + } #if FF_API_FORMAT_PARAMETERS if (ap->width > 0) s->width = ap->width; if (ap->height > 0) s->height = ap->height; + if (ap->pix_fmt) + pix_fmt = ap->pix_fmt; #endif capabilities = 0; @@ -624,7 +634,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) av_log(s1, AV_LOG_VERBOSE, "Setting frame size to %dx%d\n", s->width, s->height); } - desired_format = device_try_init(s1, ap, &s->width, &s->height, &codec_id); + desired_format = device_try_init(s1, pix_fmt, &s->width, &s->height, &codec_id); if (desired_format == 0) { av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for " "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, ap->pix_fmt); @@ -670,6 +680,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) out: av_freep(&s->video_size); + av_freep(&s->pixel_format); return res; } @@ -719,6 +730,7 @@ static const AVOption options[] = { { "standard", "", offsetof(struct video_data, standard), FF_OPT_TYPE_STRING, {.str = "NTSC" }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, { "channel", "", offsetof(struct video_data, channel), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { NULL }, }; From 2a85f218680832bc8a22155c8d5225bdb9c10279 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 09:02:11 +0200 Subject: [PATCH 06/27] rawdec: add a pixel_format private option. --- libavformat/rawdec.c | 29 +++++++++++++++++++---------- libavformat/rawdec.h | 1 + 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 434ed48f05..4f974d7045 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -25,6 +25,7 @@ #include "rawdec.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" +#include "libavutil/pixdesc.h" /* raw input */ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) @@ -70,30 +71,37 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) case AVMEDIA_TYPE_VIDEO: { FFRawVideoDemuxerContext *s1 = s->priv_data; int width = 0, height = 0, ret; + enum PixelFormat pix_fmt; + if(ap->time_base.num) av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); else av_set_pts_info(st, 64, 1, 25); - if (s1->video_size) { - ret = av_parse_video_size(&width, &height, s1->video_size); - av_freep(&s1->video_size); - if (ret < 0) { - av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n"); - return ret; - } + if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) { + av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n"); + goto fail; + } + if ((pix_fmt = av_get_pix_fmt(s1->pixel_format)) == PIX_FMT_NONE) { + av_log(s, AV_LOG_ERROR, "No such pixel format: %s.\n", s1->pixel_format); + ret = AVERROR(EINVAL); + goto fail; } #if FF_API_FORMAT_PARAMETERS if (ap->width > 0) width = ap->width; if (ap->height > 0) height = ap->height; + if (ap->pix_fmt) + pix_fmt = ap->pix_fmt; #endif st->codec->width = width; st->codec->height = height; - st->codec->pix_fmt = ap->pix_fmt; - if(st->codec->pix_fmt == PIX_FMT_NONE) - st->codec->pix_fmt= PIX_FMT_YUV420P; + st->codec->pix_fmt = pix_fmt; break; +fail: + av_freep(&s1->video_size); + av_freep(&s1->pixel_format); + return ret; } default: return -1; @@ -187,6 +195,7 @@ const AVClass ff_rawaudio_demuxer_class = { #define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption video_options[] = { { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC }, { NULL }, }; #undef OFFSET diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h index 99beadd0e1..4968915cc6 100644 --- a/libavformat/rawdec.h +++ b/libavformat/rawdec.h @@ -34,6 +34,7 @@ typedef struct RawAudioDemuxerContext { typedef struct FFRawVideoDemuxerContext { const AVClass *class; /**< Class for private options. */ char *video_size; /**< String describing video size, set by a private option. */ + char *pixel_format; /**< Set by a private option. */ } FFRawVideoDemuxerContext; extern const AVClass ff_rawaudio_demuxer_class; From f91ccb1df6fe6d043bd88eabc916be1093b6677b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 27 May 2011 07:38:49 +0200 Subject: [PATCH 07/27] lavf: deprecate AVFormatParameters.pix_fmt. --- libavformat/avformat.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 849a85d1cc..27cd0f7763 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -233,9 +233,7 @@ typedef struct AVFormatParameters { attribute_deprecated int channels; attribute_deprecated int width; attribute_deprecated int height; -#endif - enum PixelFormat pix_fmt; -#if FF_API_FORMAT_PARAMETERS + attribute_deprecated enum PixelFormat pix_fmt; attribute_deprecated int channel; /**< Used to select DV channel. */ attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */ attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */ From 945dda41a2085b3c8fb5cf99026c224aa3d2cbfa Mon Sep 17 00:00:00 2001 From: Alok Ahuja Date: Sat, 28 May 2011 08:12:22 +0200 Subject: [PATCH 08/27] webm: support stereo videos in matroska/webm muxer Create a stereo_mode metadata tag to specify the stereo 3d video layout using the StereoMode tag in a matroska/webm video track. --- doc/muxers.texi | 63 +++++++++++++++++++++++++++++++++++++++ libavformat/matroska.h | 20 ++++++++++++- libavformat/matroskaenc.c | 19 ++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 82f17ba105..74c014bc70 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -204,4 +204,67 @@ Alternatively you can write the command as: ffmpeg -benchmark -i INPUT -f null - @end example +@section matroska + +Matroska container muxer. + +This muxer implements the matroska and webm container specs. + +The recognized metadata settings in this muxer are: + +@table @option + +@item title=@var{title name} +Name provided to a single track +@end table + +@table @option + +@item language=@var{language name} +Specifies the language of the track in the Matroska languages form +@end table + +@table @option + +@item STEREO_MODE=@var{mode} +Stereo 3D video layout of two views in a single video track +@table @option +@item mono +video is not stereo +@item left_right +Both views are arranged side by side, Left-eye view is on the left +@item bottom_top +Both views are arranged in top-bottom orientation, Left-eye view is at bottom +@item top_bottom +Both views are arranged in top-bottom orientation, Left-eye view is on top +@item checkerboard_rl +Each view is arranged in a checkerboard interleaved pattern, Left-eye view being first +@item checkerboard_lr +Each view is arranged in a checkerboard interleaved pattern, Right-eye view being first +@item row_interleaved_rl +Each view is constituted by a row based interleaving, Right-eye view is first row +@item row_interleaved_lr +Each view is constituted by a row based interleaving, Left-eye view is first row +@item col_interleaved_rl +Both views are arranged in a column based interleaving manner, Right-eye view is first column +@item col_interleaved_lr +Both views are arranged in a column based interleaving manner, Left-eye view is first column +@item anaglyph_cyan_red +All frames are in anaglyph format viewable through red-cyan filters +@item right_left +Both views are arranged side by side, Right-eye view is on the left +@item anaglyph_green_magenta +All frames are in anaglyph format viewable through green-magenta filters +@item block_lr +Both eyes laced in one Block, Left-eye view is first +@item block_rl +Both eyes laced in one Block, Right-eye view is first +@end table +@end table + +For example a 3D WebM clip can be created using the following command line: +@example +ffmpeg -i sample_left_right_clip.mpg -an -vcodec libvpx -metadata STEREO_MODE=left_right -y stereo_clip.webm +@end example + @c man end MUXERS diff --git a/libavformat/matroska.h b/libavformat/matroska.h index 45d9747d39..8e747e6a9c 100644 --- a/libavformat/matroska.h +++ b/libavformat/matroska.h @@ -111,7 +111,7 @@ #define MATROSKA_ID_VIDEOPIXELCROPR 0x54DD #define MATROSKA_ID_VIDEODISPLAYUNIT 0x54B2 #define MATROSKA_ID_VIDEOFLAGINTERLACED 0x9A -#define MATROSKA_ID_VIDEOSTEREOMODE 0x53B9 +#define MATROSKA_ID_VIDEOSTEREOMODE 0x53B8 #define MATROSKA_ID_VIDEOASPECTRATIO 0x54B3 #define MATROSKA_ID_VIDEOCOLORSPACE 0x2EB524 @@ -218,6 +218,24 @@ typedef enum { MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP = 3, } MatroskaTrackEncodingCompAlgo; +typedef enum { + MATROSKA_VIDEO_STEREOMODE_TYPE_MONO = 0, + MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT = 1, + MATROSKA_VIDEO_STEREOMODE_TYPE_BOTTOM_TOP = 2, + MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM = 3, + MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_RL = 4, + MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR = 5, + MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_RL = 6, + MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR = 7, + MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_RL = 8, + MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR = 9, + MATROSKA_VIDEO_STEREOMODE_TYPE_ANAGLYPH_CYAN_RED = 10, + MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT = 11, + MATROSKA_VIDEO_STEREOMODE_TYPE_ANAGLYPH_GREEN_MAG = 12, + MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR = 13, + MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL = 14, +} MatroskaVideoStereoModeType; + /* * Matroska Codec IDs, strings */ diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 1bbabc9ff4..ba2ce28e17 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -586,6 +586,25 @@ static int mkv_write_tracks(AVFormatContext *s) // XXX: interlace flag? put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width); put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height); + if ((tag = av_metadata_get(s->metadata, "stereo_mode", NULL, 0))) { + uint8_t stereo_fmt = atoi(tag->value); + int valid_fmt = 0; + + switch (mkv->mode) { + case MODE_WEBM: + if (stereo_fmt <= MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM + || stereo_fmt == MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT) + valid_fmt = 1; + break; + case MODE_MATROSKAv2: + if (stereo_fmt <= MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL) + valid_fmt = 1; + break; + } + + if (valid_fmt) + put_ebml_uint (pb, MATROSKA_ID_VIDEOSTEREOMODE, stereo_fmt); + } if (st->sample_aspect_ratio.num) { int d_width = codec->width*av_q2d(st->sample_aspect_ratio); put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width); From 88aa21593932fbf5597996041ab669848c542ee5 Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 12 Apr 2011 04:40:47 +0200 Subject: [PATCH 09/27] vpxenc: add VP8E_SET_STATIC_THRESHOLD mapping via the equivalent AVCodecContext::mb_threshold Signed-off-by: Michael Niedermayer --- libavcodec/libvpxenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 79009b1ad5..02f8135381 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -311,6 +311,7 @@ static av_cold int vp8_init(AVCodecContext *avctx) codecctl_int(avctx, VP8E_SET_CPUUSED, cpuused); codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction); codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->slices)); + codecctl_int(avctx, VP8E_SET_STATIC_THRESHOLD, avctx->mb_threshold); //provide dummy value to initialize wrapper, values will be updated each _encode() vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1, From 009f829dde811af654af7110326aea3a72c05d5e Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 27 May 2011 19:01:47 -0400 Subject: [PATCH 10/27] swscale: fix crash in bilinear scaling. --- libswscale/swscale_internal.h | 2 + libswscale/utils.c | 1 + libswscale/x86/swscale_template.c | 141 +++++++++++++----------------- 3 files changed, 66 insertions(+), 78 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 8ba0fe9090..d41828a4ca 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -194,6 +194,7 @@ typedef struct SwsContext { #define Y_TEMP "11*8+4*4*256*2+40" #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48" #define UV_OFF "11*8+4*4*256*3+48" +#define UV_OFFx2 "11*8+4*4*256*3+56" DECLARE_ALIGNED(8, uint64_t, redDither); DECLARE_ALIGNED(8, uint64_t, greenDither); @@ -217,6 +218,7 @@ typedef struct SwsContext { DECLARE_ALIGNED(8, uint64_t, y_temp); int32_t alpMmxFilter[4*MAX_FILTER_SIZE]; DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes + DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes #if HAVE_ALTIVEC vector signed short CY; diff --git a/libswscale/utils.c b/libswscale/utils.c index 571f45be3d..a2a6a1e191 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1001,6 +1001,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize]; } c->uv_off = dst_stride_px; + c->uv_offx2 = dst_stride; for (i=0; ivChrBufSize; i++) { FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+1, fail); c->chrUPixBuf[i] = c->chrUPixBuf[i+c->vChrBufSize]; diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c index 5cc3a435be..ba0a1978cc 100644 --- a/libswscale/x86/swscale_template.c +++ b/libswscale/x86/swscale_template.c @@ -897,16 +897,16 @@ static inline void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter YSCALEYUV2PACKEDX_END } -#define REAL_YSCALEYUV2RGB_UV(index, c, uv_off) \ +#define REAL_YSCALEYUV2RGB_UV(index, c) \ "xor "#index", "#index" \n\t"\ ".p2align 4 \n\t"\ "1: \n\t"\ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "add "#uv_off", "#index" \n\t" \ + "add "UV_OFFx2"("#c"), "#index" \n\t" \ "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ - "sub "#uv_off", "#index" \n\t" \ + "sub "UV_OFFx2"("#c"), "#index" \n\t" \ "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ @@ -969,8 +969,8 @@ static inline void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter #define YSCALEYUV2RGB_YA(index, c, b1, b2) REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) -#define YSCALEYUV2RGB(index, c, uv_off) \ - REAL_YSCALEYUV2RGB_UV(index, c, uv_off) \ +#define YSCALEYUV2RGB(index, c) \ + REAL_YSCALEYUV2RGB_UV(index, c) \ REAL_YSCALEYUV2RGB_YA(index, c, %0, %1) \ REAL_YSCALEYUV2RGB_COEFF(c) @@ -984,12 +984,10 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0, const uint16_t *abuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { - x86_reg uv_off = c->uv_off << 1; - if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { #if ARCH_X86_64 __asm__ volatile( - YSCALEYUV2RGB(%%r8, %5, %8) + YSCALEYUV2RGB(%%r8, %5) YSCALEYUV2RGB_YA(%%r8, %5, %6, %7) "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ @@ -997,7 +995,7 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0, WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "r" (dest), "a" (&c->redDither), - "r" (abuf0), "r" (abuf1), "m"(uv_off) + "r" (abuf0), "r" (abuf1) : "%r8" ); #else @@ -1007,7 +1005,7 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0, "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5, %6) + YSCALEYUV2RGB(%%REGBP, %5) "push %0 \n\t" "push %1 \n\t" "mov "U_TEMP"(%5), %0 \n\t" @@ -1022,7 +1020,7 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0, "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); #endif } else { @@ -1030,13 +1028,13 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0, "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5, %6) + YSCALEYUV2RGB(%%REGBP, %5) "pcmpeqd %%mm7, %%mm7 \n\t" WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } } @@ -1048,20 +1046,18 @@ static inline void RENAME(yuv2bgr24_2)(SwsContext *c, const uint16_t *buf0, const uint16_t *abuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { - x86_reg uv_off = c->uv_off << 1; - //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5, %6) + YSCALEYUV2RGB(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" WRITEBGR24(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } @@ -1072,14 +1068,12 @@ static inline void RENAME(yuv2rgb555_2)(SwsContext *c, const uint16_t *buf0, const uint16_t *abuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { - x86_reg uv_off = c->uv_off << 1; - //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5, %6) + YSCALEYUV2RGB(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP @@ -1091,7 +1085,7 @@ static inline void RENAME(yuv2rgb555_2)(SwsContext *c, const uint16_t *buf0, "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } @@ -1102,14 +1096,12 @@ static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0, const uint16_t *abuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { - x86_reg uv_off = c->uv_off << 1; - //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5, %6) + YSCALEYUV2RGB(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP @@ -1121,11 +1113,11 @@ static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0, "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } -#define REAL_YSCALEYUV2PACKED(index, c, uv_off) \ +#define REAL_YSCALEYUV2PACKED(index, c) \ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1 \n\t"\ "psraw $3, %%mm0 \n\t"\ @@ -1137,10 +1129,10 @@ static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0, "1: \n\t"\ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "add "#uv_off", "#index" \n\t" \ + "add "UV_OFFx2"("#c"), "#index" \n\t" \ "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ - "sub "#uv_off", "#index" \n\t" \ + "sub "UV_OFFx2"("#c"), "#index" \n\t" \ "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ @@ -1163,7 +1155,7 @@ static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0, "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ -#define YSCALEYUV2PACKED(index, c, uv_off) REAL_YSCALEYUV2PACKED(index, c, uv_off) +#define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c) static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0, const uint16_t *buf1, const uint16_t *ubuf0, @@ -1172,30 +1164,28 @@ static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0, const uint16_t *abuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { - x86_reg uv_off = c->uv_off << 1; - //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2PACKED(%%REGBP, %5, %6) + YSCALEYUV2PACKED(%%REGBP, %5) WRITEYUY2(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } -#define REAL_YSCALEYUV2RGB1(index, c, uv_off) \ +#define REAL_YSCALEYUV2RGB1(index, c) \ "xor "#index", "#index" \n\t"\ ".p2align 4 \n\t"\ "1: \n\t"\ "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ - "add "#uv_off", "#index" \n\t" \ + "add "UV_OFFx2"("#c"), "#index" \n\t" \ "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ - "sub "#uv_off", "#index" \n\t" \ + "sub "UV_OFFx2"("#c"), "#index" \n\t" \ "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ @@ -1237,19 +1227,19 @@ static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0, "packuswb %%mm6, %%mm5 \n\t"\ "packuswb %%mm3, %%mm4 \n\t"\ -#define YSCALEYUV2RGB1(index, c, uv_off) REAL_YSCALEYUV2RGB1(index, c, uv_off) +#define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c) // do vertical chrominance interpolation -#define REAL_YSCALEYUV2RGB1b(index, c, uv_off) \ +#define REAL_YSCALEYUV2RGB1b(index, c) \ "xor "#index", "#index" \n\t"\ ".p2align 4 \n\t"\ "1: \n\t"\ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "add "#uv_off", "#index" \n\t" \ + "add "UV_OFFx2"("#c"), "#index" \n\t" \ "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ - "sub "#uv_off", "#index" \n\t" \ + "sub "UV_OFFx2"("#c"), "#index" \n\t" \ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\ @@ -1293,7 +1283,7 @@ static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0, "packuswb %%mm6, %%mm5 \n\t"\ "packuswb %%mm3, %%mm4 \n\t"\ -#define YSCALEYUV2RGB1b(index, c, uv_off) REAL_YSCALEYUV2RGB1b(index, c, uv_off) +#define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c) #define REAL_YSCALEYUV2RGB1_ALPHA(index) \ "movq (%1, "#index", 2), %%mm7 \n\t" /* abuf0[index ] */\ @@ -1313,7 +1303,6 @@ static inline void RENAME(yuv2rgb32_1)(SwsContext *c, const uint16_t *buf0, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) { - x86_reg uv_off = c->uv_off << 1; const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster @@ -1322,26 +1311,26 @@ static inline void RENAME(yuv2rgb32_1)(SwsContext *c, const uint16_t *buf0, "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5, %6) + YSCALEYUV2RGB1(%%REGBP, %5) YSCALEYUV2RGB1_ALPHA(%%REGBP) WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5, %6) + YSCALEYUV2RGB1(%%REGBP, %5) "pcmpeqd %%mm7, %%mm7 \n\t" WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } } else { @@ -1350,26 +1339,26 @@ static inline void RENAME(yuv2rgb32_1)(SwsContext *c, const uint16_t *buf0, "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5, %6) + YSCALEYUV2RGB1b(%%REGBP, %5) YSCALEYUV2RGB1_ALPHA(%%REGBP) WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5, %6) + YSCALEYUV2RGB1b(%%REGBP, %5) "pcmpeqd %%mm7, %%mm7 \n\t" WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } } @@ -1382,7 +1371,6 @@ static inline void RENAME(yuv2bgr24_1)(SwsContext *c, const uint16_t *buf0, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) { - x86_reg uv_off = c->uv_off << 1; const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster @@ -1390,26 +1378,26 @@ static inline void RENAME(yuv2bgr24_1)(SwsContext *c, const uint16_t *buf0, "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5, %6) + YSCALEYUV2RGB1(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" WRITEBGR24(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5, %6) + YSCALEYUV2RGB1b(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" WRITEBGR24(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } } @@ -1421,7 +1409,6 @@ static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) { - x86_reg uv_off = c->uv_off << 1; const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster @@ -1429,7 +1416,7 @@ static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0, "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5, %6) + YSCALEYUV2RGB1(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP @@ -1441,14 +1428,14 @@ static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0, "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5, %6) + YSCALEYUV2RGB1b(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP @@ -1460,7 +1447,7 @@ static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0, "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } } @@ -1472,7 +1459,6 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) { - x86_reg uv_off = c->uv_off << 1; const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster @@ -1480,7 +1466,7 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0, "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5, %6) + YSCALEYUV2RGB1(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP @@ -1492,14 +1478,14 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0, "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5, %6) + YSCALEYUV2RGB1b(%%REGBP, %5) "pxor %%mm7, %%mm7 \n\t" /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP @@ -1511,19 +1497,19 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0, "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } } -#define REAL_YSCALEYUV2PACKED1(index, c, uv_off) \ +#define REAL_YSCALEYUV2PACKED1(index, c) \ "xor "#index", "#index" \n\t"\ ".p2align 4 \n\t"\ "1: \n\t"\ "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ - "add "#uv_off", "#index" \n\t" \ + "add "UV_OFFx2"("#c"), "#index" \n\t" \ "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ - "sub "#uv_off", "#index" \n\t" \ + "sub "UV_OFFx2"("#c"), "#index" \n\t" \ "psraw $7, %%mm3 \n\t" \ "psraw $7, %%mm4 \n\t" \ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ @@ -1531,18 +1517,18 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0, "psraw $7, %%mm1 \n\t" \ "psraw $7, %%mm7 \n\t" \ -#define YSCALEYUV2PACKED1(index, c, uv_off) REAL_YSCALEYUV2PACKED1(index, c, uv_off) +#define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c) -#define REAL_YSCALEYUV2PACKED1b(index, c, uv_off) \ +#define REAL_YSCALEYUV2PACKED1b(index, c) \ "xor "#index", "#index" \n\t"\ ".p2align 4 \n\t"\ "1: \n\t"\ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "add "#uv_off", "#index" \n\t" \ + "add "UV_OFFx2"("#c"), "#index" \n\t" \ "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ - "sub "#uv_off", "#index" \n\t" \ + "sub "UV_OFFx2"("#c"), "#index" \n\t" \ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ "psrlw $8, %%mm3 \n\t" \ @@ -1551,7 +1537,7 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0, "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ "psraw $7, %%mm1 \n\t" \ "psraw $7, %%mm7 \n\t" -#define YSCALEYUV2PACKED1b(index, c, uv_off) REAL_YSCALEYUV2PACKED1b(index, c, uv_off) +#define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c) static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0, const uint16_t *ubuf0, const uint16_t *ubuf1, @@ -1560,7 +1546,6 @@ static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) { - x86_reg uv_off = c->uv_off << 1; const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster @@ -1568,24 +1553,24 @@ static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0, "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2PACKED1(%%REGBP, %5, %6) + YSCALEYUV2PACKED1(%%REGBP, %5) WRITEYUY2(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } else { __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" - YSCALEYUV2PACKED1b(%%REGBP, %5, %6) + YSCALEYUV2PACKED1b(%%REGBP, %5) WRITEYUY2(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), - "a" (&c->redDither), "m"(uv_off) + "a" (&c->redDither) ); } } From 26513856d657de3b3afacae7c13fd99a7fe79d05 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 28 May 2011 01:53:00 +0200 Subject: [PATCH 11/27] cmdutils: remove OPT_FUNC2 Make ff* tools only accept opt_* functions taking two arguments. The distinction between functions with one and two arguments is quite pointless. Simplify parse_options() code. Signed-off-by: Ronald S. Bultje --- cmdutils.c | 6 +- cmdutils.h | 10 +- cmdutils_common_opts.h | 2 +- ffmpeg.c | 215 ++++++++++++++++++++++------------------- ffplay.c | 33 ++++--- ffprobe.c | 7 +- 6 files changed, 144 insertions(+), 129 deletions(-) diff --git a/cmdutils.c b/cmdutils.c index 778f0fb3cf..31866b5563 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -277,13 +277,11 @@ unknown_opt: *po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); } else if (po->flags & OPT_FLOAT) { *po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY); - } else if (po->flags & OPT_FUNC2) { - if (po->u.func2_arg(opt, arg) < 0) { + } else { + if (po->u.func_arg(opt, arg) < 0) { fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt); exit(1); } - } else if (po->u.func_arg) { - po->u.func_arg(arg); } if(po->flags & OPT_EXIT) exit(0); diff --git a/cmdutils.h b/cmdutils.h index 3bb1cd616b..e231b1ff84 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -121,16 +121,14 @@ typedef struct { #define OPT_INT 0x0080 #define OPT_FLOAT 0x0100 #define OPT_SUBTITLE 0x0200 -#define OPT_FUNC2 0x0400 -#define OPT_INT64 0x0800 -#define OPT_EXIT 0x1000 -#define OPT_DATA 0x2000 +#define OPT_INT64 0x0400 +#define OPT_EXIT 0x0800 +#define OPT_DATA 0x1000 union { - void (*func_arg)(const char *); //FIXME passing error code as int return would be nicer then exit() in the func int *int_arg; char **str_arg; float *float_arg; - int (*func2_arg)(const char *, const char *); + int (*func_arg)(const char *, const char *); int64_t *int64_arg; } u; const char *help; diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index da309977bd..9b5e5d22cd 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -10,4 +10,4 @@ { "protocols", OPT_EXIT, {(void*)show_protocols}, "show available protocols" }, { "filters", OPT_EXIT, {(void*)show_filters }, "show available filters" }, { "pix_fmts" , OPT_EXIT, {(void*)show_pix_fmts }, "show available pixel formats" }, - { "loglevel", HAS_ARG | OPT_FUNC2, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" }, + { "loglevel", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" }, diff --git a/ffmpeg.c b/ffmpeg.c index f27513da26..7721438ad1 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2704,14 +2704,16 @@ static int transcode(AVFormatContext **output_files, return ret; } -static void opt_format(const char *arg) +static int opt_format(const char *opt, const char *arg) { last_asked_format = arg; + return 0; } -static void opt_video_rc_override_string(const char *arg) +static int opt_video_rc_override_string(const char *opt, const char *arg) { video_rc_override_string = arg; + return 0; } static int opt_me_threshold(const char *opt, const char *arg) @@ -2753,12 +2755,13 @@ static int opt_frame_crop(const char *opt, const char *arg) return AVERROR(EINVAL); } -static void opt_frame_size(const char *arg) +static int opt_frame_size(const char *opt, const char *arg) { if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) { fprintf(stderr, "Incorrect frame size\n"); - ffmpeg_exit(1); + return AVERROR(EINVAL); } + return 0; } static int opt_pad(const char *opt, const char *arg) { @@ -2766,21 +2769,22 @@ static int opt_pad(const char *opt, const char *arg) { return -1; } -static void opt_frame_pix_fmt(const char *arg) +static int opt_frame_pix_fmt(const char *opt, const char *arg) { if (strcmp(arg, "list")) { frame_pix_fmt = av_get_pix_fmt(arg); if (frame_pix_fmt == PIX_FMT_NONE) { fprintf(stderr, "Unknown pixel format requested: %s\n", arg); - ffmpeg_exit(1); + return AVERROR(EINVAL); } } else { show_pix_fmts(); ffmpeg_exit(0); } + return 0; } -static void opt_frame_aspect_ratio(const char *arg) +static int opt_frame_aspect_ratio(const char *opt, const char *arg) { int x = 0, y = 0; double ar = 0; @@ -2799,9 +2803,10 @@ static void opt_frame_aspect_ratio(const char *arg) if (!ar) { fprintf(stderr, "Incorrect aspect ratio specification.\n"); - ffmpeg_exit(1); + return AVERROR(EINVAL); } frame_aspect_ratio = ar; + return 0; } static int opt_metadata(const char *opt, const char *arg) @@ -2845,13 +2850,13 @@ static int opt_thread_count(const char *opt, const char *arg) return 0; } -static void opt_audio_sample_fmt(const char *arg) +static int opt_audio_sample_fmt(const char *opt, const char *arg) { if (strcmp(arg, "list")) { audio_sample_fmt = av_get_sample_fmt(arg); if (audio_sample_fmt == AV_SAMPLE_FMT_NONE) { av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg); - ffmpeg_exit(1); + return AVERROR(EINVAL); } } else { int i; @@ -2860,6 +2865,7 @@ static void opt_audio_sample_fmt(const char *arg) printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i)); ffmpeg_exit(0); } + return 0; } static int opt_audio_rate(const char *opt, const char *arg) @@ -2880,12 +2886,13 @@ static int opt_video_channel(const char *opt, const char *arg) return 0; } -static void opt_video_standard(const char *arg) +static int opt_video_standard(const char *opt, const char *arg) { video_standard = av_strdup(arg); + return 0; } -static void opt_codec(int *pstream_copy, char **pcodec_name, +static int opt_codec(int *pstream_copy, char **pcodec_name, int codec_type, const char *arg) { av_freep(pcodec_name); @@ -2894,26 +2901,27 @@ static void opt_codec(int *pstream_copy, char **pcodec_name, } else { *pcodec_name = av_strdup(arg); } + return 0; } -static void opt_audio_codec(const char *arg) +static int opt_audio_codec(const char *opt, const char *arg) { - opt_codec(&audio_stream_copy, &audio_codec_name, AVMEDIA_TYPE_AUDIO, arg); + return opt_codec(&audio_stream_copy, &audio_codec_name, AVMEDIA_TYPE_AUDIO, arg); } -static void opt_video_codec(const char *arg) +static int opt_video_codec(const char *opt, const char *arg) { - opt_codec(&video_stream_copy, &video_codec_name, AVMEDIA_TYPE_VIDEO, arg); + return opt_codec(&video_stream_copy, &video_codec_name, AVMEDIA_TYPE_VIDEO, arg); } -static void opt_subtitle_codec(const char *arg) +static int opt_subtitle_codec(const char *opt, const char *arg) { - opt_codec(&subtitle_stream_copy, &subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, arg); + return opt_codec(&subtitle_stream_copy, &subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, arg); } -static void opt_data_codec(const char *arg) +static int opt_data_codec(const char *opt, const char *arg) { - opt_codec(&data_stream_copy, &data_codec_name, AVMEDIA_TYPE_DATA, arg); + return opt_codec(&data_stream_copy, &data_codec_name, AVMEDIA_TYPE_DATA, arg); } static int opt_codec_tag(const char *opt, const char *arg) @@ -2934,7 +2942,7 @@ static int opt_codec_tag(const char *opt, const char *arg) return 0; } -static void opt_map(const char *arg) +static int opt_map(const char *opt, const char *arg) { AVStreamMap *m; char *p; @@ -2957,6 +2965,7 @@ static void opt_map(const char *arg) m->sync_file_index = m->file_index; m->sync_stream_index = m->stream_index; } + return 0; } static void parse_meta_type(char *arg, char *type, int *index, char **endptr) @@ -2980,7 +2989,7 @@ static void parse_meta_type(char *arg, char *type, int *index, char **endptr) *type = 'g'; } -static void opt_map_metadata(const char *arg) +static int opt_map_metadata(const char *opt, const char *arg) { AVMetaDataMap *m, *m1; char *p; @@ -3004,16 +3013,18 @@ static void opt_map_metadata(const char *arg) metadata_streams_autocopy = 0; if (m->type == 'c' || m1->type == 'c') metadata_chapters_autocopy = 0; + + return 0; } -static void opt_map_meta_data(const char *arg) +static int opt_map_meta_data(const char *opt, const char *arg) { fprintf(stderr, "-map_meta_data is deprecated and will be removed soon. " "Use -map_metadata instead.\n"); - opt_map_metadata(arg); + return opt_map_metadata(opt, arg); } -static void opt_map_chapters(const char *arg) +static int opt_map_chapters(const char *opt, const char *arg) { AVChapterMap *c; char *p; @@ -3026,9 +3037,10 @@ static void opt_map_chapters(const char *arg) p++; c->in_file = strtol(p, &p, 0); + return 0; } -static void opt_input_ts_scale(const char *arg) +static int opt_input_ts_scale(const char *opt, const char *arg) { unsigned int stream; double scale; @@ -3044,6 +3056,7 @@ static void opt_input_ts_scale(const char *arg) input_files_ts_scale[nb_input_files] = grow_array(input_files_ts_scale[nb_input_files], sizeof(*input_files_ts_scale[nb_input_files]), &nb_input_files_ts_scale[nb_input_files], stream + 1); input_files_ts_scale[nb_input_files][stream]= scale; + return 0; } static int opt_recording_time(const char *opt, const char *arg) @@ -3104,7 +3117,7 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder, i return codec->id; } -static void opt_input_file(const char *filename) +static int opt_input_file(const char *opt, const char *filename) { AVFormatContext *ic; AVFormatParameters params, *ap = ¶ms; @@ -3330,6 +3343,7 @@ static void opt_input_file(const char *filename) av_freep(&subtitle_codec_name); uninit_opts(); init_opts(); + return 0; } static void check_inputs(int *has_video_ptr, @@ -4016,7 +4030,7 @@ static void show_help(void) av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); } -static void opt_target(const char *arg) +static int opt_target(const char *opt, const char *arg) { enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN; static const char *const frame_rates[] = {"25", "30000/1001", "24000/1001"}; @@ -4073,13 +4087,12 @@ static void opt_target(const char *arg) } if(!strcmp(arg, "vcd")) { + opt_video_codec("vcodec", "mpeg1video"); + opt_audio_codec("vcodec", "mp2"); + opt_format("f", "vcd"); - opt_video_codec("mpeg1video"); - opt_audio_codec("mp2"); - opt_format("vcd"); - - opt_frame_size(norm == PAL ? "352x288" : "352x240"); - opt_frame_rate(NULL, frame_rates[norm]); + opt_frame_size("s", norm == PAL ? "352x288" : "352x240"); + opt_frame_rate("r", frame_rates[norm]); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "1150000"); @@ -4102,12 +4115,12 @@ static void opt_target(const char *arg) mux_preload= (36000+3*1200) / 90000.0; //0.44 } else if(!strcmp(arg, "svcd")) { - opt_video_codec("mpeg2video"); - opt_audio_codec("mp2"); - opt_format("svcd"); + opt_video_codec("vcodec", "mpeg2video"); + opt_audio_codec("acodec", "mp2"); + opt_format("f", "svcd"); - opt_frame_size(norm == PAL ? "480x576" : "480x480"); - opt_frame_rate(NULL, frame_rates[norm]); + opt_frame_size("s", norm == PAL ? "480x576" : "480x480"); + opt_frame_rate("r", frame_rates[norm]); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "2040000"); @@ -4124,12 +4137,12 @@ static void opt_target(const char *arg) } else if(!strcmp(arg, "dvd")) { - opt_video_codec("mpeg2video"); - opt_audio_codec("ac3"); - opt_format("dvd"); + opt_video_codec("vcodec", "mpeg2video"); + opt_audio_codec("vcodec", "ac3"); + opt_format("f", "dvd"); - opt_frame_size(norm == PAL ? "720x576" : "720x480"); - opt_frame_rate(NULL, frame_rates[norm]); + opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480"); + opt_frame_rate("r", frame_rates[norm]); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "6000000"); @@ -4145,29 +4158,31 @@ static void opt_target(const char *arg) } else if(!strncmp(arg, "dv", 2)) { - opt_format("dv"); + opt_format("f", "dv"); - opt_frame_size(norm == PAL ? "720x576" : "720x480"); - opt_frame_pix_fmt(!strncmp(arg, "dv50", 4) ? "yuv422p" : - (norm == PAL ? "yuv420p" : "yuv411p")); - opt_frame_rate(NULL, frame_rates[norm]); + opt_frame_size("s", norm == PAL ? "720x576" : "720x480"); + opt_frame_pix_fmt("pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" : + norm == PAL ? "yuv420p" : "yuv411p"); + opt_frame_rate("r", frame_rates[norm]); audio_sample_rate = 48000; audio_channels = 2; } else { fprintf(stderr, "Unknown target: %s\n", arg); - ffmpeg_exit(1); + return AVERROR(EINVAL); } + return 0; } -static void opt_vstats_file (const char *arg) +static int opt_vstats_file(const char *opt, const char *arg) { av_free (vstats_filename); vstats_filename=av_strdup (arg); + return 0; } -static void opt_vstats (void) +static int opt_vstats(const char *opt, const char *arg) { char filename[40]; time_t today2 = time(NULL); @@ -4175,7 +4190,7 @@ static void opt_vstats (void) snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec); - opt_vstats_file(filename); + return opt_vstats_file(opt, filename); } static int opt_bsf(const char *opt, const char *arg) @@ -4222,13 +4237,13 @@ static int opt_preset(const char *opt, const char *arg) ffmpeg_exit(1); } if(!strcmp(tmp, "acodec")){ - opt_audio_codec(tmp2); + opt_audio_codec(tmp, tmp2); }else if(!strcmp(tmp, "vcodec")){ - opt_video_codec(tmp2); + opt_video_codec(tmp, tmp2); }else if(!strcmp(tmp, "scodec")){ - opt_subtitle_codec(tmp2); + opt_subtitle_codec(tmp, tmp2); }else if(!strcmp(tmp, "dcodec")){ - opt_data_codec(tmp2); + opt_data_codec(tmp, tmp2); }else if(opt_default(tmp, tmp2) < 0){ fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2); ffmpeg_exit(1); @@ -4252,17 +4267,17 @@ static const OptionDef options[] = { { "map_metadata", HAS_ARG | OPT_EXPERT, {(void*)opt_map_metadata}, "set metadata information of outfile from infile", "outfile[,metadata]:infile[,metadata]" }, { "map_chapters", HAS_ARG | OPT_EXPERT, {(void*)opt_map_chapters}, "set chapters mapping", "outfile:infile" }, - { "t", OPT_FUNC2 | HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" }, + { "t", HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" }, { "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, // - { "ss", OPT_FUNC2 | HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" }, - { "itsoffset", OPT_FUNC2 | HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" }, + { "ss", HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" }, + { "itsoffset", HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" }, { "itsscale", HAS_ARG, {(void*)opt_input_ts_scale}, "set the input ts scale", "stream:scale" }, - { "timestamp", OPT_FUNC2 | HAS_ARG, {(void*)opt_recording_timestamp}, "set the recording timestamp ('now' to set the current time)", "time" }, - { "metadata", OPT_FUNC2 | HAS_ARG, {(void*)opt_metadata}, "add metadata", "string=string" }, + { "timestamp", HAS_ARG, {(void*)opt_recording_timestamp}, "set the recording timestamp ('now' to set the current time)", "time" }, + { "metadata", HAS_ARG, {(void*)opt_metadata}, "add metadata", "string=string" }, { "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[AVMEDIA_TYPE_DATA]}, "set the number of data frames to record", "number" }, { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark}, "add timings for benchmarking" }, - { "timelimit", OPT_FUNC2 | HAS_ARG, {(void*)opt_timelimit}, "set max runtime in seconds", "limit" }, + { "timelimit", HAS_ARG, {(void*)opt_timelimit}, "set max runtime in seconds", "limit" }, { "dump", OPT_BOOL | OPT_EXPERT, {(void*)&do_pkt_dump}, "dump each input packet" }, { "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump}, @@ -4270,9 +4285,9 @@ static const OptionDef options[] = { { "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" }, { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" }, { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" }, - { "v", HAS_ARG | OPT_FUNC2, {(void*)opt_verbose}, "set ffmpeg verbosity level", "number" }, + { "v", HAS_ARG, {(void*)opt_verbose}, "set ffmpeg verbosity level", "number" }, { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" }, - { "threads", OPT_FUNC2 | HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" }, + { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" }, { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" }, { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" }, { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "threshold" }, @@ -4285,32 +4300,32 @@ static const OptionDef options[] = { { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)©_initial_nonkeyframes}, "copy initial non-keyframes" }, /* video options */ - { "b", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, - { "vb", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, + { "b", HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, + { "vb", HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, { "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[AVMEDIA_TYPE_VIDEO]}, "set the number of video frames to record", "number" }, - { "r", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, + { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" }, - { "croptop", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" }, - { "cropbottom", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" }, - { "cropleft", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" }, - { "cropright", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" }, - { "padtop", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" }, - { "padbottom", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" }, - { "padleft", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" }, - { "padright", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" }, - { "padcolor", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "color" }, + { "croptop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" }, + { "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" }, + { "cropleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" }, + { "cropright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" }, + { "padtop", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" }, + { "padbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" }, + { "padleft", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" }, + { "padright", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" }, + { "padcolor", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "color" }, { "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra frames"}, { "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" }, { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" }, - { "qscale", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" }, + { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" }, { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" }, { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" }, - { "me_threshold", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "threshold" }, + { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "threshold" }, { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality}, "use same quantizer as source (implies VBR)" }, - { "pass", HAS_ARG | OPT_FUNC2 | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" }, + { "pass", HAS_ARG | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" }, { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename_prefix}, "select two pass log file name prefix", "prefix" }, { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace}, "deinterlace pictures" }, @@ -4322,39 +4337,39 @@ static const OptionDef options[] = { #endif { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" }, { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" }, - { "top", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" }, + { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" }, { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" }, - { "vtag", OPT_FUNC2 | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_codec_tag}, "force video tag/fourcc", "fourcc/tag" }, - { "newvideo", OPT_VIDEO | OPT_FUNC2, {(void*)opt_new_stream}, "add a new video stream to the current output stream" }, + { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_codec_tag}, "force video tag/fourcc", "fourcc/tag" }, + { "newvideo", OPT_VIDEO, {(void*)opt_new_stream}, "add a new video stream to the current output stream" }, { "vlang", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void *)&video_language}, "set the ISO 639 language code (3 letters) of the current video stream" , "code" }, { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&force_fps}, "force the selected framerate, disable the best supported framerate selection" }, - { "streamid", OPT_FUNC2 | HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" }, + { "streamid", HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" }, { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void *)&forced_key_frames}, "force key frames at specified timestamps", "timestamps" }, /* audio options */ - { "ab", OPT_FUNC2 | HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, + { "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, { "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[AVMEDIA_TYPE_AUDIO]}, "set the number of audio frames to record", "number" }, { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", }, - { "ar", HAS_ARG | OPT_FUNC2 | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" }, - { "ac", HAS_ARG | OPT_FUNC2 | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" }, + { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" }, + { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" }, { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" }, { "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" }, - { "atag", OPT_FUNC2 | HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_codec_tag}, "force audio tag/fourcc", "fourcc/tag" }, + { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_codec_tag}, "force audio tag/fourcc", "fourcc/tag" }, { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, // - { "newaudio", OPT_AUDIO | OPT_FUNC2, {(void*)opt_new_stream}, "add a new audio stream to the current output stream" }, + { "newaudio", OPT_AUDIO, {(void*)opt_new_stream}, "add a new audio stream to the current output stream" }, { "alang", HAS_ARG | OPT_STRING | OPT_AUDIO, {(void *)&audio_language}, "set the ISO 639 language code (3 letters) of the current audio stream" , "code" }, { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_audio_sample_fmt}, "set sample format, 'list' as argument shows all the sample formats supported", "format" }, /* subtitle options */ { "sn", OPT_BOOL | OPT_SUBTITLE, {(void*)&subtitle_disable}, "disable subtitle" }, { "scodec", HAS_ARG | OPT_SUBTITLE, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" }, - { "newsubtitle", OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_new_stream}, "add a new subtitle stream to the current output stream" }, + { "newsubtitle", OPT_SUBTITLE, {(void*)opt_new_stream}, "add a new subtitle stream to the current output stream" }, { "slang", HAS_ARG | OPT_STRING | OPT_SUBTITLE, {(void *)&subtitle_language}, "set the ISO 639 language code (3 letters) of the current subtitle stream" , "code" }, - { "stag", OPT_FUNC2 | HAS_ARG | OPT_EXPERT | OPT_SUBTITLE, {(void*)opt_codec_tag}, "force subtitle tag/fourcc", "fourcc/tag" }, + { "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE, {(void*)opt_codec_tag}, "force subtitle tag/fourcc", "fourcc/tag" }, /* grab options */ - { "vc", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "set video grab channel (DV1394 only)", "channel" }, + { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "set video grab channel (DV1394 only)", "channel" }, { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_standard}, "set television standard (NTSC, PAL (SECAM))", "standard" }, { "isync", OPT_BOOL | OPT_EXPERT | OPT_GRAB, {(void*)&input_sync}, "sync read on input", "" }, @@ -4362,18 +4377,18 @@ static const OptionDef options[] = { { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_max_delay}, "set the maximum demux-decode delay", "seconds" }, { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_preload}, "set the initial demux-decode delay", "seconds" }, - { "absf", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" }, - { "vbsf", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" }, - { "sbsf", OPT_FUNC2 | HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" }, + { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" }, + { "vbsf", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" }, + { "sbsf", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" }, - { "apre", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_preset}, "set the audio options to the indicated preset", "preset" }, - { "vpre", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_preset}, "set the video options to the indicated preset", "preset" }, - { "spre", OPT_FUNC2 | HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_preset}, "set the subtitle options to the indicated preset", "preset" }, - { "fpre", OPT_FUNC2 | HAS_ARG | OPT_EXPERT, {(void*)opt_preset}, "set options from indicated preset file", "filename" }, + { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_preset}, "set the audio options to the indicated preset", "preset" }, + { "vpre", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_preset}, "set the video options to the indicated preset", "preset" }, + { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_preset}, "set the subtitle options to the indicated preset", "preset" }, + { "fpre", HAS_ARG | OPT_EXPERT, {(void*)opt_preset}, "set options from indicated preset file", "filename" }, /* data codec support */ { "dcodec", HAS_ARG | OPT_DATA, {(void*)opt_data_codec}, "force data codec ('copy' to copy stream)", "codec" }, - { "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, + { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, { NULL, }, }; diff --git a/ffplay.c b/ffplay.c index 3bcab5452b..e036bbdf94 100644 --- a/ffplay.c +++ b/ffplay.c @@ -2837,16 +2837,17 @@ static void event_loop(void) } } -static void opt_frame_size(const char *arg) +static int opt_frame_size(const char *opt, const char *arg) { if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) { fprintf(stderr, "Incorrect frame size\n"); - exit(1); + return AVERROR(EINVAL); } if ((frame_width % 2) != 0 || (frame_height % 2) != 0) { fprintf(stderr, "Frame size must be a multiple of 2\n"); - exit(1); + return AVERROR(EINVAL); } + return 0; } static int opt_width(const char *opt, const char *arg) @@ -2861,18 +2862,20 @@ static int opt_height(const char *opt, const char *arg) return 0; } -static void opt_format(const char *arg) +static int opt_format(const char *opt, const char *arg) { file_iformat = av_find_input_format(arg); if (!file_iformat) { fprintf(stderr, "Unknown input format: %s\n", arg); - exit(1); + return AVERROR(EINVAL); } + return 0; } -static void opt_frame_pix_fmt(const char *arg) +static int opt_frame_pix_fmt(const char *opt, const char *arg) { frame_pix_fmt = av_get_pix_fmt(arg); + return 0; } static int opt_sync(const char *opt, const char *arg) @@ -2926,8 +2929,8 @@ static int opt_thread_count(const char *opt, const char *arg) static const OptionDef options[] = { #include "cmdutils_common_opts.h" - { "x", HAS_ARG | OPT_FUNC2, {(void*)opt_width}, "force displayed width", "width" }, - { "y", HAS_ARG | OPT_FUNC2, {(void*)opt_height}, "force displayed height", "height" }, + { "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" }, @@ -2935,16 +2938,16 @@ static const OptionDef options[] = { { "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 | OPT_FUNC2, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" }, - { "t", HAS_ARG | OPT_FUNC2, {(void*)&opt_duration}, "play \"duration\" seconds of audio/video", "duration" }, + { "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_FUNC2 | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" }, + { "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_FUNC2 | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" }, + { "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", ""}, @@ -2955,8 +2958,8 @@ static const OptionDef options[] = { { "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_FUNC2 | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" }, - { "threads", HAS_ARG | OPT_FUNC2 | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" }, + { "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", "" }, @@ -2967,7 +2970,7 @@ static const OptionDef options[] = { { "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", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, + { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, { "i", 0, {NULL}, "ffmpeg compatibility dummy option", ""}, { NULL, }, }; diff --git a/ffprobe.c b/ffprobe.c index b5d19f06d6..508800e8d2 100644 --- a/ffprobe.c +++ b/ffprobe.c @@ -326,13 +326,14 @@ static void show_usage(void) printf("\n"); } -static void opt_format(const char *arg) +static int opt_format(const char *opt, const char *arg) { iformat = av_find_input_format(arg); if (!iformat) { fprintf(stderr, "Unknown input format: %s\n", arg); - exit(1); + return AVERROR(EINVAL); } + return 0; } static void opt_input_file(const char *arg) @@ -379,7 +380,7 @@ static const OptionDef options[] = { { "show_format", OPT_BOOL, {(void*)&do_show_format} , "show format/container info" }, { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" }, { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" }, - { "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, + { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, { NULL, }, }; From 8f653e28f54d6629c22a7135dff4c32dfc95acda Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 28 May 2011 02:39:20 +0200 Subject: [PATCH 12/27] lavu: add av_get_pix_fmt_name() convenience function Also deprecate avcodec_get_pix_fmt_name() in its favor. Signed-off-by: Ronald S. Bultje --- doc/APIchanges | 4 ++++ libavcodec/avcodec.h | 8 ++++++++ libavcodec/imgconvert.c | 7 +++---- libavcodec/version.h | 3 +++ libavutil/avutil.h | 2 +- libavutil/pixdesc.c | 6 ++++++ libavutil/pixdesc.h | 9 +++++++++ 7 files changed, 34 insertions(+), 5 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 90dd0ec10e..d0d4f4f798 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,10 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-05-XX - xxxxxx - lavu 51.X.0 - pixdesc.h + Add av_get_pix_fmt_name() in libavutil/pixdesc.h, and deprecate + avcodec_get_pix_fmt_name() in libavcodec/avcodec.h in its favor. + 2011-05-25 - 30315a8 - lavf 53.1.0 - avformat.h Add fps_probe_size to AVFormatContext. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index e067ee0273..ce3a4a6b94 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3306,7 +3306,15 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, */ int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height); void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift); + +#if FF_API_GET_PIX_FMT_NAME +/** + * @deprecated Deprecated in favor of av_get_pix_fmt_name(). + */ +attribute_deprecated const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt); +#endif + void avcodec_set_dimensions(AVCodecContext *s, int width, int height); /** diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c index 23e4318c71..351ed7ada7 100644 --- a/libavcodec/imgconvert.c +++ b/libavcodec/imgconvert.c @@ -417,13 +417,12 @@ void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int * *v_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h; } +#if FF_API_GET_PIX_FMT_NAME const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt) { - if ((unsigned)pix_fmt >= PIX_FMT_NB) - return NULL; - else - return av_pix_fmt_descriptors[pix_fmt].name; + return av_get_pix_fmt_name(pix_fmt); } +#endif int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt) { diff --git a/libavcodec/version.h b/libavcodec/version.h index 894188b093..aded68e83e 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -65,5 +65,8 @@ #ifndef FF_API_FLAC_GLOBAL_OPTS #define FF_API_FLAC_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_GET_PIX_FMT_NAME +#define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #endif /* AVCODEC_VERSION_H */ diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 43f0815fd2..8b8ca40c94 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -40,7 +40,7 @@ #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) #define LIBAVUTIL_VERSION_MAJOR 51 -#define LIBAVUTIL_VERSION_MINOR 1 +#define LIBAVUTIL_VERSION_MINOR 2 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index bff45e522a..77584755d6 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -906,6 +906,12 @@ static enum PixelFormat get_pix_fmt_internal(const char *name) return PIX_FMT_NONE; } +const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt) +{ + return (unsigned)pix_fmt < PIX_FMT_NB ? + av_pix_fmt_descriptors[pix_fmt].name : NULL; +} + #if HAVE_BIGENDIAN # define X_NE(be, le) be #else diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h index cb75641058..979a23539b 100644 --- a/libavutil/pixdesc.h +++ b/libavutil/pixdesc.h @@ -23,6 +23,7 @@ #define AVUTIL_PIXDESC_H #include +#include "pixfmt.h" typedef struct AVComponentDescriptor{ uint16_t plane :2; ///< which of the 4 planes contains the component @@ -141,6 +142,14 @@ void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesi */ enum PixelFormat av_get_pix_fmt(const char *name); +/** + * Return the short name for a pixel format, NULL in case pix_fmt is + * unknown. + * + * @see av_get_pix_fmt(), av_get_pix_fmt_string() + */ +const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt); + /** * Print in buf the string corresponding to the pixel format with * number pix_fmt, or an header if pix_fmt is negative. From 04de5bf56c1f1f946272f436d9c8cb82c63d30b4 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sat, 28 May 2011 09:46:42 -0400 Subject: [PATCH 13/27] APIchanges: fill in git hash for av_get_pix_fmt_name (0420bd7). --- doc/APIchanges | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index d0d4f4f798..a55b15284b 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,7 +13,7 @@ libavutil: 2011-04-18 API changes, most recent first: -2011-05-XX - xxxxxx - lavu 51.X.0 - pixdesc.h +2011-05-28 - 0420bd7 - lavu 51.2.0 - pixdesc.h Add av_get_pix_fmt_name() in libavutil/pixdesc.h, and deprecate avcodec_get_pix_fmt_name() in libavcodec/avcodec.h in its favor. From 7f7726c7a23f8ca9d8cd5d2511356d724d4284a3 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 27 May 2011 20:31:57 +0100 Subject: [PATCH 14/27] ac3enc: use LOCAL_ALIGNED macro Aligned local variables must use the LOCAL_ALIGNED macro to ensure correct alignment on all systems. The unusual size argument to memset is required since the implementation of LOCAL_ALIGNED may use a pointer to an array. Signed-off-by: Mans Rullgard --- libavcodec/ac3enc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 5285874caa..c85c69d248 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -546,12 +546,15 @@ static inline float calc_cpl_coord(float energy_ch, float energy_cpl) static void apply_channel_coupling(AC3EncodeContext *s) { #if CONFIG_AC3ENC_FLOAT - DECLARE_ALIGNED(16, float, cpl_coords) [AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}}; - DECLARE_ALIGNED(16, int32_t, fixed_cpl_coords)[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}}; + LOCAL_ALIGNED_16(float, cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]); + LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]); int blk, ch, bnd, i, j; CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}}; int num_cpl_coefs = s->num_cpl_subbands * 12; + memset(cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords)); + memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*fixed_cpl_coords)); + /* calculate coupling channel from fbw channels */ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; From a84f82560e3fa6aa41de64b0a5b75d1d607599aa Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 27 May 2011 21:43:15 +0100 Subject: [PATCH 15/27] ARM: improve FASTDIV asm This uses one register less. Also add missing "cc" clobber. Signed-off-by: Mans Rullgard --- libavutil/arm/intmath.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavutil/arm/intmath.h b/libavutil/arm/intmath.h index cc3de90f04..4340b59075 100644 --- a/libavutil/arm/intmath.h +++ b/libavutil/arm/intmath.h @@ -33,12 +33,12 @@ #define FASTDIV FASTDIV static av_always_inline av_const int FASTDIV(int a, int b) { - int r, t; - __asm__ ("cmp %3, #2 \n\t" - "ldr %1, [%4, %3, lsl #2] \n\t" - "lsrle %0, %2, #1 \n\t" - "smmulgt %0, %1, %2 \n\t" - : "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse)); + int r; + __asm__ ("cmp %2, #2 \n\t" + "ldr %0, [%3, %2, lsl #2] \n\t" + "lsrle %0, %1, #1 \n\t" + "smmulgt %0, %0, %1 \n\t" + : "=&r"(r) : "r"(a), "r"(b), "r"(ff_inverse) : "cc"); return r; } From 5726ec171bf7cb833f8445d9a294f23fc047a549 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 27 May 2011 21:59:46 +0100 Subject: [PATCH 16/27] ARM: add "cc" clobbers to inline asm where needed Signed-off-by: Mans Rullgard --- libavcodec/arm/aac.h | 2 +- libavcodec/arm/mathops.h | 3 ++- libavcodec/arm/vp56_arith.h | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libavcodec/arm/aac.h b/libavcodec/arm/aac.h index e907c9ea25..8355e9c193 100644 --- a/libavcodec/arm/aac.h +++ b/libavcodec/arm/aac.h @@ -128,7 +128,7 @@ static inline float *VMUL4S(float *dst, const float *v, unsigned idx, : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), "+r"(sign), "=r"(nz) : "r"(v), "r"(idx), "r"(scale) - : "d0", "d1", "d2", "d3", "d4", "d5"); + : "cc", "d0", "d1", "d2", "d3", "d4", "d5"); return dst; } diff --git a/libavcodec/arm/mathops.h b/libavcodec/arm/mathops.h index 1fce8e3267..858e73d677 100644 --- a/libavcodec/arm/mathops.h +++ b/libavcodec/arm/mathops.h @@ -107,7 +107,8 @@ static inline av_const int mid_pred(int a, int b, int c) "cmp %0, %1 \n\t" "movgt %0, %1 \n\t" : "=&r"(m), "+r"(a) - : "r"(b), "r"(c)); + : "r"(b), "r"(c) + : "cc"); return m; } diff --git a/libavcodec/arm/vp56_arith.h b/libavcodec/arm/vp56_arith.h index 0591d614a9..8785a77860 100644 --- a/libavcodec/arm/vp56_arith.h +++ b/libavcodec/arm/vp56_arith.h @@ -48,7 +48,8 @@ static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr) : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit), "+&r"(c->bits), "+&r"(c->buffer) : "r"(high), "r"(pr), "r"(c->end - 1), - "0"(shift), "1"(code_word)); + "0"(shift), "1"(code_word) + : "cc"); return bit; } @@ -74,7 +75,8 @@ static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr) "lsl %2, %0, #16 \n" : "=&r"(low), "+&r"(code_word), "=&r"(tmp), "+&r"(c->bits), "+&r"(c->buffer) - : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift)); + : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift) + : "cc"); if (code_word >= tmp) { c->high = high - low; From 84e4804ad08a6371e9368c7db8c5d9e2c81e175d Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 27 May 2011 22:49:28 +0100 Subject: [PATCH 17/27] ARM: remove unnecessary volatile from inline asm Signed-off-by: Mans Rullgard --- libavcodec/arm/mathops.h | 2 +- libavcodec/arm/vp56_arith.h | 66 ++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/libavcodec/arm/mathops.h b/libavcodec/arm/mathops.h index 858e73d677..3a7a1f3ee9 100644 --- a/libavcodec/arm/mathops.h +++ b/libavcodec/arm/mathops.h @@ -97,7 +97,7 @@ static inline av_const int MUL16(int ra, int rb) static inline av_const int mid_pred(int a, int b, int c) { int m; - __asm__ volatile ( + __asm__ ( "mov %0, %2 \n\t" "cmp %1, %2 \n\t" "movgt %0, %1 \n\t" diff --git a/libavcodec/arm/vp56_arith.h b/libavcodec/arm/vp56_arith.h index 8785a77860..9ce3fd0d91 100644 --- a/libavcodec/arm/vp56_arith.h +++ b/libavcodec/arm/vp56_arith.h @@ -31,25 +31,25 @@ static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr) unsigned high = c->high << shift; unsigned bit; - __asm__ volatile ("adds %3, %3, %0 \n" - "cmpcs %7, %4 \n" - "ldrcsh %2, [%4], #2 \n" - "rsb %0, %6, #256 \n" - "smlabb %0, %5, %6, %0 \n" - "rev16cs %2, %2 \n" - "orrcs %1, %1, %2, lsl %3 \n" - "subcs %3, %3, #16 \n" - "lsr %0, %0, #8 \n" - "cmp %1, %0, lsl #16 \n" - "subge %1, %1, %0, lsl #16 \n" - "subge %0, %5, %0 \n" - "movge %2, #1 \n" - "movlt %2, #0 \n" - : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit), - "+&r"(c->bits), "+&r"(c->buffer) - : "r"(high), "r"(pr), "r"(c->end - 1), - "0"(shift), "1"(code_word) - : "cc"); + __asm__ ("adds %3, %3, %0 \n" + "cmpcs %7, %4 \n" + "ldrcsh %2, [%4], #2 \n" + "rsb %0, %6, #256 \n" + "smlabb %0, %5, %6, %0 \n" + "rev16cs %2, %2 \n" + "orrcs %1, %1, %2, lsl %3 \n" + "subcs %3, %3, #16 \n" + "lsr %0, %0, #8 \n" + "cmp %1, %0, lsl #16 \n" + "subge %1, %1, %0, lsl #16 \n" + "subge %0, %5, %0 \n" + "movge %2, #1 \n" + "movlt %2, #0 \n" + : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit), + "+&r"(c->bits), "+&r"(c->buffer) + : "r"(high), "r"(pr), "r"(c->end - 1), + "0"(shift), "1"(code_word) + : "cc"); return bit; } @@ -63,20 +63,20 @@ static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr) unsigned low; unsigned tmp; - __asm__ volatile ("adds %3, %3, %0 \n" - "cmpcs %7, %4 \n" - "ldrcsh %2, [%4], #2 \n" - "rsb %0, %6, #256 \n" - "smlabb %0, %5, %6, %0 \n" - "rev16cs %2, %2 \n" - "orrcs %1, %1, %2, lsl %3 \n" - "subcs %3, %3, #16 \n" - "lsr %0, %0, #8 \n" - "lsl %2, %0, #16 \n" - : "=&r"(low), "+&r"(code_word), "=&r"(tmp), - "+&r"(c->bits), "+&r"(c->buffer) - : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift) - : "cc"); + __asm__ ("adds %3, %3, %0 \n" + "cmpcs %7, %4 \n" + "ldrcsh %2, [%4], #2 \n" + "rsb %0, %6, #256 \n" + "smlabb %0, %5, %6, %0 \n" + "rev16cs %2, %2 \n" + "orrcs %1, %1, %2, lsl %3 \n" + "subcs %3, %3, #16 \n" + "lsr %0, %0, #8 \n" + "lsl %2, %0, #16 \n" + : "=&r"(low), "+&r"(code_word), "=&r"(tmp), + "+&r"(c->bits), "+&r"(c->buffer) + : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift) + : "cc"); if (code_word >= tmp) { c->high = high - low; From 7d8c17b5f62bc14d5f7c7c792630b23240b47eec Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 27 May 2011 22:52:49 +0100 Subject: [PATCH 18/27] ARM: aacdec: fix constraints on inline asm This adds output operands for modified memory allowing the volatile qualifiers to be dropped. Signed-off-by: Mans Rullgard --- libavcodec/arm/aac.h | 153 ++++++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 75 deletions(-) diff --git a/libavcodec/arm/aac.h b/libavcodec/arm/aac.h index 8355e9c193..6d5df4933a 100644 --- a/libavcodec/arm/aac.h +++ b/libavcodec/arm/aac.h @@ -30,17 +30,17 @@ static inline float *VMUL2(float *dst, const float *v, unsigned idx, const float *scale) { unsigned v0, v1; - __asm__ volatile ("ubfx %0, %4, #0, #4 \n\t" - "ubfx %1, %4, #4, #4 \n\t" - "ldr %0, [%3, %0, lsl #2] \n\t" - "ldr %1, [%3, %1, lsl #2] \n\t" - "vld1.32 {d1[]}, [%5,:32] \n\t" - "vmov d0, %0, %1 \n\t" - "vmul.f32 d0, d0, d1 \n\t" - "vst1.32 {d0}, [%2,:64]! \n\t" - : "=&r"(v0), "=&r"(v1), "+r"(dst) - : "r"(v), "r"(idx), "r"(scale) - : "d0", "d1"); + __asm__ ("ubfx %0, %6, #0, #4 \n\t" + "ubfx %1, %6, #4, #4 \n\t" + "ldr %0, [%5, %0, lsl #2] \n\t" + "ldr %1, [%5, %1, lsl #2] \n\t" + "vld1.32 {d1[]}, [%7,:32] \n\t" + "vmov d0, %0, %1 \n\t" + "vmul.f32 d0, d0, d1 \n\t" + "vst1.32 {d0}, [%2,:64]! \n\t" + : "=&r"(v0), "=&r"(v1), "+r"(dst), "=m"(dst[0]), "=m"(dst[1]) + : "r"(v), "r"(idx), "r"(scale) + : "d0", "d1"); return dst; } @@ -49,22 +49,23 @@ static inline float *VMUL4(float *dst, const float *v, unsigned idx, const float *scale) { unsigned v0, v1, v2, v3; - __asm__ volatile ("ubfx %0, %6, #0, #2 \n\t" - "ubfx %1, %6, #2, #2 \n\t" - "ldr %0, [%5, %0, lsl #2] \n\t" - "ubfx %2, %6, #4, #2 \n\t" - "ldr %1, [%5, %1, lsl #2] \n\t" - "ubfx %3, %6, #6, #2 \n\t" - "ldr %2, [%5, %2, lsl #2] \n\t" - "vmov d0, %0, %1 \n\t" - "ldr %3, [%5, %3, lsl #2] \n\t" - "vld1.32 {d2[],d3[]},[%7,:32] \n\t" - "vmov d1, %2, %3 \n\t" - "vmul.f32 q0, q0, q1 \n\t" - "vst1.32 {q0}, [%4,:128]! \n\t" - : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst) - : "r"(v), "r"(idx), "r"(scale) - : "d0", "d1", "d2", "d3"); + __asm__ ("ubfx %0, %10, #0, #2 \n\t" + "ubfx %1, %10, #2, #2 \n\t" + "ldr %0, [%9, %0, lsl #2] \n\t" + "ubfx %2, %10, #4, #2 \n\t" + "ldr %1, [%9, %1, lsl #2] \n\t" + "ubfx %3, %10, #6, #2 \n\t" + "ldr %2, [%9, %2, lsl #2] \n\t" + "vmov d0, %0, %1 \n\t" + "ldr %3, [%9, %3, lsl #2] \n\t" + "vld1.32 {d2[],d3[]},[%11,:32] \n\t" + "vmov d1, %2, %3 \n\t" + "vmul.f32 q0, q0, q1 \n\t" + "vst1.32 {q0}, [%4,:128]! \n\t" + : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), + "=m"(dst[0]), "=m"(dst[1]), "=m"(dst[2]), "=m"(dst[3]) + : "r"(v), "r"(idx), "r"(scale) + : "d0", "d1", "d2", "d3"); return dst; } @@ -73,22 +74,23 @@ static inline float *VMUL2S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale) { unsigned v0, v1, v2, v3; - __asm__ volatile ("ubfx %0, %6, #0, #4 \n\t" - "ubfx %1, %6, #4, #4 \n\t" - "ldr %0, [%5, %0, lsl #2] \n\t" - "lsl %2, %8, #30 \n\t" - "ldr %1, [%5, %1, lsl #2] \n\t" - "lsl %3, %8, #31 \n\t" - "vmov d0, %0, %1 \n\t" - "bic %2, %2, #1<<30 \n\t" - "vld1.32 {d1[]}, [%7,:32] \n\t" - "vmov d2, %2, %3 \n\t" - "veor d0, d0, d2 \n\t" - "vmul.f32 d0, d0, d1 \n\t" - "vst1.32 {d0}, [%4,:64]! \n\t" - : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst) - : "r"(v), "r"(idx), "r"(scale), "r"(sign) - : "d0", "d1", "d2"); + __asm__ ("ubfx %0, %8, #0, #4 \n\t" + "ubfx %1, %8, #4, #4 \n\t" + "ldr %0, [%7, %0, lsl #2] \n\t" + "lsl %2, %10, #30 \n\t" + "ldr %1, [%7, %1, lsl #2] \n\t" + "lsl %3, %10, #31 \n\t" + "vmov d0, %0, %1 \n\t" + "bic %2, %2, #1<<30 \n\t" + "vld1.32 {d1[]}, [%9,:32] \n\t" + "vmov d2, %2, %3 \n\t" + "veor d0, d0, d2 \n\t" + "vmul.f32 d0, d0, d1 \n\t" + "vst1.32 {d0}, [%4,:64]! \n\t" + : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), + "=m"(dst[0]), "=m"(dst[1]) + : "r"(v), "r"(idx), "r"(scale), "r"(sign) + : "d0", "d1", "d2"); return dst; } @@ -97,38 +99,39 @@ static inline float *VMUL4S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale) { unsigned v0, v1, v2, v3, nz; - __asm__ volatile ("vld1.32 {d2[],d3[]},[%9,:32] \n\t" - "ubfx %0, %8, #0, #2 \n\t" - "ubfx %1, %8, #2, #2 \n\t" - "ldr %0, [%7, %0, lsl #2] \n\t" - "ubfx %2, %8, #4, #2 \n\t" - "ldr %1, [%7, %1, lsl #2] \n\t" - "ubfx %3, %8, #6, #2 \n\t" - "ldr %2, [%7, %2, lsl #2] \n\t" - "vmov d0, %0, %1 \n\t" - "ldr %3, [%7, %3, lsl #2] \n\t" - "lsr %6, %8, #12 \n\t" - "rbit %6, %6 \n\t" - "vmov d1, %2, %3 \n\t" - "lsls %6, %6, #1 \n\t" - "and %0, %5, #1<<31 \n\t" - "lslcs %5, %5, #1 \n\t" - "lsls %6, %6, #1 \n\t" - "and %1, %5, #1<<31 \n\t" - "lslcs %5, %5, #1 \n\t" - "lsls %6, %6, #1 \n\t" - "and %2, %5, #1<<31 \n\t" - "lslcs %5, %5, #1 \n\t" - "vmov d4, %0, %1 \n\t" - "and %3, %5, #1<<31 \n\t" - "vmov d5, %2, %3 \n\t" - "veor q0, q0, q2 \n\t" - "vmul.f32 q0, q0, q1 \n\t" - "vst1.32 {q0}, [%4,:128]! \n\t" - : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), - "+r"(sign), "=r"(nz) - : "r"(v), "r"(idx), "r"(scale) - : "cc", "d0", "d1", "d2", "d3", "d4", "d5"); + __asm__ ("vld1.32 {d2[],d3[]},[%13,:32] \n\t" + "ubfx %0, %12, #0, #2 \n\t" + "ubfx %1, %12, #2, #2 \n\t" + "ldr %0, [%11,%0, lsl #2] \n\t" + "ubfx %2, %12, #4, #2 \n\t" + "ldr %1, [%11,%1, lsl #2] \n\t" + "ubfx %3, %12, #6, #2 \n\t" + "ldr %2, [%11,%2, lsl #2] \n\t" + "vmov d0, %0, %1 \n\t" + "ldr %3, [%11,%3, lsl #2] \n\t" + "lsr %6, %12, #12 \n\t" + "rbit %6, %6 \n\t" + "vmov d1, %2, %3 \n\t" + "lsls %6, %6, #1 \n\t" + "and %0, %5, #1<<31 \n\t" + "lslcs %5, %5, #1 \n\t" + "lsls %6, %6, #1 \n\t" + "and %1, %5, #1<<31 \n\t" + "lslcs %5, %5, #1 \n\t" + "lsls %6, %6, #1 \n\t" + "and %2, %5, #1<<31 \n\t" + "lslcs %5, %5, #1 \n\t" + "vmov d4, %0, %1 \n\t" + "and %3, %5, #1<<31 \n\t" + "vmov d5, %2, %3 \n\t" + "veor q0, q0, q2 \n\t" + "vmul.f32 q0, q0, q1 \n\t" + "vst1.32 {q0}, [%4,:128]! \n\t" + : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), + "+r"(sign), "=r"(nz), + "=m"(dst[0]), "=m"(dst[1]), "=m"(dst[2]), "=m"(dst[3]) + : "r"(v), "r"(idx), "r"(scale) + : "cc", "d0", "d1", "d2", "d3", "d4", "d5"); return dst; } From b8e893399ff8755721dc117695ec5ff183c1e07b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 26 May 2011 18:57:26 +0200 Subject: [PATCH 19/27] sws: replace all long with int. Signed-off-by: Ronald S. Bultje --- libswscale/bfin/internal_bfin.S | 8 +- libswscale/bfin/swscale_bfin.c | 8 +- libswscale/colorspace-test.c | 2 +- libswscale/ppc/swscale_altivec_template.c | 4 +- libswscale/ppc/swscale_template.c | 4 +- libswscale/ppc/yuv2rgb_altivec.c | 2 +- libswscale/rgb2rgb.c | 148 +++++++++---------- libswscale/rgb2rgb.h | 130 ++++++++--------- libswscale/rgb2rgb_template.c | 170 +++++++++++----------- libswscale/swscale.c | 52 +++---- libswscale/swscale.h | 4 +- libswscale/swscale_internal.h | 18 +-- libswscale/swscale_template.c | 52 +++---- libswscale/x86/rgb2rgb_template.c | 146 +++++++++---------- libswscale/x86/swscale_template.c | 68 ++++----- 15 files changed, 408 insertions(+), 408 deletions(-) diff --git a/libswscale/bfin/internal_bfin.S b/libswscale/bfin/internal_bfin.S index dea23215a0..9f985e7824 100644 --- a/libswscale/bfin/internal_bfin.S +++ b/libswscale/bfin/internal_bfin.S @@ -466,8 +466,8 @@ DEFUN_END(yuv2rgb24_line) #define ARG_srcStride 40 DEFUN(uyvytoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride)): + int width, int height, + int lumStride, int chromStride, int srcStride)): link 0; [--sp] = (r7:4,p5:4); @@ -539,8 +539,8 @@ DEFUN(uyvytoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8 DEFUN_END(uyvytoyv12) DEFUN(yuyvtoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride)): + int width, int height, + int lumStride, int chromStride, int srcStride)): link 0; [--sp] = (r7:4,p5:4); diff --git a/libswscale/bfin/swscale_bfin.c b/libswscale/bfin/swscale_bfin.c index 60b7f8310b..c8030ba29f 100644 --- a/libswscale/bfin/swscale_bfin.c +++ b/libswscale/bfin/swscale_bfin.c @@ -38,12 +38,12 @@ #endif int ff_bfin_uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride) L1CODE; + int width, int height, + int lumStride, int chromStride, int srcStride) L1CODE; int ff_bfin_yuyvtoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride) L1CODE; + int width, int height, + int lumStride, int chromStride, int srcStride) L1CODE; static int uyvytoyv12_unscaled(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) diff --git a/libswscale/colorspace-test.c b/libswscale/colorspace-test.c index 4ed9164323..07c1cbd803 100644 --- a/libswscale/colorspace-test.c +++ b/libswscale/colorspace-test.c @@ -52,7 +52,7 @@ int main(int argc, char **argv) int src_bpp; int dst_bpp; const char *name; - void (*func)(const uint8_t *src, uint8_t *dst, long src_size); + void (*func)(const uint8_t *src, uint8_t *dst, int src_size); } func_info[] = { FUNC(2, 2, rgb15to16), FUNC(2, 3, rgb15to24), diff --git a/libswscale/ppc/swscale_altivec_template.c b/libswscale/ppc/swscale_altivec_template.c index eee7bdd0a5..21e3b4eafb 100644 --- a/libswscale/ppc/swscale_altivec_template.c +++ b/libswscale/ppc/swscale_altivec_template.c @@ -29,13 +29,13 @@ altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) register int i; vector unsigned int altivec_vectorShiftInt19 = vec_add(vec_splat_u32(10), vec_splat_u32(9)); - if ((unsigned long)dest % 16) { + if ((unsigned int)dest % 16) { /* badly aligned store, we force store alignment */ /* and will handle load misalignment on val w/ vec_perm */ vector unsigned char perm1; vector signed int v1; for (i = 0 ; (i < dstW) && - (((unsigned long)dest + i) % 16) ; i++) { + (((unsigned int)dest + i) % 16) ; i++) { int t = val[i] >> 19; dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); } diff --git a/libswscale/ppc/swscale_template.c b/libswscale/ppc/swscale_template.c index 0fe97a1114..ca6777144d 100644 --- a/libswscale/ppc/swscale_template.c +++ b/libswscale/ppc/swscale_template.c @@ -30,7 +30,7 @@ static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, - uint8_t *aDest, long dstW, long chrDstW) + uint8_t *aDest, int dstW, int chrDstW) { yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize, chrFilter, chrUSrc, chrVSrc, chrFilterSize, @@ -45,7 +45,7 @@ static inline void RENAME(yuv2packedX)(SwsContext *c, const int16_t *lumFilter, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, - long dstW, long dstY) + int dstW, int dstY) { /* The following list of supported dstFormat values should match what's found in the body of ff_yuv2packedX_altivec() */ diff --git a/libswscale/ppc/yuv2rgb_altivec.c b/libswscale/ppc/yuv2rgb_altivec.c index abd49c9e96..0cc0d3084d 100644 --- a/libswscale/ppc/yuv2rgb_altivec.c +++ b/libswscale/ppc/yuv2rgb_altivec.c @@ -793,7 +793,7 @@ ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter, vector signed short RND = vec_splat_s16(1<<3); vector unsigned short SCL = vec_splat_u16(4); - DECLARE_ALIGNED(16, unsigned long, scratch)[16]; + DECLARE_ALIGNED(16, unsigned int, scratch)[16]; vector signed short *YCoeffs, *CCoeffs; diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c index e18cd51011..51cb600e6b 100644 --- a/libswscale/rgb2rgb.c +++ b/libswscale/rgb2rgb.c @@ -29,70 +29,70 @@ #include "swscale.h" #include "swscale_internal.h" -void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size); -void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); -void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size); +void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); +void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + int width, int height, + int lumStride, int chromStride, int dstStride); void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + int width, int height, + int lumStride, int chromStride, int dstStride); void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + int width, int height, + int lumStride, int chromStride, int dstStride); void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + int width, int height, + int lumStride, int chromStride, int dstStride); void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride); + int width, int height, + int lumStride, int chromStride, int srcStride); void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride); -void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, - long srcStride, long dstStride); + int width, int height, + int lumStride, int chromStride, int srcStride); +void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, + int srcStride, int dstStride); void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, - long width, long height, long src1Stride, - long src2Stride, long dstStride); + int width, int height, int src1Stride, + int src2Stride, int dstStride); void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst1, uint8_t *dst2, - long width, long height, - long srcStride1, long srcStride2, - long dstStride1, long dstStride2); + int width, int height, + int srcStride1, int srcStride2, + int dstStride1, int dstStride2); void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, uint8_t *dst, - long width, long height, - long srcStride1, long srcStride2, - long srcStride3, long dstStride); + int width, int height, + int srcStride1, int srcStride2, + int srcStride3, int dstStride); void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, - long width, long height, - long lumStride, long chromStride, long srcStride); + int width, int height, + int lumStride, int chromStride, int srcStride); void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, - long width, long height, - long lumStride, long chromStride, long srcStride); + int width, int height, + int lumStride, int chromStride, int srcStride); void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, - long width, long height, - long lumStride, long chromStride, long srcStride); + int width, int height, + int lumStride, int chromStride, int srcStride); void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, - long width, long height, - long lumStride, long chromStride, long srcStride); + int width, int height, + int lumStride, int chromStride, int srcStride); #define RGB2YUV_SHIFT 8 #define BY ((int)( 0.098*(1<> 2; + int i; + int num_pixels = src_size >> 2; for (i=0; i BGR24 (= B,G,R) */ @@ -141,9 +141,9 @@ void rgb32to24(const uint8_t *src, uint8_t *dst, long src_size) } } -void rgb24to32(const uint8_t *src, uint8_t *dst, long src_size) +void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size) { - long i; + int i; for (i=0; 3*i BGR32 (= A,R,G,B) */ @@ -160,7 +160,7 @@ void rgb24to32(const uint8_t *src, uint8_t *dst, long src_size) } } -void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size) +void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; uint8_t *d = dst; @@ -183,7 +183,7 @@ void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size) } } -void rgb16to24(const uint8_t *src, uint8_t *dst, long src_size) +void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; uint8_t *d = dst; @@ -198,10 +198,10 @@ void rgb16to24(const uint8_t *src, uint8_t *dst, long src_size) } } -void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size) +void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size) { - long i; - long num_pixels = src_size >> 1; + int i; + int num_pixels = src_size >> 1; for (i=0; i> 1; + int i; + int num_pixels = src_size >> 1; for (i=0; i> 1; + int i; + int num_pixels = src_size >> 1; for (i=0; i> 1; + int i; + int num_pixels = src_size >> 1; for (i=0; i -static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, int src_size) { uint8_t *dest = dst; const uint8_t *s = src; @@ -50,7 +50,7 @@ static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, long src_siz } } -static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) { uint8_t *dest = dst; const uint8_t *s = src; @@ -81,7 +81,7 @@ static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, long src_siz MMX2, 3DNOW optimization by Nick Kurshev 32-bit C version, and and&add trick by Michael Niedermayer */ -static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, int src_size) { register const uint8_t* s=src; register uint8_t* d=dst; @@ -101,7 +101,7 @@ static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, long src_size) } } -static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, int src_size) { register const uint8_t* s=src; register uint8_t* d=dst; @@ -122,7 +122,7 @@ static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, long src_size) } } -static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -135,7 +135,7 @@ static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, long src_size) } } -static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -147,7 +147,7 @@ static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, long src_siz } } -static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -159,7 +159,7 @@ static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, long src_size) } } -static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -171,7 +171,7 @@ static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, long src_siz } } -static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -185,7 +185,7 @@ static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, long src_siz } } -static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -199,7 +199,7 @@ static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, long src_size) } } -static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -213,7 +213,7 @@ static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, long src_siz } } -static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -248,7 +248,7 @@ static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, long src_size) | original bits */ -static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; uint8_t *d = dst; @@ -263,7 +263,7 @@ static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, long src_siz } } -static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; uint8_t *d = (uint8_t *)dst; @@ -278,7 +278,7 @@ static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, long src_siz } } -static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; uint8_t *d = dst; @@ -301,7 +301,7 @@ static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, long src_size) } } -static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; uint8_t *d = dst; @@ -324,7 +324,7 @@ static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, long src_size) } } -static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, int src_size) { int idx = 15 - src_size; const uint8_t *s = src-idx; @@ -336,7 +336,7 @@ static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, long s } } -static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, long src_size) +static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) { unsigned i; for (i=0; i> 1; for (y=0; y> 1; for (y=0; y> 1; for (y=0; y> 1; for (y=0; y> 1; y=0; for (; y>1); @@ -732,12 +732,12 @@ static inline void vu9_to_vu12_c(const uint8_t *src1, const uint8_t *src2, static inline void yvu9_to_yuy2_c(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, uint8_t *dst, - long width, long height, - long srcStride1, long srcStride2, - long srcStride3, long dstStride) + int width, int height, + int srcStride1, int srcStride2, + int srcStride3, int dstStride) { int x; - long y,w,h; + int y,w,h; w=width/2; h=height; for (y=0;y>1); + int y; + const int chromWidth= -((-width)>>1); for (y=0; y>1); + int y; + const int chromWidth= -((-width)>>1); for (y=0; y>1); + int y; + const int chromWidth= -((-width)>>1); for (y=0; y>1); + int y; + const int chromWidth= -((-width)>>1); for (y=0; y>(S);\ }\ }\ -static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\ +static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\ {\ int i;\ for (i=0; isrcFormat; const enum PixelFormat dstFormat= c->dstFormat; - void (*conv)(const uint8_t *src, uint8_t *dst, long num_pixels, + void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)=NULL; int i; uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; @@ -1455,7 +1455,7 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], const int dstBpp= (c->dstFormatBpp + 7) >> 3; const int srcId= c->srcFormatBpp >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */ const int dstId= c->dstFormatBpp >> 2; - void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL; + void (*conv)(const uint8_t *src, uint8_t *dst, int src_size)=NULL; #define CONV_IS(src, dst) (srcFormat == PIX_FMT_##src && dstFormat == PIX_FMT_##dst) @@ -2057,18 +2057,18 @@ int sws_scale(SwsContext *c, const uint8_t* const src[], const int srcStride[], } /* Convert the palette to the same packed 32-bit format as the palette */ -void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) +void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette) { - long i; + int i; for (i=0; i dst format: ABC */ -void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) +void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette) { - long i; + int i; for (i=0; i>14; } -static inline void hyscale_fast_c(SwsContext *c, int16_t *dst, long dstWidth, +static inline void hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc) { int i; @@ -394,14 +394,14 @@ static inline void hyscale_fast_c(SwsContext *c, int16_t *dst, long dstWidth, } // *** horizontal scale Y line to temp buffer -static inline void hyscale_c(SwsContext *c, uint16_t *dst, long dstWidth, +static inline void hyscale_c(SwsContext *c, uint16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc, const int16_t *hLumFilter, const int16_t *hLumFilterPos, int hLumFilterSize, uint8_t *formatConvBuffer, uint32_t *pal, int isAlpha) { - void (*toYV12)(uint8_t *, const uint8_t *, long, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12; + void (*toYV12)(uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12; void (*convertRange)(uint16_t *, int) = isAlpha ? NULL : c->lumConvertRange; src += isAlpha ? c->alpSrcOffset : c->lumSrcOffset; @@ -422,7 +422,7 @@ static inline void hyscale_c(SwsContext *c, uint16_t *dst, long dstWidth, } static inline void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2, - long dstWidth, const uint8_t *src1, + int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { int i; @@ -436,7 +436,7 @@ static inline void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2, } } -inline static void hcscale_c(SwsContext *c, uint16_t *dst1, uint16_t *dst2, long dstWidth, +inline static void hcscale_c(SwsContext *c, uint16_t *dst1, uint16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc, const int16_t *hChrFilter, const int16_t *hChrFilterPos, int hChrFilterSize, diff --git a/libswscale/x86/rgb2rgb_template.c b/libswscale/x86/rgb2rgb_template.c index 70673f75d1..c255610193 100644 --- a/libswscale/x86/rgb2rgb_template.c +++ b/libswscale/x86/rgb2rgb_template.c @@ -61,7 +61,7 @@ #if !COMPILE_TEMPLATE_AMD3DNOW -static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size) { uint8_t *dest = dst; const uint8_t *s = src; @@ -143,7 +143,7 @@ static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long s MOVNTQ" %%mm4, 16%0" -static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size) { uint8_t *dest = dst; const uint8_t *s = src; @@ -186,7 +186,7 @@ static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long s MMX2, 3DNOW optimization by Nick Kurshev 32-bit C version, and and&add trick by Michael Niedermayer */ -static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size) { register const uint8_t* s=src; register uint8_t* d=dst; @@ -230,7 +230,7 @@ static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_ } } -static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size) { register const uint8_t* s=src; register uint8_t* d=dst; @@ -279,7 +279,7 @@ static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, long src_ } } -static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -371,7 +371,7 @@ static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, long src_ } } -static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -426,7 +426,7 @@ static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long s } } -static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -518,7 +518,7 @@ static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_ } } -static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -573,7 +573,7 @@ static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long s } } -static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -630,7 +630,7 @@ static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long s } } -static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -687,7 +687,7 @@ static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_ } } -static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -744,7 +744,7 @@ static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long s } } -static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size) { const uint8_t *s = src; const uint8_t *end; @@ -822,7 +822,7 @@ static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_ | original bits */ -static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; const uint16_t *mm_end; @@ -925,7 +925,7 @@ static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long s } } -static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; const uint16_t *mm_end; @@ -1046,7 +1046,7 @@ static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long s MOVNTQ" %%mm0, %0 \n\t" \ MOVNTQ" %%mm3, 8%0 \n\t" \ -static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; const uint16_t *mm_end; @@ -1088,7 +1088,7 @@ static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_ } } -static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size) { const uint16_t *end; const uint16_t *mm_end; @@ -1130,7 +1130,7 @@ static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_ } } -static inline void RENAME(shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size) { x86_reg idx = 15 - src_size; const uint8_t *s = src-idx; @@ -1192,7 +1192,7 @@ static inline void RENAME(shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, } } -static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) +static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size) { unsigned i; x86_reg mmx_size= 23 - src_size; @@ -1260,10 +1260,10 @@ static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long s } static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride, long vertLumPerChroma) + int width, int height, + int lumStride, int chromStride, int dstStride, int vertLumPerChroma) { - long y; + int y; const x86_reg chromWidth= width>>1; for (y=0; y>1; for (y=0; y>1; for (y=0; y>1; for (y=0; y>1; for (y=0; y>1); + int y; + const int chromWidth= -((-width)>>1); for (y=0; y>1); + int y; + const int chromWidth= -((-width)>>1); for (y=0; y>1); + int y; + const int chromWidth= -((-width)>>1); for (y=0; y>1); + int y; + const int chromWidth= -((-width)>>1); for (y=0; yuv_off; @@ -159,7 +159,7 @@ static inline void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, - uint8_t *aDest, long dstW, long chrDstW) + uint8_t *aDest, int dstW, int chrDstW) { if (uDest) { x86_reg uv_off = c->uv_off; @@ -190,9 +190,9 @@ static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc, const int16_t *chrUSrc, const int16_t *chrVSrc, const int16_t *alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, - uint8_t *aDest, long dstW, long chrDstW) + uint8_t *aDest, int dstW, int chrDstW) { - long p= 4; + int p= 4; const uint8_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW }; uint8_t *dst[4]= { aDest, dest, uDest, vDest }; x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW }; @@ -231,9 +231,9 @@ static inline void RENAME(yuv2yuv1_ar)(SwsContext *c, const int16_t *lumSrc, const int16_t *chrUSrc, const int16_t *chrVSrc, const int16_t *alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, - uint8_t *aDest, long dstW, long chrDstW) + uint8_t *aDest, int dstW, int chrDstW) { - long p= 4; + int p= 4; const uint8_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW }; uint8_t *dst[4]= { aDest, dest, uDest, vDest }; x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW }; @@ -471,7 +471,7 @@ static inline void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilte const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -504,7 +504,7 @@ static inline void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -561,7 +561,7 @@ static inline void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilt const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -585,7 +585,7 @@ static inline void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -638,7 +638,7 @@ static inline void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilt const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -662,7 +662,7 @@ static inline void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -795,7 +795,7 @@ static inline void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilte const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -819,7 +819,7 @@ static inline void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -860,7 +860,7 @@ static inline void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFil const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -881,7 +881,7 @@ static inline void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, - uint8_t *dest, long dstW, long dstY) + uint8_t *dest, int dstW, int dstY) { x86_reg dummy=0; x86_reg dstW_reg = dstW; @@ -1578,7 +1578,7 @@ static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0, #if !COMPILE_TEMPLATE_MMX2 //FIXME yuy2* can read up to 7 samples too much -static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) +static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused) { __asm__ volatile( "movq "MANGLE(bm01010101)", %%mm2 \n\t" @@ -1597,7 +1597,7 @@ static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, long width, ); } -static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { __asm__ volatile( "movq "MANGLE(bm01010101)", %%mm4 \n\t" @@ -1623,7 +1623,7 @@ static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t assert(src1 == src2); } -static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { __asm__ volatile( "mov %0, %%"REG_a" \n\t" @@ -1649,7 +1649,7 @@ static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *s /* This is almost identical to the previous, end exists only because * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */ -static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) +static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused) { __asm__ volatile( "mov %0, %%"REG_a" \n\t" @@ -1667,7 +1667,7 @@ static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, long width, ); } -static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { __asm__ volatile( "movq "MANGLE(bm01010101)", %%mm4 \n\t" @@ -1693,7 +1693,7 @@ static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t assert(src1 == src2); } -static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { __asm__ volatile( "movq "MANGLE(bm01010101)", %%mm4 \n\t" @@ -1719,7 +1719,7 @@ static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *s } static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2, - const uint8_t *src, long width) + const uint8_t *src, int width) { __asm__ volatile( "movq "MANGLE(bm01010101)", %%mm4 \n\t" @@ -1746,20 +1746,20 @@ static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2, static inline void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, - long width, uint32_t *unused) + int width, uint32_t *unused) { RENAME(nvXXtoUV)(dstU, dstV, src1, width); } static inline void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, - long width, uint32_t *unused) + int width, uint32_t *unused) { RENAME(nvXXtoUV)(dstV, dstU, src1, width); } #endif /* !COMPILE_TEMPLATE_MMX2 */ -static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, long width, enum PixelFormat srcFormat) +static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, int width, enum PixelFormat srcFormat) { if(srcFormat == PIX_FMT_BGR24) { @@ -1812,7 +1812,7 @@ static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, long w ); } -static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, long width, enum PixelFormat srcFormat) +static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, int width, enum PixelFormat srcFormat) { __asm__ volatile( "movq 24(%4), %%mm6 \n\t" @@ -1870,23 +1870,23 @@ static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uin ); } -static inline void RENAME(bgr24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) +static inline void RENAME(bgr24ToY)(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused) { RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24); } -static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24); assert(src1 == src2); } -static inline void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) +static inline void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused) { RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24); } -static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { assert(src1==src2); RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24); @@ -1895,7 +1895,7 @@ static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t #if !COMPILE_TEMPLATE_MMX2 // bilinear / bicubic scaling static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW, int xInc, - const int16_t *filter, const int16_t *filterPos, long filterSize) + const int16_t *filter, const int16_t *filterPos, int filterSize) { assert(filterSize % 4 == 0 && filterSize>0); if (filterSize==4) { // Always true for upscaling, sometimes for down, too. @@ -2051,7 +2051,7 @@ static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, in #if COMPILE_TEMPLATE_MMX2 static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst, - long dstWidth, const uint8_t *src, int srcW, + int dstWidth, const uint8_t *src, int srcW, int xInc) { int32_t *filterPos = c->hLumFilterPos; @@ -2123,7 +2123,7 @@ static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst, } static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2, - long dstWidth, const uint8_t *src1, + int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { int32_t *filterPos = c->hChrFilterPos; From e01e05ee66f7ea26dd7574501e329aa5b8e788ef Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 28 May 2011 15:46:55 +0100 Subject: [PATCH 20/27] get_bits: add av_unused tag to cache variable This silences numerous compiler warnings from skip_bits(), where the cache variable is not used. Signed-off-by: Mans Rullgard --- libavcodec/get_bits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index 185ff316bb..4136498c71 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -127,7 +127,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc # define OPEN_READER(name, gb) \ unsigned int name##_index = (gb)->index; \ - unsigned int name##_cache = 0 + unsigned int av_unused name##_cache = 0 # define CLOSE_READER(name, gb) (gb)->index = name##_index From 7743865ffcb921a78a913b3de5a6d80248954d71 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 26 May 2011 15:57:21 -0400 Subject: [PATCH 21/27] ac3enc: store per-block/channel bap pointers by reference block in a 2D array rather than in the AC3Block struct. This will make it easier to access the bap values without having to chase the reference block pointers each time. --- libavcodec/ac3enc.c | 52 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index c85c69d248..1faafb61d6 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -107,7 +107,6 @@ typedef struct AC3EncOptions { * Data for a single audio block. */ typedef struct AC3Block { - uint8_t **bap; ///< bit allocation pointers (bap) CoefType **mdct_coef; ///< MDCT coefficients int32_t **fixed_coef; ///< fixed-point MDCT coefficients uint8_t **exp; ///< original exponents @@ -122,7 +121,6 @@ typedef struct AC3Block { uint8_t new_rematrixing_strategy; ///< send new rematrixing flags in this block int num_rematrixing_bands; ///< number of rematrixing bands uint8_t rematrixing_flags[4]; ///< rematrixing flags - struct AC3Block *exp_ref_block[AC3_MAX_CHANNELS]; ///< reference blocks for EXP_REUSE int new_cpl_strategy; ///< send new coupling strategy int cpl_in_use; ///< coupling in use for this block (cplinu) uint8_t channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling (chincpl) @@ -219,6 +217,9 @@ typedef struct AC3EncodeContext { uint8_t *cpl_coord_mant_buffer; uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies + uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< reference blocks for EXP_REUSE + uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap) + int ref_bap_set; ///< indicates if ref_bap pointers have been set DECLARE_ALIGNED(32, SampleType, windowed_samples)[AC3_WINDOW_SIZE]; } AC3EncodeContext; @@ -1073,10 +1074,10 @@ static void encode_exponents(AC3EncodeContext *s) blk1 = blk + 1; /* count the number of EXP_REUSE blocks after the current block - and set exponent reference block pointers */ - block->exp_ref_block[ch] = block; + and set exponent reference block numbers */ + s->exp_ref_block[ch][blk] = blk; while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE) { - s->blocks[blk1].exp_ref_block[ch] = block; + s->exp_ref_block[ch][blk1] = blk; blk1++; } num_reuse_blocks = blk1 - blk - 1; @@ -1091,6 +1092,9 @@ static void encode_exponents(AC3EncodeContext *s) blk = blk1; } } + + /* reference block numbers have been changed, so reset ref_bap_set */ + s->ref_bap_set = 0; } @@ -1472,14 +1476,18 @@ static void bit_alloc_masking(AC3EncodeContext *s) static void reset_block_bap(AC3EncodeContext *s) { int blk, ch; - int channels = s->channels + 1; - if (s->blocks[0].bap[0] == s->bap_buffer) + uint8_t *ref_bap; + + if (s->ref_bap[0][0] == s->bap_buffer && s->ref_bap_set) return; - for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { - for (ch = 0; ch < channels; ch++) { - s->blocks[blk].bap[ch] = &s->bap_buffer[AC3_MAX_COEFS * (blk * channels + ch)]; - } + + ref_bap = s->bap_buffer; + for (ch = 0; ch <= s->channels; ch++) { + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) + s->ref_bap[ch][blk] = ref_bap + AC3_MAX_COEFS * s->exp_ref_block[ch][blk]; + ref_bap += AC3_MAX_COEFS * AC3_MAX_BLOCKS; } + s->ref_bap_set = 1; } @@ -1502,7 +1510,6 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset) mantissa_bits = 0; for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; - AC3Block *ref_block; int av_uninit(ch0); int got_cpl = !block->cpl_in_use; // initialize grouped mantissa counts. these are set so that they are @@ -1522,15 +1529,14 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset) blocks within a frame are the exponent values. We can take advantage of that by reusing the bit allocation pointers whenever we reuse exponents. */ - ref_block = block->exp_ref_block[ch]; if (s->exp_strategy[ch][blk] != EXP_REUSE) { - s->ac3dsp.bit_alloc_calc_bap(ref_block->mask[ch], ref_block->psd[ch], + s->ac3dsp.bit_alloc_calc_bap(block->mask[ch], block->psd[ch], s->start_freq[ch], block->end_freq[ch], snr_offset, s->bit_alloc.floor, - ff_ac3_bap_tab, ref_block->bap[ch]); + ff_ac3_bap_tab, s->ref_bap[ch][blk]); } mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt, - ref_block->bap[ch]+s->start_freq[ch], + s->ref_bap[ch][blk]+s->start_freq[ch], block->end_freq[ch]-s->start_freq[ch]); if (ch == CPL_CH) ch = ch0; @@ -1812,7 +1818,6 @@ static void quantize_mantissas(AC3EncodeContext *s) for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; - AC3Block *ref_block; AC3Mant m = { 0 }; got_cpl = !block->cpl_in_use; @@ -1822,10 +1827,9 @@ static void quantize_mantissas(AC3EncodeContext *s) ch = CPL_CH; got_cpl = 1; } - ref_block = block->exp_ref_block[ch]; quantize_mantissas_blk_ch(&m, block->fixed_coef[ch], - ref_block->exp[ch], - ref_block->bap[ch], block->qmant[ch], + s->blocks[s->exp_ref_block[ch][blk]].exp[ch], + s->ref_bap[ch][blk], block->qmant[ch], s->start_freq[ch], block->end_freq[ch]); if (ch == CPL_CH) ch = ch0; @@ -2130,17 +2134,15 @@ static void output_audio_block(AC3EncodeContext *s, int blk) got_cpl = !block->cpl_in_use; for (ch = 1; ch <= s->channels; ch++) { int b, q; - AC3Block *ref_block; if (!got_cpl && ch > 1 && block->channel_in_cpl[ch-1]) { ch0 = ch - 1; ch = CPL_CH; got_cpl = 1; } - ref_block = block->exp_ref_block[ch]; for (i = s->start_freq[ch]; i < block->end_freq[ch]; i++) { q = block->qmant[ch][i]; - b = ref_block->bap[ch][i]; + b = s->ref_bap[ch][blk][i]; switch (b) { case 0: break; case 1: if (q != 128) put_bits(&s->pb, 5, q); break; @@ -2597,7 +2599,6 @@ static av_cold int ac3_encode_close(AVCodecContext *avctx) av_freep(&s->qmant_buffer); for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; - av_freep(&block->bap); av_freep(&block->mdct_coef); av_freep(&block->fixed_coef); av_freep(&block->exp); @@ -2896,8 +2897,6 @@ static av_cold int allocate_buffers(AVCodecContext *avctx) } for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; - FF_ALLOC_OR_GOTO(avctx, block->bap, channels * sizeof(*block->bap), - alloc_fail); FF_ALLOCZ_OR_GOTO(avctx, block->mdct_coef, channels * sizeof(*block->mdct_coef), alloc_fail); FF_ALLOCZ_OR_GOTO(avctx, block->exp, channels * sizeof(*block->exp), @@ -2921,7 +2920,6 @@ static av_cold int allocate_buffers(AVCodecContext *avctx) for (ch = 0; ch < channels; ch++) { /* arrangement: block, channel, coeff */ - block->bap[ch] = &s->bap_buffer [AC3_MAX_COEFS * (blk * channels + ch)]; block->grouped_exp[ch] = &s->grouped_exp_buffer[128 * (blk * channels + ch)]; block->psd[ch] = &s->psd_buffer [AC3_MAX_COEFS * (blk * channels + ch)]; block->band_psd[ch] = &s->band_psd_buffer [64 * (blk * channels + ch)]; From 1323828a0fbfa428d2e39a9f094039637b7fef5b Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 26 May 2011 12:31:31 -0400 Subject: [PATCH 22/27] ac3enc: split mantissa bit counting into a separate function. No speed difference. This is to allow for more flexible bit counting. --- libavcodec/ac3enc.c | 49 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 1faafb61d6..6b9bd87853 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -1491,22 +1491,12 @@ static void reset_block_bap(AC3EncodeContext *s) } -/** - * Run the bit allocation with a given SNR offset. - * This calculates the bit allocation pointers that will be used to determine - * the quantization of each mantissa. - * @return the number of bits needed for mantissas if the given SNR offset is - * is used. - */ -static int bit_alloc(AC3EncodeContext *s, int snr_offset) +static int count_mantissa_bits(AC3EncodeContext *s) { int blk, ch; int mantissa_bits; int mant_cnt[5]; - snr_offset = (snr_offset - 240) << 2; - - reset_block_bap(s); mantissa_bits = 0; for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; @@ -1524,7 +1514,36 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset) ch = CPL_CH; got_cpl = 1; } + mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt, + s->ref_bap[ch][blk]+s->start_freq[ch], + block->end_freq[ch]-s->start_freq[ch]); + if (ch == CPL_CH) + ch = ch0; + } + mantissa_bits += compute_mantissa_size_final(mant_cnt); + } + return mantissa_bits; +} + +/** + * Run the bit allocation with a given SNR offset. + * This calculates the bit allocation pointers that will be used to determine + * the quantization of each mantissa. + * @return the number of bits needed for mantissas if the given SNR offset is + * is used. + */ +static int bit_alloc(AC3EncodeContext *s, int snr_offset) +{ + int blk, ch; + + snr_offset = (snr_offset - 240) << 2; + + reset_block_bap(s); + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { + AC3Block *block = &s->blocks[blk]; + + for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { /* Currently the only bit allocation parameters which vary across blocks within a frame are the exponent values. We can take advantage of that by reusing the bit allocation pointers @@ -1535,15 +1554,9 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset) snr_offset, s->bit_alloc.floor, ff_ac3_bap_tab, s->ref_bap[ch][blk]); } - mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt, - s->ref_bap[ch][blk]+s->start_freq[ch], - block->end_freq[ch]-s->start_freq[ch]); - if (ch == CPL_CH) - ch = ch0; } - mantissa_bits += compute_mantissa_size_final(mant_cnt); } - return mantissa_bits; + return count_mantissa_bits(s); } From 6ca23db9cccac05bef9bf9c665821b396af12a0b Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 26 May 2011 15:53:25 -0400 Subject: [PATCH 23/27] ac3enc: modify mantissa bit counting to keep bap counts for all values of bap instead of just 0 to 4. This does all the actual bit counting as a final step. --- libavcodec/ac3dsp.c | 42 +++++++++------ libavcodec/ac3dsp.h | 22 +++++++- libavcodec/ac3enc.c | 92 +++++++++++++++++--------------- libavcodec/arm/ac3dsp_arm.S | 52 ------------------ libavcodec/arm/ac3dsp_init_arm.c | 2 - libavcodec/x86/ac3dsp.asm | 53 ++++++++++++++++++ libavcodec/x86/ac3dsp_mmx.c | 3 ++ 7 files changed, 151 insertions(+), 115 deletions(-) delete mode 100644 libavcodec/arm/ac3dsp_arm.S diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c index e3ca37ebdd..de58f3ab26 100644 --- a/libavcodec/ac3dsp.c +++ b/libavcodec/ac3dsp.c @@ -128,24 +128,33 @@ static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd, } while (end > ff_ac3_band_start_tab[band++]); } -static int ac3_compute_mantissa_size_c(int mant_cnt[5], uint8_t *bap, - int nb_coefs) +static void ac3_update_bap_counts_c(uint16_t mant_cnt[16], uint8_t *bap, + int len) { - int bits, b, i; + while (len-- >= 0) + mant_cnt[bap[len]]++; +} - bits = 0; - for (i = 0; i < nb_coefs; i++) { - b = bap[i]; - if (b <= 4) { - // bap=1 to bap=4 will be counted in compute_mantissa_size_final - mant_cnt[b]++; - } else if (b <= 13) { - // bap=5 to bap=13 use (bap-1) bits - bits += b - 1; - } else { - // bap=14 uses 14 bits and bap=15 uses 16 bits - bits += (b == 14) ? 14 : 16; - } +DECLARE_ALIGNED(16, const uint16_t, ff_ac3_bap_bits)[16] = { + 0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 +}; + +static int ac3_compute_mantissa_size_c(uint16_t mant_cnt[6][16]) +{ + int blk, bap; + int bits = 0; + + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { + // bap=1 : 3 mantissas in 5 bits + bits += (mant_cnt[blk][1] / 3) * 5; + // bap=2 : 3 mantissas in 7 bits + // bap=4 : 2 mantissas in 7 bits + bits += ((mant_cnt[blk][2] / 3) + (mant_cnt[blk][4] >> 1)) * 7; + // bap=3 : 1 mantissa in 3 bits + bits += mant_cnt[blk][3] * 3; + // bap=5 to 15 : get bits per mantissa from table + for (bap = 5; bap < 16; bap++) + bits += mant_cnt[blk][bap] * ff_ac3_bap_bits[bap]; } return bits; } @@ -181,6 +190,7 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) c->ac3_rshift_int32 = ac3_rshift_int32_c; c->float_to_fixed24 = float_to_fixed24_c; c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c; + c->update_bap_counts = ac3_update_bap_counts_c; c->compute_mantissa_size = ac3_compute_mantissa_size_c; c->extract_exponents = ac3_extract_exponents_c; diff --git a/libavcodec/ac3dsp.h b/libavcodec/ac3dsp.h index b750767e81..8eeafd68ac 100644 --- a/libavcodec/ac3dsp.h +++ b/libavcodec/ac3dsp.h @@ -24,6 +24,12 @@ #include +/** + * Number of mantissa bits written for each bap value. + * bap values with fractional bits are set to 0 and are calculated separately. + */ +extern const uint16_t ff_ac3_bap_bits[16]; + typedef struct AC3DSPContext { /** * Set each encoded exponent in a block to the minimum of itself and the @@ -102,9 +108,21 @@ typedef struct AC3DSPContext { const uint8_t *bap_tab, uint8_t *bap); /** - * Calculate the number of bits needed to encode a set of mantissas. + * Update bap counts using the supplied array of bap. + * + * @param[out] mant_cnt bap counts for 1 block + * @param[in] bap array of bap, pointing to start coef bin + * @param[in] len number of elements to process */ - int (*compute_mantissa_size)(int mant_cnt[5], uint8_t *bap, int nb_coefs); + void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len); + + /** + * Calculate the number of bits needed to encode a set of mantissas. + * + * @param[in] mant_cnt bap counts for all blocks + * @return mantissa bit count + */ + int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]); void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs); } AC3DSPContext; diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 6b9bd87853..66dfc29217 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -1423,22 +1423,6 @@ static void count_frame_bits(AC3EncodeContext *s) } -/** - * Finalize the mantissa bit count by adding in the grouped mantissas. - */ -static int compute_mantissa_size_final(int mant_cnt[5]) -{ - // bap=1 : 3 mantissas in 5 bits - int bits = (mant_cnt[1] / 3) * 5; - // bap=2 : 3 mantissas in 7 bits - // bap=4 : 2 mantissas in 7 bits - bits += ((mant_cnt[2] / 3) + (mant_cnt[4] >> 1)) * 7; - // bap=3 : each mantissa is 3 bits - bits += mant_cnt[3] * 3; - return bits; -} - - /** * Calculate masking curve based on the final exponents. * Also calculate the power spectral densities to use in future calculations. @@ -1491,38 +1475,60 @@ static void reset_block_bap(AC3EncodeContext *s) } -static int count_mantissa_bits(AC3EncodeContext *s) +/** + * Initialize mantissa counts. + * These are set so that they are padded to the next whole group size when bits + * are counted in compute_mantissa_size. + */ +static void count_mantissa_bits_init(uint16_t mant_cnt[AC3_MAX_BLOCKS][16]) { - int blk, ch; - int mantissa_bits; - int mant_cnt[5]; + int blk; + + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { + memset(mant_cnt[blk], 0, sizeof(mant_cnt[blk])); + mant_cnt[blk][1] = mant_cnt[blk][2] = 2; + mant_cnt[blk][4] = 1; + } +} + + +/** + * Update mantissa bit counts for all blocks in 1 channel in a given bandwidth + * range. + */ +static void count_mantissa_bits_update_ch(AC3EncodeContext *s, int ch, + uint16_t mant_cnt[AC3_MAX_BLOCKS][16], + int start, int end) +{ + int blk; - mantissa_bits = 0; for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; - int av_uninit(ch0); - int got_cpl = !block->cpl_in_use; - // initialize grouped mantissa counts. these are set so that they are - // padded to the next whole group size when bits are counted in - // compute_mantissa_size_final - mant_cnt[0] = mant_cnt[3] = 0; - mant_cnt[1] = mant_cnt[2] = 2; - mant_cnt[4] = 1; - for (ch = 1; ch <= s->channels; ch++) { - if (!got_cpl && ch > 1 && block->channel_in_cpl[ch-1]) { - ch0 = ch - 1; - ch = CPL_CH; - got_cpl = 1; - } - mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt, - s->ref_bap[ch][blk]+s->start_freq[ch], - block->end_freq[ch]-s->start_freq[ch]); - if (ch == CPL_CH) - ch = ch0; - } - mantissa_bits += compute_mantissa_size_final(mant_cnt); + if (ch == CPL_CH && !block->cpl_in_use) + continue; + s->ac3dsp.update_bap_counts(mant_cnt[blk], + s->ref_bap[ch][blk] + start, + FFMIN(end, block->end_freq[ch]) - start); } - return mantissa_bits; +} + + +/** + * Count the number of mantissa bits in the frame based on the bap values. + */ +static int count_mantissa_bits(AC3EncodeContext *s) +{ + int ch, max_end_freq; + LOCAL_ALIGNED_16(uint16_t, mant_cnt,[AC3_MAX_BLOCKS][16]); + + count_mantissa_bits_init(mant_cnt); + + max_end_freq = s->bandwidth_code * 3 + 73; + for (ch = !s->cpl_enabled; ch <= s->channels; ch++) + count_mantissa_bits_update_ch(s, ch, mant_cnt, s->start_freq[ch], + max_end_freq); + + return s->ac3dsp.compute_mantissa_size(mant_cnt); } diff --git a/libavcodec/arm/ac3dsp_arm.S b/libavcodec/arm/ac3dsp_arm.S deleted file mode 100644 index d7d498e41f..0000000000 --- a/libavcodec/arm/ac3dsp_arm.S +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2011 Mans Rullgard - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "asm.S" - -function ff_ac3_compute_mantissa_size_arm, export=1 - push {r4-r8,lr} - ldm r0, {r4-r8} - mov r3, r0 - mov r0, #0 -1: - ldrb lr, [r1], #1 - subs r2, r2, #1 - blt 2f - cmp lr, #4 - bgt 3f - subs lr, lr, #1 - addlt r4, r4, #1 - addeq r5, r5, #1 - ble 1b - subs lr, lr, #2 - addlt r6, r6, #1 - addeq r7, r7, #1 - addgt r8, r8, #1 - b 1b -3: - cmp lr, #14 - sublt lr, lr, #1 - addgt r0, r0, #16 - addle r0, r0, lr - b 1b -2: - stm r3, {r4-r8} - pop {r4-r8,pc} -endfunc diff --git a/libavcodec/arm/ac3dsp_init_arm.c b/libavcodec/arm/ac3dsp_init_arm.c index fd78e1e6a4..4414dc8170 100644 --- a/libavcodec/arm/ac3dsp_init_arm.c +++ b/libavcodec/arm/ac3dsp_init_arm.c @@ -39,8 +39,6 @@ int ff_ac3_compute_mantissa_size_arm(int cnt[5], uint8_t *bap, int nb_coefs); av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact) { - c->compute_mantissa_size = ff_ac3_compute_mantissa_size_arm; - if (HAVE_ARMV6) { c->bit_alloc_calc_bap = ff_ac3_bit_alloc_calc_bap_armv6; } diff --git a/libavcodec/x86/ac3dsp.asm b/libavcodec/x86/ac3dsp.asm index 18f9dc3894..0d8f4b78eb 100644 --- a/libavcodec/x86/ac3dsp.asm +++ b/libavcodec/x86/ac3dsp.asm @@ -27,6 +27,11 @@ SECTION_RODATA ; 16777216.0f - used in ff_float_to_fixed24() pf_1_24: times 4 dd 0x4B800000 +; used in ff_ac3_compute_mantissa_size() +cextern ac3_bap_bits +pw_bap_mul1: dw 21846, 21846, 0, 32768, 21846, 21846, 0, 32768 +pw_bap_mul2: dw 5, 7, 0, 7, 5, 7, 0, 7 + SECTION .text ;----------------------------------------------------------------------------- @@ -293,3 +298,51 @@ cglobal float_to_fixed24_sse2, 3,3,9, dst, src, len %endif ja .loop REP_RET + +;------------------------------------------------------------------------------ +; int ff_ac3_compute_mantissa_size(uint16_t mant_cnt[6][16]) +;------------------------------------------------------------------------------ + +%macro PHADDD4 2 ; xmm src, xmm tmp + movhlps %2, %1 + paddd %1, %2 + pshufd %2, %1, 0x1 + paddd %1, %2 +%endmacro + +INIT_XMM +cglobal ac3_compute_mantissa_size_sse2, 1,2,4, mant_cnt, sum + movdqa m0, [mant_cntq ] + movdqa m1, [mant_cntq+ 1*16] + paddw m0, [mant_cntq+ 2*16] + paddw m1, [mant_cntq+ 3*16] + paddw m0, [mant_cntq+ 4*16] + paddw m1, [mant_cntq+ 5*16] + paddw m0, [mant_cntq+ 6*16] + paddw m1, [mant_cntq+ 7*16] + paddw m0, [mant_cntq+ 8*16] + paddw m1, [mant_cntq+ 9*16] + paddw m0, [mant_cntq+10*16] + paddw m1, [mant_cntq+11*16] + pmaddwd m0, [ff_ac3_bap_bits ] + pmaddwd m1, [ff_ac3_bap_bits+16] + paddd m0, m1 + PHADDD4 m0, m1 + movd sumd, m0 + movdqa m3, [pw_bap_mul1] + movhpd m0, [mant_cntq +2] + movlpd m0, [mant_cntq+1*32+2] + movhpd m1, [mant_cntq+2*32+2] + movlpd m1, [mant_cntq+3*32+2] + movhpd m2, [mant_cntq+4*32+2] + movlpd m2, [mant_cntq+5*32+2] + pmulhuw m0, m3 + pmulhuw m1, m3 + pmulhuw m2, m3 + paddusw m0, m1 + paddusw m0, m2 + pmaddwd m0, [pw_bap_mul2] + PHADDD4 m0, m1 + movd eax, m0 + add eax, sumd + RET diff --git a/libavcodec/x86/ac3dsp_mmx.c b/libavcodec/x86/ac3dsp_mmx.c index 475042395c..2664736bb6 100644 --- a/libavcodec/x86/ac3dsp_mmx.c +++ b/libavcodec/x86/ac3dsp_mmx.c @@ -42,6 +42,8 @@ extern void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned i extern void ff_float_to_fixed24_sse (int32_t *dst, const float *src, unsigned int len); extern void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len); +extern int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]); + av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact) { int mm_flags = av_get_cpu_flags(); @@ -69,6 +71,7 @@ av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact) c->ac3_exponent_min = ff_ac3_exponent_min_sse2; c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2; c->float_to_fixed24 = ff_float_to_fixed24_sse2; + c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2; if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) { c->ac3_lshift_int16 = ff_ac3_lshift_int16_sse2; c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2; From edfa89b2608889626bb6c6b177283b6fd16716cf Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 28 May 2011 18:36:07 +0100 Subject: [PATCH 24/27] ARM: unbreak build Signed-off-by: Mans Rullgard --- libavcodec/arm/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/arm/Makefile b/libavcodec/arm/Makefile index a5abfdd128..a5a5dfab64 100644 --- a/libavcodec/arm/Makefile +++ b/libavcodec/arm/Makefile @@ -1,5 +1,4 @@ OBJS-$(CONFIG_AC3DSP) += arm/ac3dsp_init_arm.o \ - arm/ac3dsp_arm.o OBJS-$(CONFIG_DCA_DECODER) += arm/dcadsp_init_arm.o \ From dc0ad40de2b0d6995eb842e56b22f9096bd539ff Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sat, 28 May 2011 14:40:16 -0400 Subject: [PATCH 25/27] ac3dsp: fix loop condition in ac3_update_bap_counts_c() --- libavcodec/ac3dsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c index de58f3ab26..8ce5f8d2c5 100644 --- a/libavcodec/ac3dsp.c +++ b/libavcodec/ac3dsp.c @@ -131,7 +131,7 @@ static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd, static void ac3_update_bap_counts_c(uint16_t mant_cnt[16], uint8_t *bap, int len) { - while (len-- >= 0) + while (len-- > 0) mant_cnt[bap[len]]++; } From 70bb747a57d8df6f33803bb4824b0a447c708823 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sat, 28 May 2011 14:39:18 -0400 Subject: [PATCH 26/27] ac3dsp: do not use the ff_* prefix when referencing ff_ac3_bap_bits. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this should fix the windows builds Signed-off-by: Martin Storsjö --- libavcodec/x86/ac3dsp.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/x86/ac3dsp.asm b/libavcodec/x86/ac3dsp.asm index 0d8f4b78eb..6892ec2765 100644 --- a/libavcodec/x86/ac3dsp.asm +++ b/libavcodec/x86/ac3dsp.asm @@ -324,8 +324,8 @@ cglobal ac3_compute_mantissa_size_sse2, 1,2,4, mant_cnt, sum paddw m1, [mant_cntq+ 9*16] paddw m0, [mant_cntq+10*16] paddw m1, [mant_cntq+11*16] - pmaddwd m0, [ff_ac3_bap_bits ] - pmaddwd m1, [ff_ac3_bap_bits+16] + pmaddwd m0, [ac3_bap_bits ] + pmaddwd m1, [ac3_bap_bits+16] paddd m0, m1 PHADDD4 m0, m1 movd sumd, m0 From 90da52f01f8b6c22af22a002eb226989b1cf7ef8 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 28 May 2011 20:27:09 +0100 Subject: [PATCH 27/27] ac3enc: fix LOCAL_ALIGNED usage in count_mantissa_bits() Signed-off-by: Mans Rullgard --- libavcodec/ac3enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 66dfc29217..dbe7784eae 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -1519,7 +1519,7 @@ static void count_mantissa_bits_update_ch(AC3EncodeContext *s, int ch, static int count_mantissa_bits(AC3EncodeContext *s) { int ch, max_end_freq; - LOCAL_ALIGNED_16(uint16_t, mant_cnt,[AC3_MAX_BLOCKS][16]); + LOCAL_ALIGNED_16(uint16_t, mant_cnt, [AC3_MAX_BLOCKS], [16]); count_mantissa_bits_init(mant_cnt);