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 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;
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;
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;
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;
146 p_xml = p_sys->p_xml = xml_Create( p_demux );
147 if( !p_xml ) return -1;
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;
153 /* check root node */
154 if( xml_ReaderRead( p_xml_reader ) != 1 )
156 msg_Err( p_demux, "invalid file (no root node)" );
160 if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
161 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
162 strcmp( psz_eltname, "embed" ) )
164 msg_Err( p_demux, "invalid root node %i, %s",
165 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
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" ) )
175 msg_Err( p_demux, "invalid root node %i, %s",
176 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
183 while( xml_ReaderNextAttr( p_sys->p_xml_reader ) == VLC_SUCCESS )
185 char *psz_attrname = xml_ReaderName( p_sys->p_xml_reader );
186 char *psz_attrvalue = xml_ReaderValue( p_sys->p_xml_reader );
188 if( !psz_attrname || !psz_attrvalue )
190 FREE( psz_attrname );
191 FREE( psz_attrvalue );
195 if( !strcmp( psz_attrname, "autoplay" ) )
197 if( !strcmp( psz_attrvalue, "true" ) )
199 b_autoplay = VLC_TRUE;
203 b_autoplay = VLC_FALSE;
206 else if( !strcmp( psz_attrname, "controler" ) )
208 if( !strcmp( psz_attrvalue, "false" ) )
210 b_controler = VLC_FALSE;
214 b_controler = VLC_TRUE;
217 else if( !strcmp( psz_attrname, "fullscreen" ) )
219 if( !strcmp( psz_attrvalue, "double" ) )
221 fullscreen = FULLSCREEN_DOUBLE;
223 else if( !strcmp( psz_attrvalue, "half" ) )
225 fullscreen = FULLSCREEN_HALF;
227 else if( !strcmp( psz_attrvalue, "current" ) )
229 fullscreen = FULLSCREEN_CURRENT;
231 else if( !strcmp( psz_attrvalue, "full" ) )
233 fullscreen = FULLSCREEN_FULL;
237 fullscreen = FULLSCREEN_NORMAL;
240 else if( !strcmp( psz_attrname, "href" ) )
242 psz_href = psz_attrvalue;
243 psz_attrvalue = NULL;
245 else if( !strcmp( psz_attrname, "kioskmode" ) )
247 if( !strcmp( psz_attrvalue, "true" ) )
249 b_kioskmode = VLC_TRUE;
253 b_kioskmode = VLC_FALSE;
256 else if( !strcmp( psz_attrname, "loop" ) )
258 if( !strcmp( psz_attrvalue, "true" ) )
262 else if( !strcmp( psz_attrvalue, "palindrome" ) )
264 loop = LOOP_PALINDROME;
271 else if( !strcmp( psz_attrname, "movieid" ) )
273 i_movieid = atoi( psz_attrvalue );
275 else if( !strcmp( psz_attrname, "moviename" ) )
277 psz_moviename = psz_attrvalue;
278 psz_attrvalue = NULL;
280 else if( !strcmp( psz_attrname, "playeveryframe" ) )
282 if( !strcmp( psz_attrvalue, "true" ) )
284 b_playeveryframe = VLC_TRUE;
288 b_playeveryframe = VLC_FALSE;
291 else if( !strcmp( psz_attrname, "qtnext" ) )
293 psz_qtnext = psz_attrvalue;
294 psz_attrvalue = NULL;
296 else if( !strcmp( psz_attrname, "quitwhendone" ) )
298 if( !strcmp( psz_attrvalue, "true" ) )
300 b_quitwhendone = VLC_TRUE;
304 b_quitwhendone = VLC_FALSE;
307 else if( !strcmp( psz_attrname, "src" ) )
309 psz_src = psz_attrvalue;
310 psz_attrvalue = NULL;
312 else if( !strcmp( psz_attrname, "mimetype" ) )
314 psz_mimetype = psz_attrvalue;
315 psz_attrvalue = NULL;
317 else if( !strcmp( psz_attrname, "volume" ) )
319 i_volume = atoi( psz_attrvalue );
323 msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
324 psz_attrname, psz_attrvalue );
326 FREE( psz_attrname );
327 FREE( psz_attrvalue );
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 );
354 msg_Err( p_demux, "Mandatory attribute 'src' not found" );
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,
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,
380 HANDLE_PLAY_AND_RELEASE;
382 p_sys->p_playlist = NULL;
385 FREE( psz_moviename );
388 FREE( psz_mimetype );
393 static int Control( demux_t *p_demux, int i_query, va_list args )