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