]> git.sesse.net Git - vlc/blob - modules/demux/playlist/ifo.c
macosx: retain objects in MainMenu object
[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 VLC authors and VideoLAN
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 it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * 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
43 /*****************************************************************************
44  * Import_IFO: main import function
45  *****************************************************************************/
46 int Import_IFO( vlc_object_t *p_this )
47 {
48     demux_t *p_demux = (demux_t *)p_this;
49
50     if( !p_demux->psz_file )
51         return VLC_EGENERIC;
52
53     size_t len = strlen( p_demux->psz_file );
54
55     char *psz_file = p_demux->psz_file + len - strlen( "VIDEO_TS.IFO" );
56     /* Valid filenames are :
57      *  - VIDEO_TS.IFO
58      *  - VTS_XX_X.IFO where X are digits
59      */
60     if( len > strlen( "VIDEO_TS.IFO" )
61         && ( !strcasecmp( psz_file, "VIDEO_TS.IFO" )
62         || (!strncasecmp( psz_file, "VTS_", 4 )
63         && !strcasecmp( psz_file + strlen( "VTS_00_0" ) , ".IFO" ) ) ) )
64     {
65         int i_peek;
66         const uint8_t *p_peek;
67         i_peek = stream_Peek( p_demux->s, &p_peek, 8 );
68
69         if( i_peek != 8 || memcmp( p_peek, "DVDVIDEO", 8 ) )
70             return VLC_EGENERIC;
71
72         p_demux->pf_demux = Demux;
73     }
74     /* Valid filename for DVD-VR is VR_MANGR.IFO */
75     else if( len >= 12 && !strcmp( &p_demux->psz_file[len-12], "VR_MANGR.IFO" ) )
76     {
77         int i_peek;
78         const uint8_t *p_peek;
79         i_peek = stream_Peek( p_demux->s, &p_peek, 8 );
80
81         if( i_peek != 8 || memcmp( p_peek, "DVD_RTR_", 8 ) )
82             return VLC_EGENERIC;
83
84         p_demux->pf_demux = DemuxDVD_VR;
85     }
86     else
87         return VLC_EGENERIC;
88
89 //    STANDARD_DEMUX_INIT_MSG( "found valid VIDEO_TS.IFO" )
90     p_demux->pf_control = Control;
91
92     return VLC_SUCCESS;
93 }
94
95 static int Demux( demux_t *p_demux )
96 {
97     char *psz_url, *psz_dir;
98
99     psz_dir = strrchr( p_demux->psz_location, '/' );
100     if( psz_dir != NULL )
101        psz_dir[1] = '\0';
102
103     if( asprintf( &psz_url, "dvd://%s", p_demux->psz_location ) == -1 )
104         return 0;
105
106     input_item_t *p_current_input = GetCurrentItem(p_demux);
107     input_item_t *p_input = input_item_New( psz_url, psz_url );
108     input_item_PostSubItem( p_current_input, p_input );
109     vlc_gc_decref( p_input );
110
111     vlc_gc_decref(p_current_input);
112     free( psz_url );
113
114     return 0; /* Needed for correct operation of go back */
115 }
116
117 static int DemuxDVD_VR( demux_t *p_demux )
118 {
119     size_t len = strlen( p_demux->psz_location );
120     char *psz_url = malloc( len + 1 );
121
122     if( unlikely( psz_url == NULL ) )
123         return 0;
124     assert( len >= 12 );
125     len -= 12;
126     memcpy( psz_url, p_demux->psz_location, len );
127     memcpy( psz_url + len, "VR_MOVIE.VRO", 13 );
128
129     input_item_t *p_current_input = GetCurrentItem(p_demux);
130     input_item_t *p_input = input_item_New( psz_url, psz_url );
131     input_item_PostSubItem( p_current_input, p_input );
132
133     vlc_gc_decref( p_input );
134
135     vlc_gc_decref(p_current_input);
136     free( psz_url );
137
138     return 0; /* Needed for correct operation of go back */
139 }