]> git.sesse.net Git - vlc/blob - modules/demux/playlist/ifo.c
4dbdb73211fc817118406e7e142ad0276ce32770
[vlc] / modules / demux / playlist / ifo.c
1 /*****************************************************************************
2  * ifo.c: Dummy ifo demux to enable opening DVDs rips by double cliking on VIDEO_TS.IFO
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea @t videolan d.t 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  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_demux.h>
33 #include <assert.h>
34
35 #include "playlist.h"
36
37 /*****************************************************************************
38  * Local prototypes
39  *****************************************************************************/
40 static int Demux( demux_t *p_demux);
41 static int DemuxDVD_VR( demux_t *p_demux);
42 static int Control( demux_t *p_demux, int i_query, va_list args );
43
44 /*****************************************************************************
45  * Import_IFO: main import function
46  *****************************************************************************/
47 int Import_IFO( vlc_object_t *p_this )
48 {
49     demux_t *p_demux = (demux_t *)p_this;
50
51     if( !p_demux->psz_file )
52         return VLC_EGENERIC;
53
54     size_t len = strlen( p_demux->psz_file );
55
56     char *psz_file = p_demux->psz_file + len - strlen( "VIDEO_TS.IFO" );
57     /* Valid filenames are :
58      *  - VIDEO_TS.IFO
59      *  - VTS_XX_X.IFO where X are digits
60      */
61     if( len > strlen( "VIDEO_TS.IFO" )
62         && ( !strcasecmp( psz_file, "VIDEO_TS.IFO" )
63         || (!strncasecmp( psz_file, "VTS_", 4 )
64         && !strcasecmp( psz_file + strlen( "VTS_00_0" ) , ".IFO" ) ) ) )
65     {
66         int i_peek;
67         const uint8_t *p_peek;
68         i_peek = stream_Peek( p_demux->s, &p_peek, 8 );
69
70         if( i_peek != 8 || memcmp( p_peek, "DVDVIDEO", 8 ) )
71             return VLC_EGENERIC;
72
73         p_demux->pf_demux = Demux;
74     }
75     /* Valid filename for DVD-VR is VR_MANGR.IFO */
76     else if( len >= 12 && !strcmp( &p_demux->psz_file[len-12], "VR_MANGR.IFO" ) )
77     {
78         int i_peek;
79         const uint8_t *p_peek;
80         i_peek = stream_Peek( p_demux->s, &p_peek, 8 );
81
82         if( i_peek != 8 || memcmp( p_peek, "DVD_RTR_", 8 ) )
83             return VLC_EGENERIC;
84
85         p_demux->pf_demux = DemuxDVD_VR;
86     }
87     else
88         return VLC_EGENERIC;
89
90 //    STANDARD_DEMUX_INIT_MSG( "found valid VIDEO_TS.IFO" )
91     p_demux->pf_control = Control;
92
93     return VLC_SUCCESS;
94 }
95
96 /*****************************************************************************
97  * Deactivate: frees unused data
98  *****************************************************************************/
99 void Close_IFO( vlc_object_t *p_this )
100 {
101     VLC_UNUSED(p_this);
102 }
103
104 static int Demux( demux_t *p_demux )
105 {
106     char *psz_url;
107
108     if( asprintf( &psz_url, "dvd://%s", p_demux->psz_location ) == -1 )
109         return 0;
110
111     input_item_t *p_current_input = GetCurrentItem(p_demux);
112     input_item_t *p_input = input_item_New( p_demux, psz_url, psz_url );
113     input_item_PostSubItem( p_current_input, p_input );
114     vlc_gc_decref( p_input );
115
116     vlc_gc_decref(p_current_input);
117     free( psz_url );
118
119     return 0; /* Needed for correct operation of go back */
120 }
121
122 static int DemuxDVD_VR( demux_t *p_demux )
123 {
124     size_t len = strlen( p_demux->psz_location );
125     char *psz_url = malloc( len + 1 );
126
127     if( unlikely( psz_url == NULL ) )
128         return 0;
129     assert( len >= 12 );
130     len -= 12;
131     memcpy( psz_url, p_demux->psz_location, len );
132     memcpy( psz_url + len, "VR_MOVIE.VRO", 13 );
133
134     input_item_t *p_current_input = GetCurrentItem(p_demux);
135     input_item_t *p_input = input_item_New( p_demux, psz_url, psz_url );
136     input_item_PostSubItem( p_current_input, p_input );
137
138     vlc_gc_decref( p_input );
139
140     vlc_gc_decref(p_current_input);
141     free( psz_url );
142
143     return 0; /* Needed for correct operation of go back */
144 }
145
146
147 static int Control( demux_t *p_demux, int i_query, va_list args )
148 {
149     VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
150     return VLC_EGENERIC;
151 }