]> git.sesse.net Git - vlc/blob - modules/access/dvdplay/tools.c
* demuxes: Worked around a bug in old VLC and VLS by changing TS stream types
[vlc] / modules / access / dvdplay / tools.c
1 /*****************************************************************************
2  * tools.c: tools for dvd plugin.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: tools.c,v 1.1 2002/08/04 17:23:42 sam Exp $
6  *
7  * Author: Stéphane Borel <stef@via.ecp.fr>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <sys/stat.h>
30 #include <errno.h>
31
32 #include <vlc/vlc.h>
33
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
36 #include "input_ext-dec.h"
37 #include "input_ext-plugins.h"
38
39 #include "dvd.h"
40
41 /*****************************************************************************
42  * dvdplay_ParseCL: parse command line
43  *****************************************************************************/
44 char * dvdplay_ParseCL( input_thread_t * p_input,
45                        int * i_title, int * i_chapter, int * i_angle )
46 {
47     dvd_data_t *            p_dvd;
48     struct stat             stat_info;
49     char *                  psz_parser;
50     char *                  psz_source;
51     char *                  psz_next;
52     
53     p_dvd = (dvd_data_t*)(p_input->p_access_data);
54
55     psz_parser = psz_source = strdup( p_input->psz_name );
56     if( !psz_parser )
57     {
58         return NULL;
59     }
60
61     while( *psz_parser && *psz_parser != '@' )
62     {
63         psz_parser++;
64     }
65
66     *i_title = 0;
67     *i_chapter = 1;
68     *i_angle = 1;
69     
70     if( *psz_parser == '@' )
71     {
72         /* Found options */
73         *psz_parser = '\0';
74         ++psz_parser;
75
76         *i_title = (int)strtol( psz_parser, &psz_next, 10 );
77         if( *psz_next )
78         {
79             psz_parser = psz_next + 1;
80             *i_chapter = (int)strtol( psz_parser, &psz_next, 10 );
81             if( *psz_next )
82             {
83                 *i_angle = (int)strtol( psz_next + 1, NULL, 10 );
84             }
85         }
86     }
87
88     *i_title   = *i_title >= 0 ? *i_title : 0;
89     *i_chapter = *i_chapter    ? *i_chapter : 1;
90     *i_angle   = *i_angle      ? *i_angle : 1;
91
92     if( !*psz_source )
93     {
94         free( psz_source );
95         if( !p_input->psz_access )
96         {
97             return NULL;
98         }
99         psz_source = config_GetPsz( p_input, "dvd" );
100     }
101
102     if( stat( psz_source, &stat_info ) == -1 )
103     {
104         msg_Err( p_input, "cannot stat() source `%s' (%s)",
105                      psz_source, strerror(errno));
106         return NULL;
107     }
108     if( !S_ISBLK(stat_info.st_mode) &&
109         !S_ISCHR(stat_info.st_mode) &&
110         !S_ISDIR(stat_info.st_mode) )
111     {
112         msg_Dbg( p_input, "plugin discarded"
113                          " (not a valid source)" );
114         return NULL;
115     }
116     
117     msg_Dbg( p_input, "dvdroot=%s title=%d chapter=%d angle=%d",
118                   psz_source,  *i_title, *i_chapter, *i_angle );
119     
120     return psz_source;
121 }