X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fplaylist%2Fqtl.c;h=b3f4d733ff6a753162dd040bbcf9606642d3d6bd;hb=9d016759c25f227281fb0af9a4ea82bf38328b6d;hp=e76b7e1e067365304afefaeb2e504a508c48aace;hpb=6f2a64ee29499b3768efabe5ca9dd611b0938cd4;p=vlc diff --git a/modules/demux/playlist/qtl.c b/modules/demux/playlist/qtl.c index e76b7e1e06..b3f4d733ff 100644 --- a/modules/demux/playlist/qtl.c +++ b/modules/demux/playlist/qtl.c @@ -47,38 +47,27 @@ volume - 0 (mute) - 100 (max) /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include /* isspace() */ -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#include /* ENOMEM */ -#include "playlist.h" -#include "vlc_xml.h" - -struct demux_sys_t -{ - playlist_t *p_playlist; - playlist_item_t *p_current; - playlist_item_t *p_item_in_category; - int i_parent_id; +#include +#include - xml_t *p_xml; - xml_reader_t *p_xml_reader; -}; +#include "playlist.h" +#include typedef enum { FULLSCREEN_NORMAL, FULLSCREEN_DOUBLE, FULLSCREEN_HALF, FULLSCREEN_CURRENT, FULLSCREEN_FULL } qtl_fullscreen_t; -char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" }; +const char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" }; typedef enum { LOOP_TRUE, LOOP_FALSE, LOOP_PALINDROME } qtl_loop_t; -char* ppsz_loop[] = { "true", "false", "palindrome" }; +const char* ppsz_loop[] = { "true", "false", "palindrome" }; /***************************************************************************** * Local prototypes @@ -89,33 +78,16 @@ static int Control( demux_t *p_demux, int i_query, va_list args ); /***************************************************************************** * Import_QTL: main import function *****************************************************************************/ -int E_(Import_QTL)( vlc_object_t *p_this ) +int Import_QTL( vlc_object_t *p_this ) { demux_t *p_demux = (demux_t *)p_this; - demux_sys_t *p_sys; - - char *psz_ext; - psz_ext = strrchr ( p_demux->psz_path, '.' ); - - if( strcmp( psz_ext, ".qtl" ) ) - { + if( !demux_IsPathExtension( p_demux, ".qtl" ) ) return VLC_EGENERIC; - } - msg_Dbg( p_demux, "using QuickTime Media Link playlist import"); - p_demux->pf_control = Control; p_demux->pf_demux = Demux; - p_demux->p_sys = p_sys = malloc( sizeof(demux_sys_t) ); - if( p_sys == NULL ) - { - msg_Err( p_demux, "out of memory" ); - return VLC_ENOMEM; - } - - p_sys->p_playlist = NULL; - p_sys->p_xml = NULL; - p_sys->p_xml_reader = NULL; + p_demux->pf_control = Control; + msg_Dbg( p_demux, "using QuickTime Media Link reader" ); return VLC_SUCCESS; } @@ -123,64 +95,50 @@ int E_(Import_QTL)( vlc_object_t *p_this ) /***************************************************************************** * Deactivate: frees unused data *****************************************************************************/ -void E_(Close_QTL)( vlc_object_t *p_this ) +void Close_QTL( vlc_object_t *p_this ) { - demux_t *p_demux = (demux_t *)p_this; - demux_sys_t *p_sys = p_demux->p_sys; - - if( p_sys->p_playlist ) - vlc_object_release( p_sys->p_playlist ); - if( p_sys->p_xml_reader ) - xml_ReaderDelete( p_sys->p_xml, p_sys->p_xml_reader ); - if( p_sys->p_xml ) - xml_Delete( p_sys->p_xml ); - free( p_sys ); + (void)p_this; } -#define FREE( a ) if( a ) free( a ); - static int Demux( demux_t *p_demux ) { - demux_sys_t *p_sys = p_demux->p_sys; xml_t *p_xml; - xml_reader_t *p_xml_reader; + xml_reader_t *p_xml_reader = NULL; char *psz_eltname = NULL; + input_item_t *p_input; + int i_ret = -1; /* List of all possible attributes. The only required one is "src" */ - vlc_bool_t b_autoplay = VLC_FALSE; - vlc_bool_t b_controler = VLC_TRUE; - qtl_fullscreen_t fullscreen = VLC_FALSE; + bool b_autoplay = false; + bool b_controler = true; + qtl_fullscreen_t fullscreen = false; char *psz_href = NULL; - vlc_bool_t b_kioskmode = VLC_FALSE; + bool b_kioskmode = false; qtl_loop_t loop = LOOP_FALSE; int i_movieid = -1; char *psz_moviename = NULL; - vlc_bool_t b_playeveryframe = VLC_FALSE; + bool b_playeveryframe = false; char *psz_qtnext = NULL; - vlc_bool_t b_quitwhendone = VLC_FALSE; + bool b_quitwhendone = false; char *psz_src = NULL; char *psz_mimetype = NULL; int i_volume = 100; - INIT_PLAYLIST_STUFF; - - p_sys->p_playlist = p_playlist; - p_sys->p_current = p_current; - p_sys->i_parent_id = i_parent_id; - p_sys->p_item_in_category = p_item_in_category; + input_item_t *p_current_input = GetCurrentItem(p_demux); - p_xml = p_sys->p_xml = xml_Create( p_demux ); - if( !p_xml ) return -1; + p_xml = xml_Create( p_demux ); + if( !p_xml ) + goto error; p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s ); - if( !p_xml_reader ) return -1; - p_sys->p_xml_reader = p_xml_reader; + if( !p_xml_reader ) + goto error; /* check root node */ if( xml_ReaderRead( p_xml_reader ) != 1 ) { msg_Err( p_demux, "invalid file (no root node)" ); - return -1; + goto error; } if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM || @@ -189,7 +147,7 @@ static int Demux( demux_t *p_demux ) { msg_Err( p_demux, "invalid root node %i, %s", xml_ReaderNodeType( p_xml_reader ), psz_eltname ); - FREE( psz_eltname ); + free( psz_eltname ); /* second line has p_xml_reader ) == VLC_SUCCESS ) + while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS ) { - char *psz_attrname = xml_ReaderName( p_sys->p_xml_reader ); - char *psz_attrvalue = xml_ReaderValue( p_sys->p_xml_reader ); + char *psz_attrname = xml_ReaderName( p_xml_reader ); + char *psz_attrvalue = xml_ReaderValue( p_xml_reader ); if( !psz_attrname || !psz_attrvalue ) { - FREE( psz_attrname ); - FREE( psz_attrvalue ); - return -1; + free( psz_attrname ); + free( psz_attrvalue ); + goto error; } if( !strcmp( psz_attrname, "autoplay" ) ) { - if( !strcmp( psz_attrvalue, "true" ) ) - { - b_autoplay = VLC_TRUE; - } - else - { - b_autoplay = VLC_FALSE; - } + b_autoplay = !strcmp( psz_attrvalue, "true" ); } else if( !strcmp( psz_attrname, "controler" ) ) { - if( !strcmp( psz_attrvalue, "false" ) ) - { - b_controler = VLC_FALSE; - } - else - { - b_controler = VLC_TRUE; - } + b_controler = !strcmp( psz_attrvalue, "false" ); } else if( !strcmp( psz_attrname, "fullscreen" ) ) { @@ -270,14 +214,7 @@ static int Demux( demux_t *p_demux ) } else if( !strcmp( psz_attrname, "kioskmode" ) ) { - if( !strcmp( psz_attrvalue, "true" ) ) - { - b_kioskmode = VLC_TRUE; - } - else - { - b_kioskmode = VLC_FALSE; - } + b_kioskmode = !strcmp( psz_attrvalue, "true" ); } else if( !strcmp( psz_attrname, "loop" ) ) { @@ -305,14 +242,7 @@ static int Demux( demux_t *p_demux ) } else if( !strcmp( psz_attrname, "playeveryframe" ) ) { - if( !strcmp( psz_attrvalue, "true" ) ) - { - b_playeveryframe = VLC_TRUE; - } - else - { - b_playeveryframe = VLC_FALSE; - } + b_playeveryframe = !strcmp( psz_attrvalue, "true" ); } else if( !strcmp( psz_attrname, "qtnext" ) ) { @@ -321,14 +251,7 @@ static int Demux( demux_t *p_demux ) } else if( !strcmp( psz_attrname, "quitwhendone" ) ) { - if( !strcmp( psz_attrvalue, "true" ) ) - { - b_quitwhendone = VLC_TRUE; - } - else - { - b_quitwhendone = VLC_FALSE; - } + b_quitwhendone = !strcmp( psz_attrvalue, "true" ); } else if( !strcmp( psz_attrname, "src" ) ) { @@ -349,27 +272,27 @@ static int Demux( demux_t *p_demux ) msg_Dbg( p_demux, "Attribute %s with value %s isn't valid", psz_attrname, psz_attrvalue ); } - FREE( psz_attrname ); - FREE( psz_attrvalue ); + free( psz_attrname ); + free( psz_attrvalue ); } msg_Dbg( p_demux, "autoplay: %s (unused by VLC)", - b_autoplay==VLC_TRUE ? "true": "false" ); + b_autoplay ? "true": "false" ); msg_Dbg( p_demux, "controler: %s (unused by VLC)", - b_controler==VLC_TRUE?"true": "false" ); + b_controler ? "true": "false" ); msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)", ppsz_fullscreen[fullscreen] ); msg_Dbg( p_demux, "href: %s", psz_href ); msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)", - b_kioskmode==VLC_TRUE?"true":"false" ); + b_kioskmode ? "true":"false" ); msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] ); msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid ); msg_Dbg( p_demux, "moviename: %s", psz_moviename ); msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)", - b_playeveryframe==VLC_TRUE?"true":"false" ); + b_playeveryframe ? "true":"false" ); msg_Dbg( p_demux, "qtnext: %s", psz_qtnext ); msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)", - b_quitwhendone==VLC_TRUE?"true":"false" ); + b_quitwhendone ? "true":"false" ); msg_Dbg( p_demux, "src: %s", psz_src ); msg_Dbg( p_demux, "mimetype: %s", psz_mimetype ); msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume ); @@ -381,42 +304,43 @@ static int Demux( demux_t *p_demux ) } else { - p_input = input_ItemNewExt( p_sys->p_playlist, - psz_src, psz_moviename, 0, NULL, -1 ); -#define SADD_INFO( type, field ) if( field ) { vlc_input_item_AddInfo( \ - p_input, "QuickTime Media Link", _(type), "%s", field ) ; } + input_item_node_t *p_subitems = input_item_node_Create( p_current_input ); + p_input = input_item_New( p_demux, psz_src, psz_moviename ); +#define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \ + p_input, "QuickTime Media Link", type, "%s", field ) ; } SADD_INFO( "href", psz_href ); - SADD_INFO( "mime type", psz_mimetype ); - playlist_AddWhereverNeeded( p_sys->p_playlist, p_input, - p_sys->p_current, p_sys->p_item_in_category, - (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE, - PLAYLIST_APPEND ); - + SADD_INFO( _("Mime"), psz_mimetype ); + input_item_node_AppendItem( p_subitems, p_input ); + vlc_gc_decref( p_input ); if( psz_qtnext ) { - p_input = input_ItemNewExt( p_sys->p_playlist, - psz_qtnext, psz_qtnext, 0, NULL, -1 ); - playlist_AddWhereverNeeded( p_sys->p_playlist, p_input, - p_sys->p_current, p_sys->p_item_in_category, - (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE, - PLAYLIST_APPEND ); + p_input = input_item_New( p_demux, psz_qtnext, NULL ); + input_item_node_AppendItem( p_subitems, p_input ); + vlc_gc_decref( p_input ); } + input_item_node_PostAndDelete( p_subitems ); } - HANDLE_PLAY_AND_RELEASE; + i_ret = 0; /* Needed for correct operation of go back */ - p_sys->p_playlist = NULL; +error: + if( p_xml_reader ) + xml_ReaderDelete( p_xml_reader ); + if( p_xml ) + xml_Delete( p_xml ); - FREE( psz_href ); - FREE( psz_moviename ); - FREE( psz_qtnext ); - FREE( psz_src ); - FREE( psz_mimetype ); + vlc_gc_decref(p_current_input); - return VLC_SUCCESS; + free( psz_href ); + free( psz_moviename ); + free( psz_qtnext ); + free( psz_src ); + free( psz_mimetype ); + return i_ret; } static int Control( demux_t *p_demux, int i_query, va_list args ) { + VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args); return VLC_EGENERIC; }