]> git.sesse.net Git - vlc/blob - plugins/dvd/dvd_demux.c
* ALL: new module API. Makes a few things a lot simpler, and we gain
[vlc] / plugins / dvd / dvd_demux.c
1 /* dvd_demux.c: DVD demux functions.
2  *****************************************************************************
3  * Copyright (C) 1998-2001 VideoLAN
4  * $Id: dvd_demux.c,v 1.8 2002/07/31 20:56:51 sam Exp $
5  *
6  * Author: Stéphane Borel <stef@via.ecp.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/input.h>
32
33 #ifdef HAVE_UNISTD_H
34 #   include <unistd.h>
35 #endif
36
37 #include <fcntl.h>
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <string.h>
41 #include <errno.h>
42
43 #ifdef STRNCASECMP_IN_STRINGS_H
44 #   include <strings.h>
45 #endif
46
47 /* how many packets DVDDemux will read in each loop */
48 #define DVD_READ_ONCE 64
49
50 /*****************************************************************************
51  * Local prototypes
52  *****************************************************************************/
53 static int  DVDDemux   ( input_thread_t * );
54
55 void DVDLaunchDecoders( input_thread_t * );
56
57 /*
58  * Data demux functions
59  */
60
61 /*****************************************************************************
62  * DVDInit: initializes DVD structures
63  *****************************************************************************/
64 int E_(DVDInit) ( vlc_object_t *p_this )
65 {
66     input_thread_t *p_input = (input_thread_t *)p_this;
67
68     if( p_input->stream.i_method != INPUT_METHOD_DVD )
69     {
70         return -1;
71     }
72
73     p_input->pf_demux = DVDDemux;
74     p_input->pf_rewind = NULL;
75
76     vlc_mutex_lock( &p_input->stream.stream_lock );
77     
78     DVDLaunchDecoders( p_input );
79     
80     vlc_mutex_unlock( &p_input->stream.stream_lock );
81
82     return 0;
83 }
84
85 /*****************************************************************************
86  * DVDDemux
87  *****************************************************************************/
88 static int DVDDemux( input_thread_t * p_input )
89 {
90     data_packet_t *     p_data;
91     ssize_t             i_result;
92     int                 i;
93
94     /* Read headers to compute payload length */
95     for( i = 0 ; i < DVD_READ_ONCE ; i++ )
96     {
97         i_result = input_ReadPS( p_input, &p_data );
98
99         if( i_result < 0 )
100         {
101             return i_result;
102         }
103         else if( i_result == 0 )
104         {
105             return i;
106         }
107
108         input_DemuxPS( p_input, p_data );
109     }
110     
111     return i;
112 }