]> git.sesse.net Git - vlc/blob - modules/access/vcdx/demux.c
Remove E_()
[vlc] / modules / access / vcdx / demux.c
1 /*****************************************************************************
2  * demux.c: demux functions for dvdplay.
3  *****************************************************************************
4  * Copyright (C) 1998-2001 the VideoLAN team
5  * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stddef.h>
33 #include <vlc/vlc.h>
34 #include <vlc_input.h>
35 #include <vlc_access.h>
36 #include <vlc_interface.h>
37
38 #ifdef HAVE_UNISTD_H
39 #   include <unistd.h>
40 #endif
41
42 #include <fcntl.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <errno.h>
46
47 #ifdef STRNCASECMP_IN_STRINGS_H
48 #   include <strings.h>
49 #endif
50
51 #include "vcd.h"
52 #include "vcdplayer.h"
53 #include "intf.h"
54
55 /* how many packets vcdx_Demux will read in each loop */
56 /* #define vcdplay_READ_ONCE 64 */
57
58 /*****************************************************************************
59  * Local prototypes
60  *****************************************************************************/
61 static int  Demux         ( input_thread_t * );
62
63 /*****************************************************************************
64  * Private structure
65  *****************************************************************************/
66 struct demux_sys_t
67 {
68     vcd_data_t * p_vcd;
69
70     module_t *   p_module;
71     mpeg_demux_t mpeg;
72 };
73
74 /*****************************************************************************
75  * VCDInit: initializes structures
76  *****************************************************************************/
77 int VCDInit ( vlc_object_t *p_this )
78 {
79     input_thread_t *p_input = (input_thread_t *)p_this;
80     vcd_data_t *    p_vcd = (vcd_data_t *)p_input->p_sys;
81     demux_sys_t *   p_demux;
82
83     printf("++++ VCDInit CALLED\n");
84  
85
86     if( p_input->stream.i_method != INPUT_METHOD_VCD )
87     {
88         return VLC_EGENERIC;
89     }
90
91     p_demux = p_input->p_demux_data = malloc( sizeof(demux_sys_t ) );
92     if( p_demux == NULL )
93     {
94         return VLC_ENOMOD;
95     }
96
97     p_input->p_private = (void*)&p_demux->mpeg;
98     p_demux->p_module = module_Need( p_input, "mpeg-system", NULL, 0 );
99     if( p_demux->p_module == NULL )
100     {
101         free( p_input->p_demux_data );
102         return VLC_ENOMOD;
103     }
104
105     p_input->p_demux_data->p_vcd = p_vcd;
106
107     p_input->pf_demux = Demux;
108     p_input->pf_demux_control = demux_vaControlDefault;
109     p_input->pf_rewind = NULL;
110
111     p_vcd->p_intf = NULL;
112     p_vcd->i_still_time = 0;
113
114     return VLC_SUCCESS;
115 }
116
117 /*****************************************************************************
118  * VCDEnd: frees unused data
119  *****************************************************************************/
120 void VCDEnd ( vlc_object_t *p_this )
121 {
122     input_thread_t *p_input = (input_thread_t *)p_this;
123     vcd_data_t *    p_vcd = p_input->p_demux_data->p_vcd;
124     intf_thread_t * p_intf = NULL;
125
126     p_intf = vlc_object_find( p_input, VLC_OBJECT_INTF, FIND_CHILD );
127     if( p_intf != NULL )
128     {
129         intf_StopThread( p_intf );
130         vlc_object_detach( p_intf );
131         vlc_object_release( p_intf );
132         intf_Destroy( p_intf );
133     }
134
135     p_vcd->p_intf = NULL;
136
137     module_Unneed( p_input, p_input->p_demux_data->p_module );
138     free( p_input->p_demux_data );
139 }
140
141 /*****************************************************************************
142  * Demux
143  *****************************************************************************/
144 static int Demux( input_thread_t * p_input )
145 {
146     vcd_data_t *            p_vcd;
147     data_packet_t *         p_data;
148     ssize_t                 i_result;
149     ptrdiff_t               i_remains;
150     int                     i_data_nb = 0;
151
152     p_vcd = p_input->p_demux_data->p_vcd;
153
154     /* Read headers to compute payload length */
155     do
156     {
157         i_result = p_input->p_demux_data->mpeg.pf_read_ps( p_input, &p_data );
158
159         if( i_result <= 0 )
160         {
161             return i_result;
162         }
163
164         i_remains = p_input->p_last_data - p_input->p_current_data;
165
166         p_input->p_demux_data->mpeg.pf_demux_ps( p_input, p_data );
167
168
169         ++i_data_nb;
170     }
171     while( i_remains );
172
173
174
175 //    if( p_vcd->b_still && p_vcd->b_end_of_cell && p_vcd->p_intf != NULL )
176     if( p_vcd->i_still_time && p_vcd->b_end_of_cell && p_vcd->p_intf != NULL )
177     {
178         pgrm_descriptor_t * p_pgrm;
179
180         /* when we receive still_time flag, we have to pause immediately */
181         var_SetInteger( p_input, "state", PAUSE_S );
182
183         vcdIntfStillTime( p_vcd->p_intf, p_vcd->i_still_time );
184         p_vcd->i_still_time = 0;
185
186         vlc_mutex_lock( &p_input->stream.stream_lock );
187
188         p_pgrm = p_input->stream.p_selected_program;
189         p_pgrm->i_synchro_state = SYNCHRO_REINIT;
190
191         vlc_mutex_unlock( &p_input->stream.stream_lock );
192
193         input_ClockManageControl( p_input, p_pgrm, 0 );
194     }
195
196     return i_data_nb;
197 }