Discussion:
[PATCH] lavc: add channels field to AVFrame
Stefano Sabatini
2012-07-30 14:11:36 UTC
Permalink
This is required otherwise it is not always possible to guess the number
of channels from the layout, for example if the channel layout is
unknown.
---
libavcodec/avcodec.h | 11 +++++++++++
libavcodec/utils.c | 4 ++++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index edbc59b..fb16c83 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1337,6 +1337,15 @@ typedef struct AVFrame {
int decode_error_flags;
#define FF_DECODE_ERROR_INVALID_BITSTREAM 1
#define FF_DECODE_ERROR_MISSING_REFERENCE 2
+
+ /**
+ * number of audio channels, only used for audio.
+ * Code outside libavcodec should access this field using:
+ * av_frame_get_channels(frame)
+ * - encoding: unused
+ * - decoding: Read by user.
+ */
+ int64_t channels;
} AVFrame;

/**
@@ -1352,6 +1361,8 @@ int64_t av_frame_get_pkt_pos (const AVFrame *frame);
void av_frame_set_pkt_pos (AVFrame *frame, int64_t val);
int64_t av_frame_get_channel_layout (const AVFrame *frame);
void av_frame_set_channel_layout (AVFrame *frame, int64_t val);
+int av_frame_get_channels (const AVFrame *frame);
+void av_frame_set_channels (AVFrame *frame, int val);
int av_frame_get_sample_rate (const AVFrame *frame);
void av_frame_set_sample_rate (AVFrame *frame, int val);
AVDictionary *av_frame_get_metadata (const AVFrame *frame);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 53fda1f..2f4cb5d 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -427,6 +427,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
frame->sample_rate = avctx->sample_rate;
frame->format = avctx->sample_fmt;
frame->channel_layout = avctx->channel_layout;
+ frame->channels = avctx->channels;

if (avctx->debug & FF_DEBUG_BUFFERS)
av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, "
@@ -724,6 +725,7 @@ MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp)
MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration)
MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_pos)
MAKE_ACCESSORS(AVFrame, frame, int64_t, channel_layout)
+MAKE_ACCESSORS(AVFrame, frame, int, channels)
MAKE_ACCESSORS(AVFrame, frame, int, sample_rate)
MAKE_ACCESSORS(AVFrame, frame, AVDictionary *, metadata)
MAKE_ACCESSORS(AVFrame, frame, int, decode_error_flags)
@@ -1648,6 +1650,8 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
frame->format = avctx->sample_fmt;
if (!frame->channel_layout)
frame->channel_layout = avctx->channel_layout;
+ if (!frame->channels)
+ frame->channels = avctx->channels;
if (!frame->sample_rate)
frame->sample_rate = avctx->sample_rate;
}
--
1.7.5.4
Michael Niedermayer
2012-07-30 16:49:32 UTC
Permalink
Post by Stefano Sabatini
This is required otherwise it is not always possible to guess the number
of channels from the layout, for example if the channel layout is
unknown.
---
libavcodec/avcodec.h | 11 +++++++++++
libavcodec/utils.c | 4 ++++
2 files changed, 15 insertions(+), 0 deletions(-)
LGTM

thanks

[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 1
"Used only once" - "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."
Stefano Sabatini
2012-07-30 17:03:23 UTC
Permalink
Post by Michael Niedermayer
Post by Stefano Sabatini
This is required otherwise it is not always possible to guess the number
of channels from the layout, for example if the channel layout is
unknown.
---
libavcodec/avcodec.h | 11 +++++++++++
libavcodec/utils.c | 4 ++++
2 files changed, 15 insertions(+), 0 deletions(-)
LGTM
thanks
Nit: should be nb_channels (more meaningful, consistent with
nb_samples) or channels (consistent with AVCodecContext)?

I'm not still sure it is a good idea to propagate the info to lavfi
(since we may require that the channel layout is always set inside the
filtergraph), but this patch seems useful on its own and shouldn't
hurt anyway.
--
FFmpeg = Faithful & Fiendish Multimedia Powerful Encoding/decoding Gigant
Michael Niedermayer
2012-07-30 19:24:47 UTC
Permalink
Post by Stefano Sabatini
Post by Michael Niedermayer
Post by Stefano Sabatini
This is required otherwise it is not always possible to guess the number
of channels from the layout, for example if the channel layout is
unknown.
---
libavcodec/avcodec.h | 11 +++++++++++
libavcodec/utils.c | 4 ++++
2 files changed, 15 insertions(+), 0 deletions(-)
LGTM
thanks
Nit: should be nb_channels (more meaningful, consistent with
nb_samples) or channels (consistent with AVCodecContext)?
whichever name you prefer ...
i would probably favor consistency to the equivalent field in
other structs like AVCodecContext but thats only a very slight
preferance
Post by Stefano Sabatini
I'm not still sure it is a good idea to propagate the info to lavfi
(since we may require that the channel layout is always set inside the
filtergraph), but this patch seems useful on its own and shouldn't
hurt anyway.
yes, especially when the number changes having it in AVFrame is a good
idea

[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 1
"Used only once" - "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."
Stefano Sabatini
2012-07-31 11:33:47 UTC
Permalink
Post by Michael Niedermayer
Post by Stefano Sabatini
Post by Michael Niedermayer
Post by Stefano Sabatini
This is required otherwise it is not always possible to guess the number
of channels from the layout, for example if the channel layout is
unknown.
---
libavcodec/avcodec.h | 11 +++++++++++
libavcodec/utils.c | 4 ++++
2 files changed, 15 insertions(+), 0 deletions(-)
LGTM
thanks
Nit: should be nb_channels (more meaningful, consistent with
nb_samples) or channels (consistent with AVCodecContext)?
whichever name you prefer ...
i would probably favor consistency to the equivalent field in
other structs like AVCodecContext but thats only a very slight
preferance
Post by Stefano Sabatini
I'm not still sure it is a good idea to propagate the info to lavfi
(since we may require that the channel layout is always set inside the
filtergraph), but this patch seems useful on its own and shouldn't
hurt anyway.
yes, especially when the number changes having it in AVFrame is a good
idea
Applied.
--
FFmpeg = Free Fabulous Mythic Programmable Evil God
Loading...