Advertisement
Guest User

omem

a guest
Jan 14th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.53 KB | None | 0 0
  1. /*****************************************************************************
  2.  * omem.c: Memory stream output module
  3.  *****************************************************************************
  4.  * Copyright (C) 2003-2004 the VideoLAN team
  5.  * $Id: 6dbed32e35d319f420547a3d9aecfaa02711c066 $
  6.  *
  7.  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23.  
  24. /*****************************************************************************
  25.  * Preamble
  26.  *****************************************************************************/
  27.  
  28. #ifdef HAVE_CONFIG_H
  29. # include "config.h"
  30. #endif
  31.  
  32. #include <vlc_common.h>
  33. #include <vlc_plugin.h>
  34. #include <vlc_block.h>
  35. #include <vlc_sout.h>
  36.  
  37. /*****************************************************************************
  38.  * Exported prototypes
  39.  *****************************************************************************/
  40. static int      Open    ( vlc_object_t * );
  41. static void     Close   ( vlc_object_t * );
  42.  
  43. static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
  44. static int               Del ( sout_stream_t *, sout_stream_id_t * );
  45. static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );
  46.  
  47.  
  48. /*****************************************************************************
  49.  * Exported API
  50.  *****************************************************************************/
  51.  
  52. typedef void (*omem_handle_packet_t) (int index, const uint8_t *data,
  53.                       size_t size, int64_t dts, int64_t pts);
  54.  
  55. typedef void (*omem_add_stream_t)    (int index, const es_format_t *p_stream);
  56. typedef void (*omem_del_stream_t)    (int index);
  57.  
  58. /*****************************************************************************
  59.  * Local prototypes
  60.  *****************************************************************************/
  61. struct sout_stream_sys_t {
  62.   size_t               i_stream_count;
  63.   omem_handle_packet_t fp_handle_packet_cb;
  64.   omem_add_stream_t    fp_add_stream_cb;
  65.   omem_del_stream_t    fp_del_stream_cb;
  66. };
  67.  
  68. struct sout_stream_id_t {
  69.   int i_index;
  70. };
  71.  
  72. /*****************************************************************************
  73.  * Module descriptor
  74.  *****************************************************************************/
  75. vlc_module_begin ()
  76.     set_description( ("Memory stream output") )
  77.     set_capability( "sout stream", 50 )
  78.     add_shortcut( "omem" )
  79.  
  80.     add_string( "omem-handle-packet", "", "", "", true )
  81.     add_string( "omem-add-stream", "", "", "", true )
  82.     add_string( "omem-del-stream", "", "", "", true )
  83.     set_callbacks( Open, Close )
  84. vlc_module_end ()
  85.  
  86. /*****************************************************************************
  87.  * Open:
  88.  *****************************************************************************/
  89. static int Open( vlc_object_t *p_this )
  90. {
  91.     char *tmp;
  92.     sout_stream_t *p_stream = (sout_stream_t*)p_this;
  93.     sout_stream_sys_t *p_sys = calloc(1, sizeof(sout_stream_sys_t));
  94.     if (!p_sys)
  95.         return VLC_ENOMEM;
  96.  
  97.     tmp = var_InheritString(p_this, "omem-handle-packet");
  98.     if (tmp)
  99.       p_sys->fp_handle_packet_cb = (omem_handle_packet_t)
  100.     (intptr_t)strtoll(tmp, NULL, 0);
  101.     free(tmp);
  102.  
  103.     tmp = var_InheritString(p_this, "omem-add-stream");
  104.     if (tmp)
  105.       p_sys->fp_add_stream_cb = (omem_add_stream_t)
  106.     (intptr_t)strtoll(tmp, NULL, 0);
  107.     free(tmp);
  108.  
  109.     tmp = var_InheritString(p_this, "omem-del-stream");
  110.     if (tmp)
  111.       p_sys->fp_del_stream_cb = (omem_del_stream_t)
  112.     (intptr_t)strtoll(tmp, NULL, 0);
  113.     free(tmp);
  114.  
  115.     if( !p_sys->fp_handle_packet_cb || !p_sys->fp_add_stream_cb ||
  116.        !p_sys->fp_del_stream_cb ) {
  117.       msg_Err( p_this, "Invalid packet/stream function pointers" );
  118.       free(p_sys);
  119.       return VLC_EGENERIC;
  120.     }
  121.  
  122.     p_stream->pf_add    = Add;
  123.     p_stream->pf_del    = Del;
  124.     p_stream->pf_send   = Send;
  125.     p_stream->p_sys     = p_sys;
  126.  
  127.     return VLC_SUCCESS;
  128. }
  129.  
  130. /*****************************************************************************
  131.  * Close:
  132.  *****************************************************************************/
  133. static void Close( vlc_object_t * p_this )
  134. {
  135.     sout_stream_t *p_stream = (sout_stream_t*)p_this;
  136.     free( p_stream->p_sys );
  137. }
  138.  
  139. /*****************************************************************************
  140.  * Add:
  141.  *****************************************************************************/
  142. static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
  143. {
  144.     sout_stream_id_t *id;
  145.     sout_stream_sys_t *p_sys = p_stream->p_sys;
  146.    
  147.     if( !p_sys->fp_add_stream_cb )
  148.       return NULL;
  149.  
  150.     id = calloc( 1, sizeof( sout_stream_id_t ) );
  151.     if( !id )
  152.       return NULL;
  153.  
  154.     id->i_index = p_sys->i_stream_count++;
  155.  
  156.     p_sys->fp_add_stream_cb( id->i_index, p_fmt );
  157.  
  158.     return id;
  159. }
  160.  
  161. /*****************************************************************************
  162.  * Del:
  163.  *****************************************************************************/
  164. static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
  165. {
  166.     sout_stream_sys_t *p_sys = p_stream->p_sys;
  167.  
  168.     if( !p_sys->fp_del_stream_cb )
  169.       return VLC_EGENERIC;
  170.  
  171.     p_sys->fp_del_stream_cb( id->i_index );
  172.  
  173.     return VLC_SUCCESS;
  174. }
  175.  
  176. /*****************************************************************************
  177.  * Send:
  178.  *****************************************************************************/
  179. static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
  180.                  block_t *p_buffer )
  181. {
  182.     sout_stream_sys_t *p_sys = p_stream->p_sys;
  183.  
  184.    if( !p_sys->fp_handle_packet_cb )
  185.       return VLC_EGENERIC;
  186.  
  187.     p_sys->fp_handle_packet_cb( id->i_index, p_buffer->p_buffer,
  188.                 p_buffer->i_buffer, p_buffer->i_dts,
  189.                 p_buffer->i_pts );
  190.  
  191.     block_ChainRelease( p_buffer );
  192.  
  193.     return VLC_SUCCESS;
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement