]> git.sesse.net Git - vlc/blob - plugins/dvdplay/demux.c
e6e39b25055d9e5f3b9c13fd89d34fa6a8644cd8
[vlc] / plugins / dvdplay / demux.c
1 /*****************************************************************************
2  * demux.c: demux functions for dvdplay.
3  *****************************************************************************
4  * Copyright (C) 1998-2001 VideoLAN
5  * $Id: demux.c,v 1.1 2002/07/23 19:56:19 stef 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
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 <string.h>
42 #include <errno.h>
43
44 #ifdef STRNCASECMP_IN_STRINGS_H
45 #   include <strings.h>
46 #endif
47
48 #include "interface.h"
49 #include "dvd.h"
50 #include "intf.h"
51 #include "es.h"
52
53 /* how many packets dvdplay_Demux will read in each loop */
54 #define dvdplay_READ_ONCE 64
55
56 /*****************************************************************************
57  * Local prototypes
58  *****************************************************************************/
59
60 /* called from outside */
61 static int  dvdplay_Rewind        ( struct input_thread_t * );
62 static int  dvdplay_Demux         ( struct input_thread_t * );
63 static int  dvdplay_Init          ( struct input_thread_t * );
64 static void dvdplay_End           ( struct input_thread_t * );
65
66 /*****************************************************************************
67  * Functions exported as capabilities. They are declared as static so that
68  * we don't pollute the namespace too much.
69  *****************************************************************************/
70 void _M( demux_getfunctions)( function_list_t * p_function_list )
71 {
72 #define demux p_function_list->functions.demux
73     demux.pf_init             = dvdplay_Init;
74     demux.pf_end              = dvdplay_End;
75     demux.pf_demux            = dvdplay_Demux;
76     demux.pf_rewind           = dvdplay_Rewind;
77 #undef demux
78 }
79
80 /*
81  * Data demux functions
82  */
83
84 /*****************************************************************************
85  * dvdplay_Init: initializes dvdplay structures
86  *****************************************************************************/
87 static int dvdplay_Init( input_thread_t * p_input )
88 {
89     dvd_data_t *    p_dvd;
90     char *          psz_intf = NULL;
91
92     if( p_input->stream.i_method != INPUT_METHOD_DVD )
93     {
94         return -1;
95     }
96
97     p_input->p_demux_data = (void*)p_input->p_access_data;
98     p_dvd = (dvd_data_t *)p_input->p_demux_data;
99
100     psz_intf = config_GetPsz( p_input, "intf" );
101     config_PutPsz( p_input, "intf", "dvdplay" );
102     p_dvd->p_intf = intf_Create( p_input );
103     p_dvd->p_intf->b_block = VLC_FALSE;
104     intf_RunThread( p_dvd->p_intf );
105     
106     if( psz_intf != NULL )
107     {
108         config_PutPsz( p_input, "intf", psz_intf );
109     }
110
111     return 0;
112 }
113
114 /*****************************************************************************
115  * dvdplay_End: frees unused data
116  *****************************************************************************/
117 static void dvdplay_End( input_thread_t * p_input )
118 {
119     dvd_data_t *    p_dvd;
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_all( p_intf );
127         vlc_object_release( p_intf );
128         intf_Destroy( p_intf );
129     }
130
131     p_dvd = (dvd_data_t *)p_input->p_demux_data;
132     p_dvd->p_intf = NULL;
133 }
134
135 /*****************************************************************************
136  * dvdplay_Demux
137  *****************************************************************************/
138 static int dvdplay_Demux( input_thread_t * p_input )
139 {
140     dvd_data_t *            p_dvd;
141     data_packet_t *         p_data;
142     ssize_t                 i_result;
143     ptrdiff_t               i_remains;
144     int                     i_data_nb = 0;
145
146     p_dvd = (dvd_data_t *)p_input->p_demux_data;
147    
148     /* Read headers to compute payload length */
149     do
150     {
151         if( ( i_result = input_ReadPS( p_input, &p_data ) ) <= 0)
152         {
153             return i_result;
154         }
155
156         i_remains = p_input->p_last_data - p_input->p_current_data;
157
158         input_DemuxPS( p_input, p_data );
159         
160
161         ++i_data_nb;
162     }
163     while( i_remains );
164     
165
166     
167 //    if( p_dvd->b_still && p_dvd->b_end_of_cell && p_dvd->p_intf != NULL )
168     if( p_dvd->i_still_time && p_dvd->b_end_of_cell && p_dvd->p_intf != NULL )
169     {
170         pgrm_descriptor_t * p_pgrm;
171
172         /* when we receive still_time flag, we have to pause immediately */
173         input_SetStatus( p_input, INPUT_STATUS_PAUSE );
174
175         dvdIntfStillTime( p_dvd->p_intf, p_dvd->i_still_time );
176         p_dvd->i_still_time = 0;
177         
178         vlc_mutex_lock( &p_input->stream.stream_lock );
179         
180         p_pgrm = p_input->stream.p_selected_program;
181         p_pgrm->i_synchro_state = SYNCHRO_REINIT;
182         
183         vlc_mutex_unlock( &p_input->stream.stream_lock );
184         
185         input_ClockManageControl( p_input, p_pgrm, 0 );
186     }
187
188     return i_data_nb;
189 }
190
191 /*****************************************************************************
192  * dvdplay_Rewind : reads a stream backward
193  *****************************************************************************/
194 static int dvdplay_Rewind( input_thread_t * p_input )
195 {
196     return( -1 );
197 }