[MPlayer-cvslog] r32622 - trunk/libmpdemux/demux_avi.c

reimar subversion at mplayerhq.hu
Sat Nov 13 11:17:13 CET 2010


Author: reimar
Date: Sat Nov 13 11:17:13 2010
New Revision: 32622

Log:
Fix possible division by 0 if -aid is used for AVI files.

Modified:
   trunk/libmpdemux/demux_avi.c

Modified: trunk/libmpdemux/demux_avi.c
==============================================================================
--- trunk/libmpdemux/demux_avi.c	Fri Nov 12 08:16:32 2010	(r32621)
+++ trunk/libmpdemux/demux_avi.c	Sat Nov 13 11:17:13 2010	(r32622)
@@ -39,6 +39,32 @@ extern const demuxer_desc_t demuxer_desc
 // 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 @@ static demux_stream_t *demux_avi_select_
 
   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 @@ static demuxer_t* demux_open_avi(demuxer
 
   //---- 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);


More information about the MPlayer-cvslog mailing list