various modules: adjust to new playlist design
[vlc.git] / modules / demux / playlist / ifo.c
blobb66a42e2dc168083cd9ad81c9a1b03e23d30aefa
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$
7 * Authors: Antoine Cellerier <dionoea @t videolan d.t 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 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_demux.h>
34 #include "playlist.h"
36 /*****************************************************************************
37 * Local prototypes
38 *****************************************************************************/
39 static int Demux( demux_t *p_demux);
40 static int DemuxDVD_VR( demux_t *p_demux);
41 static int Control( demux_t *p_demux, int i_query, va_list args );
43 /*****************************************************************************
44 * Import_IFO: main import function
45 *****************************************************************************/
46 int Import_IFO( vlc_object_t *p_this )
48 demux_t *p_demux = (demux_t *)p_this;
50 size_t len = strlen( p_demux->psz_path );
52 char *psz_file = p_demux->psz_path + len - strlen( "VIDEO_TS.IFO" );
53 /* Valid filenames are :
54 * - VIDEO_TS.IFO
55 * - VTS_XX_X.IFO where X are digits
57 if( len > strlen( "VIDEO_TS.IFO" )
58 && ( !strcasecmp( psz_file, "VIDEO_TS.IFO" )
59 || (!strncasecmp( psz_file, "VTS_", 4 )
60 && !strcasecmp( psz_file + strlen( "VTS_00_0" ) , ".IFO" ) ) ) )
62 int i_peek;
63 const uint8_t *p_peek;
64 i_peek = stream_Peek( p_demux->s, &p_peek, 8 );
66 if( i_peek != 8 || memcmp( p_peek, "DVDVIDEO", 8 ) )
67 return VLC_EGENERIC;
69 p_demux->pf_demux = Demux;
71 /* Valid filename for DVD-VR is VR_MANGR.IFO */
72 else if( len >= 12 && !strcmp( &p_demux->psz_path[len-12], "VR_MANGR.IFO" ) )
74 int i_peek;
75 const uint8_t *p_peek;
76 i_peek = stream_Peek( p_demux->s, &p_peek, 8 );
78 if( i_peek != 8 || memcmp( p_peek, "DVD_RTR_", 8 ) )
79 return VLC_EGENERIC;
81 p_demux->pf_demux = DemuxDVD_VR;
83 else
84 return VLC_EGENERIC;
86 // STANDARD_DEMUX_INIT_MSG( "found valid VIDEO_TS.IFO" )
87 p_demux->pf_control = Control;
89 return VLC_SUCCESS;
92 /*****************************************************************************
93 * Deactivate: frees unused data
94 *****************************************************************************/
95 void Close_IFO( vlc_object_t *p_this )
97 VLC_UNUSED(p_this);
100 static int Demux( demux_t *p_demux )
102 size_t len = strlen( "dvd://" ) + strlen( p_demux->psz_path )
103 - strlen( "VIDEO_TS.IFO" );
104 char *psz_url;
106 psz_url = malloc( len+1 );
107 if( !psz_url )
108 return 0;
109 snprintf( psz_url, len+1, "dvd://%s", p_demux->psz_path );
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_AddSubItem( p_current_input, p_input );
114 input_item_AddSubItem2( p_current_input, p_input );
115 vlc_gc_decref( p_input );
117 vlc_gc_decref(p_current_input);
118 free( psz_url );
120 return 0; /* Needed for correct operation of go back */
123 static int DemuxDVD_VR( demux_t *p_demux )
125 char *psz_url = strdup( p_demux->psz_path );
127 if( !psz_url )
128 return 0;
130 size_t len = strlen( psz_url );
132 strncpy( psz_url + len - 12, "VR_MOVIE.VRO", 12 );
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_AddSubItem( p_current_input, p_input );
137 input_item_AddSubItem2( p_current_input, p_input );
139 vlc_gc_decref( p_input );
141 vlc_gc_decref(p_current_input);
142 free( psz_url );
144 return 0; /* Needed for correct operation of go back */
148 static int Control( demux_t *p_demux, int i_query, va_list args )
150 VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
151 return VLC_EGENERIC;