]> git.sesse.net Git - vlc/blob - modules/stream_out/standard.c
* all: new sout scheme. Now a chain of module are created that can
[vlc] / modules / stream_out / standard.c
1 /*****************************************************************************
2  * standard.c
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 VideoLAN
5  * $Id: standard.c,v 1.1 2003/04/13 20:00:21 fenrir Exp $
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/sout.h>
32
33 /*****************************************************************************
34  * Exported prototypes
35  *****************************************************************************/
36 static int      Open    ( vlc_object_t * );
37 static void     Close   ( vlc_object_t * );
38
39 static sout_stream_id_t *Add ( sout_stream_t *, sout_format_t * );
40 static int               Del ( sout_stream_t *, sout_stream_id_t * );
41 static int               Send( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
42
43 /*****************************************************************************
44  * Module descriptor
45  *****************************************************************************/
46 vlc_module_begin();
47     set_description( _("Standard stream") );
48     set_capability( "sout stream", 50 );
49     add_shortcut( "standard" );
50     add_shortcut( "std" );
51     set_callbacks( Open, Close );
52 vlc_module_end();
53
54 struct sout_stream_sys_t
55 {
56     sout_mux_t *p_mux;
57 };
58
59 /*****************************************************************************
60  * Open:
61  *****************************************************************************/
62 static int Open( vlc_object_t *p_this )
63 {
64     sout_stream_t       *p_stream = (sout_stream_t*)p_this;
65     sout_instance_t     *p_sout = p_stream->p_sout;
66     sout_stream_sys_t   *p_sys;
67
68     char                *psz_mux    = sout_cfg_find_value( p_stream->p_cfg, "mux" );
69     char                *psz_access = sout_cfg_find_value( p_stream->p_cfg, "access" );
70     char                *psz_url    = sout_cfg_find_value( p_stream->p_cfg, "url" );
71
72     sout_access_out_t *p_access;
73     sout_mux_t        *p_mux;
74
75     msg_Dbg( p_this, "creating `%s/%s://%s'",
76              psz_access, psz_mux, psz_url );
77
78     /* *** find and open appropriate access module *** */
79     p_access = sout_AccessOutNew( p_sout, psz_access, psz_url );
80     if( p_access == NULL )
81     {
82         msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
83                  psz_access, psz_mux, psz_url );
84         return( VLC_EGENERIC );
85     }
86     msg_Dbg( p_stream, "access opened" );
87
88     /* *** find and open appropriate mux module *** */
89     p_mux = sout_MuxNew( p_sout, psz_mux, p_access );
90     if( p_mux == NULL )
91     {
92         msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
93                  psz_access, psz_mux, psz_url );
94
95         sout_AccessOutDelete( p_access );
96         return( VLC_EGENERIC );
97     }
98     msg_Dbg( p_stream, "mux opened" );
99
100     /* XXX beurk */
101     p_sout->i_preheader = __MAX( p_sout->i_preheader, p_mux->i_preheader );
102
103     p_sys        = malloc( sizeof( sout_stream_sys_t ) );
104     p_sys->p_mux = p_mux;
105
106     p_stream->pf_add    = Add;
107     p_stream->pf_del    = Del;
108     p_stream->pf_send   = Send;
109
110     p_stream->p_sys     = p_sys;
111
112     return VLC_SUCCESS;
113 }
114
115 /*****************************************************************************
116  * Close:
117  *****************************************************************************/
118
119 static void Close( vlc_object_t * p_this )
120 {
121     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
122     sout_stream_sys_t *p_sys = p_stream->p_sys;
123
124     sout_access_out_t *p_access = p_sys->p_mux->p_access;
125
126
127     sout_MuxDelete( p_sys->p_mux );
128     sout_AccessOutDelete( p_access );
129
130     free( p_sys );
131 }
132
133 struct sout_stream_id_t
134 {
135     sout_input_t *p_input;
136 };
137
138
139 static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_fmt )
140 {
141     sout_stream_sys_t *p_sys = p_stream->p_sys;
142     sout_stream_id_t  *id;
143
144     id = malloc( sizeof( sout_stream_id_t ) );
145     if( ( id->p_input = sout_MuxAddStream( p_sys->p_mux, p_fmt ) ) == NULL )
146     {
147         free( id );
148
149         return NULL;
150     }
151
152     return id;
153 }
154
155 static int     Del      ( sout_stream_t *p_stream, sout_stream_id_t *id )
156 {
157     sout_stream_sys_t *p_sys = p_stream->p_sys;
158
159     sout_MuxDeleteStream( p_sys->p_mux, id->p_input );
160
161     free( id );
162
163     return VLC_SUCCESS;
164 }
165
166 static int     Send     ( sout_stream_t *p_stream, sout_stream_id_t *id, sout_buffer_t *p_buffer )
167 {
168     sout_stream_sys_t *p_sys = p_stream->p_sys;
169
170     sout_MuxSendBuffer( p_sys->p_mux, id->p_input, p_buffer );
171
172     return VLC_SUCCESS;
173 }
174