mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-27 01:42:20 +00:00
avcodecpar: switch to the new channel layout API
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com> Signed-off-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
db6efa1815
commit
276c06726f
@ -31,12 +31,14 @@
|
||||
static void codec_parameters_reset(AVCodecParameters *par)
|
||||
{
|
||||
av_freep(&par->extradata);
|
||||
av_channel_layout_uninit(&par->ch_layout);
|
||||
|
||||
memset(par, 0, sizeof(*par));
|
||||
|
||||
par->codec_type = AVMEDIA_TYPE_UNKNOWN;
|
||||
par->codec_id = AV_CODEC_ID_NONE;
|
||||
par->format = -1;
|
||||
par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
|
||||
par->field_order = AV_FIELD_UNKNOWN;
|
||||
par->color_range = AVCOL_RANGE_UNSPECIFIED;
|
||||
par->color_primaries = AVCOL_PRI_UNSPECIFIED;
|
||||
@ -71,6 +73,8 @@ void avcodec_parameters_free(AVCodecParameters **ppar)
|
||||
|
||||
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
|
||||
{
|
||||
int ret;
|
||||
|
||||
codec_parameters_reset(dst);
|
||||
memcpy(dst, src, sizeof(*dst));
|
||||
|
||||
@ -84,6 +88,10 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src
|
||||
dst->extradata_size = src->extradata_size;
|
||||
}
|
||||
|
||||
ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -118,8 +126,19 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
|
||||
break;
|
||||
case AVMEDIA_TYPE_AUDIO:
|
||||
par->format = codec->sample_fmt;
|
||||
par->channel_layout = codec->channel_layout;
|
||||
par->channels = codec->channels;
|
||||
if (codec->channel_layout)
|
||||
av_channel_layout_from_mask(&par->ch_layout, codec->channel_layout);
|
||||
else {
|
||||
par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
|
||||
par->ch_layout.nb_channels = codec->channels;
|
||||
}
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
|
||||
par->ch_layout.u.mask : 0;
|
||||
par->channels = par->ch_layout.nb_channels;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
par->sample_rate = codec->sample_rate;
|
||||
par->block_align = codec->block_align;
|
||||
par->frame_size = codec->frame_size;
|
||||
@ -173,8 +192,19 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
|
||||
break;
|
||||
case AVMEDIA_TYPE_AUDIO:
|
||||
codec->sample_fmt = par->format;
|
||||
if (par->ch_layout.nb_channels) {
|
||||
codec->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
|
||||
par->ch_layout.u.mask : 0;
|
||||
codec->channels = par->ch_layout.nb_channels;
|
||||
}
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
else {
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
codec->channel_layout = par->channel_layout;
|
||||
codec->channels = par->channels;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
}
|
||||
#endif
|
||||
codec->sample_rate = par->sample_rate;
|
||||
codec->block_align = par->block_align;
|
||||
codec->frame_size = par->frame_size;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libavutil/avutil.h"
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "libavutil/rational.h"
|
||||
#include "libavutil/pixfmt.h"
|
||||
|
||||
@ -154,16 +155,22 @@ typedef struct AVCodecParameters {
|
||||
*/
|
||||
int video_delay;
|
||||
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
/**
|
||||
* Audio only. The channel layout bitmask. May be 0 if the channel layout is
|
||||
* unknown or unspecified, otherwise the number of bits set must be equal to
|
||||
* the channels field.
|
||||
* @deprecated use ch_layout
|
||||
*/
|
||||
attribute_deprecated
|
||||
uint64_t channel_layout;
|
||||
/**
|
||||
* Audio only. The number of audio channels.
|
||||
* @deprecated use ch_layout.nb_channels
|
||||
*/
|
||||
attribute_deprecated
|
||||
int channels;
|
||||
#endif
|
||||
/**
|
||||
* Audio only. The number of audio samples per second.
|
||||
*/
|
||||
@ -198,6 +205,11 @@ typedef struct AVCodecParameters {
|
||||
* Audio only. Number of samples to skip after a discontinuity.
|
||||
*/
|
||||
int seek_preroll;
|
||||
|
||||
/**
|
||||
* Audio only. The channel layout and number of channels.
|
||||
*/
|
||||
AVChannelLayout ch_layout;
|
||||
} AVCodecParameters;
|
||||
|
||||
/**
|
||||
|
@ -814,8 +814,16 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
|
||||
|
||||
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
|
||||
{
|
||||
int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
|
||||
par->channels, par->block_align,
|
||||
int channels = par->ch_layout.nb_channels;
|
||||
int duration;
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
if (!channels)
|
||||
channels = par->channels;
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
|
||||
channels, par->block_align,
|
||||
par->codec_tag, par->bits_per_coded_sample,
|
||||
par->bit_rate, par->extradata, par->frame_size,
|
||||
frame_bytes);
|
||||
|
Loading…
Reference in New Issue
Block a user