]> git.sesse.net Git - vlc/blob - modules/demux/playlist/qtl.c
ASF: better logging and more consistent with MKV/MP4 demux
[vlc] / modules / demux / playlist / qtl.c
1 /*****************************************************************************
2  * qtl.c: QuickTime Media Link Importer
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -@t- videolan -Dot- org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*
25 See
26 http://developer.apple.com/documentation/QuickTime/QT6WhatsNew/Chap1/chapter_1_section_54.html
27 and
28 http://developer.apple.com/documentation/QuickTime/WhatsNewQT5/QT5NewChapt1/chapter_1_section_39.html
29
30 autoplay - true/false
31 controller - true/false
32 fullscreen - normal/double/half/current/full
33 href - url
34 kioskmode - true/false
35 loop - true/false/palindrome
36 movieid - integer
37 moviename - string
38 playeveryframe - true/false
39 qtnext - url
40 quitwhendone - true/false
41 src - url (required)
42 type - mime type
43 volume - 0 (mute) - 100 (max)
44
45 */
46
47 /*****************************************************************************
48  * Preamble
49  *****************************************************************************/
50
51 #ifdef HAVE_CONFIG_H
52 # include "config.h"
53 #endif
54
55 #include <vlc_common.h>
56 #include <vlc_demux.h>
57
58 #include "playlist.h"
59 #include <vlc_xml.h>
60
61 typedef enum { FULLSCREEN_NORMAL,
62                FULLSCREEN_DOUBLE,
63                FULLSCREEN_HALF,
64                FULLSCREEN_CURRENT,
65                FULLSCREEN_FULL } qtl_fullscreen_t;
66 const char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
67 typedef enum { LOOP_TRUE,
68                LOOP_FALSE,
69                LOOP_PALINDROME } qtl_loop_t;
70 const char* ppsz_loop[] = { "true", "false", "palindrome" };
71
72 /*****************************************************************************
73  * Local prototypes
74  *****************************************************************************/
75 static int Demux( demux_t *p_demux);
76
77 /*****************************************************************************
78  * Import_QTL: main import function
79  *****************************************************************************/
80 int Import_QTL( vlc_object_t *p_this )
81 {
82     demux_t *p_demux = (demux_t *)p_this;
83
84     if( !demux_IsPathExtension( p_demux, ".qtl" ) )
85         return VLC_EGENERIC;
86
87     p_demux->pf_demux = Demux;
88     p_demux->pf_control = Control;
89     msg_Dbg( p_demux, "using QuickTime Media Link reader" );
90
91     return VLC_SUCCESS;
92 }
93
94 static int Demux( demux_t *p_demux )
95 {
96     xml_reader_t *p_xml_reader;
97     const char *node;
98     input_item_t *p_input;
99     int i_ret = -1;
100
101     /* List of all possible attributes. The only required one is "src" */
102     bool b_autoplay = false;
103     bool b_controler = true;
104     qtl_fullscreen_t fullscreen = false;
105     char *psz_href = NULL;
106     bool b_kioskmode = false;
107     qtl_loop_t loop = LOOP_FALSE;
108     int i_movieid = -1;
109     char *psz_moviename = NULL;
110     bool b_playeveryframe = false;
111     char *psz_qtnext = NULL;
112     bool b_quitwhendone = false;
113     char *psz_src = NULL;
114     char *psz_mimetype = NULL;
115     int i_volume = 100;
116
117     input_item_t *p_current_input = GetCurrentItem(p_demux);
118
119     p_xml_reader = xml_ReaderCreate( p_demux, p_demux->s );
120     if( !p_xml_reader )
121         goto error;
122
123     /* check root node */
124     if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM
125      || strcmp( node, "embed" ) )
126     {
127         msg_Err( p_demux, "invalid root node <%s>", node );
128
129         /* second line has <?quicktime tag ... so we try to skip it */
130         msg_Dbg( p_demux, "trying to read one more node" );
131         if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM
132          || strcmp( node, "embed" ) )
133         {
134             msg_Err( p_demux, "invalid root node <%s>", node );
135             goto error;
136         }
137     }
138
139     const char *attrname, *value;
140     while( (attrname = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
141     {
142         if( !strcmp( attrname, "autoplay" ) )
143             b_autoplay = !strcmp( value, "true" );
144         else if( !strcmp( attrname, "controler" ) )
145             b_controler = !strcmp( attrname, "false" );
146         else if( !strcmp( attrname, "fullscreen" ) )
147         {
148             if( !strcmp( value, "double" ) )
149                 fullscreen = FULLSCREEN_DOUBLE;
150             else if( !strcmp( value, "half" ) )
151                 fullscreen = FULLSCREEN_HALF;
152             else if( !strcmp( value, "current" ) )
153                 fullscreen = FULLSCREEN_CURRENT;
154             else if( !strcmp( value, "full" ) )
155                 fullscreen = FULLSCREEN_FULL;
156             else
157                 fullscreen = FULLSCREEN_NORMAL;
158         }
159         else if( !strcmp( attrname, "href" ) )
160         {
161             free( psz_href );
162             psz_href = strdup( value );
163         }
164         else if( !strcmp( attrname, "kioskmode" ) )
165             b_kioskmode = !strcmp( value, "true" );
166         else if( !strcmp( attrname, "loop" ) )
167         {
168             if( !strcmp( value, "true" ) )
169                 loop = LOOP_TRUE;
170             else if( !strcmp( value, "palindrome" ) )
171                 loop = LOOP_PALINDROME;
172             else
173                 loop = LOOP_FALSE;
174         }
175         else if( !strcmp( attrname, "movieid" ) )
176             i_movieid = atoi( value );
177         else if( !strcmp( attrname, "moviename" ) )
178         {
179             free( psz_moviename );
180             psz_moviename = strdup( value );
181         }
182         else if( !strcmp( attrname, "playeveryframe" ) )
183             b_playeveryframe = !strcmp( value, "true" );
184         else if( !strcmp( attrname, "qtnext" ) )
185         {
186             free( psz_qtnext );
187             psz_qtnext = strdup( value );
188         }
189         else if( !strcmp( attrname, "quitwhendone" ) )
190             b_quitwhendone = !strcmp( value, "true" );
191         else if( !strcmp( attrname, "src" ) )
192         {
193             free( psz_src );
194             psz_src = strdup( value );
195         }
196         else if( !strcmp( attrname, "mimetype" ) )
197         {
198             free( psz_mimetype );
199             psz_mimetype = strdup( value );
200         }
201         else if( !strcmp( attrname, "volume" ) )
202             i_volume = atoi( value );
203         else
204             msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
205                      attrname, value );
206     }
207
208     msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
209              b_autoplay ? "true": "false" );
210     msg_Dbg( p_demux, "controler: %s (unused by VLC)",
211              b_controler ? "true": "false" );
212     msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
213              ppsz_fullscreen[fullscreen] );
214     msg_Dbg( p_demux, "href: %s", psz_href );
215     msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
216              b_kioskmode ? "true":"false" );
217     msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
218     msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
219     msg_Dbg( p_demux, "moviename: %s", psz_moviename );
220     msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
221              b_playeveryframe ? "true":"false" );
222     msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
223     msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
224              b_quitwhendone ? "true":"false" );
225     msg_Dbg( p_demux, "src: %s", psz_src );
226     msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
227     msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
228
229
230     if( !psz_src )
231     {
232         msg_Err( p_demux, "Mandatory attribute 'src' not found" );
233     }
234     else
235     {
236         input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
237         p_input = input_item_New( psz_src, psz_moviename );
238 #define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \
239                     p_input, "QuickTime Media Link", type, "%s", field ) ; }
240         SADD_INFO( "href", psz_href );
241         SADD_INFO( _("Mime"), psz_mimetype );
242         input_item_node_AppendItem( p_subitems, p_input );
243         vlc_gc_decref( p_input );
244         if( psz_qtnext )
245         {
246             p_input = input_item_New( psz_qtnext, NULL );
247             input_item_node_AppendItem( p_subitems, p_input );
248             vlc_gc_decref( p_input );
249         }
250         input_item_node_PostAndDelete( p_subitems );
251     }
252
253     i_ret = 0; /* Needed for correct operation of go back */
254
255 error:
256     if( p_xml_reader )
257         xml_ReaderDelete( p_xml_reader );
258
259     vlc_gc_decref(p_current_input);
260
261     free( psz_href );
262     free( psz_moviename );
263     free( psz_qtnext );
264     free( psz_src );
265     free( psz_mimetype );
266     return i_ret;
267 }