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>
61 typedef enum { FULLSCREEN_NORMAL,
65 FULLSCREEN_FULL } qtl_fullscreen_t;
66 const char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
67 typedef enum { LOOP_TRUE,
69 LOOP_PALINDROME } qtl_loop_t;
70 const char* ppsz_loop[] = { "true", "false", "palindrome" };
72 /*****************************************************************************
74 *****************************************************************************/
75 static int Demux( demux_t *p_demux);
76 static int Control( demux_t *p_demux, int i_query, va_list args );
78 /*****************************************************************************
79 * Import_QTL: main import function
80 *****************************************************************************/
81 int Import_QTL( vlc_object_t *p_this )
83 demux_t *p_demux = (demux_t *)p_this;
85 if( !demux_IsPathExtension( p_demux, ".qtl" ) )
88 p_demux->pf_demux = Demux;
89 p_demux->pf_control = Control;
90 msg_Dbg( p_demux, "using QuickTime Media Link reader" );
95 /*****************************************************************************
96 * Deactivate: frees unused data
97 *****************************************************************************/
98 void Close_QTL( vlc_object_t *p_this )
103 static int Demux( demux_t *p_demux )
105 xml_reader_t *p_xml_reader;
106 char *psz_eltname = NULL;
107 input_item_t *p_input;
110 /* List of all possible attributes. The only required one is "src" */
111 bool b_autoplay = false;
112 bool b_controler = true;
113 qtl_fullscreen_t fullscreen = false;
114 char *psz_href = NULL;
115 bool b_kioskmode = false;
116 qtl_loop_t loop = LOOP_FALSE;
118 char *psz_moviename = NULL;
119 bool b_playeveryframe = false;
120 char *psz_qtnext = NULL;
121 bool b_quitwhendone = false;
122 char *psz_src = NULL;
123 char *psz_mimetype = NULL;
126 input_item_t *p_current_input = GetCurrentItem(p_demux);
128 p_xml_reader = xml_ReaderCreate( p_demux, p_demux->s );
132 /* check root node */
133 if( xml_ReaderNextNode( p_xml_reader ) != XML_READER_STARTELEM ||
134 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
135 strcmp( psz_eltname, "embed" ) )
137 msg_Err( p_demux, "invalid root node: %s", psz_eltname );
141 /* second line has <?quicktime tag ... so we try to skip it */
142 msg_Dbg( p_demux, "trying to read one more node" );
143 if( xml_ReaderNextNode( p_xml_reader ) != XML_READER_STARTELEM ||
144 ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
145 strcmp( psz_eltname, "embed" ) )
147 msg_Err( p_demux, "invalid root node: %s", psz_eltname );
154 const char *attrname;
155 while( (attrname = xml_ReaderNextAttr( p_xml_reader )) != NULL )
157 char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
161 free( psz_attrvalue );
165 if( !strcmp( attrname, "autoplay" ) )
166 b_autoplay = !strcmp( psz_attrvalue, "true" );
167 else if( !strcmp( attrname, "controler" ) )
168 b_controler = !strcmp( psz_attrvalue, "false" );
169 else if( !strcmp( attrname, "fullscreen" ) )
171 if( !strcmp( psz_attrvalue, "double" ) )
172 fullscreen = FULLSCREEN_DOUBLE;
173 else if( !strcmp( psz_attrvalue, "half" ) )
174 fullscreen = FULLSCREEN_HALF;
175 else if( !strcmp( psz_attrvalue, "current" ) )
176 fullscreen = FULLSCREEN_CURRENT;
177 else if( !strcmp( psz_attrvalue, "full" ) )
178 fullscreen = FULLSCREEN_FULL;
180 fullscreen = FULLSCREEN_NORMAL;
182 else if( !strcmp( attrname, "href" ) )
184 psz_href = psz_attrvalue;
185 psz_attrvalue = NULL;
187 else if( !strcmp( attrname, "kioskmode" ) )
188 b_kioskmode = !strcmp( psz_attrvalue, "true" );
189 else if( !strcmp( attrname, "loop" ) )
191 if( !strcmp( psz_attrvalue, "true" ) )
193 else if( !strcmp( psz_attrvalue, "palindrome" ) )
194 loop = LOOP_PALINDROME;
198 else if( !strcmp( attrname, "movieid" ) )
199 i_movieid = atoi( psz_attrvalue );
200 else if( !strcmp( attrname, "moviename" ) )
202 psz_moviename = psz_attrvalue;
203 psz_attrvalue = NULL;
205 else if( !strcmp( attrname, "playeveryframe" ) )
206 b_playeveryframe = !strcmp( psz_attrvalue, "true" );
207 else if( !strcmp( attrname, "qtnext" ) )
209 psz_qtnext = psz_attrvalue;
210 psz_attrvalue = NULL;
212 else if( !strcmp( attrname, "quitwhendone" ) )
213 b_quitwhendone = !strcmp( psz_attrvalue, "true" );
214 else if( !strcmp( attrname, "src" ) )
216 psz_src = psz_attrvalue;
217 psz_attrvalue = NULL;
219 else if( !strcmp( attrname, "mimetype" ) )
221 psz_mimetype = psz_attrvalue;
222 psz_attrvalue = NULL;
224 else if( !strcmp( attrname, "volume" ) )
225 i_volume = atoi( psz_attrvalue );
227 msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
228 attrname, psz_attrvalue );
229 free( psz_attrvalue );
232 msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
233 b_autoplay ? "true": "false" );
234 msg_Dbg( p_demux, "controler: %s (unused by VLC)",
235 b_controler ? "true": "false" );
236 msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
237 ppsz_fullscreen[fullscreen] );
238 msg_Dbg( p_demux, "href: %s", psz_href );
239 msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
240 b_kioskmode ? "true":"false" );
241 msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
242 msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
243 msg_Dbg( p_demux, "moviename: %s", psz_moviename );
244 msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
245 b_playeveryframe ? "true":"false" );
246 msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
247 msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
248 b_quitwhendone ? "true":"false" );
249 msg_Dbg( p_demux, "src: %s", psz_src );
250 msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
251 msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
256 msg_Err( p_demux, "Mandatory attribute 'src' not found" );
260 input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
261 p_input = input_item_New( p_demux, psz_src, psz_moviename );
262 #define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \
263 p_input, "QuickTime Media Link", type, "%s", field ) ; }
264 SADD_INFO( "href", psz_href );
265 SADD_INFO( _("Mime"), psz_mimetype );
266 input_item_node_AppendItem( p_subitems, p_input );
267 vlc_gc_decref( p_input );
270 p_input = input_item_New( p_demux, psz_qtnext, NULL );
271 input_item_node_AppendItem( p_subitems, p_input );
272 vlc_gc_decref( p_input );
274 input_item_node_PostAndDelete( p_subitems );
277 i_ret = 0; /* Needed for correct operation of go back */
281 xml_ReaderDelete( p_xml_reader );
283 vlc_gc_decref(p_current_input);
286 free( psz_moviename );
289 free( psz_mimetype );
293 static int Control( demux_t *p_demux, int i_query, va_list args )
295 VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);