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:
committed by
James Almer
parent
db6efa1815
commit
276c06726f
@@ -31,12 +31,14 @@
|
|||||||
static void codec_parameters_reset(AVCodecParameters *par)
|
static void codec_parameters_reset(AVCodecParameters *par)
|
||||||
{
|
{
|
||||||
av_freep(&par->extradata);
|
av_freep(&par->extradata);
|
||||||
|
av_channel_layout_uninit(&par->ch_layout);
|
||||||
|
|
||||||
memset(par, 0, sizeof(*par));
|
memset(par, 0, sizeof(*par));
|
||||||
|
|
||||||
par->codec_type = AVMEDIA_TYPE_UNKNOWN;
|
par->codec_type = AVMEDIA_TYPE_UNKNOWN;
|
||||||
par->codec_id = AV_CODEC_ID_NONE;
|
par->codec_id = AV_CODEC_ID_NONE;
|
||||||
par->format = -1;
|
par->format = -1;
|
||||||
|
par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
|
||||||
par->field_order = AV_FIELD_UNKNOWN;
|
par->field_order = AV_FIELD_UNKNOWN;
|
||||||
par->color_range = AVCOL_RANGE_UNSPECIFIED;
|
par->color_range = AVCOL_RANGE_UNSPECIFIED;
|
||||||
par->color_primaries = AVCOL_PRI_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 avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
codec_parameters_reset(dst);
|
codec_parameters_reset(dst);
|
||||||
memcpy(dst, src, sizeof(*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;
|
dst->extradata_size = src->extradata_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,8 +126,19 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
|
|||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_AUDIO:
|
case AVMEDIA_TYPE_AUDIO:
|
||||||
par->format = codec->sample_fmt;
|
par->format = codec->sample_fmt;
|
||||||
par->channel_layout = codec->channel_layout;
|
if (codec->channel_layout)
|
||||||
par->channels = codec->channels;
|
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->sample_rate = codec->sample_rate;
|
||||||
par->block_align = codec->block_align;
|
par->block_align = codec->block_align;
|
||||||
par->frame_size = codec->frame_size;
|
par->frame_size = codec->frame_size;
|
||||||
@@ -173,8 +192,19 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
|
|||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_AUDIO:
|
case AVMEDIA_TYPE_AUDIO:
|
||||||
codec->sample_fmt = par->format;
|
codec->sample_fmt = par->format;
|
||||||
codec->channel_layout = par->channel_layout;
|
if (par->ch_layout.nb_channels) {
|
||||||
codec->channels = par->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->sample_rate = par->sample_rate;
|
||||||
codec->block_align = par->block_align;
|
codec->block_align = par->block_align;
|
||||||
codec->frame_size = par->frame_size;
|
codec->frame_size = par->frame_size;
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "libavutil/avutil.h"
|
#include "libavutil/avutil.h"
|
||||||
|
#include "libavutil/channel_layout.h"
|
||||||
#include "libavutil/rational.h"
|
#include "libavutil/rational.h"
|
||||||
#include "libavutil/pixfmt.h"
|
#include "libavutil/pixfmt.h"
|
||||||
|
|
||||||
@@ -154,16 +155,22 @@ typedef struct AVCodecParameters {
|
|||||||
*/
|
*/
|
||||||
int video_delay;
|
int video_delay;
|
||||||
|
|
||||||
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||||
/**
|
/**
|
||||||
* Audio only. The channel layout bitmask. May be 0 if the channel layout is
|
* 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
|
* unknown or unspecified, otherwise the number of bits set must be equal to
|
||||||
* the channels field.
|
* the channels field.
|
||||||
|
* @deprecated use ch_layout
|
||||||
*/
|
*/
|
||||||
|
attribute_deprecated
|
||||||
uint64_t channel_layout;
|
uint64_t channel_layout;
|
||||||
/**
|
/**
|
||||||
* Audio only. The number of audio channels.
|
* Audio only. The number of audio channels.
|
||||||
|
* @deprecated use ch_layout.nb_channels
|
||||||
*/
|
*/
|
||||||
|
attribute_deprecated
|
||||||
int channels;
|
int channels;
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Audio only. The number of audio samples per second.
|
* 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.
|
* Audio only. Number of samples to skip after a discontinuity.
|
||||||
*/
|
*/
|
||||||
int seek_preroll;
|
int seek_preroll;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audio only. The channel layout and number of channels.
|
||||||
|
*/
|
||||||
|
AVChannelLayout ch_layout;
|
||||||
} AVCodecParameters;
|
} 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 av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
|
||||||
{
|
{
|
||||||
int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
|
int channels = par->ch_layout.nb_channels;
|
||||||
par->channels, par->block_align,
|
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->codec_tag, par->bits_per_coded_sample,
|
||||||
par->bit_rate, par->extradata, par->frame_size,
|
par->bit_rate, par->extradata, par->frame_size,
|
||||||
frame_bytes);
|
frame_bytes);
|
||||||
|
Reference in New Issue
Block a user