On date Sunday 2011-06-05 19:37:36 -0400, Justin Ruggles encoded: > On 06/05/2011 07:27 PM, Justin Ruggles wrote: > > > On 06/05/2011 06:31 PM, Stefano Sabatini wrote: > > > >> /** > >> * Bits per sample/pixel of internal libavcodec pixel/sample format. > >> * This field is applicable only when sample_fmt is AV_SAMPLE_FMT_S32. > >> * - encoding: set by user. > >> * - decoding: set by libavcodec. > >> */ > >> int bits_per_raw_sample; > > > > > > This just describes the accuracy of the data inside the internal > > libavcodec sample *after decoding* or *before encoding*. For example, > > 24-bit audio data in AV_SAMPLE_FMT_S32 is still scaled to 32 bit range > > as required by the sample format, but this field is set to 24 to > > indicate that there is only 24 bits of information. So say you want to > > convert 24-bit audio from 1 lossless codec to another lossless codec, > > the encoder will know that it can discard the low 8 bits and encode in > > 24-bit mode if it has one because bits_per_raw_sample is 24. > > > > bits_per_coded_sample refers to the size of the samples *before > > decoding* or *after encoding*. > > > > The 2 values may be the same, and probably are in most cases, but > > they're used for different purposes. bits_per_raw_sample depends on the > > decoder implementation and sample format, where-as bits_per_coded_sample > > depends only on the CODEC_ID and thus is the one used by libavformat. > > > sorry... i just realized that last sentence isn't 100% true. > bits_per_coded_sample does depend on the CODEC_ID, but sometimes it can > be different for the same CODEC_ID and can be signaled as such by the > demuxer (e.g. wavpack). theoretically the demuxer might not even know > and might rely on the decoder init. but still bits_per_raw_sample and > bits_per_coded_sample have different meanings.
Check patch. The only drawback of the patch seems that the new avcodec_get_bits_per_coded_sample() is only able to get the value for *registered codecs* (which is not necessarily a problem), and requires to iterate through the list of registered codec for getting the information (this may be fixed by introducing an efficient search data structure), but insofar should not have efficiency penalties since I'm calling that function only during the init stage. Possibly we may move the code which sets the avctx->bits_per_coded_sample in the libavcodec/utils.c. Comments are welcome.
>From 6be9d0da142328adf37fa5382b3560326d9b497e Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <[email protected]> Date: Wed, 6 Jul 2011 10:58:24 +0200 Subject: [PATCH] lavc: deprecate av_get_bits_per_sample(), in favor of avcodec_get_bits_per_coded_sample() av_get_bits_per_sample() was misnamed. The new function has a more intuitive name and directly relies on the data stored in the new bits_per_coded_sample AVCodec field. Also change the codec/format implementations for directly accessing the avctx->bits_per_coded_sample field when it makes sense. This is preferred over relying on the new avcodec_get_bits_per_coded_sample(), since it requires iterating through the list of registered codecs. --- ffprobe.c | 3 +- libavcodec/adpcm.c | 70 +++++++++++++++++++++----------------- libavcodec/avcodec.h | 20 +++++++++++ libavcodec/g722.c | 1 + libavcodec/pcm.c | 74 +++++++++++++++++++++------------------- libavcodec/utils.c | 58 ++++++++------------------------ libavcodec/version.h | 3 ++ libavformat/aiffdec.c | 4 +- libavformat/aiffenc.c | 2 +- libavformat/au.c | 6 ++-- libavformat/audiointerleave.c | 2 +- libavformat/gxf.c | 2 +- libavformat/matroskaenc.c | 2 +- libavformat/mov.c | 2 +- libavformat/movenc.c | 9 +++-- libavformat/mxfenc.c | 2 +- libavformat/pcm.c | 2 +- libavformat/riff.c | 4 +- 18 files changed, 136 insertions(+), 130 deletions(-) diff --git a/ffprobe.c b/ffprobe.c index 61ddc3d..f7775fb 100644 --- a/ffprobe.c +++ b/ffprobe.c @@ -209,7 +209,8 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx) dec_ctx->sample_rate, unit_hertz_str)); printf("channels=%d\n", dec_ctx->channels); - printf("bits_per_sample=%d\n", av_get_bits_per_sample(dec_ctx->codec_id)); + if (dec_ctx->bits_per_coded_sample) + printf("bits_per_coded_sample=%d\n", dec_ctx->bits_per_coded_sample); break; } } else { diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index ba31255..a9a3e1a 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -236,6 +236,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) goto error; } + avctx->bits_per_coded_sample = avcodec_get_bits_per_coded_sample(avctx->codec->id); avctx->coded_frame= avcodec_alloc_frame(); avctx->coded_frame->key_frame= 1; @@ -811,6 +812,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) default: break; } + + avctx->bits_per_coded_sample = avcodec_get_bits_per_coded_sample(avctx->codec->id); avctx->sample_fmt = AV_SAMPLE_FMT_S16; return 0; } @@ -1774,7 +1777,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, #if CONFIG_ENCODERS -#define ADPCM_ENCODER(id,name,long_name_) \ +#define ADPCM_ENCODER(id,name,long_name_,bits_per_coded_sample_) \ AVCodec ff_ ## name ## _encoder = { \ #name, \ AVMEDIA_TYPE_AUDIO, \ @@ -1786,13 +1789,14 @@ AVCodec ff_ ## name ## _encoder = { \ NULL, \ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ + .bits_per_coded_sample = bits_per_coded_sample_,\ } #else -#define ADPCM_ENCODER(id,name,long_name_) +#define ADPCM_ENCODER(id,name,long_name_,bits_per_coded_sample_) #endif #if CONFIG_DECODERS -#define ADPCM_DECODER(id,name,long_name_) \ +#define ADPCM_DECODER(id,name,long_name_,bits_per_coded_sample_) \ AVCodec ff_ ## name ## _decoder = { \ #name, \ AVMEDIA_TYPE_AUDIO, \ @@ -1803,38 +1807,40 @@ AVCodec ff_ ## name ## _decoder = { \ NULL, \ adpcm_decode_frame, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ + .bits_per_coded_sample = bits_per_coded_sample_\ } #else -#define ADPCM_DECODER(id,name,long_name_) +#define ADPCM_DECODER(id,name,long_name_,bits_per_coded_sample_) #endif -#define ADPCM_CODEC(id,name,long_name_) \ - ADPCM_ENCODER(id,name,long_name_); ADPCM_DECODER(id,name,long_name_) +#define ADPCM_CODEC(id,name,long_name_,bits_per_coded_sample_) \ + ADPCM_ENCODER(id,name,long_name_,bits_per_coded_sample_); \ + ADPCM_DECODER(id,name,long_name_,bits_per_coded_sample_) /* Note: Do not forget to add new entries to the Makefile as well. */ -ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "ADPCM 4X Movie"); -ADPCM_DECODER(CODEC_ID_ADPCM_CT, adpcm_ct, "ADPCM Creative Technology"); -ADPCM_DECODER(CODEC_ID_ADPCM_EA, adpcm_ea, "ADPCM Electronic Arts"); -ADPCM_DECODER(CODEC_ID_ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA"); -ADPCM_DECODER(CODEC_ID_ADPCM_EA_R1, adpcm_ea_r1, "ADPCM Electronic Arts R1"); -ADPCM_DECODER(CODEC_ID_ADPCM_EA_R2, adpcm_ea_r2, "ADPCM Electronic Arts R2"); -ADPCM_DECODER(CODEC_ID_ADPCM_EA_R3, adpcm_ea_r3, "ADPCM Electronic Arts R3"); -ADPCM_DECODER(CODEC_ID_ADPCM_EA_XAS, adpcm_ea_xas, "ADPCM Electronic Arts XAS"); -ADPCM_DECODER(CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv, "ADPCM IMA AMV"); -ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "ADPCM IMA Duck DK3"); -ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "ADPCM IMA Duck DK4"); -ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS"); -ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD"); -ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "ADPCM IMA Funcom ISS"); -ADPCM_CODEC (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime"); -ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG"); -ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV"); -ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, "ADPCM IMA Westwood"); -ADPCM_CODEC (CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft"); -ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit"); -ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit"); -ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit"); -ADPCM_CODEC (CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash"); -ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp, "ADPCM Nintendo Gamecube THP"); -ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa, "ADPCM CDROM XA"); -ADPCM_CODEC (CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha"); +ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "ADPCM 4X Movie", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_CT, adpcm_ct, "ADPCM Creative Technology", 4); +ADPCM_DECODER(CODEC_ID_ADPCM_EA, adpcm_ea, "ADPCM Electronic Arts", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R1, adpcm_ea_r1, "ADPCM Electronic Arts R1", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R2, adpcm_ea_r2, "ADPCM Electronic Arts R2", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R3, adpcm_ea_r3, "ADPCM Electronic Arts R3", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_XAS, adpcm_ea_xas, "ADPCM Electronic Arts XAS", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv, "ADPCM IMA AMV", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "ADPCM IMA Duck DK3", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "ADPCM IMA Duck DK4", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "ADPCM IMA Funcom ISS", 0); +ADPCM_CODEC (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG", 0); +ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV", 4); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, "ADPCM IMA Westwood", 0); +ADPCM_CODEC (CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft", 4); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit", 2); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit", 3); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit", 4); +ADPCM_CODEC (CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp, "ADPCM Nintendo Gamecube THP", 0); +ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa, "ADPCM CDROM XA", 0); +ADPCM_CODEC (CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha", 4); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 7e9348a..61aed5d 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2978,6 +2978,14 @@ typedef struct AVCodec { */ int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src); /** @} */ + + /** + * The number of bits per coded sample/pixel. It refers to the + * size of each sample before decoding or after encoding. + * It represents the value assumed by default by the given codec, + * it is set to 0 if unknown. + */ + int bits_per_coded_sample; } AVCodec; /** @@ -3908,13 +3916,25 @@ attribute_deprecated char av_get_pict_type_char(int pict_type); #endif +#if FF_API_GET_BITS_PER_SAMPLE /** * Return codec bits per sample. * * @param[in] codec_id the codec * @return Number of bits per sample or zero if unknown for the given codec. + * @deprecated Use avcodec_get_bits_per_coded_sample() instead. */ +attribute_deprecated int av_get_bits_per_sample(enum CodecID codec_id); +#endif + +/** + * Return default coded bits per sample value for the given codec. + * + * @param[in] codec_id the codec + * @return number of bits per sample or zero if unknown for the given codec + */ +int avcodec_get_bits_per_coded_sample(enum CodecID codec_id); #if FF_API_OLD_SAMPLE_FMT /** diff --git a/libavcodec/g722.c b/libavcodec/g722.c index f00fa6a..83811c0 100644 --- a/libavcodec/g722.c +++ b/libavcodec/g722.c @@ -337,6 +337,7 @@ AVCodec ff_adpcm_g722_decoder = { .decode = g722_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), .max_lowres = 1, + .bits_per_coded_sample = 8, }; #endif diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c index 852e349..6fe5d36 100644 --- a/libavcodec/pcm.c +++ b/libavcodec/pcm.c @@ -45,7 +45,7 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx) break; } - avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id); + avctx->bits_per_coded_sample = avcodec_get_bits_per_coded_sample(avctx->codec->id); avctx->block_align = avctx->channels * avctx->bits_per_coded_sample/8; avctx->coded_frame= avcodec_alloc_frame(); avctx->coded_frame->key_frame= 1; @@ -90,7 +90,7 @@ static int pcm_encode_frame(AVCodecContext *avctx, const uint16_t *samples_uint16_t; const uint32_t *samples_uint32_t; - sample_size = av_get_bits_per_sample(avctx->codec->id)/8; + sample_size = avctx->bits_per_coded_sample/8; n = buf_size / sample_size; samples = data; dst = frame; @@ -226,10 +226,11 @@ static av_cold int pcm_decode_init(AVCodecContext * avctx) break; } + avctx->bits_per_coded_sample = avcodec_get_bits_per_coded_sample(avctx->codec->id); avctx->sample_fmt = avctx->codec->sample_fmts[0]; if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) - avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec->id); + avctx->bits_per_raw_sample = avctx->bits_per_coded_sample; return 0; } @@ -282,7 +283,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, return -1; } - sample_size = av_get_bits_per_sample(avctx->codec_id)/8; + sample_size = avctx->bits_per_coded_sample/8; /* av_get_bits_per_sample returns 0 for CODEC_ID_PCM_DVD */ if (CODEC_ID_PCM_DVD == avctx->codec_id) @@ -471,7 +472,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, } #if CONFIG_ENCODERS -#define PCM_ENCODER(id_,sample_fmt_,name_,long_name_) \ +#define PCM_ENCODER(id_,sample_fmt_,name_,long_name_,bits_per_coded_sample_) \ AVCodec ff_ ## name_ ## _encoder = { \ .name = #name_, \ .type = AVMEDIA_TYPE_AUDIO, \ @@ -481,13 +482,14 @@ AVCodec ff_ ## name_ ## _encoder = { \ .close = pcm_encode_close, \ .sample_fmts = (const enum AVSampleFormat[]){sample_fmt_,AV_SAMPLE_FMT_NONE}, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ + .bits_per_coded_sample = bits_per_coded_sample_,\ } #else -#define PCM_ENCODER(id,sample_fmt_,name,long_name_) +#define PCM_ENCODER(id,sample_fmt_,name,long_name_,bits_per_coded_sample_) #endif #if CONFIG_DECODERS -#define PCM_DECODER(id_,sample_fmt_,name_,long_name_) \ +#define PCM_DECODER(id_,sample_fmt_,name_,long_name_,bits_per_coded_sample_) \ AVCodec ff_ ## name_ ## _decoder = { \ .name = #name_, \ .type = AVMEDIA_TYPE_AUDIO, \ @@ -497,37 +499,39 @@ AVCodec ff_ ## name_ ## _decoder = { \ .decode = pcm_decode_frame, \ .sample_fmts = (const enum AVSampleFormat[]){sample_fmt_,AV_SAMPLE_FMT_NONE}, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ + .bits_per_coded_sample = bits_per_coded_sample_,\ } #else -#define PCM_DECODER(id,sample_fmt_,name,long_name_) +#define PCM_DECODER(id,sample_fmt_,name,long_name_,bits_per_coded_sample_) #endif -#define PCM_CODEC(id, sample_fmt_, name, long_name_) \ - PCM_ENCODER(id,sample_fmt_,name,long_name_); PCM_DECODER(id,sample_fmt_,name,long_name_) +#define PCM_CODEC(id, sample_fmt_, name, long_name_,bits_per_coded_sample_) \ + PCM_ENCODER(id,sample_fmt_,name,long_name_,bits_per_coded_sample_); \ + PCM_DECODER(id,sample_fmt_,name,long_name_,bits_per_coded_sample_) /* Note: Do not forget to add new entries to the Makefile as well. */ -PCM_CODEC (CODEC_ID_PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law"); -PCM_DECODER(CODEC_ID_PCM_DVD, AV_SAMPLE_FMT_S32, pcm_dvd, "PCM signed 20|24-bit big-endian"); -PCM_CODEC (CODEC_ID_PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be, "PCM 32-bit floating point big-endian"); -PCM_CODEC (CODEC_ID_PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le, "PCM 32-bit floating point little-endian"); -PCM_CODEC (CODEC_ID_PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be, "PCM 64-bit floating point big-endian"); -PCM_CODEC (CODEC_ID_PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le, "PCM 64-bit floating point little-endian"); -PCM_DECODER(CODEC_ID_PCM_LXF, AV_SAMPLE_FMT_S32, pcm_lxf, "PCM signed 20-bit little-endian planar"); -PCM_CODEC (CODEC_ID_PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw, "PCM mu-law"); -PCM_CODEC (CODEC_ID_PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8, "PCM signed 8-bit"); -PCM_CODEC (CODEC_ID_PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be, "PCM signed 16-bit big-endian"); -PCM_CODEC (CODEC_ID_PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian"); -PCM_DECODER(CODEC_ID_PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16, pcm_s16le_planar, "PCM 16-bit little-endian planar"); -PCM_CODEC (CODEC_ID_PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be, "PCM signed 24-bit big-endian"); -PCM_CODEC (CODEC_ID_PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud, "PCM D-Cinema audio signed 24-bit"); -PCM_CODEC (CODEC_ID_PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le, "PCM signed 24-bit little-endian"); -PCM_CODEC (CODEC_ID_PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be, "PCM signed 32-bit big-endian"); -PCM_CODEC (CODEC_ID_PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le, "PCM signed 32-bit little-endian"); -PCM_CODEC (CODEC_ID_PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8, "PCM unsigned 8-bit"); -PCM_CODEC (CODEC_ID_PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be, "PCM unsigned 16-bit big-endian"); -PCM_CODEC (CODEC_ID_PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le, "PCM unsigned 16-bit little-endian"); -PCM_CODEC (CODEC_ID_PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be, "PCM unsigned 24-bit big-endian"); -PCM_CODEC (CODEC_ID_PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian"); -PCM_CODEC (CODEC_ID_PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian"); -PCM_CODEC (CODEC_ID_PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian"); -PCM_CODEC (CODEC_ID_PCM_ZORK, AV_SAMPLE_FMT_S16, pcm_zork, "PCM Zork"); +PCM_CODEC (CODEC_ID_PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law", 8); +PCM_DECODER(CODEC_ID_PCM_DVD, AV_SAMPLE_FMT_S32, pcm_dvd, "PCM signed 20|24-bit big-endian", 32); +PCM_CODEC (CODEC_ID_PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be, "PCM 32-bit floating point big-endian", 32); +PCM_CODEC (CODEC_ID_PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le, "PCM 32-bit floating point little-endian", 32); +PCM_CODEC (CODEC_ID_PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be, "PCM 64-bit floating point big-endian", 64); +PCM_CODEC (CODEC_ID_PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le, "PCM 64-bit floating point little-endian", 64); +PCM_DECODER(CODEC_ID_PCM_LXF, AV_SAMPLE_FMT_S32, pcm_lxf, "PCM signed 20-bit little-endian planar", 0); +PCM_CODEC (CODEC_ID_PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw, "PCM mu-law", 8); +PCM_CODEC (CODEC_ID_PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8, "PCM signed 8-bit", 8); +PCM_CODEC (CODEC_ID_PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be, "PCM signed 16-bit big-endian", 16); +PCM_CODEC (CODEC_ID_PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian", 16); +PCM_DECODER(CODEC_ID_PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16, pcm_s16le_planar, "PCM 16-bit little-endian planar", 16); +PCM_CODEC (CODEC_ID_PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be, "PCM signed 24-bit big-endian", 24); +PCM_CODEC (CODEC_ID_PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud, "PCM D-Cinema audio signed 24-bit", 24); +PCM_CODEC (CODEC_ID_PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le, "PCM signed 24-bit little-endian", 24); +PCM_CODEC (CODEC_ID_PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be, "PCM signed 32-bit big-endian", 32); +PCM_CODEC (CODEC_ID_PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le, "PCM signed 32-bit little-endian", 32); +PCM_CODEC (CODEC_ID_PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8, "PCM unsigned 8-bit", 8); +PCM_CODEC (CODEC_ID_PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be, "PCM unsigned 16-bit big-endian", 16); +PCM_CODEC (CODEC_ID_PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le, "PCM unsigned 16-bit little-endian", 16); +PCM_CODEC (CODEC_ID_PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be, "PCM unsigned 24-bit big-endian", 24); +PCM_CODEC (CODEC_ID_PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian", 24); +PCM_CODEC (CODEC_ID_PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian", 32); +PCM_CODEC (CODEC_ID_PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian", 32); +PCM_CODEC (CODEC_ID_PCM_ZORK, AV_SAMPLE_FMT_S16, pcm_zork, "PCM Zork", 8); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 0c84965..df7d2d3 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -952,7 +952,7 @@ static int get_bit_rate(AVCodecContext *ctx) bit_rate = ctx->bit_rate; break; case AVMEDIA_TYPE_AUDIO: - bits_per_sample = av_get_bits_per_sample(ctx->codec_id); + bits_per_sample = avcodec_get_bits_per_coded_sample(ctx->codec_id); bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate; break; default: @@ -1166,52 +1166,22 @@ char av_get_pict_type_char(int pict_type){ } #endif -int av_get_bits_per_sample(enum CodecID codec_id){ - switch(codec_id){ - case CODEC_ID_ADPCM_SBPRO_2: - return 2; - case CODEC_ID_ADPCM_SBPRO_3: - return 3; - case CODEC_ID_ADPCM_SBPRO_4: - case CODEC_ID_ADPCM_CT: - case CODEC_ID_ADPCM_IMA_WAV: - case CODEC_ID_ADPCM_MS: - case CODEC_ID_ADPCM_YAMAHA: - return 4; - case CODEC_ID_ADPCM_G722: - case CODEC_ID_PCM_ALAW: - case CODEC_ID_PCM_MULAW: - case CODEC_ID_PCM_S8: - case CODEC_ID_PCM_U8: - case CODEC_ID_PCM_ZORK: - return 8; - case CODEC_ID_PCM_S16BE: - case CODEC_ID_PCM_S16LE: - case CODEC_ID_PCM_S16LE_PLANAR: - case CODEC_ID_PCM_U16BE: - case CODEC_ID_PCM_U16LE: - return 16; - case CODEC_ID_PCM_S24DAUD: - case CODEC_ID_PCM_S24BE: - case CODEC_ID_PCM_S24LE: - case CODEC_ID_PCM_U24BE: - case CODEC_ID_PCM_U24LE: - return 24; - case CODEC_ID_PCM_S32BE: - case CODEC_ID_PCM_S32LE: - case CODEC_ID_PCM_U32BE: - case CODEC_ID_PCM_U32LE: - case CODEC_ID_PCM_F32BE: - case CODEC_ID_PCM_F32LE: - return 32; - case CODEC_ID_PCM_F64BE: - case CODEC_ID_PCM_F64LE: - return 64; - default: +int avcodec_get_bits_per_coded_sample(enum CodecID codec_id) +{ + const AVCodec *codec; + if (!(codec = avcodec_find_decoder(codec_id)) || + !(codec = avcodec_find_encoder(codec_id))) return 0; - } + return codec->bits_per_coded_sample; } +#if FF_API_GET_BITS_PER_SAMPLE +int av_get_bits_per_sample(enum CodecID codec_id) +{ + return avcodec_get_bits_per_coded_sample(codec_id); +} +#endif + #if FF_API_OLD_SAMPLE_FMT int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) { return av_get_bytes_per_sample(sample_fmt) << 3; diff --git a/libavcodec/version.h b/libavcodec/version.h index 100c06d..6bbdf68 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -68,5 +68,8 @@ #ifndef FF_API_GET_PIX_FMT_NAME #define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_GET_BITS_PER_SAMPLE +#define FF_API_GET_BITS_PER_SAMPLE (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #endif /* AVCODEC_VERSION_H */ diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index 9608910..78e0b2a 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -113,7 +113,7 @@ static unsigned int get_aiff_header(AVIOContext *pb, AVCodecContext *codec, switch (codec->codec_id) { case CODEC_ID_PCM_S16BE: codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); - codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id); + codec->bits_per_coded_sample = avcodec_get_bits_per_coded_sample(codec->codec_id); break; case CODEC_ID_ADPCM_IMA_QT: codec->block_align = 34*codec->channels; @@ -142,7 +142,7 @@ static unsigned int get_aiff_header(AVIOContext *pb, AVCodecContext *codec, } else { /* Need the codec type */ codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); - codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id); + codec->bits_per_coded_sample = avcodec_get_bits_per_coded_sample(codec->codec_id); } /* Block align needs to be computed in all cases, as the definition diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index 0e6a061..1199c48 100644 --- a/libavformat/aiffenc.c +++ b/libavformat/aiffenc.c @@ -78,7 +78,7 @@ static int aiff_write_header(AVFormatContext *s) avio_wb32(pb, 0); /* Number of frames */ if (!enc->bits_per_coded_sample) - enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id); + enc->bits_per_coded_sample = avcodec_get_bits_per_coded_sample(enc->codec_id); if (!enc->bits_per_coded_sample) { av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n"); return -1; diff --git a/libavformat/au.c b/libavformat/au.c index 23365c4..68087c4 100644 --- a/libavformat/au.c +++ b/libavformat/au.c @@ -140,8 +140,8 @@ static int au_read_header(AVFormatContext *s, codec = ff_codec_get_id(codec_au_tags, id); - if (!av_get_bits_per_sample(codec)) { - av_log_ask_for_sample(s, "could not determine bits per sample\n"); + if (!avcodec_get_bits_per_coded_sample(codec)) { + av_log_ask_for_sample(s, "could not determine bits per coded sample\n"); return AVERROR_INVALIDDATA; } @@ -172,7 +172,7 @@ static int au_read_packet(AVFormatContext *s, ret= av_get_packet(s->pb, pkt, BLOCK_SIZE * s->streams[0]->codec->channels * - av_get_bits_per_sample(s->streams[0]->codec->codec_id) >> 3); + (s->streams[0]->codec->bits_per_coded_sample) >> 3); if (ret < 0) return ret; pkt->stream_index = 0; diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c index 844112f..0fbe573 100644 --- a/libavformat/audiointerleave.c +++ b/libavformat/audiointerleave.c @@ -53,7 +53,7 @@ int ff_audio_interleave_init(AVFormatContext *s, if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { aic->sample_size = (st->codec->channels * - av_get_bits_per_sample(st->codec->codec_id)) / 8; + st->codec->bits_per_coded_sample) / 8; if (!aic->sample_size) { av_log(s, AV_LOG_ERROR, "could not compute sample size\n"); return -1; diff --git a/libavformat/gxf.c b/libavformat/gxf.c index 7002a1d..8ece401 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -460,7 +460,7 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { st->codec->codec_id == CODEC_ID_PCM_S16LE) { int first = field_info >> 16; int last = field_info & 0xffff; // last is exclusive - int bps = av_get_bits_per_sample(st->codec->codec_id)>>3; + int bps = st->codec->bits_per_coded_sample>>3; if (first <= last && last*bps <= pkt_len) { avio_skip(pb, first*bps); skip = pkt_len - last*bps; diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 68a05c3..ea51278 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -523,7 +523,7 @@ static int mkv_write_tracks(AVFormatContext *s) ebml_master subinfo, track; int native_id = 0; int qt_id = 0; - int bit_depth = av_get_bits_per_sample(codec->codec_id); + int bit_depth = avcodec_get_bits_per_coded_sample(codec->codec_id); int sample_rate = codec->sample_rate; int output_sample_rate = 0; AVDictionaryEntry *tag; diff --git a/libavformat/mov.c b/libavformat/mov.c index 651c685..e7cab46 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1179,7 +1179,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) break; } - bits_per_sample = av_get_bits_per_sample(st->codec->codec_id); + bits_per_sample = avcodec_get_bits_per_coded_sample(st->codec->codec_id); if (bits_per_sample) { st->codec->bits_per_coded_sample = bits_per_sample; sc->sample_size = (bits_per_sample >> 3) * st->codec->channels; diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 21a82b5..3bb0217 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -458,7 +458,7 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) avio_wb64(pb, av_dbl2int(track->timescale)); avio_wb32(pb, track->enc->channels); avio_wb32(pb, 0x7F000000); - avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id)); + avio_wb32(pb, avcodec_get_bits_per_coded_sample(track->enc->codec_id)); avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id)); avio_wb32(pb, track->sampleSize); avio_wb32(pb, track->enc->frame_size); @@ -710,7 +710,7 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) (track->enc->codec_id == CODEC_ID_DVVIDEO || track->enc->codec_id == CODEC_ID_RAWVIDEO || track->enc->codec_id == CODEC_ID_H263 || - av_get_bits_per_sample(track->enc->codec_id)))) { // pcm audio + avcodec_get_bits_per_coded_sample(track->enc->codec_id)))) { // pcm audio if (track->enc->codec_id == CODEC_ID_DVVIDEO) tag = mov_get_dv_codec_tag(s, track); else if (track->enc->codec_id == CODEC_ID_RAWVIDEO) @@ -2234,7 +2234,7 @@ static int mov_write_header(AVFormatContext *s) "or choose different container.\n"); }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO){ track->timescale = st->codec->sample_rate; - if(!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) { + if(!st->codec->frame_size && !avcodec_get_bits_per_coded_sample(st->codec->codec_id)) { av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i); goto error; }else if(st->codec->codec_id == CODEC_ID_ADPCM_MS || @@ -2248,7 +2248,8 @@ static int mov_write_header(AVFormatContext *s) track->audio_vbr = 1; }else{ st->codec->frame_size = 1; - track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels; + track->sampleSize = + (avcodec_get_bits_per_coded_sample(st->codec->codec_id) >> 3) * st->codec->channels; } if (track->mode != MODE_MOV) { if (track->timescale > UINT16_MAX) { diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index d44e767..cffe197 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -891,7 +891,7 @@ static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con avio_wb32(pb, st->codec->channels); mxf_write_local_tag(pb, 4, 0x3D01); - avio_wb32(pb, av_get_bits_per_sample(st->codec->codec_id)); + avio_wb32(pb, avcodec_get_bits_per_coded_sample(st->codec->codec_id)); } static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) diff --git a/libavformat/pcm.c b/libavformat/pcm.c index d66be59..df4d2d1 100644 --- a/libavformat/pcm.c +++ b/libavformat/pcm.c @@ -33,7 +33,7 @@ int pcm_read_seek(AVFormatContext *s, st = s->streams[0]; block_align = st->codec->block_align ? st->codec->block_align : - (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3; + (st->codec->bits_per_coded_sample * st->codec->channels) >> 3; byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 : block_align * st->codec->sample_rate; diff --git a/libavformat/riff.c b/libavformat/riff.c index 060eaa0..41c43b1 100644 --- a/libavformat/riff.c +++ b/libavformat/riff.c @@ -372,7 +372,7 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) return -1; waveformatextensible = (enc->channels > 2 && enc->channel_layout) || enc->sample_rate > 48000 - || av_get_bits_per_sample(enc->codec_id) > 16; + || avcodec_get_bits_per_coded_sample(enc->codec_id) > 16; if (waveformatextensible) { avio_wl16(pb, 0xfffe); @@ -386,7 +386,7 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { bps = 4; } else { - if (!(bps = av_get_bits_per_sample(enc->codec_id))) + if (!(bps = avcodec_get_bits_per_coded_sample(enc->codec_id))) bps = 16; // default to 16 } if(bps != enc->bits_per_coded_sample && enc->bits_per_coded_sample){ -- 1.7.2.5
_______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
