CoverArtLabel::~CoverArtLabel() { QList< QAction* > artActions = actions(); foreach( QAction *act, artActions ) removeAction( act ); if ( p_item ) input_item_Release( p_item ); }
static int ReadDir(access_t* p_access, input_item_node_t* p_node) { using ItemsHeap = std::map<uint64_t, input_item_t*>; const auto& torrent = p_access->p_sys->torrent; const auto& metadata = torrent.torrent_metadata(); const auto& files = metadata.files(); ItemsHeap items; for (auto i = 0; i < metadata.num_files(); ++i) { const auto f = metadata.file_at(i); const auto psz_uri = torrent.uri().c_str(); const auto psz_name = files.file_name(i); const auto psz_option = "torrent-file-index=" + std::to_string(i); auto p_item = input_item_New(psz_uri, psz_name.c_str()); input_item_AddOption(p_item, psz_option.c_str(), VLC_INPUT_OPTION_TRUSTED); items[f.size] = p_item; } std::for_each(items.rbegin(), items.rend(), [p_node](ItemsHeap::value_type& p) { input_item_node_AppendItem(p_node, p.second); input_item_Release(p.second); }); return VLC_SUCCESS; }
static void test_cancel_thumbnail( libvlc_instance_t* p_vlc ) { vlc_thumbnailer_t* p_thumbnailer = vlc_thumbnailer_Create( VLC_OBJECT( p_vlc->p_libvlc_int ) ); assert( p_thumbnailer != NULL ); struct test_ctx ctx; vlc_cond_init( &ctx.cond ); vlc_mutex_init( &ctx.lock ); const char* psz_mrl = "mock://video_track_count=1;audio_track_count=1"; input_item_t* p_item = input_item_New( psz_mrl, "mock item" ); assert( p_item != NULL ); vlc_mutex_lock( &ctx.lock ); int res = 0; vlc_thumbnailer_request_t* p_req = vlc_thumbnailer_RequestByTime( p_thumbnailer, VLC_TICK_FROM_SEC( 1 ), VLC_THUMBNAILER_SEEK_PRECISE, p_item, VLC_TICK_INVALID, thumbnailer_callback_cancel, &ctx ); vlc_thumbnailer_Cancel( p_thumbnailer, p_req ); while ( ctx.b_done == false ) { vlc_tick_t timeout = vlc_tick_now() + VLC_TICK_FROM_SEC( 1 ); res = vlc_cond_timedwait( &ctx.cond, &ctx.lock, timeout ); assert( res != ETIMEDOUT ); } vlc_mutex_unlock( &ctx.lock ); input_item_Release( p_item ); vlc_thumbnailer_Release( p_thumbnailer ); }
static int ReadDir(stream_t *s, input_item_node_t *node) { struct vlclua_playlist *sys = s->p_sys; lua_State *L = sys->L; luaL_register_namespace( L, "vlc", p_reg_parse ); lua_getglobal( L, "parse" ); if( !lua_isfunction( L, -1 ) ) { msg_Warn(s, "error running script %s: function %s(): %s", sys->filename, "parse", "not found"); return VLC_ENOITEM; } if( lua_pcall( L, 0, 1, 0 ) ) { msg_Warn(s, "error running script %s: function %s(): %s", sys->filename, "parse", lua_tostring(L, lua_gettop(L))); return VLC_ENOITEM; } if (!lua_gettop(L)) { msg_Err(s, "script went completely foobar"); return VLC_ENOITEM; } if (!lua_istable(L, -1)) { msg_Warn(s, "Playlist should be a table."); return VLC_ENOITEM; } lua_pushnil(L); /* playlist nil */ while (lua_next(L, -2)) { input_item_t *item = vlclua_read_input_item(VLC_OBJECT(s), L); if (item != NULL) { /* copy the original URL to the meta data, * if "URL" is still empty */ char *url = input_item_GetURL(item); if (url == NULL && s->psz_url != NULL) input_item_SetURL(item, s->psz_url); free(url); input_item_node_AppendItem(node, item); input_item_Release(item); } /* pop the value, keep the key for the next lua_next() call */ lua_pop(L, 1); } /* playlist */ return VLC_SUCCESS; }
/** * Adds a source. */ static int AddSource (services_discovery_t *sd, const pa_source_info *info) { services_discovery_sys_t *sys = sd->p_sys; msg_Dbg (sd, "adding %s (%s)", info->name, info->description); char *mrl; if (unlikely(asprintf (&mrl, "pulse://%s", info->name) == -1)) return -1; input_item_t *item = input_item_NewCard (mrl, info->description); free (mrl); if (unlikely(item == NULL)) return -1; struct device *d = malloc (sizeof (*d)); if (unlikely(d == NULL)) { input_item_Release (item); return -1; } d->index = info->index; d->item = item; struct device **dp = tsearch (d, &sys->root, cmpsrc); if (dp == NULL) /* Out-of-memory */ { free (d); input_item_Release (item); return -1; } if (*dp != d) /* Update existing source */ { free (d); d = *dp; input_item_SetURI (d->item, item->psz_uri); input_item_SetName (d->item, item->psz_name); input_item_Release (item); return 0; } const char *card = pa_proplist_gets(info->proplist, "device.product.name"); services_discovery_AddItemCat(sd, item, (card != NULL) ? card : N_("Generic")); d->sd = sd; return 0; }
static void DelApp (void *data) { struct app *app = data; services_discovery_RemoveItem (app->owner, app->item); input_item_Release (app->item); free (app); }
static void ReqRelease(input_preparser_req_t *req) { if (vlc_atomic_rc_dec(&req->rc)) { input_item_Release(req->item); free(req); } }
static void DestroySource (void *data) { struct device *d = data; services_discovery_RemoveItem (d->sd, d->item); input_item_Release (d->item); free (d); }
void vlc_playlist_item_Release(vlc_playlist_item_t *item) { if (vlc_atomic_rc_dec(&item->rc)) { input_item_Release(item->media); free(item); } }
static void test_thumbnails( libvlc_instance_t* p_vlc ) { vlc_thumbnailer_t* p_thumbnailer = vlc_thumbnailer_Create( VLC_OBJECT( p_vlc->p_libvlc_int ) ); assert( p_thumbnailer != NULL ); struct test_ctx ctx; vlc_cond_init( &ctx.cond ); vlc_mutex_init( &ctx.lock ); for ( size_t i = 0; i < sizeof(test_params) / sizeof(test_params[0]); ++i) { char* psz_mrl; ctx.test_idx = i; ctx.b_done = false; if ( asprintf( &psz_mrl, "mock://video_track_count=%u;audio_track_count=%u" ";length=%" PRId64 ";video_chroma=ARGB;add_video_track_at=%" PRId64, test_params[i].i_nb_video_tracks, test_params[i].i_nb_audio_tracks, MOCK_DURATION, test_params[i].i_add_video_track_at ) < 0 ) assert( !"Failed to allocate mock mrl" ); input_item_t* p_item = input_item_New( psz_mrl, "mock item" ); assert( p_item != NULL ); vlc_mutex_lock( &ctx.lock ); int res = 0; if ( test_params[i].b_use_pos ) { vlc_thumbnailer_RequestByPos( p_thumbnailer, test_params[i].f_pos, test_params[i].b_fast_seek ? VLC_THUMBNAILER_SEEK_FAST : VLC_THUMBNAILER_SEEK_PRECISE, p_item, test_params[i].i_timeout, thumbnailer_callback, &ctx ); } else { vlc_thumbnailer_RequestByTime( p_thumbnailer, test_params[i].i_time, test_params[i].b_fast_seek ? VLC_THUMBNAILER_SEEK_FAST : VLC_THUMBNAILER_SEEK_PRECISE, p_item, test_params[i].i_timeout, thumbnailer_callback, &ctx ); } while ( ctx.b_done == false ) { vlc_tick_t timeout = vlc_tick_now() + VLC_TICK_FROM_SEC( 1 ); res = vlc_cond_timedwait( &ctx.cond, &ctx.lock, timeout ); assert( res != ETIMEDOUT ); } vlc_mutex_unlock( &ctx.lock ); input_item_Release( p_item ); free( psz_mrl ); } vlc_thumbnailer_Release( p_thumbnailer ); }
/*** Whole desktop ***/ static void AddDesktop(services_discovery_t *sd) { input_item_t *item; item = input_item_NewCard ("screen://", _("Desktop")); if (item == NULL) return; services_discovery_AddItem(sd, item); input_item_Release (item); }
static input_item_t *new_item( access_t *p_access, const char *psz_name, int i_type ) { access_sys_t *p_sys = p_access->p_sys; input_item_t *p_item; char *psz_uri, *psz_option = NULL; int i_ret; i_ret = asprintf( &psz_uri, "smb://%s/%s", p_access->psz_location, psz_name ); if( i_ret == -1 ) return NULL; p_item = input_item_NewWithTypeExt( psz_uri, psz_name, 0, NULL, 0, -1, i_type, 1 ); free( psz_uri ); if( p_item == NULL ) return NULL; /* Here we save on the node the credentials that allowed us to login. * That way the user isn't prompted more than once for credentials */ if( p_sys->creds.login ) { i_ret = asprintf( &psz_option, "smb-user=%s", p_sys->creds.login ); if( i_ret == -1 ) goto bailout; input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED ); free( psz_option ); } if( p_sys->creds.password ) { i_ret = asprintf( &psz_option, "smb-pwd=%s", p_sys->creds.password ); if( i_ret == -1 ) goto bailout; input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED ); free( psz_option ); } if( p_sys->creds.domain ) { i_ret = asprintf( &psz_option, "smb-domain=%s", p_sys->creds.domain ); if( i_ret == -1 ) goto bailout; input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED ); free( psz_option ); } return p_item; bailout: if( p_item ) input_item_Release( p_item ); free( psz_option ); return NULL; }
/** * Releases resources */ static void Close (vlc_object_t *obj) { services_discovery_t *sd = (services_discovery_t *)obj; services_discovery_sys_t *p_sys = sd->p_sys; vlc_cancel (p_sys->thread); vlc_join (p_sys->thread, NULL); 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); }
PLSelector::~PLSelector() { if( podcastsParent ) { int c = podcastsParent->childCount(); for( int i = 0; i < c; i++ ) { QTreeWidgetItem *item = podcastsParent->child(i); input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>(); input_item_Release( p_input ); } } }
static int onNewFileAdded( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { (void)p_this; services_discovery_t *p_sd = p_data; services_discovery_sys_t *p_sys = p_sd->p_sys; (void)psz_var; (void)oldval; char* psz_file = newval.psz_string; if( !psz_file || !*psz_file ) return VLC_EGENERIC; char* psz_uri = vlc_path2uri( psz_file, "file" ); input_item_t* p_item = input_item_New( psz_uri, NULL ); if( p_sys->i_type == Picture ) { if( fileType( p_sd, psz_file ) == Picture ) { formatSnapshotItem( p_item ); services_discovery_AddItem( p_sd, p_item ); msg_Dbg( p_sd, "New snapshot added : %s", psz_file ); } } else if( p_sys->i_type == Audio ) { if( fileType( p_sd, psz_file ) == Audio ) { services_discovery_AddItem( p_sd, p_item ); msg_Dbg( p_sd, "New recorded audio added : %s", psz_file ); } } else if( p_sys->i_type == Video ) { if( fileType( p_sd, psz_file ) == Video || fileType( p_sd, psz_file ) == Unknown ) { services_discovery_AddItem( p_sd, p_item ); msg_Dbg( p_sd, "New recorded video added : %s", psz_file ); } } input_item_Release( p_item ); free( psz_uri ); return VLC_SUCCESS; }
static void cancelDoFingerprint( void *p_arg ) { fingerprinter_sys_t *p_sys = ( fingerprinter_sys_t * ) p_arg; if ( p_sys->p_input ) { input_Stop( p_sys->p_input, true ); input_Close( p_sys->p_input ); } /* cleanup temporary result */ if ( p_sys->chroma_fingerprint.psz_fingerprint ) FREENULL( p_sys->chroma_fingerprint.psz_fingerprint ); if ( p_sys->p_item ) input_item_Release( p_sys->p_item ); }
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_MLLoad( playlist_t *p_playlist ) { 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; /* lousy check for media library file */ struct stat st; if( vlc_stat( psz_file, &st ) ) { free( psz_file ); return VLC_EGENERIC; } char *psz_uri = vlc_path2uri( psz_file, "file/directory" ); free( psz_file ); if( psz_uri == NULL ) return VLC_ENOMEM; input_item_t *p_input = input_item_New( psz_uri, _("Media Library") ); free( psz_uri ); if( p_input == NULL ) return VLC_EGENERIC; vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemTreeAdded, input_item_subitem_tree_added, p_playlist ); vlc_object_t *dummy = vlc_object_create( p_playlist, sizeof (*dummy) ); var_Create( dummy, "meta-file", VLC_VAR_VOID ); input_Read( dummy, p_input ); vlc_object_release( dummy ); vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemTreeAdded, input_item_subitem_tree_added, p_playlist ); input_item_Release( p_input ); return VLC_SUCCESS; }
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 ); }
static void add_to_playlist(intf_thread_t *intf, const char *uri, bool play_now, int options_count, const char *const *options) { vlc_playlist_t *playlist = vlc_intf_GetMainPlaylist(intf); input_item_t *media = input_item_New(uri, NULL); if (!media) return; input_item_AddOptions(media, options_count, options, VLC_INPUT_OPTION_TRUSTED); vlc_playlist_Lock(playlist); vlc_playlist_AppendOne(playlist, media); if (play_now) vlc_playlist_Start(playlist); vlc_playlist_Unlock(playlist); input_item_Release(media); }
/***************************************************************************** * Run: *****************************************************************************/ static void *Run( void *data ) { services_discovery_t *p_sd = data; services_discovery_sys_t *p_sys = p_sd->p_sys; int num_dir = sizeof( p_sys->psz_dir ) / sizeof( p_sys->psz_dir[0] ); for( int i = 0; i < num_dir; i++ ) { char* psz_dir = p_sys->psz_dir[i]; /* make sure the directory exists */ struct stat st; if( psz_dir == NULL || vlc_stat( psz_dir, &st ) || !S_ISDIR( st.st_mode ) ) continue; char* psz_uri = vlc_path2uri( psz_dir, "file" ); input_item_t* p_root = input_item_New( psz_uri, NULL ); if( p_sys->i_type == Picture ) input_item_AddOption( p_root, "ignore-filetypes=ini,db,lnk,txt", VLC_INPUT_OPTION_TRUSTED|VLC_INPUT_OPTION_UNIQUE ); input_item_AddOption( p_root, "recursive=collapse", VLC_INPUT_OPTION_TRUSTED|VLC_INPUT_OPTION_UNIQUE ); vlc_event_manager_t *p_em = &p_root->event_manager; vlc_event_attach( p_em, vlc_InputItemSubItemTreeAdded, input_subnode_added, p_sd ); input_Read( p_sd, p_root ); vlc_event_detach( p_em, vlc_InputItemSubItemTreeAdded, input_subnode_added, p_sd ); input_item_Release( p_root ); free( psz_uri ); } return NULL; }
static struct app *AddApp (services_discovery_t *sd, xcb_window_t xid) { services_discovery_sys_t *p_sys = sd->p_sys; char *mrl, *name; if (asprintf (&mrl, "window://0x%"PRIx8, xid) == -1) return NULL; xcb_get_property_reply_t *r = xcb_get_property_reply (p_sys->conn, xcb_get_property (p_sys->conn, 0, xid, p_sys->net_wm_name, 0, 0, 1023 /* max size */), NULL); if (r != NULL) { name = strndup (xcb_get_property_value (r), xcb_get_property_value_length (r)); if (name != NULL) EnsureUTF8 (name); /* don't trust third party apps too much ;-) */ free (r); } /* TODO: use WM_NAME (Latin-1) for very old apps */ else name = NULL; input_item_t *item = input_item_NewCard (mrl, name ? name : mrl); /* FIXME */ free (mrl); free (name); if (item == NULL) return NULL; struct app *app = malloc (sizeof (*app)); if (app == NULL) { input_item_Release (item); return NULL; } app->xid = xid; app->item = item; app->owner = sd; services_discovery_AddSubItem(sd, p_sys->apps_root, item); return app; }
static int ReadDVD( stream_t *p_stream, input_item_node_t *node ) { const char *psz_location = StreamLocation(p_stream); char *psz_url = strndup( psz_location, strlen( psz_location ) - 12 ); if( !psz_url ) return VLC_ENOMEM; input_item_t *p_input = input_item_New( psz_url, psz_url ); if( p_input ) { input_item_AddOption( p_input, "demux=dvd", VLC_INPUT_OPTION_TRUSTED ); input_item_node_AppendItem( node, p_input ); input_item_Release( p_input ); } free( psz_url ); return VLC_SUCCESS; }
static int Demux( demux_t* p_demux ) { const char* psz_name; int i_type; demux_sys_t* p_sys = p_demux->p_sys; input_item_t* p_input = GetCurrentItem( p_demux ); input_item_node_t* p_node = input_item_node_Create( p_input ); p_sys->psz_prefix = FindPrefix( p_demux ); do { i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_name ); if ( i_type == XML_READER_STARTELEM && !strcasecmp( psz_name, "head" ) ) read_head( p_demux, p_input ); else if ( i_type == XML_READER_STARTELEM && !strcasecmp( psz_name, "body" ) ) read_body( p_demux, p_node ); } while (i_type != XML_READER_ENDELEM || strcasecmp( psz_name, "smil" ) ); input_item_node_PostAndDelete( p_node ); input_item_Release( p_input ); return 0; }
void EpgDialog::updateInfos() { input_item_t *p_input_item = NULL; playlist_t *p_playlist = THEPL; input_thread_t *p_input_thread = playlist_CurrentInput( p_playlist ); /* w/hold */ if( p_input_thread ) { PL_LOCK; /* as input_GetItem still unfixed */ p_input_item = input_GetItem( p_input_thread ); if ( p_input_item ) input_item_Hold( p_input_item ); PL_UNLOCK; vlc_object_release( p_input_thread ); if ( p_input_item ) { epg->updateEPG( p_input_item ); input_item_Release( p_input_item ); } else { epg->reset(); } } }
static int ReadDVD_VR( stream_t *p_stream, input_item_node_t *node ) { const char *psz_location = StreamLocation(p_stream); size_t len = strlen( psz_location ); char *psz_url = strdup( psz_location ); if( unlikely( psz_url == NULL ) ) return VLC_EGENERIC; strcpy( &psz_url[len - 12], "VR_MOVIE.VRO" ); input_item_t *p_input = input_item_New( psz_url, psz_url ); if( p_input ) { input_item_node_AppendItem( node, p_input ); input_item_Release( p_input ); } free( psz_url ); return VLC_SUCCESS; }
bool MediaServer::addContainer( IXML_Element* containerElement ) { char* psz_url; const char* objectID = ixmlElement_getAttribute( containerElement, "id" ); if ( !objectID ) return false; const char* title = xml_getChildElementValue( containerElement, "dc:title" ); if ( !title ) return false; if( asprintf( &psz_url, "upnp://%s?ObjectID=%s", m_psz_root, objectID ) < 0 ) return false; input_item_t* p_item = input_item_NewDirectory( psz_url, title, ITEM_NET ); free( psz_url); if ( !p_item ) return false; input_item_CopyOptions( p_item, m_node->p_item ); input_item_node_AppendItem( m_node, p_item ); input_item_Release( p_item ); return true; }
static int ReadDir(stream_t *demux, input_item_node_t *subitems) { char *line; while ((line = vlc_stream_ReadLine(demux->s)) != NULL) { if (!IsUTF8(line)) goto skip; if (!strcmp(line, "[Reference]")) goto skip; const char *key = line; char *value = strchr(line, '='); if (value == NULL) { msg_Warn(demux, "unexpected entry \"%s\"", line); goto skip; } *(value++) = '\0'; unsigned id; if (sscanf(key, "Ref%u", &id) != 1) { msg_Warn(demux, "unexpected entry key \"%s\"", key); goto skip; } if (!strncasecmp(value, "http://", 7)) memcpy(value, "mmsh", 4); /* Force MMSH access/demux */ input_item_t *item = input_item_New(value, value); input_item_node_AppendItem(subitems, item); input_item_Release(item); skip: free(line); } return VLC_SUCCESS; }
/* "specs" : http://phobos.apple.com/static/iTunesRSS.html */ static int ReadDir( stream_t *p_demux, input_item_node_t *p_subitems ) { bool b_item = false; bool b_image = false; xml_reader_t *p_xml_reader; char *psz_elname = NULL; char *psz_item_mrl = NULL; char *psz_item_size = NULL; char *psz_item_type = NULL; char *psz_item_name = NULL; char *psz_item_date = NULL; char *psz_item_author = NULL; char *psz_item_category = NULL; char *psz_item_duration = NULL; char *psz_item_keywords = NULL; char *psz_item_subtitle = NULL; char *psz_item_summary = NULL; char *psz_art_url = NULL; const char *node; int i_type; input_item_t *p_input; input_item_t *p_current_input = GetCurrentItem(p_demux); p_xml_reader = xml_ReaderCreate( p_demux, p_demux->s ); if( !p_xml_reader ) goto error; /* xml */ /* check root node */ if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM ) { msg_Err( p_demux, "invalid file (no root node)" ); goto error; } if( strcmp( node, "rss" ) ) { msg_Err( p_demux, "invalid root node <%s>", node ); goto error; } while( (i_type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 ) { switch( i_type ) { case XML_READER_STARTELEM: { free( psz_elname ); psz_elname = strdup( node ); if( unlikely(!psz_elname) ) goto error; if( !strcmp( node, "item" ) ) b_item = true; else if( !strcmp( node, "image" ) ) b_image = true; // Read the attributes const char *attr, *value; while( (attr = xml_ReaderNextAttr( p_xml_reader, &value )) ) { if( !strcmp( node, "enclosure" ) ) { char **p = NULL; if( !strcmp( attr, "url" ) ) p = &psz_item_mrl; else if( !strcmp( attr, "length" ) ) p = &psz_item_size; else if( !strcmp( attr, "type" ) ) p = &psz_item_type; if( p != NULL ) { free( *p ); *p = strdup( value ); } else msg_Dbg( p_demux,"unhandled attribute %s in <%s>", attr, node ); } else msg_Dbg( p_demux,"unhandled attribute %s in <%s>", attr, node ); } break; } case XML_READER_TEXT: { if(!psz_elname) break; /* item specific meta data */ if( b_item ) { char **p; if( !strcmp( psz_elname, "title" ) ) p = &psz_item_name; else if( !strcmp( psz_elname, "itunes:author" ) || !strcmp( psz_elname, "author" ) ) /* <author> isn't standard iTunes podcast stuff */ p = &psz_item_author; else if( !strcmp( psz_elname, "itunes:summary" ) || !strcmp( psz_elname, "description" ) ) /* <description> isn't standard iTunes podcast stuff */ p = &psz_item_summary; else if( !strcmp( psz_elname, "pubDate" ) ) p = &psz_item_date; else if( !strcmp( psz_elname, "itunes:category" ) ) p = &psz_item_category; else if( !strcmp( psz_elname, "itunes:duration" ) ) p = &psz_item_duration; else if( !strcmp( psz_elname, "itunes:keywords" ) ) p = &psz_item_keywords; else if( !strcmp( psz_elname, "itunes:subtitle" ) ) p = &psz_item_subtitle; else break; free( *p ); *p = strdup( node ); } /* toplevel meta data */ else if( !b_image ) { if( !strcmp( psz_elname, "title" ) ) input_item_SetName( p_current_input, node ); #define ADD_GINFO( info, name ) \ else if( !strcmp( psz_elname, name ) ) \ input_item_AddInfo( p_current_input, _("Podcast Info"), \ info, "%s", node ); ADD_GINFO( _("Podcast Link"), "link" ) ADD_GINFO( _("Podcast Copyright"), "copyright" ) ADD_GINFO( _("Podcast Category"), "itunes:category" ) ADD_GINFO( _("Podcast Keywords"), "itunes:keywords" ) ADD_GINFO( _("Podcast Subtitle"), "itunes:subtitle" ) #undef ADD_GINFO else if( !strcmp( psz_elname, "itunes:summary" ) || !strcmp( psz_elname, "description" ) ) { /* <description> isn't standard iTunes podcast stuff */ input_item_AddInfo( p_current_input, _( "Podcast Info" ), _( "Podcast Summary" ), "%s", node ); } } else { if( !strcmp( psz_elname, "url" ) && *node ) { free( psz_art_url ); psz_art_url = strdup( node ); } else msg_Dbg( p_demux, "unhandled text in element <%s>", psz_elname ); } break; } // End element case XML_READER_ENDELEM: { FREENULL( psz_elname ); if( !strcmp( node, "item" ) ) { if( psz_item_mrl == NULL ) { if (psz_item_name) msg_Warn( p_demux, "invalid XML item, skipping %s", psz_item_name ); else msg_Warn( p_demux, "invalid XML item, skipped" ); FREENULL( psz_item_name ); FREENULL( psz_item_size ); FREENULL( psz_item_type ); FREENULL( psz_item_date ); FREENULL( psz_item_author ); FREENULL( psz_item_category ); FREENULL( psz_item_duration ); FREENULL( psz_item_keywords ); FREENULL( psz_item_subtitle ); FREENULL( psz_item_summary ); FREENULL( psz_art_url ); FREENULL( psz_elname ); continue; } vlc_xml_decode( psz_item_mrl ); vlc_xml_decode( psz_item_name ); p_input = input_item_New( psz_item_mrl, psz_item_name ); FREENULL( psz_item_mrl ); FREENULL( psz_item_name ); if( p_input == NULL ) break; /* FIXME: meta data memory leaks? */ /* Set the duration if available */ if( psz_item_duration ) p_input->i_duration = strTimeToMTime( psz_item_duration ); #define ADD_INFO( info, field ) \ if( field ) { \ input_item_AddInfo( p_input, _( "Podcast Info" ), (info), "%s", \ (field) ); \ FREENULL( field ); } ADD_INFO( _("Podcast Publication Date"), psz_item_date ); ADD_INFO( _("Podcast Author"), psz_item_author ); ADD_INFO( _("Podcast Subcategory"), psz_item_category ); ADD_INFO( _("Podcast Duration"), psz_item_duration ); ADD_INFO( _("Podcast Keywords"), psz_item_keywords ); ADD_INFO( _("Podcast Subtitle"), psz_item_subtitle ); ADD_INFO( _("Podcast Summary"), psz_item_summary ); ADD_INFO( _("Podcast Type"), psz_item_type ); #undef ADD_INFO /* Add the global art url to this item, if any */ if( psz_art_url ) { vlc_xml_decode( psz_art_url ); input_item_SetArtURL( p_input, psz_art_url ); } if( psz_item_size ) { input_item_AddInfo( p_input, _( "Podcast Info" ), _( "Podcast Size" ), _("%s bytes"), psz_item_size ); FREENULL( psz_item_size ); } input_item_node_AppendItem( p_subitems, p_input ); input_item_Release( p_input ); b_item = false; } else if( !strcmp( node, "image" ) ) { b_image = false; } break; } } }
static int ReadDir( stream_t *p_demux, input_item_node_t *p_subitems ) { xml_reader_t *p_xml_reader; input_item_t *p_input; int i_ret = -1; /* List of all possible attributes. The only required one is "src" */ bool b_autoplay = false; bool b_controller = true; qtl_fullscreen_t fullscreen = false; char *psz_href = NULL; bool b_kioskmode = false; qtl_loop_t loop = LOOP_FALSE; int i_movieid = -1; char *psz_moviename = NULL; bool b_playeveryframe = false; char *psz_qtnext = NULL; bool b_quitwhendone = false; char *psz_src = NULL; char *psz_mimetype = NULL; int i_volume = 100; p_xml_reader = xml_ReaderCreate( p_demux, p_demux->p_source ); if( !p_xml_reader ) goto error; for( int i = 0;; ++i ) /* locate root node */ { const char *node; if( i == ROOT_NODE_MAX_DEPTH || xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM ) { msg_Err( p_demux, "unable to locate root-node" ); goto error; } if( strcmp( node, "embed" ) == 0 ) break; /* found it */ msg_Dbg( p_demux, "invalid root node <%s>, trying next (%d / %d)", node, i + 1, ROOT_NODE_MAX_DEPTH ); } const char *attrname, *value; while( (attrname = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL ) { if( !strcmp( attrname, "autoplay" ) ) b_autoplay = !strcmp( value, "true" ); else if( !strcmp( attrname, "controller" ) ) b_controller = !strcmp( attrname, "false" ); else if( !strcmp( attrname, "fullscreen" ) ) { if( !strcmp( value, "double" ) ) fullscreen = FULLSCREEN_DOUBLE; else if( !strcmp( value, "half" ) ) fullscreen = FULLSCREEN_HALF; else if( !strcmp( value, "current" ) ) fullscreen = FULLSCREEN_CURRENT; else if( !strcmp( value, "full" ) ) fullscreen = FULLSCREEN_FULL; else fullscreen = FULLSCREEN_NORMAL; } else if( !strcmp( attrname, "href" ) ) { free( psz_href ); psz_href = strdup( value ); } else if( !strcmp( attrname, "kioskmode" ) ) b_kioskmode = !strcmp( value, "true" ); else if( !strcmp( attrname, "loop" ) ) { if( !strcmp( value, "true" ) ) loop = LOOP_TRUE; else if( !strcmp( value, "palindrome" ) ) loop = LOOP_PALINDROME; else loop = LOOP_FALSE; } else if( !strcmp( attrname, "movieid" ) ) i_movieid = atoi( value ); else if( !strcmp( attrname, "moviename" ) ) { free( psz_moviename ); psz_moviename = strdup( value ); } else if( !strcmp( attrname, "playeveryframe" ) ) b_playeveryframe = !strcmp( value, "true" ); else if( !strcmp( attrname, "qtnext" ) ) { free( psz_qtnext ); psz_qtnext = strdup( value ); } else if( !strcmp( attrname, "quitwhendone" ) ) b_quitwhendone = !strcmp( value, "true" ); else if( !strcmp( attrname, "src" ) ) { free( psz_src ); psz_src = strdup( value ); } else if( !strcmp( attrname, "mimetype" ) ) { free( psz_mimetype ); psz_mimetype = strdup( value ); } else if( !strcmp( attrname, "volume" ) ) i_volume = atoi( value ); else msg_Dbg( p_demux, "Attribute %s with value %s isn't valid", attrname, value ); } msg_Dbg( p_demux, "autoplay: %s (unused by VLC)", b_autoplay ? "true": "false" ); msg_Dbg( p_demux, "controller: %s (unused by VLC)", b_controller ? "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 ? "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 ? "true":"false" ); msg_Dbg( p_demux, "qtnext: %s", psz_qtnext ); msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)", 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 ); if( !psz_src ) { msg_Err( p_demux, "Mandatory attribute 'src' not found" ); } else { p_input = input_item_New( 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"), psz_mimetype ); input_item_node_AppendItem( p_subitems, p_input ); input_item_Release( p_input ); if( psz_qtnext ) { vlc_xml_decode( psz_qtnext ); p_input = input_item_New( psz_qtnext, NULL ); input_item_node_AppendItem( p_subitems, p_input ); input_item_Release( p_input ); } } i_ret = 0; /* Needed for correct operation of go back */ error: if( p_xml_reader ) xml_ReaderDelete( p_xml_reader ); free( psz_href ); free( psz_moviename ); free( psz_qtnext ); free( psz_src ); free( psz_mimetype ); return i_ret; }