Allows for changing channel layout during decoding.
---
 libavcodec/adpcm.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index f11b899..cf8c6cc 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -17,6 +17,8 @@
  * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/audioconvert.h"
 #include "avcodec.h"
 #include "get_bits.h"
 #include "put_bits.h"
@@ -89,9 +91,8 @@ typedef struct ADPCMDecodeContext {
     int vqa_version;                /**< VQA version. Used for ADPCM_IMA_WS */
 } ADPCMDecodeContext;
 
-static av_cold int adpcm_decode_init(AVCodecContext * avctx)
+static int adpcm_validate_channels(AVCodecContext *avctx)
 {
-    ADPCMDecodeContext *c = avctx->priv_data;
     unsigned int min_channels = 1;
     unsigned int max_channels = 2;
 
@@ -110,6 +111,21 @@ static av_cold int adpcm_decode_init(AVCodecContext * 
avctx)
         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
         return AVERROR(EINVAL);
     }
+    if (avctx->channel_layout &&
+        av_get_channel_layout_nb_channels(avctx->channel_layout) != 
avctx->channels) {
+        av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of 
channels\n");
+        return AVERROR(EINVAL);
+    }
+    return 0;
+}
+
+static av_cold int adpcm_decode_init(AVCodecContext * avctx)
+{
+    ADPCMDecodeContext *c = avctx->priv_data;
+    int ret;
+
+    if ((ret = adpcm_validate_channels(avctx)) < 0)
+        return ret;
 
     switch(avctx->codec->id) {
     case AV_CODEC_ID_ADPCM_CT:
@@ -578,6 +594,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void 
*data,
     int nb_samples, coded_samples, ret;
     GetByteContext gb;
 
+    if ((ret = adpcm_validate_channels(avctx)) < 0)
+        return ret;
+
     bytestream2_init(&gb, buf, buf_size);
     nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples);
     if (nb_samples <= 0) {
-- 
1.7.1

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to