From 700452e04d179cccf7775d4c4f840383769529f8 Mon Sep 17 00:00:00 2001
From: Gildas Bazin <gbazin@videolan.org>
Date: Mon, 30 Dec 2002 17:28:31 +0000
Subject: [PATCH] * modules/codec/*: make sure all audio decoders set
 output_format.i_bytes_per_frame and output_format.i_frame_length properly.

---
 modules/codec/adpcm.c              |  5 ++++-
 modules/codec/araw.c               |  4 +++-
 modules/codec/faad/decoder.c       |  5 ++++-
 modules/codec/ffmpeg/audio.c       |  5 ++++-
 modules/codec/lpcm.c               | 10 ++++++++--
 modules/codec/mad/libmad.c         |  3 +++
 modules/codec/mpeg_audio/decoder.c |  5 ++++-
 modules/codec/vorbis.c             |  5 ++++-
 8 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/modules/codec/adpcm.c b/modules/codec/adpcm.c
index 61e79df891..80ee5d76ba 100644
--- a/modules/codec/adpcm.c
+++ b/modules/codec/adpcm.c
@@ -2,7 +2,7 @@
  * adpcm.c : adpcm variant audio decoder
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: adpcm.c,v 1.2 2002/12/18 14:17:10 sam Exp $
+ * $Id: adpcm.c,v 1.3 2002/12/30 17:28:31 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *      
@@ -305,6 +305,9 @@ static int InitThread( adec_thread_t * p_adec )
     p_adec->output_format.i_physical_channels = 
         p_adec->output_format.i_original_channels =
             pi_channels_maps[p_adec->p_wf->nChannels];
+    p_adec->output_format.i_bytes_per_frame =
+        p_adec->p_wf->nChannels * 2;
+    p_adec->output_format.i_frame_length = 1;
     p_adec->p_aout = NULL;
     p_adec->p_aout_input = NULL;
 
diff --git a/modules/codec/araw.c b/modules/codec/araw.c
index 7f82596896..c5cd13be45 100644
--- a/modules/codec/araw.c
+++ b/modules/codec/araw.c
@@ -2,7 +2,7 @@
  * araw.c: Pseudo audio decoder; for raw pcm data
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: araw.c,v 1.8 2002/11/28 16:32:29 fenrir Exp $
+ * $Id: araw.c,v 1.9 2002/12/30 17:28:31 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *      
@@ -247,6 +247,8 @@ static int InitThread( adec_thread_t * p_adec )
     p_adec->output_format.i_physical_channels = 
             p_adec->output_format.i_original_channels =
             pi_channels_maps[p_adec->p_wf->nChannels];
+    p_adec->output_format.i_bytes_per_frame = p_adec->p_wf->nBlockAlign;
+    p_adec->output_format.i_frame_length = 1;
     p_adec->p_aout = NULL;
     p_adec->p_aout_input = NULL;
 
diff --git a/modules/codec/faad/decoder.c b/modules/codec/faad/decoder.c
index 427ba5ea3b..837dea7c83 100644
--- a/modules/codec/faad/decoder.c
+++ b/modules/codec/faad/decoder.c
@@ -2,7 +2,7 @@
  * decoder.c: AAC decoder using libfaad2
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: decoder.c,v 1.14 2002/11/28 16:32:29 fenrir Exp $
+ * $Id: decoder.c,v 1.15 2002/12/30 17:28:31 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *      
@@ -407,6 +407,9 @@ static void DecodeThread( adec_thread_t *p_adec )
         p_adec->output_format.i_physical_channels =
             p_adec->output_format.i_original_channels =
                 pi_channels_maps[faad_frame.channels];
+        p_adec->output_format.i_bytes_per_frame =
+            faad_frame.channels * sizeof(float);
+        p_adec->output_format.i_frame_length = 1;
 
         aout_DateInit( &p_adec->date, p_adec->output_format.i_rate );
         p_adec->p_aout_input = aout_DecNew( p_adec->p_fifo,
diff --git a/modules/codec/ffmpeg/audio.c b/modules/codec/ffmpeg/audio.c
index ca0582f384..15467dd6de 100644
--- a/modules/codec/ffmpeg/audio.c
+++ b/modules/codec/ffmpeg/audio.c
@@ -2,7 +2,7 @@
  * audio.c: audio decoder using ffmpeg library
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: audio.c,v 1.8 2002/12/18 14:17:10 sam Exp $
+ * $Id: audio.c,v 1.9 2002/12/30 17:28:31 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -260,6 +260,9 @@ void  E_( DecodeThread_Audio )( adec_thread_t *p_adec )
         p_adec->output_format.i_physical_channels = 
             p_adec->output_format.i_original_channels = 
                 pi_channels_maps[p_adec->p_context->channels];
+        p_adec->output_format.i_bytes_per_frame =
+            p_adec->p_context->channels * sizeof(int16_t);
+        p_adec->output_format.i_frame_length = 1;
 
         aout_DateInit( &p_adec->date, p_adec->output_format.i_rate );
         p_adec->p_aout_input = aout_DecNew( p_adec->p_fifo,
diff --git a/modules/codec/lpcm.c b/modules/codec/lpcm.c
index aa875e3932..c483e4ec34 100644
--- a/modules/codec/lpcm.c
+++ b/modules/codec/lpcm.c
@@ -2,7 +2,7 @@
  * lpcm.c: lpcm decoder module
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: lpcm.c,v 1.8 2002/12/28 02:02:18 massiot Exp $
+ * $Id: lpcm.c,v 1.9 2002/12/30 17:28:31 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Henri Fallon <henri@videolan.org>
@@ -176,7 +176,7 @@ static void DecodeFrame( dec_thread_t * p_dec )
     aout_buffer_t *    p_buffer;
     mtime_t            i_pts;
     uint8_t            i_header;
-    unsigned int       i_rate, i_original_channels;
+    unsigned int       i_rate, i_original_channels, i_nb_channels;
 
     /* Look for sync word - should be 0xXX80 */
     RealignBits( &p_dec->bit_stream );
@@ -214,18 +214,22 @@ static void DecodeFrame( dec_thread_t * p_dec )
     {
     case 0:
         i_original_channels = AOUT_CHAN_CENTER;
+        i_nb_channels = 1;
         break;
     case 1:
         i_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
+        i_nb_channels = 2;
         break;
     case 3:
         i_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
                                | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
+        i_nb_channels = 4;
         break;
     case 5:
         i_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
                                | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
                                | AOUT_CHAN_CENTER | AOUT_CHAN_LFE;
+        i_nb_channels = 6;
         break;
     case 2:
     case 4:
@@ -255,6 +259,8 @@ static void DecodeFrame( dec_thread_t * p_dec )
         p_dec->output_format.i_original_channels = i_original_channels;
         p_dec->output_format.i_physical_channels
                    = i_original_channels & AOUT_CHAN_PHYSMASK;
+        p_dec->output_format.i_bytes_per_frame = i_nb_channels * 2;
+        p_dec->output_format.i_frame_length = 1;
         aout_DateInit( &p_dec->end_date, i_rate );
         p_dec->p_aout_input = aout_DecNew( p_dec->p_fifo,
                                            &p_dec->p_aout,
diff --git a/modules/codec/mad/libmad.c b/modules/codec/mad/libmad.c
index 33bba9bde1..ef41e675c4 100644
--- a/modules/codec/mad/libmad.c
+++ b/modules/codec/mad/libmad.c
@@ -180,6 +180,9 @@ enum mad_flow libmad_output( void *p_data, struct mad_header const *p_header,
         p_dec->output_format.i_rate = p_pcm->samplerate;
         p_dec->output_format.i_physical_channels = i_channels;
         p_dec->output_format.i_original_channels = i_channels;
+        p_dec->output_format.i_bytes_per_frame =
+            p_pcm->channels * sizeof(mad_fixed_t);
+        p_dec->output_format.i_frame_length = 1;
         aout_DateInit( &p_dec->end_date, p_pcm->samplerate );
         p_dec->p_aout_input = aout_DecNew( p_dec->p_fifo,
                                            &p_dec->p_aout,
diff --git a/modules/codec/mpeg_audio/decoder.c b/modules/codec/mpeg_audio/decoder.c
index e53258ebde..ed252d5aaa 100644
--- a/modules/codec/mpeg_audio/decoder.c
+++ b/modules/codec/mpeg_audio/decoder.c
@@ -2,7 +2,7 @@
  * decoder.c: MPEG audio decoder thread
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: decoder.c,v 1.9 2002/12/06 16:34:05 sam Exp $
+ * $Id: decoder.c,v 1.10 2002/12/30 17:28:31 gbazin Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
@@ -192,6 +192,9 @@ static void DecodeThread( adec_thread_t * p_dec )
                ( sync_info.b_stereo ? AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT :
                  AOUT_CHAN_CENTER );
             p_dec->output_format.i_rate     = sync_info.sample_rate;
+            p_dec->output_format.i_bytes_per_frame =
+               ( sync_info.b_stereo ? 2 : 1 ) * sizeof(float);
+            p_dec->output_format.i_frame_length = 1;
             aout_DateInit( &p_dec->end_date, sync_info.sample_rate );
             p_dec->p_aout_input = aout_DecNew( p_dec->p_fifo,
                                                &p_dec->p_aout,
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index 0a13805923..84286c43f9 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -2,7 +2,7 @@
  * vorbis.c: vorbis decoder module making use of libvorbis.
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: vorbis.c,v 1.9 2002/12/19 23:23:25 sigmunau Exp $
+ * $Id: vorbis.c,v 1.10 2002/12/30 17:28:31 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -224,6 +224,9 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
         p_dec->output_format.i_original_channels =
             pi_channels_maps[p_dec->vi.channels];
     p_dec->output_format.i_rate = p_dec->vi.rate;
+    p_dec->output_format.i_bytes_per_frame =
+        p_dec->vi.channels * sizeof(float);
+    p_dec->output_format.i_frame_length = 1;
 
     aout_DateInit( &p_dec->end_date, p_dec->vi.rate );
     p_dec->p_aout = NULL;
-- 
2.25.4