Commit 8be0e1ae authored by Laurent Aimar's avatar Laurent Aimar

Added demux_Packetizer* helpers.

parent e4a1bb5b
......@@ -174,6 +174,21 @@ static inline bool demux_IsForced( demux_t *p_demux, const char *psz_name )
return true;
}
/**
* This function will create a packetizer suitable for a demuxer that parses
* elementary stream.
*
* The provided es_format_t will be cleaned on error or by
* demux_PacketizerDestroy.
*/
VLC_EXPORT( decoder_t *,demux_PacketizerNew, ( demux_t *p_demux, es_format_t *p_fmt, const char *psz_msg ) );
/**
* This function will destroy a packetizer create by demux_PacketizerNew.
*/
VLC_EXPORT( void, demux_PacketizerDestroy, ( decoder_t *p_packetizer ) );
/* */
#define DEMUX_INIT_COMMON() do { \
p_demux->pf_control = Control; \
p_demux->pf_demux = Demux; \
......@@ -218,39 +233,6 @@ static inline bool demux_IsForced( demux_t *p_demux, const char *psz_name )
#define POKE( peek, stuff, size ) (strncasecmp( (const char *)peek, stuff, size )==0)
#define COMMON_INIT_PACKETIZER( location ) \
location = vlc_object_create( p_demux, VLC_OBJECT_PACKETIZER ); \
location->pf_decode_audio = 0; \
location->pf_decode_video = 0; \
location->pf_decode_sub = 0; \
location->pf_packetize = 0; \
#define INIT_APACKETIZER( location, a,b,c,d ) \
COMMON_INIT_PACKETIZER(location ); \
es_format_Init( &location->fmt_in, AUDIO_ES, \
VLC_FOURCC( a, b, c, d ) );
#define INIT_VPACKETIZER( location, a,b,c,d ) \
COMMON_INIT_PACKETIZER(location ); \
es_format_Init( &location->fmt_in, VIDEO_ES, \
VLC_FOURCC( a, b, c, d ) );
/* BEWARE ! This can lead to memory leaks ! */
#define LOAD_PACKETIZER_OR_FAIL( location, msg ) \
location->p_module = \
module_Need( location, "packetizer", NULL, 0 ); \
if( location->p_module == NULL ) \
{ \
vlc_object_release( location ); \
msg_Err( p_demux, "cannot find packetizer for " # msg ); \
free( p_sys ); \
return VLC_EGENERIC; \
}
#define DESTROY_PACKETIZER( location ) \
if( location->p_module ) module_Unneed( location, location->p_module ); \
vlc_object_release( location );
/**
* @}
*/
......
......@@ -103,6 +103,7 @@ static int Open( vlc_object_t * p_this )
const uint8_t *p_peek;
uint8_t *p_streaminfo;
int i_streaminfo;
es_format_t fmt;
/* Have a peep at the show. */
if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC;
......@@ -140,21 +141,16 @@ static int Open( vlc_object_t * p_this )
}
/* Load the FLAC packetizer */
INIT_APACKETIZER( p_sys->p_packetizer, 'f', 'l', 'a', 'c' );
/* Store STREAMINFO for the decoder and packetizer */
p_streaminfo[4] |= 0x80; /* Fake this as the last metadata block */
p_sys->p_packetizer->fmt_in.i_extra = i_streaminfo;
p_sys->p_packetizer->fmt_in.p_extra = p_streaminfo;
es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'f', 'l', 'a', 'c' ) );
fmt.i_extra = i_streaminfo;
fmt.p_extra = p_streaminfo;
p_sys->p_packetizer->p_module =
module_Need( p_sys->p_packetizer, "packetizer", NULL, 0 );
if( !p_sys->p_packetizer->p_module )
p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "flac" );
if( !p_sys->p_packetizer )
{
free( p_sys->p_packetizer->fmt_in.p_extra );
vlc_object_release( p_sys->p_packetizer );
msg_Err( p_demux, "cannot find flac packetizer" );
free( p_sys );
return VLC_EGENERIC;
}
......@@ -186,13 +182,9 @@ static void Close( vlc_object_t * p_this )
free( p_sys->attachments[i] );
TAB_CLEAN( p_sys->i_attachments, p_sys->attachments);
/* Unneed module */
module_Unneed( p_sys->p_packetizer, p_sys->p_packetizer->p_module );
free( p_sys->p_packetizer->fmt_in.p_extra );
/* Delete the decoder */
vlc_object_release( p_sys->p_packetizer );
demux_PacketizerDestroy( p_sys->p_packetizer );
if( p_sys->p_meta )
vlc_meta_Delete( p_sys->p_meta );
free( p_sys );
......
......@@ -131,39 +131,6 @@ static const codec_t p_codec[] = {
{ 0, false, NULL, NULL, NULL }
};
static inline decoder_t *demux_PacketizerNew( demux_t *p_demux, int i_cat, vlc_fourcc_t i_codec, const char *psz_msg )
{
decoder_t *p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_PACKETIZER );
if( !p_packetizer )
return NULL;
p_packetizer->pf_decode_audio = NULL;
p_packetizer->pf_decode_video = NULL;
p_packetizer->pf_decode_sub = NULL;
p_packetizer->pf_packetize = NULL;
es_format_Init( &p_packetizer->fmt_in, i_cat, i_codec );
es_format_Init( &p_packetizer->fmt_out, UNKNOWN_ES, 0 );
p_packetizer->p_module = module_Need( p_packetizer, "packetizer", NULL, 0 );
if( !p_packetizer->p_module )
{
vlc_object_release( p_packetizer );
msg_Err( p_demux, "cannot find packetizer for %s", psz_msg );
return NULL;
}
return p_packetizer;
}
static inline void demux_PacketizerDestroy( decoder_t *p_packetizer )
{
if( p_packetizer->p_module )
module_Unneed( p_packetizer, p_packetizer->p_module );
vlc_object_release( p_packetizer );
}
/*****************************************************************************
* Open: initializes demux structures
*****************************************************************************/
......@@ -172,6 +139,7 @@ static int Open( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys;
es_format_t fmt;
int64_t i_offset;
int i_index;
......@@ -209,8 +177,8 @@ static int Open( vlc_object_t * p_this )
msg_Dbg( p_demux, "detected format %4.4s", (const char*)&p_sys->codec.i_codec );
/* Load the audio packetizer */
p_sys->p_packetizer = demux_PacketizerNew( p_demux, AUDIO_ES, p_sys->codec.i_codec,
p_sys->codec.psz_name );
es_format_Init( &fmt, AUDIO_ES, p_sys->codec.i_codec );
p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, p_sys->codec.psz_name );
if( !p_sys->p_packetizer )
{
free( p_sys );
......
......@@ -80,7 +80,7 @@ static int Open( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys;
const uint8_t *p_peek;
vlc_value_t val;
es_format_t fmt;
if( stream_Peek( p_demux->s, &p_peek, 5 ) < 5 ) return VLC_EGENERIC;
......@@ -103,16 +103,19 @@ static int Open( vlc_object_t * p_this )
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
p_sys->p_es = NULL;
p_sys->i_dts = 1;
var_Create( p_demux, "h264-fps", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
var_Get( p_demux, "h264-fps", &val );
p_sys->f_fps = val.f_float;
if( val.f_float < 0.001 ) p_sys->f_fps = 0.001;
p_sys->f_fps = var_CreateGetFloat( p_demux, "h264-fps" );
if( p_sys->f_fps < 0.001 )
p_sys->f_fps = 0.001;
msg_Dbg( p_demux, "using %.2f fps", p_sys->f_fps );
/* Load the mpegvideo packetizer */
INIT_VPACKETIZER( p_sys->p_packetizer, 'h', '2', '6', '4' );
es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "H264" );
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'h', '2', '6', '4' ) );
p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "h264" );
if( !p_sys->p_packetizer )
{
free( p_sys );
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
......@@ -125,8 +128,7 @@ static void Close( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys = p_demux->p_sys;
DESTROY_PACKETIZER( p_sys->p_packetizer );
demux_PacketizerDestroy( p_sys->p_packetizer );
free( p_sys );
}
......
......@@ -80,7 +80,7 @@ static int Open( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys;
const uint8_t *p_peek;
vlc_value_t val;
es_format_t fmt;
if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC;
......@@ -103,17 +103,17 @@ static int Open( vlc_object_t * p_this )
p_sys->i_dts = 1;
/* Load the mpeg4video packetizer */
INIT_VPACKETIZER( p_sys->p_packetizer, 'm', 'p', '4', 'v' );
es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "mpeg4 video" );
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'm', 'p', '4', 'v' ) );
p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "mpeg4 video" );
if( !p_sys->p_packetizer )
{
free( p_sys );
return VLC_EGENERIC;
}
/* We need to wait until we get p_extra (VOL header) from the packetizer
* before we create the output */
var_Create( p_demux, "m4v-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
var_Get( p_demux, "m4v-fps", &val );
p_sys->f_fps = val.f_float;
p_sys->f_fps = var_CreateGetFloat( p_demux, "m4v-fps" );
return VLC_SUCCESS;
}
......@@ -126,8 +126,7 @@ static void Close( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys = p_demux->p_sys;
DESTROY_PACKETIZER( p_sys->p_packetizer) ;
demux_PacketizerDestroy( p_sys->p_packetizer );
free( p_sys );
}
......
......@@ -108,9 +108,13 @@ static int Open( vlc_object_t * p_this )
p_sys->p_es = NULL;
/* Load the mpegvideo packetizer */
INIT_VPACKETIZER( p_sys->p_packetizer, 'm', 'p', 'g', 'v' );
es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "MPEG Video" );
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'm', 'p', 'g', 'v' ) );
p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "mpeg video" );
if( !p_sys->p_packetizer )
{
free( p_sys );
return VLC_EGENERIC;
}
/* create the output */
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'm', 'p', 'g', 'v' ) );
......@@ -127,8 +131,7 @@ static void Close( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys = p_demux->p_sys;
DESTROY_PACKETIZER( p_sys->p_packetizer );
demux_PacketizerDestroy( p_sys->p_packetizer );
free( p_sys );
}
......
......@@ -79,7 +79,7 @@ static int Open( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys;
const uint8_t *p_peek;
vlc_value_t val;
es_format_t fmt;
if( stream_Peek( p_demux->s, &p_peek, 5 ) < 5 ) return VLC_EGENERIC;
......@@ -103,13 +103,17 @@ static int Open( vlc_object_t * p_this )
p_sys->p_es = NULL;
p_sys->i_dts = 1;
p_sys->f_fps = var_CreateGetFloat( p_demux, "vc1-fps" );
if( val.f_float < 0.001 ) p_sys->f_fps = 0.0;
if( p_sys->f_fps < 0.001 )
p_sys->f_fps = 0.0;
/* Load the packetizer */
INIT_VPACKETIZER( p_sys->p_packetizer, 'W', 'V', 'C', '1' );
es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "VC-1" );
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'W', 'V', 'C', '1' ) );
p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "VC-1" );
if( !p_sys->p_packetizer )
{
free( p_sys );
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
......@@ -121,8 +125,7 @@ static void Close( vlc_object_t * p_this )
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys = p_demux->p_sys;
DESTROY_PACKETIZER( p_sys->p_packetizer );
demux_PacketizerDestroy( p_sys->p_packetizer );
free( p_sys );
}
......
......@@ -26,6 +26,7 @@
#endif
#include <vlc_common.h>
#include <vlc_codec.h>
#include "input_internal.h"
......@@ -567,6 +568,43 @@ static void* DStreamThread( vlc_object_t* p_this )
/****************************************************************************
* Utility functions
****************************************************************************/
decoder_t *demux_PacketizerNew( demux_t *p_demux, es_format_t *p_fmt, const char *psz_msg )
{
decoder_t *p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_PACKETIZER );
if( !p_packetizer )
{
es_format_Clean( p_fmt );
return NULL;
}
p_packetizer->pf_decode_audio = NULL;
p_packetizer->pf_decode_video = NULL;
p_packetizer->pf_decode_sub = NULL;
p_packetizer->pf_packetize = NULL;
p_packetizer->fmt_in = *p_fmt;
es_format_Init( &p_packetizer->fmt_out, UNKNOWN_ES, 0 );
p_packetizer->p_module = module_Need( p_packetizer, "packetizer", NULL, 0 );
if( !p_packetizer->p_module )
{
es_format_Clean( p_fmt );
vlc_object_release( p_packetizer );
msg_Err( p_demux, "cannot find packetizer for %s", psz_msg );
return NULL;
}
return p_packetizer;
}
void demux_PacketizerDestroy( decoder_t *p_packetizer )
{
if( p_packetizer->p_module )
module_Unneed( p_packetizer, p_packetizer->p_module );
es_format_Clean( &p_packetizer->fmt_in );
vlc_object_release( p_packetizer );
}
static bool SkipID3Tag( demux_t *p_demux )
{
const uint8_t *p_peek;
......
......@@ -91,6 +91,8 @@ decoder_SynchroReset
decoder_SynchroTrash
decode_URI
decode_URI_duplicate
demux_PacketizerDestroy
demux_PacketizerNew
demux_vaControlHelper
encode_URI_component
EndMD5
......
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