1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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>
This commit is contained in:
Michael Niedermayer 2012-04-09 22:48:20 +02:00
commit 6bfb3042b3
10 changed files with 89 additions and 28 deletions

View File

@ -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.

View File

@ -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);
}
}

View File

@ -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,

View File

@ -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--;

View File

@ -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, \

View File

@ -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, },
};

View File

@ -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);

View File

@ -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, \

View File

@ -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;
}

View File

@ -61,6 +61,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()
*/