Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************
- * omem.c: Memory stream output module
- *****************************************************************************
- * Copyright (C) 2003-2004 the VideoLAN team
- * $Id: 6dbed32e35d319f420547a3d9aecfaa02711c066 $
- *
- * Authors: Laurent Aimar <fenrir@via.ecp.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
- /*****************************************************************************
- * Preamble
- *****************************************************************************/
- #ifdef HAVE_CONFIG_H
- # include "config.h"
- #endif
- #include <vlc_common.h>
- #include <vlc_plugin.h>
- #include <vlc_block.h>
- #include <vlc_sout.h>
- /*****************************************************************************
- * Exported prototypes
- *****************************************************************************/
- static int Open ( vlc_object_t * );
- static void Close ( vlc_object_t * );
- static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
- static int Del ( sout_stream_t *, sout_stream_id_t * );
- static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
- /*****************************************************************************
- * Exported API
- *****************************************************************************/
- typedef void (*omem_handle_packet_t) (int index, const uint8_t *data,
- size_t size, int64_t dts, int64_t pts);
- typedef void (*omem_add_stream_t) (int index, const es_format_t *p_stream);
- typedef void (*omem_del_stream_t) (int index);
- /*****************************************************************************
- * Local prototypes
- *****************************************************************************/
- struct sout_stream_sys_t {
- size_t i_stream_count;
- omem_handle_packet_t fp_handle_packet_cb;
- omem_add_stream_t fp_add_stream_cb;
- omem_del_stream_t fp_del_stream_cb;
- };
- struct sout_stream_id_t {
- int i_index;
- };
- /*****************************************************************************
- * Module descriptor
- *****************************************************************************/
- vlc_module_begin ()
- set_description( ("Memory stream output") )
- set_capability( "sout stream", 50 )
- add_shortcut( "omem" )
- add_string( "omem-handle-packet", "", "", "", true )
- add_string( "omem-add-stream", "", "", "", true )
- add_string( "omem-del-stream", "", "", "", true )
- set_callbacks( Open, Close )
- vlc_module_end ()
- /*****************************************************************************
- * Open:
- *****************************************************************************/
- static int Open( vlc_object_t *p_this )
- {
- char *tmp;
- sout_stream_t *p_stream = (sout_stream_t*)p_this;
- sout_stream_sys_t *p_sys = calloc(1, sizeof(sout_stream_sys_t));
- if (!p_sys)
- return VLC_ENOMEM;
- tmp = var_InheritString(p_this, "omem-handle-packet");
- if (tmp)
- p_sys->fp_handle_packet_cb = (omem_handle_packet_t)
- (intptr_t)strtoll(tmp, NULL, 0);
- free(tmp);
- tmp = var_InheritString(p_this, "omem-add-stream");
- if (tmp)
- p_sys->fp_add_stream_cb = (omem_add_stream_t)
- (intptr_t)strtoll(tmp, NULL, 0);
- free(tmp);
- tmp = var_InheritString(p_this, "omem-del-stream");
- if (tmp)
- p_sys->fp_del_stream_cb = (omem_del_stream_t)
- (intptr_t)strtoll(tmp, NULL, 0);
- free(tmp);
- if( !p_sys->fp_handle_packet_cb || !p_sys->fp_add_stream_cb ||
- !p_sys->fp_del_stream_cb ) {
- msg_Err( p_this, "Invalid packet/stream function pointers" );
- free(p_sys);
- return VLC_EGENERIC;
- }
- p_stream->pf_add = Add;
- p_stream->pf_del = Del;
- p_stream->pf_send = Send;
- p_stream->p_sys = p_sys;
- return VLC_SUCCESS;
- }
- /*****************************************************************************
- * Close:
- *****************************************************************************/
- static void Close( vlc_object_t * p_this )
- {
- sout_stream_t *p_stream = (sout_stream_t*)p_this;
- free( p_stream->p_sys );
- }
- /*****************************************************************************
- * Add:
- *****************************************************************************/
- static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
- {
- sout_stream_id_t *id;
- sout_stream_sys_t *p_sys = p_stream->p_sys;
- if( !p_sys->fp_add_stream_cb )
- return NULL;
- id = calloc( 1, sizeof( sout_stream_id_t ) );
- if( !id )
- return NULL;
- id->i_index = p_sys->i_stream_count++;
- p_sys->fp_add_stream_cb( id->i_index, p_fmt );
- return id;
- }
- /*****************************************************************************
- * Del:
- *****************************************************************************/
- static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
- {
- sout_stream_sys_t *p_sys = p_stream->p_sys;
- if( !p_sys->fp_del_stream_cb )
- return VLC_EGENERIC;
- p_sys->fp_del_stream_cb( id->i_index );
- return VLC_SUCCESS;
- }
- /*****************************************************************************
- * Send:
- *****************************************************************************/
- static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *p_buffer )
- {
- sout_stream_sys_t *p_sys = p_stream->p_sys;
- if( !p_sys->fp_handle_packet_cb )
- return VLC_EGENERIC;
- p_sys->fp_handle_packet_cb( id->i_index, p_buffer->p_buffer,
- p_buffer->i_buffer, p_buffer->i_dts,
- p_buffer->i_pts );
- block_ChainRelease( p_buffer );
- return VLC_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement