]> git.sesse.net Git - vlc/blob - modules/demux/playlist/qtl.c
b3f4d733ff6a753162dd040bbcf9606642d3d6bd
[vlc] / modules / demux / playlist / qtl.c
1 /*****************************************************************************
2  * qtl.c: QuickTime Media Link Importer
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -@t- videolan -Dot- org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*
25 See
26 http://developer.apple.com/documentation/QuickTime/QT6WhatsNew/Chap1/chapter_1_section_54.html
27 and
28 http://developer.apple.com/documentation/QuickTime/WhatsNewQT5/QT5NewChapt1/chapter_1_section_39.html
29
30 autoplay - true/false
31 controller - true/false
32 fullscreen - normal/double/half/current/full
33 href - url
34 kioskmode - true/false
35 loop - true/false/palindrome
36 movieid - integer
37 moviename - string
38 playeveryframe - true/false
39 qtnext - url
40 quitwhendone - true/false
41 src - url (required)
42 type - mime type
43 volume - 0 (mute) - 100 (max)
44
45 */
46
47 /*****************************************************************************
48  * Preamble
49  *****************************************************************************/
50
51 #ifdef HAVE_CONFIG_H
52 # include "config.h"
53 #endif
54
55 #include <vlc_common.h>
56 #include <vlc_demux.h>
57
58 #include "playlist.h"
59 #include <vlc_xml.h>
60
61 typedef enum { FULLSCREEN_NORMAL,
62                FULLSCREEN_DOUBLE,
63                FULLSCREEN_HALF,
64                FULLSCREEN_CURRENT,
65                FULLSCREEN_FULL } qtl_fullscreen_t;
66 const char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
67 typedef enum { LOOP_TRUE,
68                LOOP_FALSE,
69                LOOP_PALINDROME } qtl_loop_t;
70 const char* ppsz_loop[] = { "true", "false", "palindrome" };
71
72 /*****************************************************************************
73  * Local prototypes
74  *****************************************************************************/
75 static int Demux( demux_t *p_demux);
76 static int Control( demux_t *p_demux, int i_query, va_list args );
77
78 /*****************************************************************************
79  * Import_QTL: main import function
80  *****************************************************************************/
81 int Import_QTL( vlc_object_t *p_this )
82 {
83     demux_t *p_demux = (demux_t *)p_this;
84
85     if( !demux_IsPathExtension( p_demux, ".qtl" ) )
86         return VLC_EGENERIC;
87
88     p_demux->pf_demux = Demux;
89     p_demux->pf_control = Control;
90     msg_Dbg( p_demux, "using QuickTime Media Link reader" );
91
92     return VLC_SUCCESS;
93 }
94
95 /*****************************************************************************
96  * Deactivate: frees unused data
97  *****************************************************************************/
98 void Close_QTL( vlc_object_t *p_this )
99 {
100     (void)p_this;
101 }
102
103 static int Demux( demux_t *p_demux )
104 {
105     xml_t *p_xml;
106     xml_reader_t *p_xml_reader = NULL;
107     char *psz_eltname = NULL;
108     input_item_t *p_input;
109     int i_ret = -1;
110
111     /* List of all possible attributes. The only required one is "src" */
112     bool b_autoplay = false;
113     bool b_controler = true;
114     qtl_fullscreen_t fullscreen = false;
115     char *psz_href = NULL;
116     bool b_kioskmode = false;
117     qtl_loop_t loop = LOOP_FALSE;
118     int i_movieid = -1;
119     char *psz_moviename = NULL;
120     bool b_playeveryframe = false;
121     char *psz_qtnext = NULL;
122     bool b_quitwhendone = false;
123     char *psz_src = NULL;
124     char *psz_mimetype = NULL;
125     int i_volume = 100;
126
127     input_item_t *p_current_input = GetCurrentItem(p_demux);
128
129     p_xml = xml_Create( p_demux );
130     if( !p_xml )
131         goto error;
132
133     p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s );
134     if( !p_xml_reader )
135         goto error;
136
137     /* check root node */
138     if( xml_ReaderRead( p_xml_reader ) != 1 )
139     {
140         msg_Err( p_demux, "invalid file (no root node)" );
141         goto error;
142     }
143
144     if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
145         ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
146         strcmp( psz_eltname, "embed" ) )
147     {
148         msg_Err( p_demux, "invalid root node %i, %s",
149                  xml_ReaderNodeType( p_xml_reader ), psz_eltname );
150         free( psz_eltname );
151
152         /* second line has <?quicktime tag ... so we try to skip it */
153         msg_Dbg( p_demux, "trying to read one more node" );
154         xml_ReaderRead( p_xml_reader );
155         if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
156             ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
157             strcmp( psz_eltname, "embed" ) )
158         {
159             msg_Err( p_demux, "invalid root node %i, %s",
160                      xml_ReaderNodeType( p_xml_reader ), psz_eltname );
161             free( psz_eltname );
162             goto error;
163         }
164     }
165     free( psz_eltname );
166
167     while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
168     {
169         char *psz_attrname = xml_ReaderName( p_xml_reader );
170         char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
171
172         if( !psz_attrname || !psz_attrvalue )
173         {
174             free( psz_attrname );
175             free( psz_attrvalue );
176             goto error;
177         }
178
179         if( !strcmp( psz_attrname, "autoplay" ) )
180         {
181             b_autoplay = !strcmp( psz_attrvalue, "true" );
182         }
183         else if( !strcmp( psz_attrname, "controler" ) )
184         {
185             b_controler = !strcmp( psz_attrvalue, "false" );
186         }
187         else if( !strcmp( psz_attrname, "fullscreen" ) )
188         {
189             if( !strcmp( psz_attrvalue, "double" ) )
190             {
191                 fullscreen = FULLSCREEN_DOUBLE;
192             }
193             else if( !strcmp( psz_attrvalue, "half" ) )
194             {
195                 fullscreen = FULLSCREEN_HALF;
196             }
197             else if( !strcmp( psz_attrvalue, "current" ) )
198             {
199                 fullscreen = FULLSCREEN_CURRENT;
200             }
201             else if( !strcmp( psz_attrvalue, "full" ) )
202             {
203                 fullscreen = FULLSCREEN_FULL;
204             }
205             else
206             {
207                 fullscreen = FULLSCREEN_NORMAL;
208             }
209         }
210         else if( !strcmp( psz_attrname, "href" ) )
211         {
212             psz_href = psz_attrvalue;
213             psz_attrvalue = NULL;
214         }
215         else if( !strcmp( psz_attrname, "kioskmode" ) )
216         {
217             b_kioskmode = !strcmp( psz_attrvalue, "true" );
218         }
219         else if( !strcmp( psz_attrname, "loop" ) )
220         {
221             if( !strcmp( psz_attrvalue, "true" ) )
222             {
223                 loop = LOOP_TRUE;
224             }
225             else if( !strcmp( psz_attrvalue, "palindrome" ) )
226             {
227                 loop = LOOP_PALINDROME;
228             }
229             else
230             {
231                 loop = LOOP_FALSE;
232             }
233         }
234         else if( !strcmp( psz_attrname, "movieid" ) )
235         {
236             i_movieid = atoi( psz_attrvalue );
237         }
238         else if( !strcmp( psz_attrname, "moviename" ) )
239         {
240             psz_moviename = psz_attrvalue;
241             psz_attrvalue = NULL;
242         }
243         else if( !strcmp( psz_attrname, "playeveryframe" ) )
244         {
245             b_playeveryframe = !strcmp( psz_attrvalue, "true" );
246         }
247         else if( !strcmp( psz_attrname, "qtnext" ) )
248         {
249             psz_qtnext = psz_attrvalue;
250             psz_attrvalue = NULL;
251         }
252         else if( !strcmp( psz_attrname, "quitwhendone" ) )
253         {
254             b_quitwhendone = !strcmp( psz_attrvalue, "true" );
255         }
256         else if( !strcmp( psz_attrname, "src" ) )
257         {
258             psz_src = psz_attrvalue;
259             psz_attrvalue = NULL;
260         }
261         else if( !strcmp( psz_attrname, "mimetype" ) )
262         {
263             psz_mimetype = psz_attrvalue;
264             psz_attrvalue = NULL;
265         }
266         else if( !strcmp( psz_attrname, "volume" ) )
267         {
268             i_volume = atoi( psz_attrvalue );
269         }
270         else
271         {
272             msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
273                      psz_attrname, psz_attrvalue );
274         }
275         free( psz_attrname );
276         free( psz_attrvalue );
277     }
278
279     msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
280              b_autoplay ? "true": "false" );
281     msg_Dbg( p_demux, "controler: %s (unused by VLC)",
282              b_controler ? "true": "false" );
283     msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
284              ppsz_fullscreen[fullscreen] );
285     msg_Dbg( p_demux, "href: %s", psz_href );
286     msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
287              b_kioskmode ? "true":"false" );
288     msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
289     msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
290     msg_Dbg( p_demux, "moviename: %s", psz_moviename );
291     msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
292              b_playeveryframe ? "true":"false" );
293     msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
294     msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
295              b_quitwhendone ? "true":"false" );
296     msg_Dbg( p_demux, "src: %s", psz_src );
297     msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
298     msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
299
300
301     if( !psz_src )
302     {
303         msg_Err( p_demux, "Mandatory attribute 'src' not found" );
304     }
305     else
306     {
307         input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
308         p_input = input_item_New( p_demux, psz_src, psz_moviename );
309 #define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \
310                     p_input, "QuickTime Media Link", type, "%s", field ) ; }
311         SADD_INFO( "href", psz_href );
312         SADD_INFO( _("Mime"), psz_mimetype );
313         input_item_node_AppendItem( p_subitems, p_input );
314         vlc_gc_decref( p_input );
315         if( psz_qtnext )
316         {
317             p_input = input_item_New( p_demux, psz_qtnext, NULL );
318             input_item_node_AppendItem( p_subitems, p_input );
319             vlc_gc_decref( p_input );
320         }
321         input_item_node_PostAndDelete( p_subitems );
322     }
323
324     i_ret = 0; /* Needed for correct operation of go back */
325
326 error:
327     if( p_xml_reader )
328         xml_ReaderDelete( p_xml_reader );
329     if( p_xml )
330         xml_Delete( p_xml );
331
332     vlc_gc_decref(p_current_input);
333
334     free( psz_href );
335     free( psz_moviename );
336     free( psz_qtnext );
337     free( psz_src );
338     free( psz_mimetype );
339     return i_ret;
340 }
341
342 static int Control( demux_t *p_demux, int i_query, va_list args )
343 {
344     VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
345     return VLC_EGENERIC;
346 }