]> git.sesse.net Git - vlc/blob - modules/demux/playlist/ifo.c
a8d5a65cd2d01625ed39187f9aaf781f8d0cb7c5
[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 #include <vlc/vlc.h>
28 #include <vlc_demux.h>
29
30 #include <errno.h>                                                 /* ENOMEM */
31 #include "playlist.h"
32
33 /*****************************************************************************
34  * Local prototypes
35  *****************************************************************************/
36 static int Demux( demux_t *p_demux);
37 static int Control( demux_t *p_demux, int i_query, va_list args );
38
39 /*****************************************************************************
40  * Import_IFO: main import function
41  *****************************************************************************/
42 int E_(Import_IFO)( vlc_object_t *p_this )
43 {
44     demux_t *p_demux = (demux_t *)p_this;
45
46     char *psz_file = p_demux->psz_path + strlen( p_demux->psz_path )
47                      - strlen( "VIDEO_TS.IFO" );
48     /* Valid filenamed are :
49      *  - VIDEO_TS.IFO
50      *  - VTS_XX_X.IFO where X are digits
51      */
52     if( strlen( p_demux->psz_path ) > strlen( "VIDEO_TS.IFO" )
53         && ( !strcasecmp( psz_file, "VIDEO_TS.IFO" )
54         || (!strncasecmp( psz_file, "VTS_", 4 )
55         && !strcasecmp( psz_file + strlen( "VTS_00_0" ) , ".IFO" ) ) ) )
56     {
57         int i_peek;
58         byte_t *p_peek;
59         i_peek = stream_Peek( p_demux->s, &p_peek, 8 );
60
61         if( strncmp( p_peek, "DVDVIDEO", 8 ) )
62             return VLC_EGENERIC;
63     }
64     else
65         return VLC_EGENERIC;
66
67 //    STANDARD_DEMUX_INIT_MSG( "found valid VIDEO_TS.IFO" )
68     p_demux->pf_control = Control;
69     p_demux->pf_demux = Demux;
70
71     return VLC_SUCCESS;
72 }
73
74 /*****************************************************************************
75  * Deactivate: frees unused data
76  *****************************************************************************/
77 void E_(Close_IFO)( vlc_object_t *p_this )
78 {
79 }
80
81 static int Demux( demux_t *p_demux )
82 {
83     char *psz_url = NULL;
84     char *psz_file = p_demux->psz_path + strlen( p_demux->psz_path )
85                      - strlen( "VIDEO_TS.IFO" );
86     size_t len = 0;
87     input_item_t *p_input;
88
89     INIT_PLAYLIST_STUFF;
90
91     len = strlen( "dvd://" ) + strlen( p_demux->psz_path )
92           - strlen( "VIDEO_TS.IFO" );
93     psz_url = (char *)malloc( len+1 );
94     snprintf( psz_url, len+1, "dvd://%s", p_demux->psz_path );
95
96     p_input = input_ItemNewExt( p_playlist, psz_url, psz_url, 0, NULL, -1 );
97     playlist_BothAddInput( p_playlist, p_input,
98                            p_item_in_category,
99                            PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
100                            PLAYLIST_END, NULL, NULL, VLC_FALSE );
101
102     HANDLE_PLAY_AND_RELEASE;
103
104     return -1; /* Needed for correct operation of go back */
105 }
106
107 static int Control( demux_t *p_demux, int i_query, va_list args )
108 {
109     return VLC_EGENERIC;
110 }