* aac.c : Raw aac Stream input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: aac.c,v 1.1 2003/08/01 00:08:35 fenrir Exp $
+ * $Id: aac.c,v 1.8 2003/11/21 00:38:01 gbazin Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
#include <vlc/vlc.h>
#include <vlc/input.h>
-#include <ninput.h>
-
/*****************************************************************************
* Module descriptor
*****************************************************************************/
-
-static int Activate ( vlc_object_t * );
-static void Deactivate ( vlc_object_t * );
+static int Open ( vlc_object_t * );
+static void Close ( vlc_object_t * );
vlc_module_begin();
set_description( _("AAC demuxer" ) );
set_capability( "demux", 10 );
- set_callbacks( Activate, Deactivate );
+ set_callbacks( Open, Close );
add_shortcut( "aac" );
vlc_module_end();
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-
static int Demux ( input_thread_t * );
struct demux_sys_t
{
- stream_t *s;
mtime_t i_time;
- es_descriptor_t *p_es;
+ es_out_id_t *p_es;
};
static int i_aac_samplerate[16] =
/*****************************************************************************
- * Activate: initializes AAC demux structures
+ * Open: initializes AAC demux structures
*****************************************************************************/
-static int Activate( vlc_object_t * p_this )
+static int Open( vlc_object_t * p_this )
{
input_thread_t *p_input = (input_thread_t *)p_this;
demux_sys_t *p_sys;
module_t *p_id3;
+ es_format_t fmt;
+
if( p_input->psz_demux && !strncmp( p_input->psz_demux, "aac", 3 ) )
{
}
p_input->pf_demux = Demux;
+ p_input->pf_demux_control = demux_vaControlDefault;
p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) );
p_sys->i_time = 0;
- if( ( p_sys->s = stream_OpenInput( p_input ) ) == NULL )
- {
- msg_Err( p_input, "cannot create stream" );
- goto error;
- }
-
/* peek the begining (10 is for adts header) */
- if( stream_Peek( p_sys->s, &p_peek, 10 ) < 10 )
+ if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 )
{
msg_Err( p_input, "cannot peek" );
goto error;
goto error;
}
+ es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'm', 'p', '4', 'a' ) );
if( HeaderCheck( p_peek ) )
{
- input_info_category_t * p_category;
+ fmt.audio.i_channels = AAC_CHANNELS( p_peek );
+ fmt.audio.i_rate = AAC_SAMPLE_RATE( p_peek );
+
msg_Dbg( p_input,
"adts header: id=%d channels=%d sample_rate=%d",
AAC_ID( p_peek ),
AAC_CHANNELS( p_peek ),
AAC_SAMPLE_RATE( p_peek ) );
-
- vlc_mutex_lock( &p_input->stream.stream_lock );
-
- p_category = input_InfoCategory( p_input, _("Aac") );
-
- input_AddInfo( p_category, _("Input Type"), "MPEG-%d AAC",
- AAC_ID( p_peek ) == 1 ? 2 : 4 );
- input_AddInfo( p_category, _("Channels"), "%d",
- AAC_CHANNELS( p_peek ) );
- input_AddInfo( p_category, _("Sample Rate"), "%dHz",
- AAC_SAMPLE_RATE( p_peek ) );
-
- vlc_mutex_unlock( &p_input->stream.stream_lock );
}
vlc_mutex_lock( &p_input->stream.stream_lock );
msg_Err( p_input, "cannot init stream" );
goto error;
}
- if( input_AddProgram( p_input, 0, 0) == NULL )
- {
- vlc_mutex_unlock( &p_input->stream.stream_lock );
- msg_Err( p_input, "cannot add program" );
- goto error;
- }
- p_input->stream.pp_programs[0]->b_is_ok = 0;
- p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
-
p_input->stream.i_mux_rate = 0 / 50;
-
- p_sys->p_es = input_AddES( p_input,
- p_input->stream.p_selected_program,
- 1 , AUDIO_ES, NULL, 0 );
-
- p_sys->p_es->i_stream_id = 1;
- p_sys->p_es->i_fourcc = VLC_FOURCC( 'm', 'p', '4', 'a' );
- input_SelectES( p_input, p_sys->p_es );
-
- p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock );
+ p_sys->p_es = es_out_Add( p_input->p_es_out, &fmt );
+
return VLC_SUCCESS;
error:
- if( p_sys->s )
- {
- stream_Release( p_sys->s );
- }
free( p_sys );
return VLC_EGENERIC;
}
static int Demux( input_thread_t * p_input )
{
demux_sys_t *p_sys = p_input->p_demux_data;
- pes_packet_t *p_pes;
+ block_t *p_block;
uint8_t h[8];
uint8_t *p_peek;
- if( stream_Peek( p_sys->s, &p_peek, 8 ) < 8 )
+ if( stream_Peek( p_input->s, &p_peek, 8 ) < 8 )
{
msg_Warn( p_input, "cannot peek" );
return 0;
int i_skip = 0;
int i_peek;
- i_peek = stream_Peek( p_sys->s, &p_peek, 8096 );
+ i_peek = stream_Peek( p_input->s, &p_peek, 8096 );
if( i_peek < 8 )
{
msg_Warn( p_input, "cannot peek" );
}
msg_Warn( p_input, "garbage=%d bytes", i_skip );
- stream_Read( p_sys->s, NULL, i_skip );
+ stream_Read( p_input->s, NULL, i_skip );
return 1;
}
p_input->stream.p_selected_program,
p_sys->i_time * 9 / 100 );
- if( ( p_pes = stream_PesPacket( p_sys->s, AAC_FRAME_SIZE( h ) ) ) == NULL )
+ if( ( p_block = stream_Block( p_input->s, AAC_FRAME_SIZE( h ) ) ) == NULL )
{
msg_Warn( p_input, "cannot read data" );
return 0;
}
- p_pes->i_dts =
- p_pes->i_pts = input_ClockGetTS( p_input,
+ p_block->i_dts =
+ p_block->i_pts = input_ClockGetTS( p_input,
p_input->stream.p_selected_program,
p_sys->i_time * 9 / 100 );
- if( !p_sys->p_es->p_decoder_fifo )
- {
- msg_Err( p_input, "no audio decoder" );
- input_DeletePES( p_input->p_method_data, p_pes );
- return( -1 );
- }
+ es_out_Send( p_input->p_es_out, p_sys->p_es, p_block );
- input_DecodePES( p_sys->p_es->p_decoder_fifo, p_pes );
p_sys->i_time += (mtime_t)1000000 *
(mtime_t)AAC_FRAME_SAMPLES( h ) /
(mtime_t)AAC_SAMPLE_RATE( h );
}
/*****************************************************************************
- * Deactivate: frees unused data
+ * Close: frees unused data
*****************************************************************************/
-static void Deactivate( vlc_object_t * p_this )
+static void Close( vlc_object_t * p_this )
{
input_thread_t *p_input = (input_thread_t*)p_this;
demux_sys_t *p_sys = p_input->p_demux_data;
- if( p_sys->s )
- {
- stream_Release( p_sys->s );
- }
free( p_sys );
}