]> git.sesse.net Git - vlc/blob - modules/demux/playlist/qtl.c
841d07450864906b746379c57af5284898793970
[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 #include <ctype.h>                                              /* isspace() */
51
52 #include <vlc/vlc.h>
53 #include <vlc/input.h>
54 #include <vlc/intf.h>
55
56 #include "playlist.h"
57 #include "vlc_xml.h"
58
59 struct demux_sys_t
60 {
61     playlist_t *p_playlist;
62     playlist_item_t *p_current;
63     playlist_item_t *p_item_in_category;
64     int i_parent_id;
65
66     xml_t *p_xml;
67     xml_reader_t *p_xml_reader;
68 };
69
70 typedef enum { FULLSCREEN_NORMAL,
71                FULLSCREEN_DOUBLE,
72                FULLSCREEN_HALF,
73                FULLSCREEN_CURRENT,
74                FULLSCREEN_FULL } qtl_fullscreen_t;
75 char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
76 typedef enum { LOOP_TRUE,
77                LOOP_FALSE,
78                LOOP_PALINDROME } qtl_loop_t;
79 char* ppsz_loop[] = { "true", "false", "palindrome" };
80
81 /*****************************************************************************
82  * Local prototypes
83  *****************************************************************************/
84 static int Demux( demux_t *p_demux);
85 static int Control( demux_t *p_demux, int i_query, va_list args );
86
87 /*****************************************************************************
88  * Import_QTL: main import function
89  *****************************************************************************/
90 int E_(Import_QTL)( vlc_object_t *p_this )
91 {
92     DEMUX_BY_EXTENSION_MSG( ".qtl", "using QuickTime Media Link reader" );
93     p_demux->p_sys->p_playlist = NULL;
94     p_demux->p_sys->p_xml = NULL;
95     p_demux->p_sys->p_xml_reader = NULL;
96     return VLC_SUCCESS;
97 }
98
99 /*****************************************************************************
100  * Deactivate: frees unused data
101  *****************************************************************************/
102 void E_(Close_QTL)( vlc_object_t *p_this )
103 {
104     demux_t *p_demux = (demux_t *)p_this;
105     demux_sys_t *p_sys = p_demux->p_sys;
106
107     if( p_sys->p_playlist )
108         vlc_object_release( p_sys->p_playlist );
109     if( p_sys->p_xml_reader )
110         xml_ReaderDelete( p_sys->p_xml, p_sys->p_xml_reader );
111     if( p_sys->p_xml )
112         xml_Delete( p_sys->p_xml );
113     free( p_sys );
114 }
115
116 static int Demux( demux_t *p_demux )
117 {
118     demux_sys_t *p_sys = p_demux->p_sys;
119     xml_t *p_xml;
120     xml_reader_t *p_xml_reader;
121     char *psz_eltname = NULL;
122
123     /* List of all possible attributes. The only required one is "src" */
124     vlc_bool_t b_autoplay = VLC_FALSE;
125     vlc_bool_t b_controler = VLC_TRUE;
126     qtl_fullscreen_t fullscreen = VLC_FALSE;
127     char *psz_href = NULL;
128     vlc_bool_t b_kioskmode = VLC_FALSE;
129     qtl_loop_t loop = LOOP_FALSE;
130     int i_movieid = -1;
131     char *psz_moviename = NULL;
132     vlc_bool_t b_playeveryframe = VLC_FALSE;
133     char *psz_qtnext = NULL;
134     vlc_bool_t b_quitwhendone = VLC_FALSE;
135     char *psz_src = NULL;
136     char *psz_mimetype = NULL;
137     int i_volume = 100;
138
139     INIT_PLAYLIST_STUFF;
140
141     p_sys->p_playlist = p_playlist;
142     p_sys->p_current = p_current;
143     p_sys->i_parent_id = i_parent_id;
144     p_sys->p_item_in_category = p_item_in_category;
145
146     p_xml = p_sys->p_xml = xml_Create( p_demux );
147     if( !p_xml ) return -1;
148
149     p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s );
150     if( !p_xml_reader ) return -1;
151     p_sys->p_xml_reader = p_xml_reader;
152
153     /* check root node */
154     if( xml_ReaderRead( p_xml_reader ) != 1 )
155     {
156         msg_Err( p_demux, "invalid file (no root node)" );
157         return -1;
158     }
159
160     if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
161         ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
162         strcmp( psz_eltname, "embed" ) )
163     {
164         msg_Err( p_demux, "invalid root node %i, %s",
165                  xml_ReaderNodeType( p_xml_reader ), psz_eltname );
166         FREE( psz_eltname );
167
168         /* second line has <?quicktime tag ... so we try to skip it */
169         msg_Dbg( p_demux, "trying to read one more node" );
170         xml_ReaderRead( p_xml_reader );
171         if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
172             ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
173             strcmp( psz_eltname, "embed" ) )
174         {
175             msg_Err( p_demux, "invalid root node %i, %s",
176                      xml_ReaderNodeType( p_xml_reader ), psz_eltname );
177             FREE( psz_eltname );
178             return -1;
179         }
180     }
181     FREE( psz_eltname );
182
183     while( xml_ReaderNextAttr( p_sys->p_xml_reader ) == VLC_SUCCESS )
184     {
185         char *psz_attrname = xml_ReaderName( p_sys->p_xml_reader );
186         char *psz_attrvalue = xml_ReaderValue( p_sys->p_xml_reader );
187
188         if( !psz_attrname || !psz_attrvalue )
189         {
190             FREE( psz_attrname );
191             FREE( psz_attrvalue );
192             return -1;
193         }
194
195         if( !strcmp( psz_attrname, "autoplay" ) )
196         {
197             if( !strcmp( psz_attrvalue, "true" ) )
198             {
199                 b_autoplay = VLC_TRUE;
200             }
201             else
202             {
203                 b_autoplay = VLC_FALSE;
204             }
205         }
206         else if( !strcmp( psz_attrname, "controler" ) )
207         {
208             if( !strcmp( psz_attrvalue, "false" ) )
209             {
210                 b_controler = VLC_FALSE;
211             }
212             else
213             {
214                 b_controler = VLC_TRUE;
215             }
216         }
217         else if( !strcmp( psz_attrname, "fullscreen" ) )
218         {
219             if( !strcmp( psz_attrvalue, "double" ) )
220             {
221                 fullscreen = FULLSCREEN_DOUBLE;
222             }
223             else if( !strcmp( psz_attrvalue, "half" ) )
224             {
225                 fullscreen = FULLSCREEN_HALF;
226             }
227             else if( !strcmp( psz_attrvalue, "current" ) )
228             {
229                 fullscreen = FULLSCREEN_CURRENT;
230             }
231             else if( !strcmp( psz_attrvalue, "full" ) )
232             {
233                 fullscreen = FULLSCREEN_FULL;
234             }
235             else
236             {
237                 fullscreen = FULLSCREEN_NORMAL;
238             }
239         }
240         else if( !strcmp( psz_attrname, "href" ) )
241         {
242             psz_href = psz_attrvalue;
243             psz_attrvalue = NULL;
244         }
245         else if( !strcmp( psz_attrname, "kioskmode" ) )
246         {
247             if( !strcmp( psz_attrvalue, "true" ) )
248             {
249                 b_kioskmode = VLC_TRUE;
250             }
251             else
252             {
253                 b_kioskmode = VLC_FALSE;
254             }
255         }
256         else if( !strcmp( psz_attrname, "loop" ) )
257         {
258             if( !strcmp( psz_attrvalue, "true" ) )
259             {
260                 loop = LOOP_TRUE;
261             }
262             else if( !strcmp( psz_attrvalue, "palindrome" ) )
263             {
264                 loop = LOOP_PALINDROME;
265             }
266             else
267             {
268                 loop = LOOP_FALSE;
269             }
270         }
271         else if( !strcmp( psz_attrname, "movieid" ) )
272         {
273             i_movieid = atoi( psz_attrvalue );
274         }
275         else if( !strcmp( psz_attrname, "moviename" ) )
276         {
277             psz_moviename = psz_attrvalue;
278             psz_attrvalue = NULL;
279         }
280         else if( !strcmp( psz_attrname, "playeveryframe" ) )
281         {
282             if( !strcmp( psz_attrvalue, "true" ) )
283             {
284                 b_playeveryframe = VLC_TRUE;
285             }
286             else
287             {
288                 b_playeveryframe = VLC_FALSE;
289             }
290         }
291         else if( !strcmp( psz_attrname, "qtnext" ) )
292         {
293             psz_qtnext = psz_attrvalue;
294             psz_attrvalue = NULL;
295         }
296         else if( !strcmp( psz_attrname, "quitwhendone" ) )
297         {
298             if( !strcmp( psz_attrvalue, "true" ) )
299             {
300                 b_quitwhendone = VLC_TRUE;
301             }
302             else
303             {
304                 b_quitwhendone = VLC_FALSE;
305             }
306         }
307         else if( !strcmp( psz_attrname, "src" ) )
308         {
309             psz_src = psz_attrvalue;
310             psz_attrvalue = NULL;
311         }
312         else if( !strcmp( psz_attrname, "mimetype" ) )
313         {
314             psz_mimetype = psz_attrvalue;
315             psz_attrvalue = NULL;
316         }
317         else if( !strcmp( psz_attrname, "volume" ) )
318         {
319             i_volume = atoi( psz_attrvalue );
320         }
321         else
322         {
323             msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
324                      psz_attrname, psz_attrvalue );
325         }
326         FREE( psz_attrname );
327         FREE( psz_attrvalue );
328     }
329
330     msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
331              b_autoplay==VLC_TRUE ? "true": "false" );
332     msg_Dbg( p_demux, "controler: %s (unused by VLC)",
333              b_controler==VLC_TRUE?"true": "false" );
334     msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
335              ppsz_fullscreen[fullscreen] );
336     msg_Dbg( p_demux, "href: %s", psz_href );
337     msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
338              b_kioskmode==VLC_TRUE?"true":"false" );
339     msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
340     msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
341     msg_Dbg( p_demux, "moviename: %s", psz_moviename );
342     msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
343              b_playeveryframe==VLC_TRUE?"true":"false" );
344     msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
345     msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
346              b_quitwhendone==VLC_TRUE?"true":"false" );
347     msg_Dbg( p_demux, "src: %s", psz_src );
348     msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
349     msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
350
351
352     if( !psz_src )
353     {
354         msg_Err( p_demux, "Mandatory attribute 'src' not found" );
355     }
356     else
357     {
358         p_input = input_ItemNewExt( p_sys->p_playlist,
359                                 psz_src, psz_moviename, 0, NULL, -1 );
360 #define SADD_INFO( type, field ) if( field ) { input_ItemAddInfo( \
361                     p_input, "QuickTime Media Link", _(type), "%s", field ) ; }
362         SADD_INFO( "href", psz_href );
363         SADD_INFO( "mime type", psz_mimetype );
364         playlist_AddWhereverNeeded( p_sys->p_playlist, p_input,
365                             p_sys->p_current, p_sys->p_item_in_category,
366                             (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE,
367                             PLAYLIST_APPEND );
368
369         if( psz_qtnext )
370         {
371             p_input = input_ItemNewExt( p_sys->p_playlist,
372                                         psz_qtnext, psz_qtnext, 0, NULL, -1 );
373             playlist_AddWhereverNeeded( p_sys->p_playlist, p_input,
374                             p_sys->p_current, p_sys->p_item_in_category,
375                             (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE,
376                             PLAYLIST_APPEND );
377         }
378     }
379
380     HANDLE_PLAY_AND_RELEASE;
381
382     p_sys->p_playlist = NULL;
383
384     FREE( psz_href );
385     FREE( psz_moviename );
386     FREE( psz_qtnext );
387     FREE( psz_src );
388     FREE( psz_mimetype );
389
390     return VLC_SUCCESS;
391 }
392
393 static int Control( demux_t *p_demux, int i_query, va_list args )
394 {
395     return VLC_EGENERIC;
396 }