[FFmpeg-devel] [PATCH] add AVCodecContext field to specify desired number of channels

Reimar Döffinger Reimar.Doeffinger
Sun Aug 19 16:56:44 CEST 2007


Hello,
since the current way of setting ->channels no matter how it is done
will break some codecs I suggest adding a new field.
Also has the advantage that it will be easier to allow handling the
cases where either the number of desired channels changes or the number
of channels in the file changes.
I also think that the current behaviour of dca is not good: if it can't
deliver the requested number of channels it should just use either
something close or the native number instead of failing.
Is it right to add this at the end of the context or should it be near
"channels"?

Greetings,
Reimar D?ffinger
-------------- next part --------------
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 1719b02..0fdc65f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -33,8 +33,8 @@
 #define AV_STRINGIFY(s)         AV_TOSTRING(s)
 #define AV_TOSTRING(s) #s
 
-#define LIBAVCODEC_VERSION_INT  ((51<<16)+(41<<8)+0)
-#define LIBAVCODEC_VERSION      51.41.0
+#define LIBAVCODEC_VERSION_INT  ((51<<16)+(42<<8)+0)
+#define LIBAVCODEC_VERSION      51.42.0
 #define LIBAVCODEC_BUILD        LIBAVCODEC_VERSION_INT
 
 #define LIBAVCODEC_IDENT        "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
@@ -2123,6 +2123,13 @@ typedef struct AVCodecContext {
      * - decoding: unused
      */
     int64_t timecode_frame_start;
+
+    /**
+     * Decoder should decode to this many channels if it can (0 for default)
+     * - encoding: unused
+     * - decoding: Set by user.
+     */
+    int request_channels;
 } AVCodecContext;
 
 /**
diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index d9bf03a..0426693 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -1158,6 +1158,7 @@ static int dca_decode_frame(AVCodecContext * avctx,
     avctx->bit_rate = s->bit_rate;
 
     channels = s->prim_channels + !!s->lfe;
+    avctx->channels = avctx->request_channels;
     if(avctx->channels == 0) {
         avctx->channels = channels;
     } else if(channels < avctx->channels) {



More information about the ffmpeg-devel mailing list