Commit 31fa9d1e authored by Laurent Aimar's avatar Laurent Aimar

* all: split muxer and access into independant part.

parent 8da3bb94
......@@ -2,7 +2,7 @@
* stream_output.h : stream output module
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: stream_output.h,v 1.4 2003/01/13 02:33:13 fenrir Exp $
* $Id: stream_output.h,v 1.5 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr>
......@@ -90,6 +90,24 @@ struct sout_input_t
#define SOUT_METHOD_FILE 0x10
#define SOUT_METHOD_NETWORK 0x20
struct sout_access_out_t
{
VLC_COMMON_MEMBERS
module_t *p_module;
sout_instance_t *p_sout;
char *psz_access;
char *psz_name;
sout_access_out_sys_t *p_sys;
int (* pf_seek )( sout_access_out_t *,
off_t );
int (* pf_write )( sout_access_out_t *,
sout_buffer_t * );
};
struct sout_instance_t
{
VLC_COMMON_MEMBERS
......@@ -99,12 +117,9 @@ struct sout_instance_t
char * psz_mux;
char * psz_name;
module_t *p_access;
int i_method;
void *p_access_data;
int i_access_preheader;
int (* pf_write )( sout_instance_t *, sout_buffer_t * );
int (* pf_seek )( sout_instance_t *, off_t );
sout_access_out_t *p_access;
module_t *p_mux;
void *p_mux_data;
......@@ -153,3 +168,8 @@ VLC_EXPORT( int, sout_BufferDelete, ( sout_instance_t *, sout_buffer_
VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
VLC_EXPORT( void, sout_BufferChain, ( sout_buffer_t **, sout_buffer_t * ) );
VLC_EXPORT( sout_access_out_t *, sout_AccessOutNew, ( sout_instance_t *, char *psz_access, char *psz_name ) );
VLC_EXPORT( void, sout_AccessDelete, ( sout_access_out_t * ) );
VLC_EXPORT( int, sout_AccessSeek, ( sout_access_out_t *, off_t ) );
VLC_EXPORT( int, sout_AccessWrite, ( sout_access_out_t *, sout_buffer_t * ) );
......@@ -3,7 +3,7 @@
* Collection of useful common types and macros definitions
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: vlc_common.h,v 1.53 2003/02/08 22:20:28 massiot Exp $
* $Id: vlc_common.h,v 1.54 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr>
......@@ -245,6 +245,8 @@ typedef struct sout_fifo_t sout_fifo_t;
typedef struct sout_input_t sout_input_t;
typedef struct sout_buffer_t sout_buffer_t;
typedef struct sout_packet_format_t sout_packet_format_t;
typedef struct sout_access_out_t sout_access_out_t;
typedef struct sout_access_out_sys_t sout_access_out_sys_t;
/* Decoders */
typedef struct decoder_fifo_t decoder_fifo_t;
......
......@@ -2,7 +2,7 @@
* dummy.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: dummy.c,v 1.1 2002/12/14 21:32:41 fenrir Exp $
* $Id: dummy.c,v 1.2 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
......@@ -48,8 +48,8 @@
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int Write( sout_instance_t *, sout_buffer_t * );
static int Seek( sout_instance_t *, off_t );
static int Write( sout_access_out_t *, sout_buffer_t * );
static int Seek ( sout_access_out_t *, off_t );
/*****************************************************************************
* Module descriptor
......@@ -67,14 +67,13 @@ vlc_module_end();
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
sout_access_out_t *p_access = (sout_access_out_t*)p_this;
p_sout->i_method = SOUT_METHOD_NONE;
p_sout->p_access_data = NULL;
p_sout->pf_write = Write;
p_sout->pf_seek = Seek;
p_access->p_sys = NULL;
p_access->pf_write = Write;
p_access->pf_seek = Seek;
msg_Info( p_sout, "dummy stream output access launched" );
msg_Info( p_access, "dummy stream output access launched" );
return VLC_SUCCESS;
}
......@@ -83,14 +82,14 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
msg_Info( p_sout, "Close" );
sout_access_out_t *p_access = (sout_access_out_t*)p_this;
msg_Info( p_access, "Close" );
}
/*****************************************************************************
* Read: standard read on a file descriptor.
*****************************************************************************/
static int Write( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
static int Write( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
{
size_t i_write = 0;
......@@ -99,11 +98,11 @@ static int Write( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
sout_buffer_t *p_next;
i_write += p_buffer->i_size;
p_next = p_buffer->p_next;
sout_BufferDelete( p_sout, p_buffer );
sout_BufferDelete( p_access->p_sout, p_buffer );
p_buffer = p_next;
} while( p_buffer );
msg_Dbg( p_sout, "Dummy Skipped: len:%d", (uint32_t)i_write );
msg_Dbg( p_access, "Dummy Skipped: len:"I64Fd, (int64_t)i_write );
return( i_write );
}
......@@ -111,11 +110,10 @@ static int Write( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
/*****************************************************************************
* Seek: seek to a specific location in a file
*****************************************************************************/
static int Seek( sout_instance_t *p_sout, off_t i_pos )
static int Seek( sout_access_out_t *p_access, off_t i_pos )
{
msg_Dbg( p_sout, "Seek: pos:%lld", (int64_t)i_pos );
msg_Dbg( p_access, "Seek: pos:"I64Fd, (int64_t)i_pos );
return( 0 );
}
......@@ -2,7 +2,7 @@
* file.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: file.c,v 1.2 2003/01/08 10:40:10 fenrir Exp $
* $Id: file.c,v 1.3 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
......@@ -48,8 +48,8 @@
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int Write( sout_instance_t *, sout_buffer_t * );
static int Seek( sout_instance_t *, off_t );
static int Write( sout_access_out_t *, sout_buffer_t * );
static int Seek ( sout_access_out_t *, off_t );
/*****************************************************************************
* Module descriptor
......@@ -61,36 +61,36 @@ vlc_module_begin();
set_callbacks( Open, Close );
vlc_module_end();
typedef struct sout_access_data_s
struct sout_access_out_sys_t
{
FILE *p_file;
} sout_access_data_t;
};
/*****************************************************************************
* Open: open the file
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
sout_access_data_t *p_access;
char * psz_name = p_sout->psz_name;
sout_access_out_t *p_access = (sout_access_out_t*)p_this;
p_access = malloc( sizeof( sout_access_data_t ) );
if( !( p_access->p_sys = malloc( sizeof( sout_access_out_sys_t ) ) ) )
{
msg_Err( p_access, "out of memory" );
return( VLC_EGENERIC );
}
if( !( p_access->p_file = fopen( psz_name, "wb" ) ) )
if( !( p_access->p_sys->p_file = fopen( p_access->psz_name, "wb" ) ) )
{
msg_Err( p_sout, "cannot open `%s'", psz_name );
free( p_access );
return( -1 );
msg_Err( p_access, "cannot open `%s'", p_access->psz_name );
free( p_access->p_sys );
return( VLC_EGENERIC );
}
p_sout->i_method = SOUT_METHOD_FILE;
p_sout->p_access_data = p_access;
p_sout->pf_write = Write;
p_sout->pf_seek = Seek;
p_access->pf_write = Write;
p_access->pf_seek = Seek;
msg_Info( p_sout, "Open: name:`%s'", psz_name );
msg_Info( p_access, "Open: name:`%s'", p_access->psz_name );
return VLC_SUCCESS;
}
......@@ -99,23 +99,22 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
sout_access_data_t *p_access = (sout_access_data_t*)p_sout->p_access_data;
sout_access_out_t *p_access = (sout_access_out_t*)p_this;
if( p_access->p_file )
if( p_access->p_sys->p_file )
{
fclose( p_access->p_file );
fclose( p_access->p_sys->p_file );
}
free( p_access->p_sys );
msg_Info( p_sout, "Close" );
msg_Info( p_access, "Close" );
}
/*****************************************************************************
* Read: standard read on a file descriptor.
*****************************************************************************/
static int Write( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
static int Write( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
{
sout_access_data_t *p_access = (sout_access_data_t*)p_sout->p_access_data;
size_t i_write = 0;
do
......@@ -123,28 +122,24 @@ static int Write( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
sout_buffer_t *p_next;
i_write += fwrite( p_buffer->p_buffer, 1, p_buffer->i_size,
p_access->p_file );
p_access->p_sys->p_file );
p_next = p_buffer->p_next;
sout_BufferDelete( p_sout, p_buffer );
sout_BufferDelete( p_access->p_sout, p_buffer );
p_buffer = p_next;
} while( p_buffer );
// msg_Dbg( p_sout, "Write: len:%d", (uint32_t)i_write );
return( i_write );
}
/*****************************************************************************
* Seek: seek to a specific location in a file
*****************************************************************************/
static int Seek( sout_instance_t *p_sout, off_t i_pos )
static int Seek( sout_access_out_t *p_access, off_t i_pos )
{
sout_access_data_t *p_access = (sout_access_data_t*)p_sout->p_access_data;
msg_Dbg( p_sout, "Seek: pos:%lld", (int64_t)i_pos );
return( fseek( p_access->p_file, i_pos, SEEK_SET ) );
msg_Dbg( p_access, "Seek: pos:"I64Fd, (int64_t)i_pos );
return( fseek( p_access->p_sys->p_file, i_pos, SEEK_SET ) );
}
......
......@@ -2,7 +2,7 @@
* avi.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: avi.c,v 1.4 2003/01/19 08:28:02 fenrir Exp $
* $Id: avi.c,v 1.5 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -179,7 +179,7 @@ static int Open( vlc_object_t *p_this )
/* room to add header at the end */
p_hdr = sout_BufferNew( p_sout, HDR_SIZE );
memset( p_hdr->p_buffer, 0, HDR_SIZE );
p_sout->pf_write( p_sout, p_hdr );
sout_AccessWrite( p_sout->p_access, p_hdr );
return VLC_SUCCESS;
}
......@@ -200,7 +200,7 @@ static void Close( vlc_object_t * p_this )
/* first create idx1 chunk (write at the end of the stream */
p_idx1 = avi_HeaderCreateidx1( p_sout );
p_mux->i_idx1_size = p_idx1->i_size;
p_sout->pf_write( p_sout, p_idx1 );
sout_AccessWrite( p_sout->p_access, p_idx1 );
/* calculate some value for headers creations */
for( i_stream = 0; i_stream < p_mux->i_streams; i_stream++ )
......@@ -232,8 +232,8 @@ static void Close( vlc_object_t * p_this )
}
p_hdr = avi_HeaderCreateRIFF( p_sout );
p_sout->pf_seek( p_sout, 0 );
p_sout->pf_write( p_sout, p_hdr );
sout_AccessSeek( p_sout->p_access, 0 );
sout_AccessWrite( p_sout->p_access, p_hdr );
}
......@@ -374,7 +374,7 @@ static int Mux ( sout_instance_t *p_sout )
SetFCC( p_hdr->p_buffer, p_stream->fcc );
SetDWLE( p_hdr->p_buffer + 4, p_data->i_size );
p_sout->pf_write( p_sout, p_hdr );
sout_AccessWrite( p_sout->p_access, p_hdr );
p_mux->i_movi_size += p_hdr->i_size;
}
......@@ -390,7 +390,7 @@ static int Mux ( sout_instance_t *p_sout )
p_data->i_size += 1;
}
p_sout->pf_write( p_sout, p_data );
sout_AccessWrite( p_sout->p_access, p_data );
p_mux->i_movi_size += p_data->i_size;
i_count--;
......
......@@ -2,7 +2,7 @@
* dummy.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: dummy.c,v 1.1 2002/12/14 21:32:41 fenrir Exp $
* $Id: dummy.c,v 1.2 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
......@@ -120,7 +120,7 @@ static int Mux ( sout_instance_t *p_sout )
p_data = sout_FifoGet( p_fifo );
p_sout->pf_write( p_sout, p_data );
sout_AccessWrite( p_sout->p_access, p_data );
i_count--;
}
......
......@@ -2,7 +2,7 @@
* ps.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: ps.c,v 1.5 2003/01/13 02:33:13 fenrir Exp $
* $Id: ps.c,v 1.6 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
......@@ -148,7 +148,7 @@ static void Close( vlc_object_t * p_this )
p_end = sout_BufferNew( p_sout, 4 );
SetDWBE( p_end->p_buffer, 0x01b9 );
p_sout->pf_write( p_sout, p_end );
sout_AccessWrite( p_sout->p_access, p_end );
free( p_mux );
......@@ -247,7 +247,7 @@ static int MuxWritePackHeader( sout_instance_t *p_sout,
bits_write( &bits, 5, 0x1f ); // FIXME reserved
bits_write( &bits, 3, 0 ); // stuffing bytes
p_hdr->i_size = 14;
p_sout->pf_write( p_sout, p_hdr );
sout_AccessWrite( p_sout->p_access, p_hdr );
return( 0 );
}
......@@ -281,7 +281,7 @@ static int MuxWriteSystemHeader( sout_instance_t *p_sout )
/* FIXME missing stream_id ... */
p_sout->pf_write( p_sout, p_hdr );
sout_AccessWrite( p_sout->p_access, p_hdr );
return( 0 );
}
......@@ -365,7 +365,7 @@ static int Mux ( sout_instance_t *p_sout )
p_data = sout_FifoGet( p_fifo );
E_( EStoPES )( p_sout, &p_data, p_data, p_stream->i_stream_id, 1);
p_sout->pf_write( p_sout, p_data );
sout_AccessWrite( p_sout->p_access, p_data );
p_mux->i_pes_count++;
......
......@@ -2,7 +2,7 @@
* ts.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: ts.c,v 1.7 2003/01/13 02:33:13 fenrir Exp $
* $Id: ts.c,v 1.8 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
......@@ -574,7 +574,7 @@ static int Mux( sout_instance_t *p_sout )
p_mux->i_ts_packet++;
SetTSDate( p_ts, i_dts, i_length );
p_sout->pf_write( p_sout, p_ts );
sout_AccessWrite( p_sout->p_access, p_ts );
}
return( 0 );
......
......@@ -2,7 +2,7 @@
* stream_output.c : stream output module
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: stream_output.c,v 1.12 2003/01/17 15:26:24 fenrir Exp $
* $Id: stream_output.c,v 1.13 2003/02/16 14:10:44 fenrir Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr>
......@@ -82,7 +82,6 @@ static int InitInstance( sout_instance_t * p_sout )
p_sout->psz_name = "";
p_sout->p_access = NULL;
p_sout->p_mux = NULL;
p_sout->i_access_preheader = 0;
p_sout->i_mux_preheader = 0;
p_sout->i_nb_inputs = 0;
p_sout->pp_inputs = NULL;
......@@ -165,8 +164,7 @@ static int InitInstance( sout_instance_t * p_sout )
/* Find and open appropriate access module */
p_sout->p_access =
module_Need( p_sout, "sout access", p_sout->psz_access );
sout_AccessOutNew( p_sout, p_sout->psz_access, p_sout->psz_name );
if( p_sout->p_access == NULL )
{
msg_Err( p_sout, "no suitable sout access module for `%s/%s://%s'",
......@@ -174,6 +172,7 @@ static int InitInstance( sout_instance_t * p_sout )
return -1;
}
/* Find and open appropriate mux module */
p_sout->p_mux =
module_Need( p_sout, "sout mux", p_sout->psz_mux );
......@@ -182,7 +181,8 @@ static int InitInstance( sout_instance_t * p_sout )
{
msg_Err( p_sout, "no suitable mux module for `%s/%s://%s'",
p_sout->psz_access, p_sout->psz_mux, p_sout->psz_name );
module_Unneed( p_sout, p_sout->p_access );
sout_AccessDelete( p_sout->p_access );
return -1;
}
......@@ -206,7 +206,7 @@ void sout_DeleteInstance( sout_instance_t * p_sout )
}
if( p_sout->p_access )
{
module_Unneed( p_sout, p_sout->p_access );
sout_AccessDelete( p_sout->p_access );
}
vlc_mutex_destroy( &p_sout->lock );
......@@ -215,6 +215,71 @@ void sout_DeleteInstance( sout_instance_t * p_sout )
vlc_object_destroy( p_sout );
}
/*****************************************************************************
* sout_AccessOutNew: allocate a new access out
*****************************************************************************/
sout_access_out_t *sout_AccessOutNew( sout_instance_t *p_sout,
char *psz_access, char *psz_name )
{
sout_access_out_t *p_access;
if( !( p_access = vlc_object_create( p_sout,
sizeof( sout_access_out_t ) ) ) )
{
msg_Err( p_sout, "out of memory" );
return NULL;
}
p_access->psz_access = strdup( psz_access ? psz_access : "" );
p_access->psz_name = strdup( psz_name ? psz_name : "" );
p_access->p_sout = p_sout;
p_access->p_sys = NULL;
p_access->pf_seek = NULL;
p_access->pf_write = NULL;
p_access->p_module = module_Need( p_access,
"sout access",
p_access->psz_access );;
if( !p_access->p_module )
{
vlc_object_destroy( p_access );
p_access = NULL;
}
return p_access;
}
/*****************************************************************************
* sout_AccessDelete: delete an access out
*****************************************************************************/
void sout_AccessDelete( sout_access_out_t *p_access )
{
if( p_access->p_module )
{
module_Unneed( p_access, p_access->p_module );
}
free( p_access->psz_access );
free( p_access->psz_name );
vlc_object_destroy( p_access );
}
/*****************************************************************************
* sout_AccessSeek:
*****************************************************************************/
int sout_AccessSeek( sout_access_out_t *p_access, off_t i_pos )
{
return( p_access->pf_seek( p_access, i_pos ) );
}
/*****************************************************************************
* sout_AccessWrite:
*****************************************************************************/
int sout_AccessWrite( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
{
return( p_access->pf_write( p_access, p_buffer ) );
}
/*****************************************************************************
*
......@@ -494,7 +559,7 @@ sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size )
#endif
p_buffer = malloc( sizeof( sout_buffer_t ) );
i_prehader = p_sout->i_access_preheader + p_sout->i_mux_preheader;
i_prehader = p_sout->i_mux_preheader;
if( i_size > 0 )
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment