changeset 37104:91b00a4407cd

demux_real: Improve buffer allocation for interleaved audio handling. Allocate buffers where they are needed. This avoids code duplication, allocating them when they are not needed, and might avoid a crash if an audio stream is specified via -aid that does not exist in the headers but does exist in the file since then we might run the deinterleaving without having the buffers allocated first (note: I have not tested this can actually happen).
author reimar
date Tue, 13 May 2014 21:06:38 +0000
parents bc3d67969fcc
children f05b151463ca
files libmpdemux/demux_real.c
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_real.c	Sat May 10 23:48:24 2014 +0000
+++ b/libmpdemux/demux_real.c	Tue May 13 21:06:38 2014 +0000
@@ -744,6 +744,10 @@
         if ((priv->intl_id[demuxer->audio->id] == mmioFOURCC('I', 'n', 't', '4')) ||
             (priv->intl_id[demuxer->audio->id] == mmioFOURCC('g', 'e', 'n', 'r')) ||
             (priv->intl_id[demuxer->audio->id] == mmioFOURCC('s', 'i', 'p', 'r'))) {
+            if (!priv->audio_buf) {
+                priv->audio_buf = calloc(priv->sub_packet_h[demuxer->audio->id], priv->audiopk_size[demuxer->audio->id]);
+                priv->audio_timestamp = calloc(priv->sub_packet_h[demuxer->audio->id], sizeof(double));
+            }
             sps = priv->sub_packet_size[demuxer->audio->id];
             sph = priv->sub_packet_h[demuxer->audio->id];
             cfs = priv->coded_framesize[demuxer->audio->id];
@@ -1078,8 +1082,6 @@
 	sh_audio_t *sh = demuxer->a_streams[mp_stream_id];
 	demuxer->audio->id=mp_stream_id;
 	demuxer->audio->sh=sh;
-	priv->audio_buf = calloc(priv->sub_packet_h[demuxer->audio->id], priv->audiopk_size[demuxer->audio->id]);
-	priv->audio_timestamp = calloc(priv->sub_packet_h[demuxer->audio->id], sizeof(double));
         mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected RM audio ID = %d (rm id %d)\n",mp_stream_id, rm_stream_id);
 	goto got_audio;
     }
@@ -1509,8 +1511,6 @@
 
 		    if(demuxer->audio->id==stream_id){
 			demuxer->audio->sh=sh;
-        	priv->audio_buf = calloc(priv->sub_packet_h[demuxer->audio->id], priv->audiopk_size[demuxer->audio->id]);
-        	priv->audio_timestamp = calloc(priv->sub_packet_h[demuxer->audio->id], sizeof(double));
 		    }
 
 		    ++a_streams;