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 *****************************************************************************/
56 #include <vlc_demux.h>
63 playlist_t *p_playlist;
64 input_item_t *p_current_input;
67 xml_reader_t *p_xml_reader;
70 typedef enum { FULLSCREEN_NORMAL,
74 FULLSCREEN_FULL } qtl_fullscreen_t;
75 const char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
76 typedef enum { LOOP_TRUE,
78 LOOP_PALINDROME } qtl_loop_t;
79 const 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 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 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 static int Demux( demux_t *p_demux )
118 demux_sys_t *p_sys = p_demux->p_sys;
120 xml_reader_t *p_xml_reader;
121 char *psz_eltname = NULL;
122 input_item_t *p_input;
124 /* List of all possible attributes. The only required one is "src" */
125 bool b_autoplay = false;
126 bool b_controler = true;
127 qtl_fullscreen_t fullscreen = false;
128 char *psz_href = NULL;
129 bool b_kioskmode = false;
130 qtl_loop_t loop = LOOP_FALSE;
132 char *psz_moviename = NULL;
133 bool b_playeveryframe = false;
134 char *psz_qtnext = NULL;
135 bool b_quitwhendone = false;
136 char *psz_src = NULL;
137 char *psz_mimetype = NULL;
142 p_sys->p_playlist = p_playlist;
143 p_sys->p_current_input = p_current_input;
145 p_xml = p_sys->p_xml = xml_Create( p_demux );
146 if( !p_xml ) return -1;
148 p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s );
149 if( !p_xml_reader ) return -1;
150 p_sys->p_xml_reader = p_xml_reader;
152 /* check root node */
153 if( xml_ReaderRead( p_xml_reader ) != 1 )
155 msg_Err( p_demux, "invalid file (no root node)" );
159 if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
160 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
161 strcmp( psz_eltname, "embed" ) )
163 msg_Err( p_demux, "invalid root node %i, %s",
164 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
167 /* second line has <?quicktime tag ... so we try to skip it */
168 msg_Dbg( p_demux, "trying to read one more node" );
169 xml_ReaderRead( p_xml_reader );
170 if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
171 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
172 strcmp( psz_eltname, "embed" ) )
174 msg_Err( p_demux, "invalid root node %i, %s",
175 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
182 while( xml_ReaderNextAttr( p_sys->p_xml_reader ) == VLC_SUCCESS )
184 char *psz_attrname = xml_ReaderName( p_sys->p_xml_reader );
185 char *psz_attrvalue = xml_ReaderValue( p_sys->p_xml_reader );
187 if( !psz_attrname || !psz_attrvalue )
189 free( psz_attrname );
190 free( psz_attrvalue );
194 if( !strcmp( psz_attrname, "autoplay" ) )
196 if( !strcmp( psz_attrvalue, "true" ) )
205 else if( !strcmp( psz_attrname, "controler" ) )
207 if( !strcmp( psz_attrvalue, "false" ) )
216 else if( !strcmp( psz_attrname, "fullscreen" ) )
218 if( !strcmp( psz_attrvalue, "double" ) )
220 fullscreen = FULLSCREEN_DOUBLE;
222 else if( !strcmp( psz_attrvalue, "half" ) )
224 fullscreen = FULLSCREEN_HALF;
226 else if( !strcmp( psz_attrvalue, "current" ) )
228 fullscreen = FULLSCREEN_CURRENT;
230 else if( !strcmp( psz_attrvalue, "full" ) )
232 fullscreen = FULLSCREEN_FULL;
236 fullscreen = FULLSCREEN_NORMAL;
239 else if( !strcmp( psz_attrname, "href" ) )
241 psz_href = psz_attrvalue;
242 psz_attrvalue = NULL;
244 else if( !strcmp( psz_attrname, "kioskmode" ) )
246 if( !strcmp( psz_attrvalue, "true" ) )
255 else if( !strcmp( psz_attrname, "loop" ) )
257 if( !strcmp( psz_attrvalue, "true" ) )
261 else if( !strcmp( psz_attrvalue, "palindrome" ) )
263 loop = LOOP_PALINDROME;
270 else if( !strcmp( psz_attrname, "movieid" ) )
272 i_movieid = atoi( psz_attrvalue );
274 else if( !strcmp( psz_attrname, "moviename" ) )
276 psz_moviename = psz_attrvalue;
277 psz_attrvalue = NULL;
279 else if( !strcmp( psz_attrname, "playeveryframe" ) )
281 if( !strcmp( psz_attrvalue, "true" ) )
283 b_playeveryframe = true;
287 b_playeveryframe = false;
290 else if( !strcmp( psz_attrname, "qtnext" ) )
292 psz_qtnext = psz_attrvalue;
293 psz_attrvalue = NULL;
295 else if( !strcmp( psz_attrname, "quitwhendone" ) )
297 if( !strcmp( psz_attrvalue, "true" ) )
299 b_quitwhendone = true;
303 b_quitwhendone = false;
306 else if( !strcmp( psz_attrname, "src" ) )
308 psz_src = psz_attrvalue;
309 psz_attrvalue = NULL;
311 else if( !strcmp( psz_attrname, "mimetype" ) )
313 psz_mimetype = psz_attrvalue;
314 psz_attrvalue = NULL;
316 else if( !strcmp( psz_attrname, "volume" ) )
318 i_volume = atoi( psz_attrvalue );
322 msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
323 psz_attrname, psz_attrvalue );
325 free( psz_attrname );
326 free( psz_attrvalue );
329 msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
330 b_autoplay==true ? "true": "false" );
331 msg_Dbg( p_demux, "controler: %s (unused by VLC)",
332 b_controler==true?"true": "false" );
333 msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
334 ppsz_fullscreen[fullscreen] );
335 msg_Dbg( p_demux, "href: %s", psz_href );
336 msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
337 b_kioskmode==true?"true":"false" );
338 msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
339 msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
340 msg_Dbg( p_demux, "moviename: %s", psz_moviename );
341 msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
342 b_playeveryframe==true?"true":"false" );
343 msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
344 msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
345 b_quitwhendone==true?"true":"false" );
346 msg_Dbg( p_demux, "src: %s", psz_src );
347 msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
348 msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
353 msg_Err( p_demux, "Mandatory attribute 'src' not found" );
357 p_input = input_ItemNewExt( p_sys->p_playlist,
358 psz_src, psz_moviename, 0, NULL, -1 );
359 #define SADD_INFO( type, field ) if( field ) { input_ItemAddInfo( \
360 p_input, "QuickTime Media Link", _(type), "%s", field ) ; }
361 SADD_INFO( "href", psz_href );
362 SADD_INFO( "mime type", psz_mimetype );
363 input_ItemAddSubItem( p_current_input, p_input );
364 vlc_gc_decref( p_input );
367 p_input = input_ItemNewExt( p_sys->p_playlist,
368 psz_qtnext, NULL, 0, NULL, -1 );
369 input_ItemAddSubItem( p_current_input, p_input );
370 vlc_gc_decref( p_input );
374 HANDLE_PLAY_AND_RELEASE;
376 p_sys->p_playlist = NULL;
379 free( psz_moviename );
382 free( psz_mimetype );
384 return 0; /* Needed for correct operation of go back */
387 static int Control( demux_t *p_demux, int i_query, va_list args )
389 VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);