Exemplo n.º 1
0
/**
 * 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;
}
Exemplo n.º 2
0
stream_t *stream_FilterNew( stream_t *p_source,
                            const char *psz_stream_filter )
{
    stream_t *s;
    assert( p_source != NULL );

    s = stream_CommonNew( p_source->p_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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *out )
{
    vlc_object_t *p_obj = VLC_OBJECT(p_demux);
    /* We create a stream reader, and launch a thread */
    stream_t     *s;
    stream_sys_t *p_sys;

    s = stream_CommonNew( p_obj );
    if( s == NULL )
        return NULL;
    s->p_input = p_demux->p_input;
    s->pf_read   = DStreamRead;
    s->pf_control= DStreamControl;
    s->pf_destroy= DStreamDelete;

    s->p_sys = p_sys = malloc( sizeof( *p_sys) );
    if( !s->p_sys )
    {
        stream_Delete( s );
        return NULL;
    }

    p_sys->i_pos = 0;
    p_sys->out = out;
    p_sys->p_block = NULL;
    p_sys->psz_name = strdup( psz_demux );
    p_sys->stats.position = 0.;
    p_sys->stats.length = 0;
    p_sys->stats.time = 0;

    /* decoder fifo */
    if( ( p_sys->p_fifo = block_FifoNew() ) == NULL )
    {
        stream_Delete( s );
        free( p_sys->psz_name );
        free( p_sys );
        return NULL;
    }

    atomic_init( &p_sys->active, true );
    vlc_mutex_init( &p_sys->lock );

    if( vlc_clone( &p_sys->thread, DStreamThread, s, VLC_THREAD_PRIORITY_INPUT ) )
    {
        vlc_mutex_destroy( &p_sys->lock );
        block_FifoRelease( p_sys->p_fifo );
        stream_Delete( s );
        free( p_sys->psz_name );
        free( p_sys );
        return NULL;
    }

    return s;
}
Exemplo n.º 5
0
/**
 * Allocates a custom VLC stream object
 */
stream_t *stream_CustomNew(vlc_object_t *parent, void (*destroy)(stream_t *))
{
    return stream_CommonNew(parent, destroy);
}