aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-04-09 22:48:20 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-04-09 23:02:33 +0200
commit6bfb3042b3158f0a87629ab0c126cccb269c3d5a (patch)
tree08699d0bcef99f30b084db2980759af901f8af91
parent7f66912f1a303a369f6ac435d630971d74310a81 (diff)
parent679a973e9701576b1c3c6d71838c45c10ac20564 (diff)
downloadffmpeg-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>
-rw-r--r--doc/APIchanges3
-rw-r--r--ffmpeg.c17
-rw-r--r--libavcodec/avcodec.h2
-rw-r--r--libavcodec/utils.c18
-rw-r--r--libavcodec/version.h2
-rw-r--r--libavutil/audioconvert.c3
-rw-r--r--libavutil/audioconvert.h8
-rw-r--r--libavutil/avutil.h2
-rw-r--r--libavutil/samplefmt.c31
-rw-r--r--libavutil/samplefmt.h31
10 files changed, 89 insertions, 28 deletions
diff --git a/doc/APIchanges b/doc/APIchanges
index d0357516ca..991630969e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -16,6 +16,9 @@ API changes, most recent first:
2012-03-26 - a67d9cf - lavfi 2.66.100
Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.
+2012-xx-xx - xxxxxxx - lavu 51.27.0 - samplefmt.h
+ Add av_get_packed_sample_fmt() and av_get_planar_sample_fmt()
+
2012-03-21 - b75c67d - lavu 51.43.100
Add bprint.h for bprint API.
diff --git a/ffmpeg.c b/ffmpeg.c
index 0f70118982..0a2375d38a 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -272,7 +272,6 @@ typedef struct OutputStream {
AVFilterContext *output_video_filter;
AVFilterContext *input_video_filter;
- AVFilterBufferRef *picref;
char *avfilter;
AVFilterGraph *graph;
@@ -1130,7 +1129,7 @@ static int alloc_audio_output_buf(AVCodecContext *dec, AVCodecContext *enc,
audio_buf_size = av_samples_get_buffer_size(NULL, enc->channels,
audio_buf_samples,
- enc->sample_fmt, 32);
+ enc->sample_fmt, 0);
if (audio_buf_size < 0)
return audio_buf_size;
@@ -2116,6 +2115,9 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
rate_emu_sleep(ist);
+ if (ist->st->sample_aspect_ratio.num)
+ decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
+
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = &output_streams[i];
@@ -2125,8 +2127,9 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
while (av_buffersink_poll_frame(ost->output_video_filter)) {
AVRational ist_pts_tb = ost->output_video_filter->inputs[0]->time_base;
AVFrame *filtered_frame;
+ AVFilterBufferRef *picref;
- if (av_buffersink_get_buffer_ref(ost->output_video_filter, &ost->picref, 0) < 0){
+ if (av_buffersink_get_buffer_ref(ost->output_video_filter, &picref, 0) < 0){
av_log(NULL, AV_LOG_WARNING, "AV Filter told us it has a frame available but failed to output one\n");
goto cont;
}
@@ -2136,13 +2139,13 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
}
filtered_frame = ist->filtered_frame;
*filtered_frame= *decoded_frame; //for me_threshold
- avfilter_fill_frame_from_video_buffer_ref(filtered_frame, ost->picref);
- filtered_frame->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
+ avfilter_fill_frame_from_video_buffer_ref(filtered_frame, picref);
+ filtered_frame->pts = av_rescale_q(picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
if (!ost->frame_aspect_ratio)
- ost->st->codec->sample_aspect_ratio = ost->picref->video->sample_aspect_ratio;
+ ost->st->codec->sample_aspect_ratio = picref->video->sample_aspect_ratio;
do_video_out(output_files[ost->file_index].ctx, ost, ist, filtered_frame);
cont:
- avfilter_unref_buffer(ost->picref);
+ avfilter_unref_buffer(picref);
}
}
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index de9b245879..56fc15cad1 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4018,7 +4018,7 @@ int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
* @param sample_fmt sample format
* @param buf buffer to use for frame data
* @param buf_size size of buffer
- * @param align plane size sample alignment
+ * @param align plane size sample alignment (0 = default)
* @return 0 on success, negative error code on failure
*/
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index ab34b40c62..f6c9466fbc 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -319,7 +319,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
frame->nb_samples, avctx->sample_fmt,
- 32);
+ 0);
if (buf_size < 0)
return AVERROR(EINVAL);
@@ -361,7 +361,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
}
if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,
avctx->sample_fmt, buf->data[0],
- buf->audio_data_size, 32)))
+ buf->audio_data_size, 0)))
return ret;
if (frame->extended_data == frame->data)
@@ -913,10 +913,18 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD
}
}
- if (av_codec_is_decoder(avctx->codec) && !avctx->bit_rate)
- avctx->bit_rate = get_bit_rate(avctx);
-
ret=0;
+
+ if (av_codec_is_decoder(avctx->codec)) {
+ if (!avctx->bit_rate)
+ avctx->bit_rate = get_bit_rate(avctx);
+ /* validate channel layout from the decoder */
+ if (avctx->channel_layout &&
+ av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) {
+ av_log(avctx, AV_LOG_WARNING, "channel layout does not match number of channels\n");
+ avctx->channel_layout = 0;
+ }
+ }
end:
entangled_thread_counter--;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 47591fde76..6c631d8045 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -22,7 +22,7 @@
#define LIBAVCODEC_VERSION_MAJOR 54
#define LIBAVCODEC_VERSION_MINOR 14
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
diff --git a/libavutil/audioconvert.c b/libavutil/audioconvert.c
index aa652a66b1..877027f1f7 100644
--- a/libavutil/audioconvert.c
+++ b/libavutil/audioconvert.c
@@ -80,19 +80,16 @@ static const struct {
{ "4.1", 5, AV_CH_LAYOUT_4POINT1 },
{ "5.1", 6, AV_CH_LAYOUT_5POINT1_BACK },
{ "5.1(side)", 6, AV_CH_LAYOUT_5POINT1 },
-// { "5.1+downmix", 8, AV_CH_LAYOUT_5POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, },
{ "6.0", 6, AV_CH_LAYOUT_6POINT0 },
{ "6.0(front)", 6, AV_CH_LAYOUT_6POINT0_FRONT },
{ "hexagonal", 6, AV_CH_LAYOUT_HEXAGONAL },
{ "6.1", 7, AV_CH_LAYOUT_6POINT1 },
{ "6.1", 7, AV_CH_LAYOUT_6POINT1_BACK },
{ "6.1(front)", 7, AV_CH_LAYOUT_6POINT1_FRONT },
-// { "6.1+downmix", 9, AV_CH_LAYOUT_6POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, },
{ "7.0", 7, AV_CH_LAYOUT_7POINT0 },
{ "7.0(front)", 7, AV_CH_LAYOUT_7POINT0_FRONT },
{ "7.1", 8, AV_CH_LAYOUT_7POINT1 },
{ "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE },
-// { "7.1+downmix", 10, AV_CH_LAYOUT_7POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, },
{ "octagonal", 8, AV_CH_LAYOUT_OCTAGONAL },
{ "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, },
};
diff --git a/libavutil/audioconvert.h b/libavutil/audioconvert.h
index 6414d3c3a0..f402b62f63 100644
--- a/libavutil/audioconvert.h
+++ b/libavutil/audioconvert.h
@@ -106,19 +106,21 @@
*/
/**
- * Return a channel layout id that matches name, 0 if no match.
+ * Return a channel layout id that matches name, or 0 if no match is found.
+ *
* name can be one or several of the following notations,
* separated by '+' or '|':
* - the name of an usual channel layout (mono, stereo, 4.0, quad, 5.0,
* 5.0(side), 5.1, 5.1(side), 7.1, 7.1(wide), downmix);
* - the name of a single channel (FL, FR, FC, LFE, BL, BR, FLC, FRC, BC,
* SL, SR, TC, TFL, TFC, TFR, TBL, TBC, TBR, DL, DR);
- * - a number of channels, in decimal, optionnally followed by 'c', yielding
+ * - a number of channels, in decimal, optionally followed by 'c', yielding
* the default channel layout for that number of channels (@see
* av_get_default_channel_layout);
* - a channel layout mask, in hexadecimal starting with "0x" (see the
* AV_CH_* macros).
- + Example: "stereo+FC" = "2+FC" = "2c+1c" = "0x7"
+ *
+ * Example: "stereo+FC" = "2+FC" = "2c+1c" = "0x7"
*/
uint64_t av_get_channel_layout(const char *name);
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 150b788bfb..6464167473 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -153,7 +153,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 45
+#define LIBAVUTIL_VERSION_MINOR 46
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
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;
}
diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h
index 855cffd838..af015d0cc3 100644
--- a/libavutil/samplefmt.h
+++ b/libavutil/samplefmt.h
@@ -62,6 +62,28 @@ enum AVSampleFormat av_get_sample_fmt(const char *name);
enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar);
/**
+ * Get the packed alternative form of the given sample format.
+ *
+ * If the passed sample_fmt is already in packed format, the format returned is
+ * the same as the input.
+ *
+ * @return the packed alternative form of the given sample format or
+ AV_SAMPLE_FMT_NONE on error.
+ */
+enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt);
+
+/**
+ * Get the planar alternative form of the given sample format.
+ *
+ * If the passed sample_fmt is already in planar format, the format returned is
+ * the same as the input.
+ *
+ * @return the planar alternative form of the given sample format or
+ AV_SAMPLE_FMT_NONE on error.
+ */
+enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt);
+
+/**
* Generate a string corresponding to the sample format with
* sample_fmt, or a header if sample_fmt is negative.
*
@@ -107,6 +129,7 @@ int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
* @param nb_channels the number of channels
* @param nb_samples the number of samples in a single channel
* @param sample_fmt the sample format
+ * @param align buffer size alignment (0 = default, 1 = no alignment)
* @return required buffer size, or negative error code on failure
*/
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
@@ -125,12 +148,12 @@ int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
* for packed layout.
*
* @param[out] audio_data array to be filled with the pointer for each channel
- * @param[out] linesize calculated linesize
+ * @param[out] linesize calculated linesize, may be NULL
* @param buf the pointer to a buffer containing the samples
* @param nb_channels the number of channels
* @param nb_samples the number of samples in a single channel
* @param sample_fmt the sample format
- * @param align buffer size alignment (1 = no alignment required)
+ * @param align buffer size alignment (0 = default, 1 = no alignment)
* @return 0 on success or a negative error code on failure
*/
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, uint8_t *buf,
@@ -143,10 +166,10 @@ int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, uint8_t *buf,
* The allocated samples buffer can be freed by using av_freep(&audio_data[0])
*
* @param[out] audio_data array to be filled with the pointer for each channel
- * @param[out] linesize aligned size for audio buffer(s)
+ * @param[out] linesize aligned size for audio buffer(s), may be NULL
* @param nb_channels number of audio channels
* @param nb_samples number of samples per channel
- * @param align buffer size alignment (1 = no alignment required)
+ * @param align buffer size alignment (0 = default, 1 = no alignment)
* @return 0 on success or a negative error code on failure
* @see av_samples_fill_arrays()
*/