stream_t *vlc_stream_FilterNew( stream_t *p_source, const char *psz_stream_filter ) { stream_t *s; assert( p_source != NULL ); s = vlc_stream_CommonNew( p_source->obj.parent, StreamDelete ); if( s == NULL ) return NULL; s->p_input = p_source->p_input; if( p_source->psz_url != NULL ) { s->psz_url = strdup( p_source->psz_url ); if( unlikely(s->psz_url == NULL) ) goto error; } s->p_source = p_source; /* */ s->p_module = module_need( s, "stream_filter", psz_stream_filter, true ); if( s->p_module == NULL ) goto error; return s; error: stream_CommonDelete( s ); return NULL; }
/** * Destroy a stream */ void vlc_stream_Delete(stream_t *s) { stream_priv_t *priv = (stream_priv_t *)s; priv->destroy(s); stream_CommonDelete(s); }
stream_t *(vlc_stream_MemoryNew)(vlc_object_t *p_this, uint8_t *p_buffer, size_t i_size, bool preserve) { stream_t *s = vlc_stream_CommonNew( p_this, preserve ? stream_MemoryPreserveDelete : stream_MemoryDelete ); stream_sys_t *p_sys; if( !s ) return NULL; s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) ); if( !s->p_sys ) { stream_CommonDelete( s ); return NULL; } p_sys->i_pos = 0; p_sys->i_size = i_size; p_sys->p_buffer = p_buffer; s->pf_read = Read; s->pf_seek = Seek; s->pf_control = Control; return s; }
/** * Create a stream from a memory buffer * * \param p_this the calling vlc_object * \param p_buffer the memory buffer for the stream * \param i_buffer the size of the buffer * \param i_preserve_memory if this is set to false the memory buffer * pointed to by p_buffer is freed on stream_Destroy */ stream_t *stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, uint64_t i_size, bool i_preserve_memory ) { stream_t *s = stream_CommonNew( p_this ); stream_sys_t *p_sys; if( !s ) return NULL; s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) ); if( !s->p_sys ) { stream_CommonDelete( s ); free( p_sys ); return NULL; } p_sys->i_pos = 0; p_sys->i_size = i_size; p_sys->p_buffer = p_buffer; p_sys->i_preserve_memory = i_preserve_memory; s->pf_read = Read; s->pf_control = Control; s->pf_destroy = Delete; s->p_input = NULL; return s; }
stream_t *vlc_stream_AttachmentNew(vlc_object_t *p_this, input_attachment_t *attachment) { struct vlc_stream_attachment_private *p_sys; stream_t *s = vlc_stream_CustomNew(p_this, stream_AttachmentDelete, sizeof (*p_sys), "stream"); if (unlikely(s == NULL)) return NULL; s->psz_name = strdup("attachment"); if (unlikely(s->psz_name == NULL)) { stream_CommonDelete(s); return NULL; } p_sys = vlc_stream_Private(s); p_sys->memory.i_pos = 0; p_sys->memory.i_size = attachment->i_data; p_sys->memory.p_buffer = attachment->p_data; p_sys->attachment = attachment; s->pf_read = Read; s->pf_seek = Seek; s->pf_control = Control; return s; }
stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input, const char *url) { stream_t *s = stream_CommonNew(parent, AStreamDestroy); if (unlikely(s == NULL)) return NULL; stream_sys_t *sys = malloc(sizeof (*sys)); if (unlikely(sys == NULL)) goto error; sys->access = access_New(VLC_OBJECT(s), input, url); if (sys->access == NULL) goto error; sys->block = NULL; s->p_input = input; s->psz_url = strdup(sys->access->psz_url); const char *cachename; if (sys->access->pf_block != NULL) { s->pf_read = AStreamReadBlock; cachename = "cache_block"; } else if (sys->access->pf_read != NULL) { s->pf_read = AStreamReadStream; cachename = "prefetch,cache_read"; } else { s->pf_read = AStreamNoRead; cachename = NULL; } if (sys->access->pf_readdir != NULL) s->pf_readdir = AStreamReadDir; else s->pf_readdir = AStreamNoReadDir; s->pf_seek = AStreamSeek; s->pf_control = AStreamControl; s->p_sys = sys; if (cachename != NULL) s = stream_FilterChainNew(s, cachename); return s; error: free(sys); stream_CommonDelete(s); return NULL; }
/** * Create the public stream_t that wraps a stream-extractor * * This initializes the relevant data-members of the public stream_t which is * used to read from the underlying stream-extractor. * * \param priv the private section of the stream_extractor_t * \param source the source stream which the stream_extractor_t should * will read from * \return VLC_SUCCESS on success, an error-code on failure. **/ static int se_AttachWrapper( struct stream_extractor_private* priv, stream_t* source ) { stream_t* s = vlc_stream_CommonNew( source->obj.parent, se_StreamDelete ); if( unlikely( !s ) ) return VLC_ENOMEM; if( priv->pf_init( priv, s ) ) { stream_CommonDelete( s ); return VLC_EGENERIC; } priv->wrapper = s; priv->wrapper->p_input = source->p_input; priv->wrapper->p_sys = priv; priv->source = source; return VLC_SUCCESS; }
stream_t *vlc_stream_FilterNew( stream_t *p_source, const char *psz_stream_filter ) { assert(p_source != NULL); struct vlc_stream_filter_private *priv; stream_t *s = vlc_stream_CustomNew(p_source->obj.parent, StreamDelete, sizeof (*priv), "stream filter"); if( s == NULL ) return NULL; priv = vlc_stream_Private(s); s->p_input_item = p_source->p_input_item; if( p_source->psz_url != NULL ) { s->psz_url = strdup( p_source->psz_url ); if( unlikely(s->psz_url == NULL) ) goto error; if( p_source->psz_filepath != NULL ) s->psz_filepath = strdup( p_source->psz_filepath ); } s->s = p_source; /* */ priv->module = module_need(s, "stream_filter", psz_stream_filter, true); if (priv->module == NULL) goto error; return s; error: free(s->psz_filepath); stream_CommonDelete( s ); return NULL; }
static void Delete( stream_t *s ) { if( !s->p_sys->i_preserve_memory ) free( s->p_sys->p_buffer ); free( s->p_sys ); stream_CommonDelete( s ); }
/***************************************************************************** * access_New: *****************************************************************************/ static stream_t *access_New(vlc_object_t *parent, input_thread_t *input, bool preparsing, const char *mrl) { char *redirv[MAX_REDIR]; unsigned redirc = 0; stream_t *access = vlc_stream_CommonNew(parent, vlc_access_Destroy); if (unlikely(access == NULL)) return NULL; access->p_input = input; access->psz_name = NULL; access->psz_url = strdup(mrl); access->psz_filepath = NULL; access->b_preparsing = preparsing; if (unlikely(access->psz_url == NULL)) goto error; while (redirc < MAX_REDIR) { char *url = access->psz_url; msg_Dbg(access, "creating access: %s", url); const char *p = strstr(url, "://"); if (p == NULL) goto error; access->psz_name = strndup(url, p - url); if (unlikely(access->psz_name == NULL)) goto error; access->psz_location = p + 3; access->psz_filepath = get_path(access->psz_location); if (access->psz_filepath != NULL) msg_Dbg(access, " (path: %s)", access->psz_filepath); access->p_module = module_need(access, "access", access->psz_name, true); if (access->p_module != NULL) /* success */ { while (redirc > 0) free(redirv[--redirc]); assert(access->pf_control != NULL); return access; } if (access->psz_url == url) /* failure (no redirection) */ goto error; /* redirection */ msg_Dbg(access, "redirecting to: %s", access->psz_url); redirv[redirc++] = url; for (unsigned j = 0; j < redirc; j++) if (!strcmp(redirv[j], access->psz_url)) { msg_Err(access, "redirection loop"); goto error; } free(access->psz_filepath); free(access->psz_name); access->psz_filepath = access->psz_name = NULL; } msg_Err(access, "too many redirections"); error: while (redirc > 0) free(redirv[--redirc]); free(access->psz_filepath); free(access->psz_name); stream_CommonDelete(access); return NULL; }