Advertisement
Guest User

Untitled

a guest
Apr 1st, 2013
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.38 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: John Törnblom <john.tornblom@gmail.com>
  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_block_t) (void *arg, int id, const block_t *block);
  53. typedef void (*omem_add_stream_t)   (void *arg, int id,
  54.                      const es_format_t *p_stream);
  55. typedef void (*omem_del_stream_t)   (void *arg, int id);
  56.  
  57. /*****************************************************************************
  58.  * Local prototypes
  59.  *****************************************************************************/
  60. struct sout_stream_sys_t {
  61.   size_t              i_stream_count;
  62.   void               *p_argument;
  63.   omem_handle_block_t fp_handle_block_cb;
  64.   omem_add_stream_t   fp_add_stream_cb;
  65.   omem_del_stream_t   fp_del_stream_cb;
  66.  
  67. };
  68.  
  69. struct sout_stream_id_t {
  70.   int      i_id;
  71.   uint32_t i_codec;
  72.   int      i_cat;
  73.  
  74.   union {
  75.     struct {
  76.       /* Audio specific */
  77.       unsigned    i_channels;
  78.       unsigned    i_rate;
  79.     } audio;
  80.     struct {
  81.       /* Video specific */
  82.       unsigned    i_height;
  83.       unsigned    i_width;
  84.     } video;
  85.   } u;
  86. };
  87.  
  88. /*****************************************************************************
  89.  * Module descriptor
  90.  *****************************************************************************/
  91. vlc_module_begin ()
  92.     set_description( ("Memory stream output") )
  93.     set_capability( "sout stream", 50 )
  94.     add_shortcut( "omem" )
  95.  
  96.     add_string( "omem-handle-block", "", "", "", true )
  97.     add_string( "omem-argument", "", "", "", true )
  98.     add_string( "omem-add-stream", "", "", "", true )
  99.     add_string( "omem-del-stream", "", "", "", true )
  100.     set_callbacks( Open, Close )
  101. vlc_module_end ()
  102.  
  103. /*****************************************************************************
  104.  * Open:
  105.  *****************************************************************************/
  106. static int Open( vlc_object_t *p_this )
  107. {
  108.     char *tmp;
  109.     sout_stream_t *p_stream = (sout_stream_t*)p_this;
  110.     sout_stream_sys_t *p_sys = calloc(1, sizeof(sout_stream_sys_t));
  111.     if (!p_sys)
  112.         return VLC_ENOMEM;
  113.  
  114.     tmp = var_InheritString(p_this, "omem-handle-block");
  115.     if (tmp)
  116.       p_sys->fp_handle_block_cb = (omem_handle_block_t)
  117.     (intptr_t)strtoll(tmp, NULL, 0);
  118.     free(tmp);
  119.  
  120.     tmp = var_InheritString(p_this, "omem-add-stream");
  121.     if (tmp)
  122.       p_sys->fp_add_stream_cb = (omem_add_stream_t)
  123.     (intptr_t)strtoll(tmp, NULL, 0);
  124.     free(tmp);
  125.  
  126.     tmp = var_InheritString(p_this, "omem-del-stream");
  127.     if (tmp)
  128.       p_sys->fp_del_stream_cb = (omem_del_stream_t)
  129.     (intptr_t)strtoll(tmp, NULL, 0);
  130.     free(tmp);
  131.  
  132.     tmp = var_InheritString(p_this, "omem-argument");
  133.     if (tmp)
  134.       p_sys->p_argument = (void *)(uintptr_t)strtoull(tmp, NULL, 0);
  135.     free(tmp);
  136.  
  137.     if( !p_sys->fp_handle_block_cb || !p_sys->fp_add_stream_cb ||
  138.        !p_sys->fp_del_stream_cb ) {
  139.       msg_Err( p_this, "Invalid block/stream function pointers" );
  140.       free(p_sys);
  141.       return VLC_EGENERIC;
  142.     }
  143.  
  144.     p_stream->pf_add    = Add;
  145.     p_stream->pf_del    = Del;
  146.     p_stream->pf_send   = Send;
  147.     p_stream->p_sys     = p_sys;
  148.  
  149.     return VLC_SUCCESS;
  150. }
  151.  
  152. /*****************************************************************************
  153.  * Close:
  154.  *****************************************************************************/
  155. static void Close( vlc_object_t * p_this )
  156. {
  157.     sout_stream_t *p_stream = (sout_stream_t*)p_this;
  158.     free( p_stream->p_sys );
  159. }
  160.  
  161. /*****************************************************************************
  162.  * Add:
  163.  *****************************************************************************/
  164. static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
  165. {
  166.     sout_stream_id_t *id;
  167.     sout_stream_sys_t *p_sys = p_stream->p_sys;
  168.    
  169.     if( !p_sys->fp_add_stream_cb )
  170.       return NULL;
  171.  
  172.     id = calloc( 1, sizeof( sout_stream_id_t ) );
  173.     if( !id )
  174.       return NULL;
  175.  
  176.     id->i_id    = p_sys->i_stream_count++;
  177.     id->i_codec = p_fmt->i_codec;
  178.     id->i_cat   = p_fmt->i_cat;
  179.  
  180.     switch(id->i_cat)
  181.       {
  182.       case VIDEO_ES:
  183.     id->u.video.i_height = p_fmt->video.i_height;
  184.     id->u.video.i_width = p_fmt->video.i_width;
  185.     break;
  186.       case AUDIO_ES:
  187.     id->u.audio.i_channels = p_fmt->audio.i_channels;
  188.     id->u.audio.i_rate = p_fmt->audio.i_rate;
  189.     break;
  190.       default:
  191.     break;
  192.       }
  193.  
  194.     p_sys->fp_add_stream_cb( p_sys->p_argument, id->i_id, p_fmt );
  195.  
  196.     return id;
  197. }
  198.  
  199. /*****************************************************************************
  200.  * Del:
  201.  *****************************************************************************/
  202. static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
  203. {
  204.     sout_stream_sys_t *p_sys = p_stream->p_sys;
  205.  
  206.     if( !p_sys->fp_del_stream_cb )
  207.       return VLC_EGENERIC;
  208.  
  209.     p_sys->fp_del_stream_cb( p_sys->p_argument, id->i_id );
  210.  
  211.     return VLC_SUCCESS;
  212. }
  213.  
  214. /*****************************************************************************
  215.  * Send:
  216.  *****************************************************************************/
  217. static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
  218.                  block_t *p_buffer )
  219. {
  220.     sout_stream_sys_t *p_sys = p_stream->p_sys;
  221.  
  222.     if( !p_sys->fp_handle_block_cb )
  223.       return VLC_EGENERIC;
  224.  
  225.     p_sys->fp_handle_block_cb( p_sys->p_argument, id->i_id, p_buffer );
  226.  
  227.     block_ChainRelease( p_buffer );
  228.  
  229.     return VLC_SUCCESS;
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement