]> git.sesse.net Git - vlc/blob - modules/demux/demux2.c
* configure.ac, modules/demux/Modules.am: added ps2, ts2 and dvdnav modules to the...
[vlc] / modules / demux / demux2.c
1 /*****************************************************************************
2  * demux2 adaptation layer.
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id: demux2.c,v 1.5 2004/01/18 11:14:23 gbazin 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>                                      /* malloc(), free() */
28
29 #include <vlc/vlc.h>
30 #include <vlc/input.h>
31
32 /*****************************************************************************
33  * Module descriptor
34  *****************************************************************************/
35 static int  Demux2Open    ( vlc_object_t * );
36 static void Demux2Close  ( vlc_object_t * );
37
38 vlc_module_begin();
39     set_description( _("demux2 adaptation layer" ) );
40     set_capability( "demux", 2 );
41     set_callbacks( Demux2Open, Demux2Close );
42     add_shortcut( "demux2" );
43
44     /* Hack */
45     add_shortcut( "nsv" );
46     add_shortcut( "real" );
47     add_shortcut( "rm" );
48     add_shortcut( "ts2" );
49     add_shortcut( "ps2" );
50     add_shortcut( "dvdnav" );
51     add_shortcut( "ffmpeg" );
52 vlc_module_end();
53
54 /*****************************************************************************
55  * Local prototypes
56  *****************************************************************************/
57 static int  Demux2Demux  ( input_thread_t * );
58 static int  Demux2Control( input_thread_t *, int, va_list );
59
60 typedef struct
61 {
62     demux_t  *p_demux;
63 } demux2_sys_t;
64
65 /*****************************************************************************
66  * Demux2Open: initializes structures
67  *****************************************************************************/
68 static int Demux2Open( vlc_object_t * p_this )
69 {
70     input_thread_t *p_input = (input_thread_t *)p_this;
71     demux2_sys_t   *p_sys   = malloc( sizeof( demux2_sys_t ) );
72     demux_t        *p_demux;
73
74     char           *psz_uri;
75
76     if( input_InitStream( p_input, 0 ) )
77     {
78         return VLC_EGENERIC;
79     }
80
81     psz_uri = malloc( strlen( p_input->psz_access ) + strlen( p_input->psz_demux ) + strlen( p_input->psz_name  ) + 1 + 3 + 1 );
82     if( p_input->psz_demux && *p_input->psz_demux )
83     {
84         sprintf( psz_uri, "%s/%s://%s", p_input->psz_access, p_input->psz_demux, p_input->psz_name );
85     }
86     else if( p_input->psz_access && *p_input->psz_access )
87     {
88         sprintf( psz_uri, "%s://%s", p_input->psz_access, p_input->psz_name );
89     }
90     else
91     {
92         sprintf( psz_uri, "%s", p_input->psz_name );
93     }
94
95     p_demux = demux2_New( p_input, psz_uri, p_input->s, p_input->p_es_out );
96
97     free( psz_uri );
98
99     if( !p_demux )
100     {
101         /* We should handle special access+demuxer but later */
102         free( p_sys );
103         return VLC_EGENERIC;
104     }
105
106     p_input->pf_demux = Demux2Demux;
107     p_input->pf_demux_control = Demux2Control;
108     p_input->p_demux_data = (demux_sys_t*)p_sys;
109
110     p_sys->p_demux = p_demux;
111
112     return VLC_SUCCESS;
113 }
114
115
116 /*****************************************************************************
117  * Demux2Demux: reads and demuxes data packets
118  *****************************************************************************
119  * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
120  *****************************************************************************/
121 static int Demux2Demux( input_thread_t * p_input )
122 {
123     demux2_sys_t  *p_sys = (demux2_sys_t*)p_input->p_demux_data;
124
125     return demux2_Demux( p_sys->p_demux );
126 }
127
128 /*****************************************************************************
129  * Demux2Control:
130  *****************************************************************************/
131 static int  Demux2Control( input_thread_t *p_input, int i_query, va_list args )
132 {
133     demux2_sys_t  *p_sys = (demux2_sys_t*)p_input->p_demux_data;
134
135     return demux2_vaControl( p_sys->p_demux, i_query, args );
136 }
137
138 /*****************************************************************************
139  * Demux2Close: frees unused data
140  *****************************************************************************/
141 static void Demux2Close( vlc_object_t * p_this )
142 {
143     input_thread_t *p_input = (input_thread_t*)p_this;
144     demux2_sys_t   *p_sys = (demux2_sys_t*)p_input->p_demux_data;
145
146     demux2_Delete( p_sys->p_demux );
147
148     free( p_sys );
149 }