1 /*****************************************************************************
2 * stream_output.c : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: stream_output.c,v 1.4 2002/11/10 18:04:24 sam 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 <stdlib.h> /* free() */
28 #include <stdio.h> /* sprintf() */
29 #include <string.h> /* strerror() */
35 /*****************************************************************************
37 *****************************************************************************/
38 static int InitInstance ( sout_instance_t * );
40 /*****************************************************************************
41 * sout_NewInstance: creates a new stream output instance
42 *****************************************************************************/
43 sout_instance_t * __sout_NewInstance ( vlc_object_t *p_parent,
46 sout_instance_t * p_sout;
48 /* Allocate descriptor */
49 p_sout = vlc_object_create( p_parent, VLC_OBJECT_SOUT );
52 msg_Err( p_parent, "out of memory" );
56 p_sout->psz_dest = psz_dest;
57 if ( InitInstance( p_sout ) == -1 )
59 vlc_object_destroy( p_sout );
66 /*****************************************************************************
67 * InitInstance: opens appropriate modules
68 *****************************************************************************/
69 static int InitInstance( sout_instance_t * p_sout )
71 /* Parse dest string. Syntax : [[<access>][/<mux>]:][<dest>] */
72 /* This code is identical to input.c:InitThread. FIXME : factorize it ? */
73 char * psz_parser = p_sout->psz_dest;
75 /* Skip the plug-in names */
76 while( *psz_parser && *psz_parser != ':' )
81 if( psz_parser - p_sout->psz_dest == 1 )
83 msg_Warn( p_sout, "drive letter %c: found in source string",
91 p_sout->psz_access = p_sout->psz_mux = "";
92 p_sout->psz_name = p_sout->psz_dest;
99 if( psz_parser[0] == '/' && psz_parser[1] == '/' )
104 p_sout->psz_name = psz_parser ;
106 /* Come back to parse the access and mux plug-ins */
107 psz_parser = p_sout->psz_dest;
112 p_sout->psz_access = "";
114 else if( *psz_parser == '/' )
117 p_sout->psz_access = "";
122 p_sout->psz_access = psz_parser;
124 while( *psz_parser && *psz_parser != '/' )
129 if( *psz_parser == '/' )
131 *psz_parser++ = '\0';
138 p_sout->psz_mux = "";
142 p_sout->psz_mux = psz_parser;
146 msg_Dbg( p_sout, "access `%s', mux `%s', name `%s'",
147 p_sout->psz_access, p_sout->psz_mux, p_sout->psz_name );
150 /* Find and open appropriate access module */
152 module_Need( p_sout, "sout access", p_sout->psz_access );
154 if( p_sout->p_access == NULL )
156 msg_Err( p_sout, "no suitable sout access module for `%s/%s://%s'",
157 p_sout->psz_access, p_sout->psz_mux, p_sout->psz_name );
161 /* Find and open appropriate mux module */
163 module_Need( p_sout, "sout mux", p_sout->psz_mux );
165 if( p_sout->p_mux == NULL )
167 msg_Err( p_sout, "no suitable mux module for `%s/%s://%s'",
168 p_sout->psz_access, p_sout->psz_mux, p_sout->psz_name );
169 module_Unneed( p_sout, p_sout->p_access );
177 /*****************************************************************************
178 * sout_DeleteInstance: delete a previously allocated instance
179 *****************************************************************************/
180 void sout_DeleteInstance( sout_instance_t * p_sout )
183 vlc_object_detach( p_sout );
186 vlc_object_destroy( p_sout );