]> git.sesse.net Git - vlc/blob - modules/access/dvd/demux.c
21ef8366c558b9dae9f09d49c56262604f633f57
[vlc] / modules / access / dvd / demux.c
1 /* demux.c: DVD demux functions.
2  *****************************************************************************
3  * Copyright (C) 1998-2001 VideoLAN
4  * $Id: demux.c,v 1.2 2002/08/07 00:29:36 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 #include "../../demux/mpeg/system.h"
34
35 #ifdef HAVE_UNISTD_H
36 #   include <unistd.h>
37 #endif
38
39 #include <fcntl.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <string.h>
43 #include <errno.h>
44
45 #ifdef STRNCASECMP_IN_STRINGS_H
46 #   include <strings.h>
47 #endif
48
49 /* how many packets DVDDemux will read in each loop */
50 #define DVD_READ_ONCE 64
51
52 /*****************************************************************************
53  * Private structure
54  *****************************************************************************/
55 struct demux_sys_t
56 {
57     module_t *   p_module;
58     mpeg_demux_t mpeg;
59 };
60
61 /*****************************************************************************
62  * Local prototypes
63  *****************************************************************************/
64 static int  DVDDemux   ( input_thread_t * );
65
66 void DVDLaunchDecoders( input_thread_t * );
67
68 /*****************************************************************************
69  * DVDInit: initialize DVD structures
70  *****************************************************************************/
71 int E_(DVDInit) ( vlc_object_t *p_this )
72 {
73     input_thread_t *p_input = (input_thread_t *)p_this;
74     demux_sys_t *   p_demux;
75
76     if( p_input->stream.i_method != INPUT_METHOD_DVD )
77     {
78         return -1;
79     }
80
81     p_demux = p_input->p_demux_data = malloc( sizeof(demux_sys_t ) );
82     if( p_demux == NULL )
83     {
84         return -1;
85     }
86
87     p_input->p_private = (void*)&p_demux->mpeg;
88     p_demux->p_module = module_Need( p_input, "mpeg-system", NULL );
89     if( p_demux->p_module == NULL )
90     {
91         free( p_input->p_demux_data );
92         return -1;
93     }
94
95     p_input->pf_demux = DVDDemux;
96     p_input->pf_rewind = NULL;
97
98     vlc_mutex_lock( &p_input->stream.stream_lock );
99     
100     DVDLaunchDecoders( p_input );
101     
102     vlc_mutex_unlock( &p_input->stream.stream_lock );
103
104     return 0;
105 }
106
107 /*****************************************************************************
108  * DVDEnd: free DVD structures
109  *****************************************************************************/
110 void E_(DVDEnd) ( vlc_object_t *p_this )
111 {
112     input_thread_t *p_input = (input_thread_t *)p_this;
113
114     module_Unneed( p_input, p_input->p_demux_data->p_module );
115     free( p_input->p_demux_data );
116 }
117
118 /*****************************************************************************
119  * DVDDemux
120  *****************************************************************************/
121 static int DVDDemux( input_thread_t * p_input )
122 {
123     data_packet_t *     p_data;
124     ssize_t             i_result;
125     int                 i;
126
127     /* Read headers to compute payload length */
128     for( i = 0 ; i < DVD_READ_ONCE ; i++ )
129     {
130         i_result = p_input->p_demux_data->mpeg.pf_read_ps( p_input, &p_data );
131
132         if( i_result < 0 )
133         {
134             return i_result;
135         }
136         else if( i_result == 0 )
137         {
138             return i;
139         }
140
141         p_input->p_demux_data->mpeg.pf_demux_ps( p_input, p_data );
142     }
143     
144     return i;
145 }