[FFmpeg-devel] [PATCH 006/279] avcodecpar: switch to the new channel layout API
James Almer
jamrial at gmail.com
Wed Dec 8 03:06:22 EET 2021
From: Vittorio Giovara <vittorio.giovara at gmail.com>
Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>
Signed-off-by: Anton Khirnov <anton at khirnov.net>
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/codec_par.c | 37 +++++++++++++++++++++++++++++++++----
libavcodec/codec_par.h | 12 ++++++++++++
libavcodec/utils.c | 12 ++++++++++--
3 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index 1a5168a04b..9d43af1db4 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -31,6 +31,7 @@
static void codec_parameters_reset(AVCodecParameters *par)
{
av_freep(&par->extradata);
+ av_channel_layout_uninit(&par->ch_layout);
memset(par, 0, sizeof(*par));
@@ -71,6 +72,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 +87,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 +125,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 +191,19 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
break;
case AVMEDIA_TYPE_AUDIO:
codec->sample_fmt = par->format;
- codec->channel_layout = par->channel_layout;
- codec->channels = par->channels;
+ 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;
diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h
index 10cf79dff1..4cacfbf3b3 100644
--- a/libavcodec/codec_par.h
+++ b/libavcodec/codec_par.h
@@ -24,6 +24,7 @@
#include <stdint.h>
#include "libavutil/avutil.h"
+#include "libavutil/channel_layout.h"
#include "libavutil/rational.h"
#include "libavutil/pixfmt.h"
@@ -149,6 +150,7 @@ typedef struct AVCodecParameters {
enum AVColorSpace color_space;
enum AVChromaLocation chroma_location;
+#if FF_API_OLD_CHANNEL_LAYOUT
/**
* Video only. Number of delayed frames.
*/
@@ -158,12 +160,17 @@ typedef struct AVCodecParameters {
* 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;
/**
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index a91a54b0dc..dc5156210f 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -826,8 +826,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);
--
2.34.1
More information about the ffmpeg-devel
mailing list