# HG changeset patch # User reimar # Date 1400015198 0 # Node ID 91b00a4407cd03d8377fbe9a53f8143418ced99c # Parent bc3d67969fcc91db551a129279cf36452122a56d 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). diff -r bc3d67969fcc -r 91b00a4407cd libmpdemux/demux_real.c --- 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;