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