stream: replace input_thread_t by input_item_t
[vlc.git] / modules / demux / playlist / ifo.c
blob836acb7f7d1f804d22d5a774e0691e50d3e8f4ca
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$
7 * Authors: Antoine Cellerier <dionoea @t videolan d.t org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_access.h>
33 #include <vlc_url.h>
34 #include <assert.h>
36 #include "playlist.h"
38 /*****************************************************************************
39 * Local prototypes
40 *****************************************************************************/
41 static int ReadDVD( stream_t *, input_item_node_t * );
42 static int ReadDVD_VR( stream_t *, input_item_node_t * );
44 static const char *StreamLocation( const stream_t *s )
46 return s->psz_filepath ? s->psz_filepath : s->psz_url;
49 /*****************************************************************************
50 * Import_IFO: main import function
51 *****************************************************************************/
52 int Import_IFO( vlc_object_t *p_this )
54 stream_t *p_stream = (stream_t *)p_this;
56 CHECK_FILE(p_stream);
58 if( !stream_HasExtension( p_stream, ".IFO" ) )
59 return VLC_EGENERIC;
61 const char *psz_location = StreamLocation( p_stream );
62 if( psz_location == NULL )
63 return VLC_EGENERIC;
65 size_t len = strlen( psz_location );
66 if( len < 12 )
67 return VLC_EGENERIC;
69 const char *psz_probe;
70 const char *psz_file = &psz_location[len - 12];
71 /* Valid filenames are :
72 * - VIDEO_TS.IFO
73 * - VTS_XX_X.IFO where X are digits
75 if( !strncasecmp( psz_file, "VIDEO_TS", 8 ) ||
76 !strncasecmp( psz_file, "VTS_", 4 ) )
78 psz_probe = "DVDVIDEO";
79 p_stream->pf_readdir = ReadDVD;
81 /* Valid filename for DVD-VR is VR_MANGR.IFO */
82 else if( !strncasecmp( psz_file, "VR_MANGR", 8 ) )
84 psz_probe = "DVD_RTR_";
85 p_stream->pf_readdir = ReadDVD_VR;
87 else
88 return VLC_EGENERIC;
90 const uint8_t *p_peek;
91 ssize_t i_peek = vlc_stream_Peek( p_stream->s, &p_peek, 8 );
92 if( i_peek < 8 || memcmp( p_peek, psz_probe, 8 ) )
93 return VLC_EGENERIC;
95 p_stream->pf_control = access_vaDirectoryControlHelper;
97 return VLC_SUCCESS;
100 static int ReadDVD( stream_t *p_stream, input_item_node_t *node )
102 const char *psz_location = StreamLocation(p_stream);
104 char *psz_url = strndup( psz_location, strlen( psz_location ) - 12 );
105 if( !psz_url )
106 return VLC_ENOMEM;
108 input_item_t *p_input = input_item_New( psz_url, psz_url );
109 if( p_input )
111 input_item_AddOption( p_input, "demux=dvd", VLC_INPUT_OPTION_TRUSTED );
112 input_item_node_AppendItem( node, p_input );
113 input_item_Release( p_input );
116 free( psz_url );
118 return VLC_SUCCESS;
121 static int ReadDVD_VR( stream_t *p_stream, input_item_node_t *node )
123 const char *psz_location = StreamLocation(p_stream);
125 size_t len = strlen( psz_location );
126 char *psz_url = strdup( psz_location );
128 if( unlikely( psz_url == NULL ) )
129 return VLC_EGENERIC;
131 strcpy( &psz_url[len - 12], "VR_MOVIE.VRO" );
133 input_item_t *p_input = input_item_New( psz_url, psz_url );
134 if( p_input )
136 input_item_node_AppendItem( node, p_input );
137 input_item_Release( p_input );
140 free( psz_url );
142 return VLC_SUCCESS;