1 /*****************************************************************************
2 * qtl.c: QuickTime Media Link Importer
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -@t- videolan -Dot- org>
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.
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.
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 *****************************************************************************/
26 http://developer.apple.com/documentation/QuickTime/QT6WhatsNew/Chap1/chapter_1_section_54.html
28 http://developer.apple.com/documentation/QuickTime/WhatsNewQT5/QT5NewChapt1/chapter_1_section_39.html
31 controller - true/false
32 fullscreen - normal/double/half/current/full
34 kioskmode - true/false
35 loop - true/false/palindrome
38 playeveryframe - true/false
40 quitwhendone - true/false
43 volume - 0 (mute) - 100 (max)
47 /*****************************************************************************
49 *****************************************************************************/
50 #include <ctype.h> /* isspace() */
53 #include <vlc/input.h>
61 playlist_t *p_playlist;
62 playlist_item_t *p_current;
63 playlist_item_t *p_item_in_category;
67 xml_reader_t *p_xml_reader;
70 typedef enum { FULLSCREEN_NORMAL,
74 FULLSCREEN_FULL } qtl_fullscreen_t;
75 char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
76 typedef enum { LOOP_TRUE,
78 LOOP_PALINDROME } qtl_loop_t;
79 char* ppsz_loop[] = { "true", "false", "palindrome" };
81 /*****************************************************************************
83 *****************************************************************************/
84 static int Demux( demux_t *p_demux);
85 static int Control( demux_t *p_demux, int i_query, va_list args );
87 /*****************************************************************************
88 * Import_QTL: main import function
89 *****************************************************************************/
90 int E_(Import_QTL)( vlc_object_t *p_this )
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;
99 /*****************************************************************************
100 * Deactivate: frees unused data
101 *****************************************************************************/
102 void E_(Close_QTL)( vlc_object_t *p_this )
104 demux_t *p_demux = (demux_t *)p_this;
105 demux_sys_t *p_sys = p_demux->p_sys;
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 );
112 xml_Delete( p_sys->p_xml );
116 #define FREE( a ) if( a ) free( a );
118 static int Demux( demux_t *p_demux )
120 demux_sys_t *p_sys = p_demux->p_sys;
122 xml_reader_t *p_xml_reader;
123 char *psz_eltname = NULL;
125 /* List of all possible attributes. The only required one is "src" */
126 vlc_bool_t b_autoplay = VLC_FALSE;
127 vlc_bool_t b_controler = VLC_TRUE;
128 qtl_fullscreen_t fullscreen = VLC_FALSE;
129 char *psz_href = NULL;
130 vlc_bool_t b_kioskmode = VLC_FALSE;
131 qtl_loop_t loop = LOOP_FALSE;
133 char *psz_moviename = NULL;
134 vlc_bool_t b_playeveryframe = VLC_FALSE;
135 char *psz_qtnext = NULL;
136 vlc_bool_t b_quitwhendone = VLC_FALSE;
137 char *psz_src = NULL;
138 char *psz_mimetype = NULL;
143 p_sys->p_playlist = p_playlist;
144 p_sys->p_current = p_current;
145 p_sys->i_parent_id = i_parent_id;
146 p_sys->p_item_in_category = p_item_in_category;
148 p_xml = p_sys->p_xml = xml_Create( p_demux );
149 if( !p_xml ) return -1;
151 p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s );
152 if( !p_xml_reader ) return -1;
153 p_sys->p_xml_reader = p_xml_reader;
155 /* check root node */
156 if( xml_ReaderRead( p_xml_reader ) != 1 )
158 msg_Err( p_demux, "invalid file (no root node)" );
162 if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
163 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
164 strcmp( psz_eltname, "embed" ) )
166 msg_Err( p_demux, "invalid root node %i, %s",
167 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
170 /* second line has <?quicktime tag ... so we try to skip it */
171 msg_Dbg( p_demux, "trying to read one more node" );
172 xml_ReaderRead( p_xml_reader );
173 if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
174 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
175 strcmp( psz_eltname, "embed" ) )
177 msg_Err( p_demux, "invalid root node %i, %s",
178 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
185 while( xml_ReaderNextAttr( p_sys->p_xml_reader ) == VLC_SUCCESS )
187 char *psz_attrname = xml_ReaderName( p_sys->p_xml_reader );
188 char *psz_attrvalue = xml_ReaderValue( p_sys->p_xml_reader );
190 if( !psz_attrname || !psz_attrvalue )
192 FREE( psz_attrname );
193 FREE( psz_attrvalue );
197 if( !strcmp( psz_attrname, "autoplay" ) )
199 if( !strcmp( psz_attrvalue, "true" ) )
201 b_autoplay = VLC_TRUE;
205 b_autoplay = VLC_FALSE;
208 else if( !strcmp( psz_attrname, "controler" ) )
210 if( !strcmp( psz_attrvalue, "false" ) )
212 b_controler = VLC_FALSE;
216 b_controler = VLC_TRUE;
219 else if( !strcmp( psz_attrname, "fullscreen" ) )
221 if( !strcmp( psz_attrvalue, "double" ) )
223 fullscreen = FULLSCREEN_DOUBLE;
225 else if( !strcmp( psz_attrvalue, "half" ) )
227 fullscreen = FULLSCREEN_HALF;
229 else if( !strcmp( psz_attrvalue, "current" ) )
231 fullscreen = FULLSCREEN_CURRENT;
233 else if( !strcmp( psz_attrvalue, "full" ) )
235 fullscreen = FULLSCREEN_FULL;
239 fullscreen = FULLSCREEN_NORMAL;
242 else if( !strcmp( psz_attrname, "href" ) )
244 psz_href = psz_attrvalue;
245 psz_attrvalue = NULL;
247 else if( !strcmp( psz_attrname, "kioskmode" ) )
249 if( !strcmp( psz_attrvalue, "true" ) )
251 b_kioskmode = VLC_TRUE;
255 b_kioskmode = VLC_FALSE;
258 else if( !strcmp( psz_attrname, "loop" ) )
260 if( !strcmp( psz_attrvalue, "true" ) )
264 else if( !strcmp( psz_attrvalue, "palindrome" ) )
266 loop = LOOP_PALINDROME;
273 else if( !strcmp( psz_attrname, "movieid" ) )
275 i_movieid = atoi( psz_attrvalue );
277 else if( !strcmp( psz_attrname, "moviename" ) )
279 psz_moviename = psz_attrvalue;
280 psz_attrvalue = NULL;
282 else if( !strcmp( psz_attrname, "playeveryframe" ) )
284 if( !strcmp( psz_attrvalue, "true" ) )
286 b_playeveryframe = VLC_TRUE;
290 b_playeveryframe = VLC_FALSE;
293 else if( !strcmp( psz_attrname, "qtnext" ) )
295 psz_qtnext = psz_attrvalue;
296 psz_attrvalue = NULL;
298 else if( !strcmp( psz_attrname, "quitwhendone" ) )
300 if( !strcmp( psz_attrvalue, "true" ) )
302 b_quitwhendone = VLC_TRUE;
306 b_quitwhendone = VLC_FALSE;
309 else if( !strcmp( psz_attrname, "src" ) )
311 psz_src = psz_attrvalue;
312 psz_attrvalue = NULL;
314 else if( !strcmp( psz_attrname, "mimetype" ) )
316 psz_mimetype = psz_attrvalue;
317 psz_attrvalue = NULL;
319 else if( !strcmp( psz_attrname, "volume" ) )
321 i_volume = atoi( psz_attrvalue );
325 msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
326 psz_attrname, psz_attrvalue );
328 FREE( psz_attrname );
329 FREE( psz_attrvalue );
332 msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
333 b_autoplay==VLC_TRUE ? "true": "false" );
334 msg_Dbg( p_demux, "controler: %s (unused by VLC)",
335 b_controler==VLC_TRUE?"true": "false" );
336 msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
337 ppsz_fullscreen[fullscreen] );
338 msg_Dbg( p_demux, "href: %s", psz_href );
339 msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
340 b_kioskmode==VLC_TRUE?"true":"false" );
341 msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
342 msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
343 msg_Dbg( p_demux, "moviename: %s", psz_moviename );
344 msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
345 b_playeveryframe==VLC_TRUE?"true":"false" );
346 msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
347 msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
348 b_quitwhendone==VLC_TRUE?"true":"false" );
349 msg_Dbg( p_demux, "src: %s", psz_src );
350 msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
351 msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
356 msg_Err( p_demux, "Mandatory attribute 'src' not found" );
360 p_input = input_ItemNewExt( p_sys->p_playlist,
361 psz_src, psz_moviename, 0, NULL, -1 );
362 #define SADD_INFO( type, field ) if( field ) { vlc_input_item_AddInfo( \
363 p_input, "QuickTime Media Link", _(type), "%s", field ) ; }
364 SADD_INFO( "href", psz_href );
365 SADD_INFO( "mime type", psz_mimetype );
366 playlist_AddWhereverNeeded( p_sys->p_playlist, p_input,
367 p_sys->p_current, p_sys->p_item_in_category,
368 (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE,
373 p_input = input_ItemNewExt( p_sys->p_playlist,
374 psz_qtnext, psz_qtnext, 0, NULL, -1 );
375 playlist_AddWhereverNeeded( p_sys->p_playlist, p_input,
376 p_sys->p_current, p_sys->p_item_in_category,
377 (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE,
382 HANDLE_PLAY_AND_RELEASE;
384 p_sys->p_playlist = NULL;
387 FREE( psz_moviename );
390 FREE( psz_mimetype );
395 static int Control( demux_t *p_demux, int i_query, va_list args )