static int vlclua_memory_stream_new( lua_State *L ) { vlc_object_t * p_this = vlclua_get_this( L ); /* FIXME: duplicating the whole buffer is suboptimal. Keeping a reference to the string so that it doesn't get garbage collected would be better */ char * psz_content = strdup( luaL_checkstring( L, 1 ) ); stream_t *p_stream = stream_MemoryNew( p_this, (uint8_t *)psz_content, strlen( psz_content ), false ); return vlclua_stream_new_inner( L, p_stream ); }
int Import_WPL( vlc_object_t* p_this ) { demux_t* p_demux = (demux_t*)p_this; CHECK_FILE(); if( !demux_IsPathExtension( p_demux, ".wpl" ) && !demux_IsPathExtension( p_demux, ".zpl" ) ) return VLC_EGENERIC; DEMUX_INIT_COMMON(); demux_sys_t* p_sys = p_demux->p_sys; uint8_t *p_peek; ssize_t i_peek = stream_Peek( p_demux->s, (const uint8_t **) &p_peek, 2048 ); if( unlikely( i_peek <= 0 ) ) { Close_WPL( p_this ); return VLC_EGENERIC; } stream_t *p_probestream = stream_MemoryNew( p_demux->s, p_peek, i_peek, true ); if( unlikely( !p_probestream ) ) { Close_WPL( p_this ); return VLC_EGENERIC; } p_sys->p_reader = xml_ReaderCreate( p_this, p_probestream ); if ( !p_sys->p_reader ) { msg_Err( p_demux, "Failed to create an XML reader" ); Close_WPL( p_this ); stream_Delete( p_probestream ); return VLC_EGENERIC; } const int i_flags = p_sys->p_reader->i_flags; p_sys->p_reader->i_flags |= OBJECT_FLAGS_QUIET; const char* psz_name; int type = xml_ReaderNextNode( p_sys->p_reader, &psz_name ); p_sys->p_reader->i_flags = i_flags; if ( type != XML_READER_STARTELEM || strcasecmp( psz_name, "smil" ) ) { msg_Err( p_demux, "Invalid WPL playlist. Root element should have been <smil>" ); Close_WPL( p_this ); stream_Delete( p_probestream ); return VLC_EGENERIC; } p_sys->p_reader = xml_ReaderReset( p_sys->p_reader, p_demux->s ); stream_Delete( p_probestream ); msg_Dbg( p_demux, "Found valid WPL playlist" ); return VLC_SUCCESS; }
int RarStreamOpen(vlc_object_t *object) { stream_t *s = (stream_t*)object; if (RarProbe(s->p_source)) return VLC_EGENERIC; int count; rar_file_t **files; const int64_t position = stream_Tell(s->p_source); if ((RarParse(s->p_source, &count, &files, false) && RarParse(s->p_source, &count, &files, true )) || count == 0 ) { stream_Seek(s->p_source, position); msg_Info(s, "Invalid or unsupported RAR archive"); free(files); return VLC_EGENERIC; } /* TODO use xspf to have node for directories * Reusing WriteXSPF from the zip access is probably a good idea * (becareful about '\' and '/'. */ char *mrl; if (asprintf(&mrl, "%s://%s", s->psz_access, s->psz_path)< 0) mrl = NULL; char *base; char *encoded = mrl ? encode_URI_component(mrl) : NULL; free(mrl); if (!encoded || asprintf(&base, "rar://%s", encoded) < 0) base = NULL; free(encoded); char *data = strdup("#EXTM3U\n"); for (int i = 0; i < count; i++) { rar_file_t *f = files[i]; char *next; if (base && data && asprintf(&next, "%s" "#EXTINF:,,%s\n" "%s|%s\n", data, f->name, base, f->name) >= 0) { free(data); data = next; } RarFileDelete(f); } free(base); free(files); if (!data) return VLC_EGENERIC; stream_t *payload = stream_MemoryNew(s, (uint8_t*)data, strlen(data), false); if (!payload) { free(data); return VLC_EGENERIC; } s->pf_read = Read; s->pf_peek = Peek; s->pf_control = Control; stream_sys_t *sys = s->p_sys = malloc(sizeof(*sys)); if (!sys) { stream_Delete(payload); return VLC_ENOMEM; } sys->payload = payload; char *tmp; if (asprintf(&tmp, "%s.m3u", s->psz_path) < 0) { RarStreamClose(object); return VLC_ENOMEM; } free(s->psz_path); s->psz_path = tmp; return VLC_SUCCESS; }