static input_item_t *new_item( access_t *p_access, const char *psz_name, int i_type ) { input_item_t *p_item; char *psz_uri; int i_ret; char *psz_encoded_name = vlc_uri_encode( psz_name ); if( psz_encoded_name == NULL ) return NULL; const char *psz_sep = p_access->psz_location[0] != '\0' && p_access->psz_location[strlen(p_access->psz_location) -1] != '/' ? "/" : ""; i_ret = asprintf( &psz_uri, "smb://%s%s%s", p_access->psz_location, psz_sep, psz_encoded_name ); free( psz_encoded_name ); if( i_ret == -1 ) return NULL; p_item = input_item_NewExt( psz_uri, psz_name, -1, i_type, ITEM_NET ); free( psz_uri ); if( p_item == NULL ) return NULL; return p_item; }
/************************************************************************** * add_file_content (Public) **************************************************************************/ int libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist, const char * psz_uri ) { input_item_t * p_input_item; libvlc_media_t * p_md; p_input_item = input_item_NewExt( psz_uri, _("Media Library"), 0, NULL, 0, -1 ); if( !p_input_item ) { libvlc_printerr( "Not enough memory" ); return -1; } p_md = libvlc_media_new_from_input_item( p_mlist->p_libvlc_instance, p_input_item ); if( !p_md ) { vlc_gc_decref( p_input_item ); return -1; } if( libvlc_media_list_add_media( p_mlist, p_md ) ) { #warning Missing error handling! /* printerr and leaks */ return -1; } input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item ); return 0; }
static int vlclua_node_add_subitem( lua_State *L ) { services_discovery_t *p_sd = (services_discovery_t *)vlclua_get_this( L ); input_item_t **pp_node = (input_item_t **)luaL_checkudata( L, 1, "node" ); if( *pp_node ) { if( lua_istable( L, -1 ) ) { lua_getfield( L, -1, "path" ); if( lua_isstring( L, -1 ) ) { char **ppsz_options = NULL; int i_options = 0; const char *psz_path = lua_tostring( L, -1 ); vlclua_read_options( p_sd, L, &i_options, &ppsz_options ); input_item_node_t *p_input_node = input_item_node_Create( *pp_node ); input_item_t *p_input = input_item_NewExt( p_sd, psz_path, psz_path, i_options, (const char **)ppsz_options, VLC_INPUT_OPTION_TRUSTED, -1 ); lua_pop( L, 1 ); if( p_input ) { vlclua_read_meta_data( p_sd, L, p_input ); /* This one is to be tested... */ vlclua_read_custom_meta_data( p_sd, L, p_input ); lua_getfield( L, -1, "duration" ); if( lua_isnumber( L, -1 ) ) input_item_SetDuration( p_input, (lua_tonumber( L, -1 )*1e6) ); else if( !lua_isnil( L, -1 ) ) msg_Warn( p_sd, "Item duration should be a number (in seconds)." ); lua_pop( L, 1 ); input_item_node_AppendItem( p_input_node, p_input ); input_item_node_PostAndDelete( p_input_node ); input_item_t **udata = (input_item_t **) lua_newuserdata( L, sizeof( input_item_t * ) ); *udata = p_input; if( luaL_newmetatable( L, "input_item_t" ) ) { lua_pushliteral( L, "none of your business" ); lua_setfield( L, -2, "__metatable" ); } lua_setmetatable( L, -2 ); vlc_gc_decref( p_input ); } while( i_options > 0 ) free( ppsz_options[--i_options] ); free( ppsz_options ); } else msg_Err( p_sd, "node:add_subitem: the \"path\" parameter can't be empty" ); } else msg_Err( p_sd, "Error parsing add_subitem arguments" ); } return 1; }
/***************************************************************************** * DirRead: *****************************************************************************/ static input_item_t* DirRead (access_t *p_access ) { access_sys_t *p_sys = p_access->p_sys; struct smbc_dirent *p_entry; input_item_t *p_item = NULL; while( !p_item && ( p_entry = smbc_readdir( p_sys->i_smb ) ) ) { char *psz_uri; const char *psz_server = p_sys->url.psz_host; const char *psz_path = p_sys->url.psz_path; const char *psz_name = p_entry->name; int i_type; switch( p_entry->smbc_type ) { case SMBC_SERVER: case SMBC_WORKGROUP: psz_server = p_sys->url.psz_host; psz_path = NULL; psz_name = NULL; case SMBC_FILE_SHARE: case SMBC_DIR: i_type = ITEM_TYPE_DIRECTORY; break; case SMBC_FILE: i_type = ITEM_TYPE_FILE; break; default: case SMBC_PRINTER_SHARE: case SMBC_COMMS_SHARE: case SMBC_IPC_SHARE: case SMBC_LINK: continue; } char *psz_encoded_name = NULL; if( psz_name != NULL && ( psz_encoded_name = vlc_uri_encode( psz_name ) ) == NULL ) return NULL; if( smb_get_uri( p_access, &psz_uri, NULL, NULL, NULL, psz_server, psz_path, psz_encoded_name ) < 0 ) { free(psz_encoded_name); return NULL; } free(psz_encoded_name); p_item = input_item_NewExt( psz_uri, p_entry->name, -1, i_type, ITEM_NET ); free( psz_uri ); if( !p_item ) return NULL; } return p_item; }
static int Demux( demux_t *p_demux ) { char *psz_line; input_item_t *p_current_input = GetCurrentItem(p_demux); input_item_node_t *p_subitems = input_item_node_Create( p_current_input ); while( (psz_line = stream_ReadLine( p_demux->s )) ) { char *psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; /* if the line is the uri of the media item */ if( !strncasecmp( psz_parse, "<media src=\"", strlen( "<media src=\"" ) ) ) { char *psz_uri = psz_parse + strlen( "<media src=\"" ); psz_parse = strchr( psz_uri, '"' ); if( psz_parse != NULL ) { *psz_parse = '\0'; resolve_xml_special_chars( psz_uri ); psz_uri = ProcessMRL( psz_uri, p_demux->p_sys->psz_prefix ); if( psz_uri != NULL ) { input_item_t *p_input; p_input = input_item_NewExt( psz_uri, psz_uri, 0, NULL, 0, -1 ); input_item_node_AppendItem( p_subitems, p_input ); vlc_gc_decref( p_input ); free( psz_uri ); } } } /* Fetch another line */ free( psz_line ); } input_item_node_PostAndDelete( p_subitems ); vlc_gc_decref(p_current_input); var_Destroy( p_demux, "wpl-extvlcopt" ); return 0; /* Needed for correct operation of go back */ }
int access_fsdir_additem(struct access_fsdir *p_fsdir, const char *psz_uri, const char *psz_filename, int i_type, int i_net) { enum slave_type i_slave_type; struct fsdir_slave *p_fsdir_slave = NULL; input_item_node_t *p_node; if (p_fsdir->i_sub_autodetect_fuzzy != 0 && input_item_slave_GetType(psz_filename, &i_slave_type)) { p_fsdir_slave = malloc(sizeof(*p_fsdir_slave)); if (!p_fsdir_slave) return VLC_ENOMEM; p_fsdir_slave->p_node = NULL; p_fsdir_slave->psz_filename = strdup(psz_filename); p_fsdir_slave->p_slave = input_item_slave_New(psz_uri, i_slave_type, SLAVE_PRIORITY_MATCH_NONE); if (!p_fsdir_slave->p_slave || !p_fsdir_slave->psz_filename) { free(p_fsdir_slave->psz_filename); free(p_fsdir_slave); return VLC_ENOMEM; } INSERT_ELEM(p_fsdir->pp_slaves, p_fsdir->i_slaves, p_fsdir->i_slaves, p_fsdir_slave); } if (fsdir_is_ignored(p_fsdir, psz_filename)) return VLC_SUCCESS; input_item_t *p_item = input_item_NewExt(psz_uri, psz_filename, -1, i_type, i_net); if (p_item == NULL) return VLC_ENOMEM; input_item_CopyOptions(p_item, p_fsdir->p_node->p_item); p_node = input_item_node_AppendItem(p_fsdir->p_node, p_item); input_item_Release(p_item); /* A slave can also be an item. If there is a match, this item will be * removed from the parent node. This is not a common case, since most * slaves will be ignored by fsdir_is_ignored() */ if (p_fsdir_slave != NULL) p_fsdir_slave->p_node = p_node; return VLC_SUCCESS; }
int playlist_Import( playlist_t *p_playlist, const char *psz_file ) { input_item_t *p_input; const char *const psz_option = "meta-file"; char *psz_uri = make_URI( psz_file, NULL ); if( psz_uri == NULL ) return VLC_EGENERIC; p_input = input_item_NewExt( psz_uri, psz_file, 1, &psz_option, VLC_INPUT_OPTION_TRUSTED, -1 ); free( psz_uri ); playlist_AddInput( p_playlist, p_input, PLAYLIST_APPEND, PLAYLIST_END, true, false ); return input_Read( p_playlist, p_input ); }
static void read_body( demux_t* p_demux, input_item_node_t* p_node ) { demux_sys_t* p_sys = p_demux->p_sys; const char* psz_name; int i_type; i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_name ); if ( i_type != XML_READER_STARTELEM || strcasecmp( psz_name, "seq" ) ) { msg_Err( p_demux, "Expected opening <seq> tag. Got <%s> with type %d", psz_name, i_type ); return; } do { i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_name ); if ( !strcasecmp( psz_name, "media" ) ) { const char* psz_attr = NULL; const char* psz_val = NULL; while ((psz_attr = xml_ReaderNextAttr( p_sys->p_reader, &psz_val ))) { if ( !psz_val ) continue; if (!strcasecmp( psz_attr, "src" ) ) { char* mrl = ProcessMRL( psz_val, p_sys->psz_prefix ); if ( unlikely( !mrl ) ) return; input_item_t* p_item = input_item_NewExt( mrl, NULL, 0, NULL, 0, -1 ); if ( likely( p_item ) ) { input_item_node_AppendItem( p_node, p_item ); input_item_Release( p_item ); } free( mrl ); } } } } while ( i_type != XML_READER_ENDELEM || strcasecmp( psz_name, "seq" ) ); i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_name ); if ( i_type != XML_READER_ENDELEM || strcasecmp( psz_name, "body" ) ) msg_Err( p_demux, "Expected closing <body> tag. Got: <%s> with type %d", psz_name, i_type ); }
/** * Adds a udev device. */ static int AddDevice (services_discovery_t *sd, struct udev_device *dev) { services_discovery_sys_t *p_sys = sd->p_sys; char *mrl = p_sys->subsys->get_mrl (dev); if (mrl == NULL) return 0; /* don't know if it was an error... */ char *name = p_sys->subsys->get_name (dev); input_item_t *item = input_item_NewExt (mrl, name ? name : mrl, -1, p_sys->subsys->item_type, ITEM_LOCAL); msg_Dbg (sd, "adding %s (%s)", mrl, name); free (name); free (mrl); if (item == NULL) return -1; struct device *d = malloc (sizeof (*d)); if (d == NULL) { vlc_gc_decref (item); return -1; } d->devnum = udev_device_get_devnum (dev); d->item = item; d->sd = NULL; struct device **dp = tsearch (d, &p_sys->root, cmpdev); if (dp == NULL) /* Out-of-memory */ { DestroyDevice (d); return -1; } if (*dp != d) /* Overwrite existing device */ { DestroyDevice (*dp); *dp = d; } services_discovery_AddItem (sd, item, NULL); d->sd = sd; return 0; }
static int Demux( demux_t *p_demux ) { char *psz_line; char *psz_uri = NULL; char *psz_parse; input_item_t *p_input; INIT_PLAYLIST_STUFF; psz_line = stream_ReadLine( p_demux->s ); while( psz_line ) { psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; /* if the line is the uri of the media item */ if( !strncasecmp( psz_parse, "<media src=\"", strlen( "<media src=\"" ) ) ) { psz_uri = ParseUriValue( psz_parse ); if( !EMPTY_STR(psz_uri) ) { psz_uri = ProcessMRL( psz_uri, p_demux->p_sys->psz_prefix ); MaybeFromLocaleRep( &psz_uri ); p_input = input_item_NewExt( p_demux, psz_uri, psz_uri, 0, NULL, 0, -1 ); input_item_AddSubItem( p_current_input, p_input ); } free( psz_uri ); } /* Fetch another line */ free( psz_line ); psz_line = stream_ReadLine( p_demux->s ); } HANDLE_PLAY_AND_RELEASE; var_Destroy( p_demux, "wpl-extvlcopt" ); return 0; /* Needed for correct operation of go back */ }
/** * Add a MRL into the playlist or the media library, duration and options given * * \param p_playlist the playlist to add into * \param psz_uri the mrl to add to the playlist * \param psz_name a text giving a name or description of this item * \param i_mode the mode used when adding * \param i_pos the position in the playlist where to add. If this is * PLAYLIST_END the item will be added at the end of the playlist * regardless of its size * \param i_duration length of the item in milliseconds. * \param i_options the number of options * \param ppsz_options an array of options * \param i_option_flags options flags * \param b_playlist TRUE for playlist, FALSE for media library * \param b_locked TRUE if the playlist is locked * \return VLC_SUCCESS or a VLC error code */ int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri, const char *psz_name, int i_mode, int i_pos, mtime_t i_duration, int i_options, const char *const *ppsz_options, unsigned i_option_flags, bool b_playlist, bool b_locked ) { int i_ret; input_item_t *p_input; p_input = input_item_NewExt( psz_uri, psz_name, i_duration, ITEM_TYPE_UNKNOWN, ITEM_NET_UNKNOWN ); if( p_input == NULL ) return VLC_ENOMEM; input_item_AddOptions( p_input, i_options, ppsz_options, i_option_flags ); i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist, b_locked ); vlc_gc_decref( p_input ); return i_ret; }
/***************************************************************************** * Demux: The important stuff *****************************************************************************/ static int Demux( demux_t *p_demux ) { char *psz_line; input_item_t *p_input; input_item_t *p_current_input = GetCurrentItem(p_demux); input_item_node_t *p_subitems = input_item_node_Create( p_current_input ); while( (psz_line = stream_ReadLine( p_demux->s )) ) { char **ppsz_options = NULL; int i_options = 0; char *psz_name = NULL; if( !ParseLine( psz_line, &psz_name, &ppsz_options, &i_options ) ) { free( psz_line ); continue; } EnsureUTF8( psz_name ); for( int i = 0; i< i_options; i++ ) EnsureUTF8( ppsz_options[i] ); p_input = input_item_NewExt( "dvb://", psz_name, i_options, (const char**)ppsz_options, VLC_INPUT_OPTION_TRUSTED, -1 ); input_item_node_AppendItem( p_subitems, p_input ); vlc_gc_decref( p_input ); while( i_options-- ) free( ppsz_options[i_options] ); free( ppsz_options ); free( psz_line ); } input_item_node_PostAndDelete( p_subitems ); vlc_gc_decref(p_current_input); return 0; /* Needed for correct operation of go back */ }
/* * Builds playlist based on available input items. */ void MediaServer::_buildPlaylist( Container* p_parent, input_item_node_t *p_input_node ) { bool b_send = p_input_node == NULL; if( b_send ) p_input_node = input_item_node_Create( p_parent->getInputItem() ); for ( unsigned int i = 0; i < p_parent->getNumContainers(); i++ ) { Container* p_container = p_parent->getContainer( i ); input_item_t* p_input_item = input_item_New( "vlc://nop", p_container->getTitle() ); input_item_node_t *p_new_node = input_item_node_AppendItem( p_input_node, p_input_item ); p_container->setInputItem( p_input_item ); _buildPlaylist( p_container, p_new_node ); } for ( unsigned int i = 0; i < p_parent->getNumItems(); i++ ) { Item* p_item = p_parent->getItem( i ); input_item_t* p_input_item = input_item_NewExt( p_item->getResource(), p_item->getTitle(), 0, NULL, 0, p_item->getDuration() ); assert( p_input_item ); input_item_node_AppendItem( p_input_node, p_input_item ); p_item->setInputItem( p_input_item ); } if( b_send ) input_item_node_PostAndDelete( p_input_node ); }
/************************************************************************** * add_file_content (Public) **************************************************************************/ void libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist, const char * psz_uri, libvlc_exception_t * p_e ) { input_item_t * p_input_item; libvlc_media_t * p_md; p_input_item = input_item_NewExt( p_mlist->p_libvlc_instance->p_libvlc_int, psz_uri, _("Media Library"), 0, NULL, 0, -1 ); if( !p_input_item ) { libvlc_exception_raise( p_e ); libvlc_printerr( "Not enough memory" ); return; } p_md = libvlc_media_new_from_input_item( p_mlist->p_libvlc_instance, p_input_item, p_e ); if( !p_md ) { vlc_gc_decref( p_input_item ); return; } libvlc_media_list_add_media( p_mlist, p_md, p_e ); if( libvlc_exception_raised( p_e ) ) return; input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item ); return; }
static int Demux( demux_t *p_demux ) { char *psz_line; mtime_t i_duration = -1; char *psz_title = NULL, *psz_genre = NULL, *psz_tracknum = NULL, *psz_language = NULL, *psz_artist = NULL, *psz_album = NULL, *psz_date = NULL, *psz_publisher = NULL, *psz_encodedby = NULL, *psz_description = NULL, *psz_url = NULL, *psz_copyright = NULL, *psz_mrl = NULL; input_item_t *p_current_input = GetCurrentItem(p_demux); psz_line = stream_ReadLine( p_demux->s ); char *psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; /* if the 1st line is "AC", skip it */ /* TODO: using this information ? */ if( !strncasecmp( psz_parse, "AC", strlen( "AC" ) ) ) { free( psz_line ); psz_line = stream_ReadLine( p_demux->s ); } input_item_node_t *p_subitems = input_item_node_Create( p_current_input ); /* Loop on all lines */ while( psz_line ) { psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; /* filename */ if( !strncasecmp( psz_parse, "NM", strlen( "NM" ) ) ) { char *psz_tabvalue = ParseTabValue( psz_parse ); if( !EMPTY_STR(psz_tabvalue) ) { psz_mrl = ProcessMRL( psz_tabvalue, p_demux->p_sys->psz_prefix ); } free( psz_tabvalue ); } /* duration */ else if( !strncasecmp( psz_parse, "DR", strlen( "DR" ) ) ) { char *psz_tabvalue = ParseTabValue( psz_parse ); if( !EMPTY_STR(psz_tabvalue) ) { int i_parsed_duration = atoi( psz_tabvalue ); if( i_parsed_duration >= 0 ) i_duration = i_parsed_duration * INT64_C(1000); } free( psz_tabvalue ); } #define PARSE(tag,variable) \ else if( !strncasecmp( psz_parse, tag, strlen( tag ) ) ) \ variable = ParseTabValue( psz_parse ); PARSE( "TT", psz_title ) PARSE( "TG", psz_genre ) PARSE( "TR", psz_tracknum ) PARSE( "TL", psz_language ) PARSE( "TA", psz_artist ) PARSE( "TB", psz_album ) PARSE( "TY", psz_date ) PARSE( "TH", psz_publisher ) PARSE( "TE", psz_encodedby ) PARSE( "TC", psz_description ) PARSE( "TU", psz_url ) PARSE( "TO", psz_copyright ) #undef PARSE /* force a duration ? */ else if( !strncasecmp( psz_parse, "FD", strlen( "FD" ) ) ) {} /* end of file entry */ else if( !strncasecmp( psz_parse, "BR!", strlen( "BR!" ) ) ) { /* create the input item */ input_item_t *p_input = input_item_NewExt( p_demux, psz_mrl, psz_title, 0, NULL, 0, i_duration ); input_item_node_AppendItem( p_subitems, p_input ); FREENULL( psz_mrl ); FREENULL( psz_title ); i_duration = -1; #define SET(variable, type) \ if( !EMPTY_STR(variable) ) \ { \ input_item_Set##type( p_input, variable ); \ FREENULL( variable ); \ } /* set the meta */ SET( psz_genre, Genre ); SET( psz_tracknum, TrackNum ); SET( psz_language, Language ); SET( psz_artist, Artist ); SET( psz_album, Album ); SET( psz_date, Date ); SET( psz_encodedby, EncodedBy ); SET( psz_description, Description ); SET( psz_copyright, Copyright ); #undef SET vlc_gc_decref( p_input ); } else msg_Warn( p_demux, "invalid line '%s'", psz_parse ); /* Fetch another line */ free( psz_line ); psz_line = stream_ReadLine( p_demux->s ); } input_item_node_PostAndDelete( p_subitems ); vlc_gc_decref(p_current_input); var_Destroy( p_demux, "zpl-extvlcopt" ); return 0; /* Needed for correct operation of go back */ }
int playlist_MLLoad( playlist_t *p_playlist ) { char *psz_datadir; char *psz_uri = NULL; input_item_t *p_input; if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS; psz_datadir = config_GetUserDir( VLC_DATA_DIR ); if( !psz_datadir ) /* XXX: This should never happen */ { msg_Err( p_playlist, "no data directory, cannot load media library") ; return VLC_EGENERIC; } if( asprintf( &psz_uri, "%s" DIR_SEP "ml.xspf", psz_datadir ) != -1 ) { /* loosy check for media library file */ struct stat st; int ret = utf8_stat( psz_uri , &st ); free( psz_uri ); if( ret ) { free( psz_datadir ); return VLC_EGENERIC; } } psz_uri = make_URI( psz_datadir ); free( psz_datadir ); psz_datadir = psz_uri; if( psz_datadir == NULL ) return VLC_EGENERIC; /* Force XSPF demux (psz_datadir was a path, now it is a file URI) */ if( asprintf( &psz_uri, "file/xspf-open%s/ml.xspf", psz_datadir+4 ) == -1 ) psz_uri = NULL; free( psz_datadir ); psz_datadir = NULL; if( psz_uri == NULL ) return VLC_ENOMEM; const char *const options[1] = { "meta-file", }; /* that option has to be cleaned in input_item_subitem_added() */ /* vlc_gc_decref() in the same function */ p_input = input_item_NewExt( p_playlist, psz_uri, _("Media Library"), 1, options, VLC_INPUT_OPTION_TRUSTED, -1 ); free( psz_uri ); if( p_input == NULL ) return VLC_EGENERIC; PL_LOCK; if( p_playlist->p_ml_onelevel->p_input ) vlc_gc_decref( p_playlist->p_ml_onelevel->p_input ); if( p_playlist->p_ml_category->p_input ) vlc_gc_decref( p_playlist->p_ml_category->p_input ); p_playlist->p_ml_onelevel->p_input = p_playlist->p_ml_category->p_input = p_input; /* We save the input at two different place, incref */ vlc_gc_incref( p_input ); vlc_gc_incref( p_input ); vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemAdded, input_item_subitem_added, p_playlist ); pl_priv(p_playlist)->b_doing_ml = true; PL_UNLOCK; stats_TimerStart( p_playlist, "ML Load", STATS_TIMER_ML_LOAD ); input_Read( p_playlist, p_input ); stats_TimerStop( p_playlist,STATS_TIMER_ML_LOAD ); PL_LOCK; pl_priv(p_playlist)->b_doing_ml = false; PL_UNLOCK; vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemAdded, input_item_subitem_added, p_playlist ); vlc_gc_decref( p_input ); return VLC_SUCCESS; }
int __vlclua_playlist_add_internal( vlc_object_t *p_this, lua_State *L, playlist_t *p_playlist, input_item_t *p_parent, bool b_play ) { int i_count = 0; input_item_node_t *p_parent_node = NULL; assert( p_parent || p_playlist ); /* playlist */ if( lua_istable( L, -1 ) ) { if( p_parent ) p_parent_node = input_item_node_Create( p_parent ); lua_pushnil( L ); /* playlist nil */ while( lua_next( L, -2 ) ) { /* playlist key item */ /* <Parse playlist item> */ if( lua_istable( L, -1 ) ) { lua_getfield( L, -1, "path" ); /* playlist key item path */ if( lua_isstring( L, -1 ) ) { const char *psz_path = NULL; const char *psz_name = NULL; char **ppsz_options = NULL; int i_options = 0; mtime_t i_duration = -1; input_item_t *p_input; /* Read path and name */ psz_path = lua_tostring( L, -1 ); msg_Dbg( p_this, "Path: %s", psz_path ); lua_getfield( L, -2, "name" ); /* playlist key item path name */ if( lua_isstring( L, -1 ) ) { psz_name = lua_tostring( L, -1 ); msg_Dbg( p_this, "Name: %s", psz_name ); } else { if( !lua_isnil( L, -1 ) ) msg_Warn( p_this, "Playlist item name should be a string." ); psz_name = psz_path; } /* Read duration */ lua_getfield( L, -3, "duration" ); /* playlist key item path name duration */ if( lua_isnumber( L, -1 ) ) { i_duration = (mtime_t)(lua_tonumber( L, -1 )*1e6); } else if( !lua_isnil( L, -1 ) ) { msg_Warn( p_this, "Playlist item duration should be a number (in seconds)." ); } lua_pop( L, 1 ); /* pop "duration" */ /* playlist key item path name */ /* Read options: item must be on top of stack */ lua_pushvalue( L, -3 ); /* playlist key item path name item */ vlclua_read_options( p_this, L, &i_options, &ppsz_options ); /* Create input item */ p_input = input_item_NewExt( p_playlist, psz_path, psz_name, i_options, (const char **)ppsz_options, VLC_INPUT_OPTION_TRUSTED, i_duration ); lua_pop( L, 3 ); /* pop "path name item" */ /* playlist key item */ /* Read meta data: item must be on top of stack */ vlclua_read_meta_data( p_this, L, p_input ); /* Read custom meta data: item must be on top of stack*/ vlclua_read_custom_meta_data( p_this, L, p_input ); /* Append item to playlist */ if( p_parent ) /* Add to node */ { input_item_CopyOptions( p_parent, p_input ); input_item_node_AppendItem( p_parent_node, p_input ); } else /* Play or Enqueue (preparse) */ /* FIXME: playlist_AddInput() can fail */ playlist_AddInput( p_playlist, p_input, PLAYLIST_APPEND | ( b_play ? PLAYLIST_GO : PLAYLIST_PREPARSE ), PLAYLIST_END, true, false ); i_count ++; /* increment counter */ vlc_gc_decref( p_input ); while( i_options > 0 ) free( ppsz_options[--i_options] ); free( ppsz_options ); } else { lua_pop( L, 1 ); /* pop "path" */ msg_Warn( p_this, "Playlist item's path should be a string" ); } /* playlist key item */ } else { msg_Warn( p_this, "Playlist item should be a table" ); } /* <Parse playlist item> */ lua_pop( L, 1 ); /* pop the value, keep the key for * the next lua_next() call */ /* playlist key */ } /* playlist */ if( p_parent ) { if( i_count ) input_item_node_PostAndDelete( p_parent_node ); else input_item_node_Delete( p_parent_node ); } } else { msg_Warn( p_this, "Playlist should be a table." ); } return i_count; }
/** * Probes and initializes. */ static int Open (vlc_object_t *obj) { services_discovery_t *sd = (services_discovery_t *)obj; services_discovery_sys_t *p_sys = malloc (sizeof (*p_sys)); if (p_sys == NULL) return VLC_ENOMEM; sd->p_sys = p_sys; sd->description = _("Screen capture"); /* Connect to X server */ char *display = var_InheritString (obj, "x11-display"); int snum; xcb_connection_t *conn = xcb_connect (display, &snum); free (display); if (xcb_connection_has_error (conn)) { free (p_sys); return VLC_EGENERIC; } p_sys->conn = conn; /* Find configured screen */ const xcb_setup_t *setup = xcb_get_setup (conn); const xcb_screen_t *scr = NULL; for (xcb_screen_iterator_t i = xcb_setup_roots_iterator (setup); i.rem > 0; xcb_screen_next (&i)) { if (snum == 0) { scr = i.data; break; } snum--; } if (scr == NULL) { msg_Err (obj, "bad X11 screen number"); goto error; } /* Add a permanent item for the entire desktop */ AddDesktop (sd); p_sys->root_window = scr->root; xcb_change_window_attributes (conn, scr->root, XCB_CW_EVENT_MASK, &(uint32_t) { XCB_EVENT_MASK_PROPERTY_CHANGE }); /* TODO: check that _NET_CLIENT_LIST is in _NET_SUPPORTED * (and _NET_SUPPORTING_WM_CHECK) */ xcb_intern_atom_reply_t *r; xcb_intern_atom_cookie_t ncl, nwn; ncl = xcb_intern_atom (conn, 1, strlen ("_NET_CLIENT_LIST"), "_NET_CLIENT_LIST"); nwn = xcb_intern_atom (conn, 0, strlen ("_NET_WM_NAME"), "_NET_WM_NAME"); r = xcb_intern_atom_reply (conn, ncl, NULL); if (r == NULL || r->atom == 0) { vlc_dialog_display_error (sd, _("Screen capture"), _("Your window manager does not provide a list of applications.")); msg_Err (sd, "client list not supported (_NET_CLIENT_LIST absent)"); } p_sys->net_client_list = r ? r->atom : 0; free (r); r = xcb_intern_atom_reply (conn, nwn, NULL); if (r != NULL) { p_sys->net_wm_name = r->atom; free (r); } p_sys->apps = NULL; p_sys->apps_root = input_item_NewExt("vlc://nop", _("Applications"), -1, ITEM_TYPE_NODE, ITEM_LOCAL); if (likely(p_sys->apps_root != NULL)) services_discovery_AddItem(sd, p_sys->apps_root); UpdateApps (sd); if (vlc_clone (&p_sys->thread, Run, sd, VLC_THREAD_PRIORITY_LOW)) goto error; return VLC_SUCCESS; error: xcb_disconnect (p_sys->conn); tdestroy (p_sys->apps, DelApp); if (p_sys->apps_root != NULL) input_item_Release(p_sys->apps_root); free (p_sys); return VLC_EGENERIC; }
/** * Main demux callback function * @param p_demux: this demux object */ static int Demux( demux_t *p_demux ) { char *psz_line; char *psz_artist = NULL, *psz_album = NULL, *psz_genre = NULL, *psz_year = NULL; char *psz_author = NULL, *psz_title = NULL, *psz_copyright = NULL, *psz_cdnum = NULL, *psz_comments = NULL; mtime_t i_duration = -1; const char **ppsz_options = NULL; int i_options = 0, i_start = 0, i_stop = 0; bool b_cleanup = false; input_item_t *p_input; input_item_t *p_current_input = GetCurrentItem(p_demux); input_item_node_t *p_subitems = input_item_node_Create( p_current_input ); psz_line = vlc_stream_ReadLine( p_demux->s ); while( psz_line ) { char *psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; if( *psz_parse == '#' ) { /* Ignore comments */ } else if( *psz_parse ) { char *psz_mrl, *psz_option_next, *psz_option; char *psz_param, *psz_value; /* Get the MRL from the file. Note that this might contain parameters of form ?param1=value1¶m2=value2 in a RAM file */ psz_mrl = ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix ); b_cleanup = true; if ( !psz_mrl ) goto error; /* We have the MRL, now we have to check for options and parse them from MRL */ psz_option = strchr( psz_mrl, '?' ); /* Look for start of options */ if( psz_option ) { /* Remove options from MRL because VLC can't get the file otherwise */ *psz_option = '\0'; psz_option++; psz_option_next = psz_option; while( 1 ) /* Process each option */ { /* Look for end of first option which maybe a & or \0 */ psz_option = psz_option_next; psz_option_next = strchr( psz_option, '&' ); if( psz_option_next ) { *psz_option_next = '\0'; psz_option_next++; } else psz_option_next = strchr( psz_option, '\0' ); /* Quit if options are over */ if( psz_option_next == psz_option ) break; /* Parse out param and value */ psz_param = psz_option; psz_value = strchr( psz_option, '=' ); if( psz_value == NULL ) break; *psz_value = '\0'; psz_value++; /* Take action based on parameter value in the below if else structure */ /* TODO: Remove any quotes surrounding values if required */ if( !strcmp( psz_param, "clipinfo" ) ) { ParseClipInfo( psz_value, &psz_artist, &psz_title, &psz_album, &psz_genre, &psz_year, &psz_cdnum, &psz_comments ); /* clipinfo has various sub parameters, which is parsed by this function */ } else if( !strcmp( psz_param, "author" ) ) { psz_author = vlc_uri_decode_duplicate(psz_value); EnsureUTF8( psz_author ); } else if( !strcmp( psz_param, "start" ) && strncmp( psz_mrl, "rtsp", 4 ) /* Our rtsp-real or our real demuxer is wrong */ ) { i_start = ParseTime( psz_value, strlen( psz_value ) ); char *temp; if( i_start ) { if( asprintf( &temp, ":start-time=%d", i_start ) != -1 ) INSERT_ELEM( ppsz_options, i_options, i_options, temp ); } } else if( !strcmp( psz_param, "end" ) ) { i_stop = ParseTime( psz_value, strlen( psz_value ) ); char *temp; if( i_stop ) { if( asprintf( &temp, ":stop-time=%d", i_stop ) != -1 ) INSERT_ELEM( ppsz_options, i_options, i_options, temp ); } } else if( !strcmp( psz_param, "title" ) ) { free( psz_title ); psz_title = vlc_uri_decode_duplicate(psz_value); EnsureUTF8( psz_title ); } else if( !strcmp( psz_param, "copyright" ) ) { psz_copyright = vlc_uri_decode_duplicate(psz_value); EnsureUTF8( psz_copyright ); } else { /* TODO: insert option anyway? Currently ignores*/ /* INSERT_ELEM( ppsz_options, i_options, i_options, psz_option ); */ } } } /* Create the input item and pump in all the options into playlist item */ p_input = input_item_NewExt( psz_mrl, psz_title, i_duration, ITEM_TYPE_UNKNOWN, ITEM_NET_UNKNOWN ); if( !p_input ) { free( psz_mrl ); goto error; } input_item_AddOptions( p_input, i_options, ppsz_options, 0 ); if( !EMPTY_STR( psz_artist ) ) input_item_SetArtist( p_input, psz_artist ); if( !EMPTY_STR( psz_author ) ) input_item_SetPublisher( p_input, psz_author ); if( !EMPTY_STR( psz_title ) ) input_item_SetTitle( p_input, psz_title ); if( !EMPTY_STR( psz_copyright ) ) input_item_SetCopyright( p_input, psz_copyright ); if( !EMPTY_STR( psz_album ) ) input_item_SetAlbum( p_input, psz_album ); if( !EMPTY_STR( psz_genre ) ) input_item_SetGenre( p_input, psz_genre ); if( !EMPTY_STR( psz_year ) ) input_item_SetDate( p_input, psz_year ); if( !EMPTY_STR( psz_cdnum ) ) input_item_SetTrackNum( p_input, psz_cdnum ); if( !EMPTY_STR( psz_comments ) ) input_item_SetDescription( p_input, psz_comments ); input_item_node_AppendItem( p_subitems, p_input ); vlc_gc_decref( p_input ); free( psz_mrl ); } error: /* Fetch another line */ free( psz_line ); psz_line = vlc_stream_ReadLine( p_demux->s ); if( !psz_line ) b_cleanup = true; if( b_cleanup ) { /* Cleanup state */ while( i_options-- ) free( (char*)ppsz_options[i_options] ); FREENULL( ppsz_options ); FREENULL( psz_artist ); FREENULL( psz_title ); FREENULL( psz_author ); FREENULL( psz_copyright ); FREENULL( psz_album ); FREENULL( psz_genre ); FREENULL( psz_year ); FREENULL( psz_cdnum ); FREENULL( psz_comments ); i_options = 0; i_duration = -1; i_start = 0; i_stop = 0; b_cleanup = false; } } input_item_node_PostAndDelete( p_subitems ); vlc_gc_decref(p_current_input); var_Destroy( p_demux, "m3u-extvlcopt" ); return 0; /* Needed for correct operation of go back */ }
static int vlclua_sd_add_item( lua_State *L ) { services_discovery_t *p_sd = (services_discovery_t *)vlclua_get_this( L ); if( lua_istable( L, -1 ) ) { lua_getfield( L, -1, "path" ); if( lua_isstring( L, -1 ) ) { const char *psz_path = lua_tostring( L, -1 ); lua_getfield( L, -2, "title" ); const char *psz_title = luaL_checkstring( L, -1 ) ? luaL_checkstring( L, -1 ) : psz_path; /* The table must be at the top of the stack when calling * vlclua_read_options() */ char **ppsz_options = NULL; int i_options = 0; lua_pushvalue( L, -3 ); vlclua_read_options( p_sd, L, &i_options, &ppsz_options ); input_item_t *p_input = input_item_NewExt( psz_path, psz_title, i_options, (const char **)ppsz_options, VLC_INPUT_OPTION_TRUSTED, -1 ); lua_pop( L, 3 ); if( p_input ) { vlclua_read_meta_data( p_sd, L, p_input ); /* This one is to be tested... */ vlclua_read_custom_meta_data( p_sd, L, p_input ); /* The duration is given in seconds, convert to microseconds */ lua_getfield( L, -1, "duration" ); if( lua_isnumber( L, -1 ) ) input_item_SetDuration( p_input, (lua_tonumber( L, -1 )*1e6) ); else if( !lua_isnil( L, -1 ) ) msg_Warn( p_sd, "Item duration should be a number (in seconds)." ); lua_pop( L, 1 ); lua_getfield( L, -1, "category" ); if( lua_isstring( L, -1 ) ) services_discovery_AddItem( p_sd, p_input, luaL_checkstring( L, -1 ) ); else services_discovery_AddItem( p_sd, p_input, NULL ); lua_pop( L, 1 ); input_item_t **udata = (input_item_t **) lua_newuserdata( L, sizeof( input_item_t * ) ); *udata = p_input; if( luaL_newmetatable( L, "input_item_t" ) ) { lua_newtable( L ); luaL_register( L, NULL, vlclua_item_reg ); lua_setfield( L, -2, "__index" ); lua_pushliteral( L, "none of your business" ); lua_setfield( L, -2, "__metatable" ); } lua_setmetatable( L, -2 ); vlc_gc_decref( p_input ); } while( i_options > 0 ) free( ppsz_options[--i_options] ); free( ppsz_options ); } else msg_Err( p_sd, "vlc.sd.add_item: the \"path\" parameter can't be empty" ); } else msg_Err( p_sd, "Error parsing add_item arguments" ); return 1; }
static void ProcessEntry( int *pi_n_entry, xml_reader_t *p_xml_reader, input_item_node_t *p_subitems, input_item_t *p_current_input, char *psz_prefix ) { const char *psz_node = NULL; const char *psz_txt = NULL; int i_type; char *psz_title = NULL; char *psz_artist = NULL; char *psz_copyright = NULL; char *psz_moreinfo = NULL; char *psz_description = NULL; char *psz_name = NULL; char *psz_mrl = NULL; char *psz_href = NULL; input_item_t *p_entry = NULL; int i_options; mtime_t i_start = 0; mtime_t i_duration = 0; char *ppsz_options[2]; do { i_type = xml_ReaderNextNode( p_xml_reader, &psz_node ); if( i_type == XML_READER_STARTELEM ) { /* Metadata Node */ if( !strncasecmp( psz_node, "TITLE", 5 ) ) ReadElement( p_xml_reader, &psz_title ); else if( !strncasecmp( psz_node, "AUTHOR", 6 ) ) ReadElement( p_xml_reader, &psz_artist ); else if( !strncasecmp( psz_node, "COPYRIGHT", 9 ) ) ReadElement( p_xml_reader, &psz_copyright ); else if( !strncasecmp( psz_node,"MOREINFO", 8 ) ) { do { psz_txt = xml_ReaderNextAttr( p_xml_reader, &psz_node ); } while(psz_txt && strncasecmp( psz_txt, "HREF", 4 ) ); if( !psz_txt ) ReadElement( p_xml_reader, &psz_moreinfo ); else psz_moreinfo = strdup( psz_node ); resolve_xml_special_chars( psz_moreinfo ); } else if( !strncasecmp( psz_node, "ABSTRACT", 8 ) ) ReadElement( p_xml_reader, &psz_description ); else if( !strncasecmp( psz_node, "DURATION", 8 ) ) i_duration = ParseTime( p_xml_reader ); else if( !strncasecmp( psz_node, "STARTTIME", 9 ) ) i_start = ParseTime( p_xml_reader ); else /* Reference Node */ /* All ref node will be converted into an entry */ if( !strncasecmp( psz_node, "REF", 3 ) ) { *pi_n_entry = *pi_n_entry + 1; if( !psz_title ) psz_title = input_item_GetTitle( p_current_input ); if( !psz_artist ) psz_artist = input_item_GetArtist( p_current_input ); if( !psz_copyright ) psz_copyright = input_item_GetCopyright( p_current_input ); if( !psz_description ) psz_description = input_item_GetDescription( p_current_input ); do { psz_txt = xml_ReaderNextAttr( p_xml_reader, &psz_node ); } while( strncasecmp( psz_txt, "HREF", 4) ); psz_href = strdup( psz_node ); if( asprintf( &psz_name, "%d. %s", *pi_n_entry, psz_title ) == -1) psz_name = strdup( psz_title ); resolve_xml_special_chars( psz_href ); psz_mrl = ProcessMRL( psz_href, psz_prefix ); /* Add Time information */ i_options = 0; if( i_start ) { if( asprintf( ppsz_options, ":start-time=%d" ,(int) i_start/1000000 ) != -1) i_options++; } if( i_duration) { if( asprintf( ppsz_options + i_options, ":stop-time=%d", (int) (i_start+i_duration)/1000000 ) != -1) i_options++; } /* Create the input item */ p_entry = input_item_NewExt( psz_mrl, psz_name, i_options, (const char* const*) ppsz_options, VLC_INPUT_OPTION_TRUSTED, i_duration ); input_item_CopyOptions( p_current_input, p_entry ); /* Add the metadata */ if( psz_name ) input_item_SetTitle( p_entry, psz_name ); if( psz_artist ) input_item_SetArtist( p_entry, psz_artist ); if( psz_copyright ) input_item_SetCopyright( p_entry, psz_copyright ); if( psz_moreinfo ) input_item_SetURL( p_entry, psz_moreinfo ); if( psz_description ) input_item_SetDescription( p_entry, psz_description ); if( i_duration > 0) input_item_SetDuration( p_entry, i_duration ); input_item_node_AppendItem( p_subitems, p_entry ); while( i_options ) free( ppsz_options[--i_options] ); free( psz_name ); free( psz_mrl ); } } } while( i_type != XML_READER_ENDELEM || strncasecmp( psz_node, "ENTRY", 5 ) ); free( psz_href ); free( psz_title ); free( psz_artist ); free( psz_copyright ); free( psz_moreinfo ); free( psz_description ); }
int playlist_MLLoad( playlist_t *p_playlist ) { input_item_t *p_input; char *psz_datadir = config_GetUserDir( VLC_DATA_DIR ); if( !psz_datadir ) /* XXX: This should never happen */ { msg_Err( p_playlist, "no data directory, cannot load media library") ; return VLC_EGENERIC; } char *psz_file; if( asprintf( &psz_file, "%s" DIR_SEP "ml.xspf", psz_datadir ) == -1 ) psz_file = NULL; free( psz_datadir ); if( psz_file == NULL ) return VLC_ENOMEM; /* loosy check for media library file */ struct stat st; if( vlc_stat( psz_file, &st ) ) { free( psz_file ); return VLC_EGENERIC; } char *psz_uri = make_URI( psz_file, "file/xspf-open" ); free( psz_file ); if( psz_uri == NULL ) return VLC_ENOMEM; const char *const options[1] = { "meta-file", }; /* that option has to be cleaned in input_item_subitem_tree_added() */ /* vlc_gc_decref() in the same function */ p_input = input_item_NewExt( psz_uri, _("Media Library"), 1, options, VLC_INPUT_OPTION_TRUSTED, -1 ); free( psz_uri ); if( p_input == NULL ) return VLC_EGENERIC; PL_LOCK; if( p_playlist->p_media_library->p_input ) vlc_gc_decref( p_playlist->p_media_library->p_input ); p_playlist->p_media_library->p_input = p_input; vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemTreeAdded, input_item_subitem_tree_added, p_playlist ); pl_priv(p_playlist)->b_doing_ml = true; PL_UNLOCK; stats_TimerStart( p_playlist, "ML Load", STATS_TIMER_ML_LOAD ); input_Read( p_playlist, p_input ); stats_TimerStop( p_playlist,STATS_TIMER_ML_LOAD ); PL_LOCK; pl_priv(p_playlist)->b_doing_ml = false; PL_UNLOCK; vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemTreeAdded, input_item_subitem_tree_added, p_playlist ); return VLC_SUCCESS; }
static int Demux( demux_t *p_demux ) { char *psz_line; char *psz_name = NULL; char *psz_artist = NULL; char *psz_album_art = NULL; int i_parsed_duration = 0; mtime_t i_duration = -1; const char**ppsz_options = NULL; char * (*pf_dup) (const char *) = p_demux->p_sys->pf_dup; int i_options = 0; bool b_cleanup = false; input_item_t *p_input; input_item_t *p_current_input = GetCurrentItem(p_demux); input_item_node_t *p_subitems = input_item_node_Create( p_current_input ); psz_line = vlc_stream_ReadLine( p_demux->s ); while( psz_line ) { char *psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; if( *psz_parse == '#' ) { /* Parse extra info */ /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' || *psz_parse == '#' ) psz_parse++; if( !*psz_parse ) goto error; if( !strncasecmp( psz_parse, "EXTINF:", sizeof("EXTINF:") -1 ) ) { /* Extended info */ psz_parse += sizeof("EXTINF:") - 1; FREENULL( psz_name ); FREENULL( psz_artist ); parseEXTINF( psz_parse, &psz_artist, &psz_name, &i_parsed_duration ); if( i_parsed_duration >= 0 ) i_duration = i_parsed_duration * INT64_C(1000000); if( psz_name ) psz_name = pf_dup( psz_name ); if( psz_artist ) psz_artist = pf_dup( psz_artist ); } else if( !strncasecmp( psz_parse, "EXTVLCOPT:", sizeof("EXTVLCOPT:") -1 ) ) { /* VLC Option */ char *psz_option; psz_parse += sizeof("EXTVLCOPT:") -1; if( !*psz_parse ) goto error; psz_option = pf_dup( psz_parse ); if( psz_option ) INSERT_ELEM( ppsz_options, i_options, i_options, psz_option ); } /* Special case for jamendo which provide the albumart */ else if( !strncasecmp( psz_parse, "EXTALBUMARTURL:", sizeof( "EXTALBUMARTURL:" ) -1 ) ) { psz_parse += sizeof( "EXTALBUMARTURL:" ) - 1; free( psz_album_art ); psz_album_art = pf_dup( psz_parse ); } } else if( !strncasecmp( psz_parse, "RTSPtext", sizeof("RTSPtext") -1 ) ) { ;/* special case to handle QuickTime RTSPtext redirect files */ } else if( *psz_parse ) { char *psz_mrl; psz_parse = pf_dup( psz_parse ); if( !psz_name && psz_parse ) /* Use filename as name for relative entries */ psz_name = strdup( psz_parse ); psz_mrl = ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix ); b_cleanup = true; if( !psz_mrl ) { free( psz_parse ); goto error; } p_input = input_item_NewExt( psz_mrl, psz_name, i_duration, ITEM_TYPE_UNKNOWN, ITEM_NET_UNKNOWN ); free( psz_parse ); free( psz_mrl ); if( !p_input ) goto error; input_item_AddOptions( p_input, i_options, ppsz_options, 0 ); input_item_CopyOptions( p_input, p_current_input ); if( !EMPTY_STR(psz_artist) ) input_item_SetArtist( p_input, psz_artist ); if( psz_name ) input_item_SetTitle( p_input, psz_name ); if( !EMPTY_STR(psz_album_art) ) input_item_SetArtURL( p_input, psz_album_art ); input_item_node_AppendItem( p_subitems, p_input ); vlc_gc_decref( p_input ); } error: /* Fetch another line */ free( psz_line ); psz_line = vlc_stream_ReadLine( p_demux->s ); if( !psz_line ) b_cleanup = true; if( b_cleanup ) { /* Cleanup state */ while( i_options-- ) free( (char*)ppsz_options[i_options] ); FREENULL( ppsz_options ); i_options = 0; FREENULL( psz_name ); FREENULL( psz_artist ); FREENULL( psz_album_art ); i_parsed_duration = 0; i_duration = -1; b_cleanup = false; } } input_item_node_PostAndDelete( p_subitems ); vlc_gc_decref(p_current_input); var_Destroy( p_demux, "m3u-extvlcopt" ); return 0; /* Needed for correct operation of go back */ }
static int Demux( demux_t *p_demux ) { char *psz_line; char *psz_name = NULL; char *psz_artist = NULL; int i_parsed_duration = 0; mtime_t i_duration = -1; const char**ppsz_options = NULL; char * (*pf_dup) (const char *) = p_demux->p_sys->pf_dup; int i_options = 0; bool b_cleanup = false; input_item_t *p_input; input_item_t *p_current_input = GetCurrentItem(p_demux); psz_line = stream_ReadLine( p_demux->s ); while( psz_line ) { char *psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; if( *psz_parse == '#' ) { /* Parse extra info */ /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' || *psz_parse == '#' ) psz_parse++; if( !*psz_parse ) goto error; if( !strncasecmp( psz_parse, "EXTINF:", sizeof("EXTINF:") -1 ) ) { /* Extended info */ psz_parse += sizeof("EXTINF:") - 1; parseEXTINF( psz_parse, &psz_artist, &psz_name, &i_parsed_duration ); if( i_parsed_duration >= 0 ) i_duration = i_parsed_duration * INT64_C(1000000); if( psz_name ) psz_name = pf_dup( psz_name ); if( psz_artist ) psz_artist = pf_dup( psz_artist ); } else if( !strncasecmp( psz_parse, "EXTVLCOPT:", sizeof("EXTVLCOPT:") -1 ) ) { /* VLC Option */ char *psz_option; psz_parse += sizeof("EXTVLCOPT:") -1; if( !*psz_parse ) goto error; psz_option = pf_dup( psz_parse ); if( psz_option ) INSERT_ELEM( ppsz_options, i_options, i_options, psz_option ); } } else if( !strncasecmp( psz_parse, "RTSPtext", sizeof("RTSPtext") -1 ) ) { ;/* special case to handle QuickTime RTSPtext redirect files */ } else if( *psz_parse ) { char *psz_mrl; psz_parse = pf_dup( psz_parse ); if( !psz_name && psz_parse ) /* Use filename as name for relative entries */ psz_name = strdup( psz_parse ); psz_mrl = ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix ); b_cleanup = true; if( !psz_mrl ) goto error; p_input = input_item_NewExt( p_demux, psz_mrl, psz_name, i_options, ppsz_options, 0, i_duration ); LocaleFree( psz_parse ); free( psz_mrl ); if ( psz_artist && *psz_artist ) input_item_SetArtist( p_input, psz_artist ); if( psz_name ) input_item_SetTitle( p_input, psz_name ); input_item_AddSubItem( p_current_input, p_input ); vlc_gc_decref( p_input ); } error: /* Fetch another line */ free( psz_line ); psz_line = stream_ReadLine( p_demux->s ); if( !psz_line ) b_cleanup = true; if( b_cleanup ) { /* Cleanup state */ while( i_options-- ) free( (char*)ppsz_options[i_options] ); free( ppsz_options ); ppsz_options = NULL; i_options = 0; free( psz_name ); psz_name = NULL; free( psz_artist ); psz_artist = NULL; i_parsed_duration = 0; i_duration = -1; b_cleanup = false; } } vlc_gc_decref(p_current_input); var_Destroy( p_demux, "m3u-extvlcopt" ); return 0; /* Needed for correct operation of go back */ }