]> git.sesse.net Git - vlc/blob - modules/access/dvdplay/demux.c
679e343dea162fc7239c295e363436008eeec49a
[vlc] / modules / access / dvdplay / demux.c
1 /*****************************************************************************
2  * demux.c: demux functions for dvdplay.
3  *****************************************************************************
4  * Copyright (C) 1998-2001 VideoLAN
5  * $Id: demux.c,v 1.6 2003/02/07 00:29:53 sam Exp $
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 #include "../../demux/mpeg/system.h"
36
37 #ifdef HAVE_UNISTD_H
38 #   include <unistd.h>
39 #endif
40
41 #include <fcntl.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <string.h>
45 #include <errno.h>
46
47 #ifdef STRNCASECMP_IN_STRINGS_H
48 #   include <strings.h>
49 #endif
50
51 #include "dvd.h"
52 #include "intf.h"
53 #include "es.h"
54
55 /* how many packets dvdplay_Demux will read in each loop */
56 #define dvdplay_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     dvd_data_t * p_dvd;
69
70     module_t *   p_module;
71     mpeg_demux_t mpeg;
72 };
73
74 /*****************************************************************************
75  * InitDVD: initializes dvdplay structures
76  *****************************************************************************/
77 int E_(InitDVD) ( vlc_object_t *p_this )
78 {
79     input_thread_t *p_input = (input_thread_t *)p_this;
80     dvd_data_t *    p_dvd = (dvd_data_t *)p_input->p_access_data;
81     demux_sys_t *   p_demux;
82
83     if( p_input->stream.i_method != INPUT_METHOD_DVD )
84     {
85         return VLC_EGENERIC;
86     }
87
88     p_demux = p_input->p_demux_data = malloc( sizeof(demux_sys_t ) );
89     if( p_demux == NULL )
90     {
91         return VLC_ENOMEM;
92     }
93
94     p_input->p_private = (void*)&p_demux->mpeg;
95     p_demux->p_module = module_Need( p_input, "mpeg-system", NULL );
96     if( p_demux->p_module == NULL )
97     {
98         free( p_input->p_demux_data );
99         return VLC_ENOMOD;
100     }
101
102     p_input->p_demux_data->p_dvd = p_dvd;
103
104     p_input->pf_demux = Demux;
105     p_input->pf_rewind = NULL;
106
107     p_dvd->p_intf = intf_Create( p_input, "dvdplay" );
108     p_dvd->p_intf->b_block = VLC_FALSE;
109     intf_RunThread( p_dvd->p_intf );
110
111     return VLC_SUCCESS;
112 }
113
114 /*****************************************************************************
115  * EndDVD: frees unused data
116  *****************************************************************************/
117 void E_(EndDVD) ( vlc_object_t *p_this )
118 {
119     input_thread_t *p_input = (input_thread_t *)p_this;
120     dvd_data_t *    p_dvd = p_input->p_demux_data->p_dvd;
121     intf_thread_t * p_intf = NULL;
122
123     p_intf = vlc_object_find( p_input, VLC_OBJECT_INTF, FIND_CHILD );
124     if( p_intf != NULL )
125     {
126         intf_StopThread( p_intf );
127         vlc_object_detach( p_intf );
128         vlc_object_release( p_intf );
129         intf_Destroy( p_intf );
130     }
131
132     p_dvd->p_intf = NULL;
133
134     module_Unneed( p_input, p_input->p_demux_data->p_module );
135     free( p_input->p_demux_data );
136 }
137
138 /*****************************************************************************
139  * Demux
140  *****************************************************************************/
141 static int Demux( input_thread_t * p_input )
142 {
143     dvd_data_t *            p_dvd;
144     data_packet_t *         p_data;
145     ssize_t                 i_result;
146     ptrdiff_t               i_remains;
147     int                     i_data_nb = 0;
148
149     p_dvd = p_input->p_demux_data->p_dvd;
150
151     /* Read headers to compute payload length */
152     do
153     {
154         i_result = p_input->p_demux_data->mpeg.pf_read_ps( p_input, &p_data );
155
156         if( i_result <= 0 )
157         {
158             return i_result;
159         }
160
161         i_remains = p_input->p_last_data - p_input->p_current_data;
162
163         p_input->p_demux_data->mpeg.pf_demux_ps( p_input, p_data );
164
165
166         ++i_data_nb;
167     }
168     while( i_remains );
169
170
171
172 //    if( p_dvd->b_still && p_dvd->b_end_of_cell && p_dvd->p_intf != NULL )
173     if( p_dvd->i_still_time && p_dvd->b_end_of_cell && p_dvd->p_intf != NULL )
174     {
175         pgrm_descriptor_t * p_pgrm;
176
177         /* when we receive still_time flag, we have to pause immediately */
178         input_SetStatus( p_input, INPUT_STATUS_PAUSE );
179
180         dvdIntfStillTime( p_dvd->p_intf, p_dvd->i_still_time );
181         p_dvd->i_still_time = 0;
182
183         vlc_mutex_lock( &p_input->stream.stream_lock );
184
185         p_pgrm = p_input->stream.p_selected_program;
186         p_pgrm->i_synchro_state = SYNCHRO_REINIT;
187
188         vlc_mutex_unlock( &p_input->stream.stream_lock );
189
190         input_ClockManageControl( p_input, p_pgrm, 0 );
191     }
192
193     return i_data_nb;
194 }
195