/*****************************************************************************
* mpeg4audio.c: parse and packetize an MPEG 4 audio stream
*****************************************************************************
- * Copyright (C) 2001, 2002, 2006 the VideoLAN team
+ * Copyright (C) 2001, 2002, 2006 VLC authors and VideoLAN
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#include <vlc_common.h>
#include <vlc_plugin.h>
-#include <vlc_aout.h>
#include <vlc_codec.h>
#include <vlc_block.h>
#include <vlc_bits.h>
-#include "vlc_block_helper.h"
+#include <vlc_block_helper.h>
+#include "packetizer_helper.h"
#include <assert.h>
/*
* Common properties
*/
- audio_date_t end_date;
+ date_t end_date;
mtime_t i_pts;
int i_frame_size;
latm_mux_t latm;
};
-enum {
- STATE_NOSYNC,
- STATE_SYNC,
- STATE_HEADER,
- STATE_NEXT_SYNC,
- STATE_GET_DATA,
- STATE_SEND_DATA
-};
-
enum {
TYPE_NONE,
TYPE_RAW,
/* Misc init */
p_sys->i_state = STATE_NOSYNC;
- aout_DateSet( &p_sys->end_date, 0 );
- p_sys->bytestream = block_BytestreamInit();
+ date_Set( &p_sys->end_date, 0 );
+ block_BytestreamInit( &p_sys->bytestream );
p_sys->b_latm_cfg = false;
/* Set output properties */
p_dec->fmt_out.audio.i_rate,
p_dec->fmt_out.audio.i_frame_length );
- aout_DateInit( &p_sys->end_date, p_dec->fmt_out.audio.i_rate );
+ date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra;
p_dec->fmt_out.p_extra = malloc( p_dec->fmt_in.i_extra );
{
msg_Dbg( p_dec, "no decoder specific info, must be an ADTS or LOAS stream" );
- aout_DateInit( &p_sys->end_date, p_dec->fmt_in.audio.i_rate );
+ date_Init( &p_sys->end_date, p_dec->fmt_in.audio.i_rate, 1 );
/* We will try to create a AAC Config from adts/loas */
p_dec->fmt_out.i_extra = 0;
if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
- aout_DateSet( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, 0 );
block_Release( *pp_block );
return NULL;
}
p_block = *pp_block;
*pp_block = NULL; /* Don't reuse this block */
- if( !aout_DateGet( &p_sys->end_date ) && !p_block->i_pts )
+ if( !date_Get( &p_sys->end_date ) && p_block->i_pts <= VLC_TS_INVALID )
{
/* We've just started the stream, wait for the first PTS. */
block_Release( p_block );
return NULL;
}
- else if( p_block->i_pts != 0 &&
- p_block->i_pts != aout_DateGet( &p_sys->end_date ) )
+ else if( p_block->i_pts > VLC_TS_INVALID &&
+ p_block->i_pts != date_Get( &p_sys->end_date ) )
{
- aout_DateSet( &p_sys->end_date, p_block->i_pts );
+ date_Set( &p_sys->end_date, p_block->i_pts );
}
- p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date );
+ p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date );
- p_block->i_length = aout_DateIncrement( &p_sys->end_date,
+ p_block->i_length = date_Increment( &p_sys->end_date,
p_dec->fmt_out.audio.i_frame_length ) - p_block->i_pts;
return p_block;
p_sys->i_rate = st->cfg.i_samplerate;
p_sys->i_frame_length = st->cfg.i_frame_length;
- /* FIXME And if it changes ? */
- if( !p_dec->fmt_out.i_extra && st->i_extra > 0 )
+ if ( p_sys->i_channels > 0 && p_sys->i_rate > 0 &&
+ p_sys->i_frame_length > 0 )
{
- p_dec->fmt_out.i_extra = st->i_extra;
- p_dec->fmt_out.p_extra = malloc( st->i_extra );
- if( !p_dec->fmt_out.p_extra )
+ /* FIXME And if it changes ? */
+ if( !p_dec->fmt_out.i_extra && st->i_extra > 0 )
{
- p_dec->fmt_out.i_extra = 0;
- return 0;
+ p_dec->fmt_out.i_extra = st->i_extra;
+ p_dec->fmt_out.p_extra = malloc( st->i_extra );
+ if( !p_dec->fmt_out.p_extra )
+ {
+ p_dec->fmt_out.i_extra = 0;
+ return 0;
+ }
+ memcpy( p_dec->fmt_out.p_extra, st->extra, st->i_extra );
}
- memcpy( p_dec->fmt_out.p_extra, st->extra, st->i_extra );
+ p_sys->b_latm_cfg = true;
}
-
- p_sys->b_latm_cfg = true;
}
}
/* Wait for the configuration */
p_sys->i_state = STATE_NOSYNC;
block_BytestreamEmpty( &p_sys->bytestream );
}
- aout_DateSet( &p_sys->end_date, 0 );
+ date_Set( &p_sys->end_date, 0 );
block_Release( *pp_block );
return NULL;
}
- if( !aout_DateGet( &p_sys->end_date ) && !(*pp_block)->i_pts )
+ if( !date_Get( &p_sys->end_date ) && (*pp_block)->i_pts <= VLC_TS_INVALID )
{
/* We've just started the stream, wait for the first PTS. */
block_Release( *pp_block );
case STATE_SYNC:
/* New frame, set the Presentation Time Stamp */
p_sys->i_pts = p_sys->bytestream.p_block->i_pts;
- if( p_sys->i_pts != 0 &&
- p_sys->i_pts != aout_DateGet( &p_sys->end_date ) )
+ if( p_sys->i_pts > VLC_TS_INVALID &&
+ p_sys->i_pts != date_Get( &p_sys->end_date ) )
{
- aout_DateSet( &p_sys->end_date, p_sys->i_pts );
+ date_Set( &p_sys->end_date, p_sys->i_pts );
}
p_sys->i_state = STATE_HEADER;
break;
/* When we reach this point we already know we have enough
* data available. */
- p_out_buffer = block_New( p_dec, p_sys->i_frame_size );
+ p_out_buffer = block_Alloc( p_sys->i_frame_size );
if( !p_out_buffer )
{
//p_dec->b_error = true;
SetupOutput( p_dec, p_out_buffer );
/* Make sure we don't reuse the same pts twice */
if( p_sys->i_pts == p_sys->bytestream.p_block->i_pts )
- p_sys->i_pts = p_sys->bytestream.p_block->i_pts = 0;
+ p_sys->i_pts = p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID;
/* So p_block doesn't get re-added several times */
*pp_block = block_BytestreamPop( &p_sys->bytestream );
msg_Info( p_dec, "AAC channels: %d samplerate: %d",
p_sys->i_channels, p_sys->i_rate );
- aout_DateInit( &p_sys->end_date, p_sys->i_rate );
- aout_DateSet( &p_sys->end_date, p_sys->i_pts );
+ const mtime_t i_end_date = date_Get( &p_sys->end_date );
+ date_Init( &p_sys->end_date, p_sys->i_rate, 1 );
+ date_Set( &p_sys->end_date, i_end_date );
}
p_dec->fmt_out.audio.i_rate = p_sys->i_rate;
#if 0
p_dec->fmt_out.audio.i_original_channels = p_sys->i_channels_conf;
- p_dec->fmt_out.audio.i_physical_channels =
- p_sys->i_channels_conf & AOUT_CHAN_PHYSMASK;
+ p_dec->fmt_out.audio.i_physical_channels = p_sys->i_channels_conf;
#endif
- p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date );
+ p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date );
p_block->i_length =
- aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length ) - p_block->i_pts;
+ date_Increment( &p_sys->end_date, p_sys->i_frame_length ) - p_block->i_pts;
}
/*****************************************************************************