changeset 32535:6320065226a6

Fix possible division by 0 if -aid is used for AVI files.
author reimar
date Sat, 13 Nov 2010 10:17:13 +0000
parents 899d7464d246
children 187f26cba0ce
files libmpdemux/demux_avi.c
diffstat 1 files changed, 29 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_avi.c	Fri Nov 12 07:16:32 2010 +0000
+++ b/libmpdemux/demux_avi.c	Sat Nov 13 10:17:13 2010 +0000
@@ -39,6 +39,32 @@
 // PTS:  0=interleaved  1=BPS-based
 int pts_from_bps=1;
 
+static void update_audio_block_size(demuxer_t *demux)
+{
+  avi_priv_t *priv = demux->priv;
+  sh_audio_t *sh = demux->audio->sh;
+  if (!sh)
+    return;
+  priv->audio_block_size = sh->audio.dwSampleSize;
+  if (sh->wf) {
+    priv->audio_block_size = sh->wf->nBlockAlign;
+    if (!priv->audio_block_size) {
+      // for PCM audio we can calculate the blocksize:
+      if (sh->format == 1)
+        priv->audio_block_size = sh->wf->nChannels*(sh->wf->wBitsPerSample/8);
+      else
+        priv->audio_block_size = 1; // hope the best...
+    } else {
+      // workaround old mencoder bug:
+      if (sh->audio.dwSampleSize == 1 && sh->audio.dwScale == 1 &&
+          (sh->wf->nBlockAlign == 1152 || sh->wf->nBlockAlign == 576)) {
+        mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_WorkAroundBlockAlignHeaderBug);
+        priv->audio_block_size = 1;
+      }
+    }
+  }
+}
+
 // Select ds from ID
 static demux_stream_t *demux_avi_select_stream(demuxer_t *demux,
                                                unsigned int id)
@@ -56,29 +82,9 @@
 
   if(stream_id==demux->audio->id){
       if(!demux->audio->sh){
-        sh_audio_t* sh;
-	avi_priv_t *priv=demux->priv;
-        sh=demux->audio->sh=demux->a_streams[stream_id];
+        demux->audio->sh=demux->a_streams[stream_id];
         mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected AVI audio ID = %d\n",demux->audio->id);
-	if(sh->wf){
-	  priv->audio_block_size=sh->wf->nBlockAlign;
-	  if(!priv->audio_block_size){
-	    // for PCM audio we can calculate the blocksize:
-	    if(sh->format==1)
-		priv->audio_block_size=sh->wf->nChannels*(sh->wf->wBitsPerSample/8);
-	    else
-		priv->audio_block_size=1; // hope the best...
-	  } else {
-	    // workaround old mencoder's bug:
-	    if(sh->audio.dwSampleSize==1 && sh->audio.dwScale==1 &&
-	       (sh->wf->nBlockAlign==1152 || sh->wf->nBlockAlign==576)){
-		mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_WorkAroundBlockAlignHeaderBug);
-		priv->audio_block_size=1;
-	    }
-	  }
-	} else {
-	  priv->audio_block_size=sh->audio.dwSampleSize;
-	}
+        update_audio_block_size(demux);
       }
       return demux->audio;
   }
@@ -442,6 +448,7 @@
 
   //---- AVI header:
   read_avi_header(demuxer,(demuxer->stream->flags & MP_STREAM_SEEK_BW)?index_mode:-2);
+  update_audio_block_size(demuxer);
 
   if(demuxer->audio->id>=0 && !demuxer->a_streams[demuxer->audio->id]){
       mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_InvalidAudioStreamNosound,demuxer->audio->id);