diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-04-09 22:48:20 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-04-09 23:02:33 +0200 |
commit | 6bfb3042b3158f0a87629ab0c126cccb269c3d5a (patch) | |
tree | 08699d0bcef99f30b084db2980759af901f8af91 /libavutil/samplefmt.c | |
parent | 7f66912f1a303a369f6ac435d630971d74310a81 (diff) | |
parent | 679a973e9701576b1c3c6d71838c45c10ac20564 (diff) | |
download | ffmpeg-6bfb3042b3158f0a87629ab0c126cccb269c3d5a.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
avconv: use default alignment for audio buffer
avcodec: use align == 0 for default alignment in avcodec_fill_audio_frame()
avutil: use align == 0 for default alignment in audio sample buffer functions
avutil: allow NULL linesize in av_samples_fill_arrays() and av_samples_alloc()
avconv: remove OutputStream.picref.
avconv: only set SAR once on the decoded frame.
avcodec: validate the channel layout vs. channel count for decoders
audioconvert: make av_get_channel_layout accept composite names.
avutil: add av_get_packed_sample_fmt() and av_get_planar_sample_fmt()
Conflicts:
doc/APIchanges
ffmpeg.c
libavcodec/utils.c
libavcodec/version.h
libavutil/audioconvert.c
libavutil/audioconvert.h
libavutil/avutil.h
libavutil/samplefmt.c
libavutil/samplefmt.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/samplefmt.c')
-rw-r--r-- | libavutil/samplefmt.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c index f4300036c2..98dacb1f66 100644 --- a/libavutil/samplefmt.c +++ b/libavutil/samplefmt.c @@ -69,6 +69,24 @@ enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int pl return sample_fmt_info[sample_fmt].altform; } +enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt) +{ + if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB) + return AV_SAMPLE_FMT_NONE; + if (sample_fmt_info[sample_fmt].planar) + return sample_fmt_info[sample_fmt].altform; + return sample_fmt; +} + +enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt) +{ + if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB) + return AV_SAMPLE_FMT_NONE; + if (sample_fmt_info[sample_fmt].planar) + return sample_fmt; + return sample_fmt_info[sample_fmt].altform; +} + char *av_get_sample_fmt_string (char *buf, int buf_size, enum AVSampleFormat sample_fmt) { /* print header */ @@ -114,6 +132,10 @@ int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, if (!sample_size || nb_samples <= 0 || nb_channels <= 0) return AVERROR(EINVAL); + /* auto-select alignment if not specified */ + if (!align) + align = 32; + /* check for integer overflow */ if (nb_channels > INT_MAX / align || (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size) @@ -131,17 +153,20 @@ int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align) { - int ch, planar, buf_size; + int ch, planar, buf_size, line_size; planar = av_sample_fmt_is_planar(sample_fmt); - buf_size = av_samples_get_buffer_size(linesize, nb_channels, nb_samples, + buf_size = av_samples_get_buffer_size(&line_size, nb_channels, nb_samples, sample_fmt, align); if (buf_size < 0) return buf_size; audio_data[0] = buf; for (ch = 1; planar && ch < nb_channels; ch++) - audio_data[ch] = audio_data[ch-1] + *linesize; + audio_data[ch] = audio_data[ch-1] + line_size; + + if (linesize) + *linesize = line_size; return 0; } |