]> git.sesse.net Git - vlc/blob - plugins/dvd/dvd_demux.c
* ./src/misc/modules_plugin.h: exported input_ClockManageRef for fenrir.
[vlc] / plugins / dvd / dvd_demux.c
1 /* dvd_demux.c: DVD demux functions.
2  *****************************************************************************
3  * Copyright (C) 1998-2001 VideoLAN
4  * $Id: dvd_demux.c,v 1.5 2002/04/25 21:52:42 sam Exp $
5  *
6  * Author: Stéphane Borel <stef@via.ecp.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include <videolan/vlc.h>
31
32 #ifdef HAVE_UNISTD_H
33 #   include <unistd.h>
34 #endif
35
36 #include <fcntl.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <string.h>
40 #include <errno.h>
41
42 #ifdef STRNCASECMP_IN_STRINGS_H
43 #   include <strings.h>
44 #endif
45
46 #include "stream_control.h"
47 #include "input_ext-intf.h"
48 #include "input_ext-dec.h"
49 #include "input_ext-plugins.h"
50
51 /* how many packets DVDDemux will read in each loop */
52 #define DVD_READ_ONCE 64
53
54 /*****************************************************************************
55  * Local prototypes
56  *****************************************************************************/
57
58 /* called from outside */
59 static int  DVDRewind       ( struct input_thread_s * );
60 static int  DVDDemux        ( struct input_thread_s * );
61 static int  DVDInit         ( struct input_thread_s * );
62 static void DVDEnd          ( struct input_thread_s * );
63
64 void DVDLaunchDecoders( 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             = DVDInit;
74     demux.pf_end              = DVDEnd;
75     demux.pf_demux            = DVDDemux;
76     demux.pf_rewind           = DVDRewind;
77 #undef demux
78 }
79
80 /*
81  * Data demux functions
82  */
83
84 /*****************************************************************************
85  * DVDInit: initializes DVD structures
86  *****************************************************************************/
87 static int DVDInit( input_thread_t * p_input )
88 {
89     if( p_input->stream.i_method != INPUT_METHOD_DVD )
90     {
91         return -1;
92     }
93
94     vlc_mutex_lock( &p_input->stream.stream_lock );
95     
96     DVDLaunchDecoders( p_input );
97     
98     vlc_mutex_unlock( &p_input->stream.stream_lock );
99
100     return 0;
101 }
102
103 /*****************************************************************************
104  * DVDEnd: frees unused data
105  *****************************************************************************/
106 static void DVDEnd( input_thread_t * p_input )
107 {
108 }
109
110 /*****************************************************************************
111  * DVDDemux
112  *****************************************************************************/
113 static int DVDDemux( input_thread_t * p_input )
114 {
115     data_packet_t *     p_data;
116     ssize_t             i_result;
117     int                 i;
118
119     /* Read headers to compute payload length */
120     for( i = 0 ; i < DVD_READ_ONCE ; i++ )
121     {
122         if( ( i_result = input_ReadPS( p_input, &p_data ) ) <= 0)
123         {
124             return i_result;
125         }
126
127         input_DemuxPS( p_input, p_data );
128     }
129     
130     return i;
131 }
132
133 /*****************************************************************************
134  * DVDRewind : reads a stream backward
135  *****************************************************************************/
136 static int DVDRewind( input_thread_t * p_input )
137 {
138     return( -1 );
139 }