]> git.sesse.net Git - vlc/blob - modules/demux/demux2.c
Fix deadlocks in playlist
[vlc] / modules / demux / demux2.c
1 /*****************************************************************************
2  * demux2 adaptation layer.
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id$
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 #include "vlc_playlist.h"
33
34 /*****************************************************************************
35  * Module descriptor
36  *****************************************************************************/
37 static int  Demux2Open    ( vlc_object_t * );
38 static void Demux2Close  ( vlc_object_t * );
39
40 vlc_module_begin();
41     set_description( _("Demux2 adaptation layer" ) );
42     set_capability( "demux", 2 );
43     set_callbacks( Demux2Open, Demux2Close );
44     add_shortcut( "demux2" );
45
46     /* Hack */
47     add_shortcut( "nsv" );
48     add_shortcut( "ts2" );
49     add_shortcut( "ps2" );
50     add_shortcut( "dvdnav" );
51     add_shortcut( "dvdnavsimple" );
52     add_shortcut( "ffmpeg" );
53     add_shortcut( "mp3" );
54     add_shortcut( "mpga" );
55     add_shortcut( "aac" );
56     add_shortcut( "a52" );
57     add_shortcut( "dts" );
58     add_shortcut( "mod" );
59     add_shortcut( "flac" );
60     add_shortcut( "m3u" );
61     add_shortcut( "playlist" );
62 vlc_module_end();
63
64 /*****************************************************************************
65  * Local prototypes
66  *****************************************************************************/
67 static int  Demux2Demux  ( input_thread_t * );
68 static int  Demux2Control( input_thread_t *, int, va_list );
69
70 typedef struct
71 {
72     demux_t  *p_demux;
73 } demux2_sys_t;
74
75 /*****************************************************************************
76  * Demux2Open: initializes structures
77  *****************************************************************************/
78 static int Demux2Open( vlc_object_t * p_this )
79 {
80     input_thread_t *p_input = (input_thread_t *)p_this;
81     demux2_sys_t   *p_sys   = malloc( sizeof( demux2_sys_t ) );
82     demux_t        *p_demux;
83     playlist_t     *p_playlist;
84
85     char           *psz_uri;
86
87     if( input_InitStream( p_input, 0 ) )
88     {
89         return VLC_EGENERIC;
90     }
91
92     psz_uri = malloc( strlen( p_input->psz_access ) + strlen( p_input->psz_demux ) + strlen( p_input->psz_name  ) + 1 + 3 + 1 );
93     if( p_input->psz_demux && *p_input->psz_demux )
94     {
95         sprintf( psz_uri, "%s/%s://%s", p_input->psz_access, p_input->psz_demux, p_input->psz_name );
96     }
97     else if( p_input->psz_access && *p_input->psz_access )
98     {
99         sprintf( psz_uri, "%s://%s", p_input->psz_access, p_input->psz_name );
100     }
101     else
102     {
103         sprintf( psz_uri, "%s", p_input->psz_name );
104     }
105
106     p_demux = demux2_New( p_input, psz_uri, p_input->s, p_input->p_es_out );
107
108     free( psz_uri );
109
110     if( !p_demux )
111     {
112         /* We should handle special access+demuxer but later */
113         free( p_sys );
114         return VLC_EGENERIC;
115     }
116
117     /* Now retreive meta info from demuxer */
118     if( ( p_playlist = vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
119                                         FIND_ANYWHERE ) ) )
120     {
121         int64_t i_length;
122
123         if( !demux2_Control( p_demux, DEMUX_GET_LENGTH, &i_length ) )
124         {
125             playlist_SetDuration( p_playlist, -1, i_length );
126         }
127         vlc_object_release( p_playlist );
128     }
129
130     p_input->pf_demux = Demux2Demux;
131     p_input->pf_demux_control = Demux2Control;
132     p_input->p_demux_data = (demux_sys_t*)p_sys;
133
134     p_sys->p_demux = p_demux;
135
136     return VLC_SUCCESS;
137 }
138
139
140 /*****************************************************************************
141  * Demux2Demux: reads and demuxes data packets
142  *****************************************************************************
143  * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
144  *****************************************************************************/
145 static int Demux2Demux( input_thread_t * p_input )
146 {
147     demux2_sys_t  *p_sys = (demux2_sys_t*)p_input->p_demux_data;
148
149     return demux2_Demux( p_sys->p_demux );
150 }
151
152 /*****************************************************************************
153  * Demux2Control:
154  *****************************************************************************/
155 static int  Demux2Control( input_thread_t *p_input, int i_query, va_list args )
156 {
157     demux2_sys_t  *p_sys = (demux2_sys_t*)p_input->p_demux_data;
158
159     return demux2_vaControl( p_sys->p_demux, i_query, args );
160 }
161
162 /*****************************************************************************
163  * Demux2Close: frees unused data
164  *****************************************************************************/
165 static void Demux2Close( vlc_object_t * p_this )
166 {
167     input_thread_t *p_input = (input_thread_t*)p_this;
168     demux2_sys_t   *p_sys = (demux2_sys_t*)p_input->p_demux_data;
169
170     demux2_Delete( p_sys->p_demux );
171
172     free( p_sys );
173 }