1 /*****************************************************************************
2 * stream_output.c : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: stream_output.c,v 1.1 2002/08/12 22:12:51 massiot Exp $
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
28 #include <stdlib.h> /* free() */
29 #include <stdio.h> /* sprintf() */
30 #include <string.h> /* strerror() */
36 /*****************************************************************************
38 *****************************************************************************/
39 static int InitInstance ( sout_instance_t * );
41 /*****************************************************************************
42 * sout_NewInstance: creates a new stream output instance
43 *****************************************************************************/
44 sout_instance_t * __sout_NewInstance ( vlc_object_t *p_parent,
47 sout_instance_t * p_sout;
49 /* Allocate descriptor */
50 p_sout = vlc_object_create( p_parent, VLC_OBJECT_SOUT );
53 msg_Err( p_parent, "out of memory" );
57 p_sout->psz_dest = psz_dest;
58 if ( InitInstance( p_sout ) == -1 )
60 vlc_object_destroy( p_sout );
67 /*****************************************************************************
68 * InitInstance: opens appropriate modules
69 *****************************************************************************/
70 static int InitInstance( sout_instance_t * p_sout )
72 /* Parse dest string. Syntax : [[<access>][/<mux>]:][<dest>] */
73 /* This code is identical to input.c:InitThread. FIXME : factorize it ? */
74 char * psz_parser = p_sout->psz_dest;
76 /* Skip the plug-in names */
77 while( *psz_parser && *psz_parser != ':' )
82 if( psz_parser - psz_dest == 1 )
84 msg_Warn( p_sout, "drive letter %c: found in source string",
92 p_sout->psz_access = p_sout->psz_mux = "";
93 p_sout->psz_name = p_sout->psz_dest;
100 if( psz_parser[0] == '/' && psz_parser[1] == '/' )
105 p_sout->psz_name = psz_parser ;
107 /* Come back to parse the access and mux plug-ins */
108 psz_parser = p_sout->psz_dest;
113 p_sout->psz_access = "";
115 else if( *psz_parser == '/' )
118 p_sout->psz_access = "";
123 p_sout->psz_access = psz_parser;
125 while( *psz_parser && *psz_parser != '/' )
130 if( *psz_parser == '/' )
132 *psz_parser++ = '\0';
139 p_sout->psz_mux = "";
143 p_sout->psz_mux = psz_parser;
147 msg_Dbg( p_sout, "access `%s', mux `%s', name `%s'",
148 p_sout->psz_access, p_sout->psz_mux, p_sout->psz_name );
151 /* Find and open appropriate access module */
153 module_Need( p_sout, "sout access", p_sout->psz_access );
155 if( p_sout->p_access == NULL )
157 msg_Err( p_sout, "no suitable sout access module for `%s/%s://%s'",
158 p_sout->psz_access, p_sout->psz_mux, p_sout->psz_name );
162 /* Find and open appropriate mux module */
164 module_Need( p_sout, "sout mux", p_sout->psz_mux );
166 if( p_sout->p_mux == NULL )
168 msg_Err( p_sout, "no suitable mux module for `%s/%s://%s'",
169 p_sout->psz_access, p_sout->psz_mux, p_sout->psz_name );
170 module_Unneed( p_sout, p_sout->p_access );
176 /*****************************************************************************
177 * sout_DeleteInstance: delete a previously allocated instance
178 *****************************************************************************/
179 void sout_DeleteInstance( sout_instance_t * p_sout )
182 vlc_object_detach( p_sout );
185 vlc_object_destroy( p_sout );