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