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 *****************************************************************************/
55 #include <vlc_common.h>
56 #include <vlc_demux.h>
63 input_item_t *p_current_input;
66 xml_reader_t *p_xml_reader;
69 typedef enum { FULLSCREEN_NORMAL,
73 FULLSCREEN_FULL } qtl_fullscreen_t;
74 const char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
75 typedef enum { LOOP_TRUE,
77 LOOP_PALINDROME } qtl_loop_t;
78 const char* ppsz_loop[] = { "true", "false", "palindrome" };
80 /*****************************************************************************
82 *****************************************************************************/
83 static int Demux( demux_t *p_demux);
84 static int Control( demux_t *p_demux, int i_query, va_list args );
86 /*****************************************************************************
87 * Import_QTL: main import function
88 *****************************************************************************/
89 int Import_QTL( vlc_object_t *p_this )
91 DEMUX_BY_EXTENSION_MSG( ".qtl", "using QuickTime Media Link reader" );
92 p_demux->p_sys->p_xml = NULL;
93 p_demux->p_sys->p_xml_reader = NULL;
97 /*****************************************************************************
98 * Deactivate: frees unused data
99 *****************************************************************************/
100 void Close_QTL( vlc_object_t *p_this )
102 demux_t *p_demux = (demux_t *)p_this;
103 demux_sys_t *p_sys = p_demux->p_sys;
105 if( p_sys->p_xml_reader )
106 xml_ReaderDelete( p_sys->p_xml, p_sys->p_xml_reader );
108 xml_Delete( p_sys->p_xml );
112 static int Demux( demux_t *p_demux )
114 demux_sys_t *p_sys = p_demux->p_sys;
116 xml_reader_t *p_xml_reader;
117 char *psz_eltname = NULL;
118 input_item_t *p_input;
120 /* List of all possible attributes. The only required one is "src" */
121 bool b_autoplay = false;
122 bool b_controler = true;
123 qtl_fullscreen_t fullscreen = false;
124 char *psz_href = NULL;
125 bool b_kioskmode = false;
126 qtl_loop_t loop = LOOP_FALSE;
128 char *psz_moviename = NULL;
129 bool b_playeveryframe = false;
130 char *psz_qtnext = NULL;
131 bool b_quitwhendone = false;
132 char *psz_src = NULL;
133 char *psz_mimetype = NULL;
138 p_sys->p_current_input = p_current_input;
140 p_xml = p_sys->p_xml = xml_Create( p_demux );
141 if( !p_xml ) return -1;
143 p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s );
144 if( !p_xml_reader ) return -1;
145 p_sys->p_xml_reader = p_xml_reader;
147 /* check root node */
148 if( xml_ReaderRead( p_xml_reader ) != 1 )
150 msg_Err( p_demux, "invalid file (no root node)" );
154 if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
155 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
156 strcmp( psz_eltname, "embed" ) )
158 msg_Err( p_demux, "invalid root node %i, %s",
159 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
162 /* second line has <?quicktime tag ... so we try to skip it */
163 msg_Dbg( p_demux, "trying to read one more node" );
164 xml_ReaderRead( p_xml_reader );
165 if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
166 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
167 strcmp( psz_eltname, "embed" ) )
169 msg_Err( p_demux, "invalid root node %i, %s",
170 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
177 while( xml_ReaderNextAttr( p_sys->p_xml_reader ) == VLC_SUCCESS )
179 char *psz_attrname = xml_ReaderName( p_sys->p_xml_reader );
180 char *psz_attrvalue = xml_ReaderValue( p_sys->p_xml_reader );
182 if( !psz_attrname || !psz_attrvalue )
184 free( psz_attrname );
185 free( psz_attrvalue );
189 if( !strcmp( psz_attrname, "autoplay" ) )
191 if( !strcmp( psz_attrvalue, "true" ) )
200 else if( !strcmp( psz_attrname, "controler" ) )
202 if( !strcmp( psz_attrvalue, "false" ) )
211 else if( !strcmp( psz_attrname, "fullscreen" ) )
213 if( !strcmp( psz_attrvalue, "double" ) )
215 fullscreen = FULLSCREEN_DOUBLE;
217 else if( !strcmp( psz_attrvalue, "half" ) )
219 fullscreen = FULLSCREEN_HALF;
221 else if( !strcmp( psz_attrvalue, "current" ) )
223 fullscreen = FULLSCREEN_CURRENT;
225 else if( !strcmp( psz_attrvalue, "full" ) )
227 fullscreen = FULLSCREEN_FULL;
231 fullscreen = FULLSCREEN_NORMAL;
234 else if( !strcmp( psz_attrname, "href" ) )
236 psz_href = psz_attrvalue;
237 psz_attrvalue = NULL;
239 else if( !strcmp( psz_attrname, "kioskmode" ) )
241 if( !strcmp( psz_attrvalue, "true" ) )
250 else if( !strcmp( psz_attrname, "loop" ) )
252 if( !strcmp( psz_attrvalue, "true" ) )
256 else if( !strcmp( psz_attrvalue, "palindrome" ) )
258 loop = LOOP_PALINDROME;
265 else if( !strcmp( psz_attrname, "movieid" ) )
267 i_movieid = atoi( psz_attrvalue );
269 else if( !strcmp( psz_attrname, "moviename" ) )
271 psz_moviename = psz_attrvalue;
272 psz_attrvalue = NULL;
274 else if( !strcmp( psz_attrname, "playeveryframe" ) )
276 if( !strcmp( psz_attrvalue, "true" ) )
278 b_playeveryframe = true;
282 b_playeveryframe = false;
285 else if( !strcmp( psz_attrname, "qtnext" ) )
287 psz_qtnext = psz_attrvalue;
288 psz_attrvalue = NULL;
290 else if( !strcmp( psz_attrname, "quitwhendone" ) )
292 if( !strcmp( psz_attrvalue, "true" ) )
294 b_quitwhendone = true;
298 b_quitwhendone = false;
301 else if( !strcmp( psz_attrname, "src" ) )
303 psz_src = psz_attrvalue;
304 psz_attrvalue = NULL;
306 else if( !strcmp( psz_attrname, "mimetype" ) )
308 psz_mimetype = psz_attrvalue;
309 psz_attrvalue = NULL;
311 else if( !strcmp( psz_attrname, "volume" ) )
313 i_volume = atoi( psz_attrvalue );
317 msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
318 psz_attrname, psz_attrvalue );
320 free( psz_attrname );
321 free( psz_attrvalue );
324 msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
325 b_autoplay==true ? "true": "false" );
326 msg_Dbg( p_demux, "controler: %s (unused by VLC)",
327 b_controler==true?"true": "false" );
328 msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
329 ppsz_fullscreen[fullscreen] );
330 msg_Dbg( p_demux, "href: %s", psz_href );
331 msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
332 b_kioskmode==true?"true":"false" );
333 msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
334 msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
335 msg_Dbg( p_demux, "moviename: %s", psz_moviename );
336 msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
337 b_playeveryframe==true?"true":"false" );
338 msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
339 msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
340 b_quitwhendone==true?"true":"false" );
341 msg_Dbg( p_demux, "src: %s", psz_src );
342 msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
343 msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
348 msg_Err( p_demux, "Mandatory attribute 'src' not found" );
352 p_input = input_item_NewExt( p_demux,
353 psz_src, psz_moviename, 0, NULL, -1 );
354 #define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \
355 p_input, "QuickTime Media Link", _(type), "%s", field ) ; }
356 SADD_INFO( "href", psz_href );
357 SADD_INFO( "mime type", psz_mimetype );
358 input_item_AddSubItem( p_current_input, p_input );
359 vlc_gc_decref( p_input );
362 p_input = input_item_NewExt( p_demux,
363 psz_qtnext, NULL, 0, NULL, -1 );
364 input_item_AddSubItem( p_current_input, p_input );
365 vlc_gc_decref( p_input );
369 HANDLE_PLAY_AND_RELEASE;
372 free( psz_moviename );
375 free( psz_mimetype );
377 return 0; /* Needed for correct operation of go back */
380 static int Control( demux_t *p_demux, int i_query, va_list args )
382 VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);