Commit 89471fa0 authored by Clément Stenac's avatar Clément Stenac

Some initial work for streaming profiles

+ some misc test cleanup
parent ebc698a5
......@@ -334,6 +334,15 @@ typedef struct announce_method_t announce_method_t;
typedef struct announce_handler_t announce_handler_t;
typedef struct sap_handler_t sap_handler_t;
typedef struct sout_std_t sout_std_t;
typedef struct sout_display_t sout_display_t;
typedef struct sout_duplicate_t sout_duplicate_t;
typedef struct sout_transcode_t sout_transcode_t;
typedef struct sout_chain_t sout_chain_t;
typedef struct streaming_profile_t streaming_profile_t;
typedef struct sout_module_t sout_module_t;
typedef struct sout_gui_descr_t sout_gui_descr_t;
/* Decoders */
typedef struct decoder_t decoder_t;
typedef struct decoder_sys_t decoder_sys_t;
......@@ -358,6 +367,8 @@ typedef struct iso639_lang_t iso639_lang_t;
typedef struct device_t device_t;
typedef struct device_probe_t device_probe_t;
typedef struct probe_sys_t probe_sys_t;
typedef struct localized_string_t localized_string_t;
typedef struct i18n_string_t i18n_string_t;
/* block */
typedef struct block_t block_t;
......
/*****************************************************************************
* vlc_streaming.h: Methods and descriptions for Streaming profiles
*****************************************************************************
* Copyright (C) 2002-2005 the VideoLAN team
* $Id: stream_output.h 14151 2006-02-04 00:08:50Z zorglub $
*
* Authors: Clément Stenac <zorglub@videolan.org>
*
* 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
* (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.
*
* 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.
*****************************************************************************/
#ifndef _VLC_STREAMING_H_
#define _VLC_STREAMING_H_
#include <vlc/vlc.h>
#ifdef WIN32
#define VCODECS_NUMBER 13
#else
#define VCODECS_NUMBER 12
#endif
#define ACODECS_NUMBER 9
/// Keep this up to date !
#define MUXERS_NUMBER 10
enum
{
MUX_PS,
MUX_TS,
MUX_MPEG,
MUX_OGG,
MUX_RAW,
MUX_ASF,
MUX_AVI,
MUX_MP4,
MUX_MOV,
MUX_WAV,
};
enum
{
ACCESS_HTTP,
ACCESS_UDP,
ACCESS_MMS,
ACCESS_RTP,
ACCESS_FILE
};
struct codec_desc_t {
char *psz_display;
char *psz_codec;
char *psz_descr;
int muxers[MUXERS_NUMBER];
};
//extern const struct codec vcodecs_array[];
//extern const struct codec acodecs_array[];
struct method_desc_t {
char *psz_access;
char *psz_method;
char *psz_descr;
char *psz_address;
int muxers[MUXERS_NUMBER];
};
//xtern const struct method methods_array[];
struct mux_desc_t {
int id;
char *psz_mux;
char *psz_encap;
char *psz_descr;
};
//extern const struct mux_desc_t muxers_array[];
/* Standard bitrates arrays */
//static const char * vbitrates_array[] =
//{ "3072", "2048", "1024", "768", "512", "384", "256", "192", "128", "96",
// "64" };
//static const char *abitrates_array[] =
//{ "512", "256", "192", "128", "96", "64", "32", "16" } ;
struct sout_transcode_t
{
int i_vb, i_ab, i_channels;
float f_scale;
vlc_bool_t b_audio, b_video, b_subtitles, b_soverlay;
char *psz_vcodec, *psz_acodec, *psz_scodec, *psz_venc, *psz_aenc;
char *psz_additional;
};
struct sout_std_t
{
char *psz_mux, *psz_access;
char *psz_url, *psz_name, *psz_group;
};
struct sout_display_t
{
};
struct sout_duplicate_t
{
int i_children;
sout_chain_t **pp_children;
/// Conditions
};
typedef union
{
sout_transcode_t *p_transcode;
sout_std_t *p_std;
sout_duplicate_t *p_duplicate;
sout_display_t *p_display;
} sout_module_type_t;
struct sout_module_t
{
int i_type;
sout_module_type_t typed;
sout_module_t *p_parent;
};
enum
{
SOUT_MOD_TRANSCODE,
SOUT_MOD_STD,
SOUT_MOD_RTP,
SOUT_MOD_DUPLICATE,
SOUT_MOD_DISPLAY
};
struct sout_chain_t
{
int i_modules;
sout_module_t **pp_modules;
int i_options;
char **ppsz_options;
};
struct sout_gui_descr_t
{
/* Access */
vlc_bool_t b_local, b_file, b_http, b_mms, b_rtp, b_udp, b_dump;
char *psz_file, *psz_http, *psz_mms, *psz_rtp, *psz_udp;
int i_http, i_mms, i_rtp, i_udp;
/* Mux */
char *psz_mux;
/* Transcode */
vlc_bool_t b_video, b_audio, b_subtitles, b_soverlay;
char *psz_vcodec, *psz_acodec, *psz_scodec;
int i_vb, i_ab, i_channels;
float f_scale;
/* Misc */
vlc_bool_t b_sap, b_all_es;
char *psz_group, *psz_name;
int i_ttl;
};
struct streaming_profile_t
{
i18n_string_t *p_title;
i18n_string_t *p_description;
sout_chain_t *p_chain;
};
static inline sout_chain_t *streaming_ChainNew()
{
DECMALLOC_NULL( p_chain, sout_chain_t );
memset( p_chain, 0, sizeof( sout_chain_t ) );
p_chain->i_options = 0;
return p_chain;
}
//VLC_XEXPORT( char *, streaming_ChainToPsz, (sout_chain_t * ) );
#endif
......@@ -34,6 +34,38 @@
VLC_EXPORT( void, resolve_xml_special_chars, ( char *psz_value ) );
VLC_EXPORT( char *, convert_xml_special_chars, ( const char *psz_content ) );
struct localized_string_t
{
char *psz_lang;
char *psz_text;
};
struct i18n_string_t
{
int i_langs;
localized_string_t **pp_langs;
};
static inline void i18n_AddLang( i18n_string_t *p_src,
char *psz_lang, char *psz_text )
{
DECMALLOC_VOID( pl10n, localized_string_t );
pl10n->psz_lang = strdup( psz_lang );
pl10n->psz_text = strdup( psz_text );
INSERT_ELEM( p_src->pp_langs, p_src->i_langs, p_src->i_langs, pl10n );
};
static inline char *i18n_Get( i18n_string_t *p_src, char *psz_lang )
{
int i;
for( i = 0 ; i < p_src->i_langs; i++ )
{
if( !strcmp( p_src->pp_langs[i]->psz_lang, psz_lang ) )
return p_src->pp_langs[i]->psz_text;
}
return strdup( "" );
};
/**
* @}
*/
......
......@@ -519,6 +519,7 @@ struct module_symbols_t
void (*__stats_TimersClean_inner) (vlc_object_t *);
void (*__intf_IntfProgressUpdate_inner) (vlc_object_t*, int, const char*, float);
int (*__intf_IntfProgress_inner) (vlc_object_t*, const char*, float);
void *streaming_ChainToPsz_deprecated;
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -1493,6 +1494,7 @@ struct module_symbols_t
(p_symbols)->playlist_ItemNewFromInput_deprecated = NULL; \
(p_symbols)->stats_TimerClean_deprecated = NULL; \
(p_symbols)->stats_TimersClean_deprecated = NULL; \
(p_symbols)->streaming_ChainToPsz_deprecated = NULL; \
# endif /* __PLUGIN__ */
#endif /* __VLC_SYMBOLS_H */
......@@ -57,6 +57,7 @@ HEADERS_include = \
../include/os_specific.h \
../include/snapshot.h \
../include/stream_output.h \
../include/vlc_streaming.h \
../include/variables.h \
../include/video_output.h \
../include/vlc_access.h \
......@@ -287,6 +288,7 @@ SOURCES_libvlc_common = \
audio_output/intf.c \
stream_output/stream_output.c \
stream_output/announce.c \
stream_output/profiles.c \
stream_output/sap.c \
osd/osd.c \
osd/osd_parser.c \
......
/*****************************************************************************
* profiles.c: Streaming profiles
*****************************************************************************
* Copyright (C) 2002-2004 the VideoLAN team
* $Id: stream_output.c 15915 2006-06-15 21:22:35Z zorglub $
*
* Authors: Clment Stenac <zorglub@videolan.org>
*
* 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
* (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.
*
* 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.
*****************************************************************************/
#include <vlc_streaming.h>
#define MAX_CHAIN 32768
#define CHAIN_APPEND( format, args... ) { \
memcpy( psz_temp, psz_output, MAX_CHAIN ); \
snprintf( psz_output, MAX_CHAIN - 1, "%s" format , psz_temp, ## args ); }
#define DUPM p_module->typed.p_duplicate
#define STDM p_module->typed.p_std
#define DISM p_module->typed.p_display
#define TRAM p_module->typed.p_transcode
/**********************************************************************
* General chain manipulation
**********************************************************************/
sout_duplicate_t *streaming_ChainAddDup( sout_chain_t *p_chain )
{
DECMALLOC_NULL( p_module, sout_module_t );
MALLOC_NULL( DUPM, sout_duplicate_t );
p_module->i_type = SOUT_MOD_DUPLICATE;
DUPM->i_children = 0;
DUPM->pp_children = NULL;
INSERT_ELEM( p_chain->pp_modules, p_chain->i_modules, p_chain->i_modules,
p_module );
return p_module->typed.p_duplicate;
}
sout_std_t *streaming_ChainAddStd( sout_chain_t *p_chain, char *psz_access,
char *psz_mux, char *psz_url )
{
DECMALLOC_NULL( p_module, sout_module_t );
MALLOC_NULL( STDM, sout_std_t );
p_module->i_type = SOUT_MOD_STD;
STDM->psz_mux = strdup( psz_mux );
STDM->psz_access = strdup( psz_access );
STDM->psz_url = strdup( psz_url );
INSERT_ELEM( p_chain->pp_modules, p_chain->i_modules, p_chain->i_modules,
p_module );
return STDM;
}
sout_display_t *streaming_ChainAddDisplay( sout_chain_t *p_chain )
{
DECMALLOC_NULL( p_module, sout_module_t );
MALLOC_NULL( DISM, sout_display_t );
p_module->i_type = SOUT_MOD_DISPLAY;
return DISM;
}
sout_transcode_t *streaming_ChainAddTranscode( sout_chain_t *p_chain,
char *psz_vcodec, char * psz_acodec, char * psz_scodec,
int i_vb, float f_scale, int i_ab, int i_channels,
char *psz_additional )
{
DECMALLOC_NULL( p_module, sout_module_t );
MALLOC_NULL( TRAM, sout_transcode_t );
p_module->i_type = SOUT_MOD_TRANSCODE;
if( psz_vcodec )
{ TRAM->b_video = VLC_TRUE; TRAM->psz_vcodec = strdup( psz_vcodec); }
if( psz_acodec )
{ TRAM->b_audio = VLC_TRUE; TRAM->psz_acodec = strdup( psz_acodec ); }
TRAM->psz_scodec = strdup( psz_scodec );
TRAM->i_vb = i_vb; TRAM->i_ab = i_ab; TRAM->f_scale = f_scale;
TRAM->i_channels = i_channels;
TRAM->psz_additional = strdup( psz_additional );
return TRAM;
}
void streaming_DupAddChild( sout_duplicate_t *p_dup )
{
if( p_dup )
{
sout_chain_t * p_child = streaming_ChainNew();
INSERT_ELEM( p_dup->pp_children, p_dup->i_children,
p_dup->i_children, p_child );
}
}
#define DUP_OR_CHAIN p_dup ? p_dup->pp_children[p_dup->i_children-1] : p_chain
#define ADD_OPT( format, args... ) { \
char *psz_opt; asprintf( &psz_opt, format, ##args ); \
INSERT_ELEM( p_chain->ppsz_options, p_chain->i_options, p_chain->i_options,\
psz_opt );\
free( psz_opt ); }
void streaming_ChainClean( sout_chain_t *p_chain )
{
int i,j;
sout_module_t *p_module;
if( p_chain->i_modules )
{
for( i = p_chain->i_modules -1; i >= 0 ; i-- )
{
p_module = p_chain->pp_modules[i];
switch( p_module->i_type )
{
case SOUT_MOD_DUPLICATE:
if( DUPM->i_children == 0 ) break;
for( j = DUPM->i_children - 1 ; j >= 0; j-- )
{
streaming_ChainClean( DUPM->pp_children[j] );
}
break;
case SOUT_MOD_STD:
FREENULL( STDM->psz_url );
FREENULL( STDM->psz_name );
FREENULL( STDM->psz_group );
memset( STDM, 0, sizeof( sout_std_t ) );
break;
case SOUT_MOD_TRANSCODE:
FREENULL( TRAM->psz_vcodec );
FREENULL( TRAM->psz_acodec );
FREENULL( TRAM->psz_scodec );
FREENULL( TRAM->psz_venc );
FREENULL( TRAM->psz_aenc );
memset( TRAM, 0, sizeof( sout_transcode_t ) ) ;
break;
}
REMOVE_ELEM( p_chain->pp_modules, p_chain->i_modules, i );
}
}
}
/**********************************************************************
* Interaction with streaming GUI descriptors
**********************************************************************/
#define DO_ENABLE_ACCESS \
if( !strcmp( STDM->psz_access, "file" ) )\
{ \
pd->b_file = VLC_TRUE; pd->psz_file = strdup( STDM->psz_url ); \
} \
else if( !strcmp( STDM->psz_access, "http" ) )\
{ \
pd->b_http = VLC_TRUE; pd->psz_http = strdup( STDM->psz_url ); \
} \
else if( !strcmp( STDM->psz_access, "mms" ) )\
{ \
pd->b_mms = VLC_TRUE; pd->psz_mms = strdup( STDM->psz_url ); \
} \
else if( !strcmp( STDM->psz_access, "udp" ) )\
{ \
pd->b_udp = VLC_TRUE; pd->psz_udp = strdup( STDM->psz_url ); \
} \
else \
{ \
msg_Err( p_this, "unahandled access %s", STDM->psz_access ); \
}
/**
* Try to convert a chain to a gui descriptor. This is only possible for
* "simple" chains.
* \param p_this vlc object
* \param p_chain the source streaming chain
* \param pd the destination gui descriptor object
* \return TRUE if the conversion succeeded, false else
*/
vlc_bool_t streaming_ChainToGuiDesc( vlc_object_t *p_this,
sout_chain_t *p_chain,
sout_gui_descr_t *pd )
{
int j, i_last = 0;
sout_module_t *p_module;
if( p_chain->i_modules == 0 || p_chain->i_modules > 2 ) return VLC_FALSE;
if( p_chain->pp_modules[0]->i_type == SOUT_MOD_TRANSCODE )
{
if( p_chain->i_modules == 1 ) return VLC_FALSE;
p_module = p_chain->pp_modules[0];
i_last++;
pd->b_video = TRAM->b_video; pd->b_audio = TRAM->b_audio;
pd->b_subtitles = TRAM->b_subtitles; pd->b_soverlay = TRAM->b_soverlay;
pd->i_vb = TRAM->i_vb; pd->i_ab = TRAM->i_ab;
pd->i_channels = TRAM->i_channels; pd->f_scale = TRAM->f_scale;
pd->psz_vcodec = strdup( TRAM->psz_vcodec );
pd->psz_acodec = strdup( TRAM->psz_acodec );
pd->psz_scodec = strdup( TRAM->psz_scodec );
}
if( p_chain->pp_modules[i_last]->i_type == SOUT_MOD_DUPLICATE )
{
p_module = p_chain->pp_modules[i_last];
// Nothing allowed after duplicate. Duplicate mustn't be empty
if( p_chain->i_modules > i_last +1 || !DUPM->i_children )
return VLC_FALSE;
for( j = 0 ; j< DUPM->i_children ; j++ )
{
sout_chain_t *p_child = DUPM->pp_children[j];
if( p_child->i_modules != 1 ) return VLC_FALSE;
p_module = p_child->pp_modules[0];
if( p_module->i_type == SOUT_MOD_STD )
{
DO_ENABLE_ACCESS
}
else if( p_module->i_type == SOUT_MOD_DISPLAY )
pd->b_local = VLC_TRUE;
else if( p_module->i_type == SOUT_MOD_RTP )
{
msg_Err( p_this, "RTP unhandled" );
return VLC_FALSE;
}
}
i_last++;
}
if( p_chain->pp_modules[i_last]->i_type == SOUT_MOD_STD )
{
p_module = p_chain->pp_modules[i_last];
DO_ENABLE_ACCESS;
}
else if( p_chain->pp_modules[i_last]->i_type == SOUT_MOD_DISPLAY )
{
pd->b_local = VLC_TRUE;
}
else if( p_chain->pp_modules[i_last]->i_type == SOUT_MOD_RTP )
{
msg_Err( p_this, "RTP unhandled" );
return VLC_FALSE;
}
return VLC_TRUE;
}
#define HANDLE_GUI_URL( type, access ) if( pd->b_##type ) { \
streaming_DupAddChild( p_dup ); \
if( pd->i_##type > 0 ) \
{ \
char *psz_url; \
asprintf( &psz_url, "%s:%i", pd->psz_##type, pd->i_##type ); \
streaming_ChainAddStd( DUP_OR_CHAIN, access, pd->psz_mux,\
psz_url ); \
free( psz_url ); \
} \
else \
{ \
streaming_ChainAddStd( DUP_OR_CHAIN, access, pd->psz_mux,\
pd->psz_##type );\
}\
}
void streaming_GuiDescToChain( vlc_object_t *p_obj, sout_chain_t *p_chain,
sout_gui_descr_t *pd )
{
sout_duplicate_t *p_dup = NULL;
/* Clean up the chain */
streaming_ChainClean( p_chain );
/* Transcode */
if( pd->b_video || pd->b_audio || pd->b_subtitles || pd->b_soverlay )
{
streaming_ChainAddTranscode( p_chain, pd->psz_vcodec, pd->psz_acodec,
pd->psz_scodec, pd->i_vb, pd->f_scale,
pd->i_ab, pd->i_channels, NULL );
}
/* #std{} */
if( pd->b_local + pd->b_file + pd->b_http + pd->b_mms + pd->b_rtp +
pd->b_udp > 1 )
{
p_dup = streaming_ChainAddDup( p_chain );
}
if( pd->b_local )
{
streaming_DupAddChild( p_dup );
streaming_ChainAddDisplay( DUP_OR_CHAIN );
}
if( pd->b_file )
{
streaming_DupAddChild( p_dup );
streaming_ChainAddStd( DUP_OR_CHAIN, "file", pd->psz_mux,
pd->psz_file );
}
if( pd->b_udp )
{
sout_std_t *p_std;
streaming_DupAddChild( p_dup );
if( pd->i_udp > 0 )
{
char *psz_url;
asprintf( &psz_url, "%s:%i", pd->psz_udp, pd->i_udp );
p_std = streaming_ChainAddStd( DUP_OR_CHAIN, "udp",
pd->psz_mux, psz_url );
free( psz_url );
}
else
{
p_std = streaming_ChainAddStd( DUP_OR_CHAIN, "udp",
pd->psz_mux, pd->psz_udp );
}
if( pd->i_ttl ) ADD_OPT( "ttl=%i", pd->i_ttl );
if( pd->b_sap )
{
pd->b_sap = VLC_TRUE;
p_std->psz_name = strdup( pd->psz_name );
p_std->psz_group = pd->psz_group ? strdup( pd->psz_group ) : NULL;
}
}
HANDLE_GUI_URL( http, "http" )
HANDLE_GUI_URL( mms, "mms" )
}
#undef HANDLE_GUI_URL
/**********************************************************************
* Create a sout string from a chain
**********************************************************************/
char * streaming_ChainToPsz( sout_chain_t *p_chain )
{
int i;
char psz_output[MAX_CHAIN];
char psz_temp[MAX_CHAIN];
sprintf( psz_output, "#" );
for( i = 0 ; i< p_chain->i_modules; i++ )
{
sout_module_t *p_module = p_chain->pp_modules[i];
switch( p_module->i_type )
{
case SOUT_MOD_TRANSCODE:
CHAIN_APPEND( "transcode{" );
if( TRAM->b_video )
{
CHAIN_APPEND( "vcodec=%s,vb=%i,scale=%f", TRAM->psz_vcodec,
TRAM->i_vb, TRAM->f_scale );
if( TRAM->b_audio || TRAM->b_subtitles || TRAM->b_soverlay )
CHAIN_APPEND( "," );
}
if( TRAM->b_audio )
{
CHAIN_APPEND( "acodec=%s,ab=%i,channels=%i", TRAM->psz_acodec,
TRAM->i_ab, TRAM->i_channels );
if( TRAM->b_subtitles || TRAM->b_soverlay )