* ./src/misc/modules_plugin.h: exported input_ClockManageRef for fenrir.
[vlc.git] / plugins / dvd / dvd_es.c
blobf954ad51a8d3e42d5c004677a216b009d2d94e10
1 /* dvd_es.c: functions to find and select ES
2 *****************************************************************************
3 * Copyright (C) 1998-2001 VideoLAN
4 * $Id: dvd_es.c,v 1.9 2002/04/25 21:52:42 sam Exp $
6 * Author: Stéphane Borel <stef@via.ecp.fr>
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.
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.
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 *****************************************************************************/
23 /*****************************************************************************
24 * Preamble
25 *****************************************************************************/
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include <videolan/vlc.h>
32 #ifdef HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif
36 #include <fcntl.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <string.h>
40 #include <errno.h>
42 #ifdef STRNCASECMP_IN_STRINGS_H
43 # include <strings.h>
44 #endif
46 #ifdef GOD_DAMN_DMCA
47 # include "dummy_dvdcss.h"
48 #else
49 # include <dvdcss/dvdcss.h>
50 #endif
52 #include "stream_control.h"
53 #include "input_ext-intf.h"
54 #include "input_ext-dec.h"
55 #include "input_ext-plugins.h"
57 #include "dvd.h"
58 #include "dvd_ifo.h"
59 #include "dvd_summary.h"
60 #include "iso_lang.h"
62 /*****************************************************************************
63 * Local prototypes
64 *****************************************************************************/
66 void DVDLaunchDecoders( input_thread_t * p_input );
68 #define vmg p_dvd->p_ifo->vmg
69 #define vts p_dvd->p_ifo->vts
71 #define ADDES( stream_id, private_id, type, cat, lang, size ) \
72 i_id = ( (private_id) << 8 ) | (stream_id); \
73 p_es = input_AddES( p_input, NULL, i_id, size ); \
74 p_es->i_stream_id = (stream_id); \
75 p_es->i_type = (type); \
76 p_es->i_cat = (cat); \
77 if( lang ) \
78 { \
79 strcpy( p_es->psz_desc, DecodeLanguage( hton16( lang ) ) ); \
83 /*****************************************************************************
84 * DVDReadVideo: read video ES
85 *****************************************************************************/
86 void DVDReadVideo( input_thread_t * p_input )
88 thread_dvd_data_t * p_dvd;
89 es_descriptor_t * p_es;
90 int i_id;
91 int i_ratio;
93 p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
95 /* ES 0 -> video MPEG2 */
96 IfoPrintVideo( p_dvd );
97 i_ratio = vts.manager_inf.video_attr.i_ratio;
99 if( i_ratio )
101 ADDES( 0xe0, 0, MPEG2_VIDEO_ES, VIDEO_ES, 0, sizeof(int) );
102 *(int*)(p_es->p_demux_data) = i_ratio;
104 else
106 ADDES( 0xe0, 0, MPEG2_VIDEO_ES, VIDEO_ES, 0, 0 );
111 /*****************************************************************************
112 * DVDReadAudio: read audio ES
113 *****************************************************************************/
114 #define audio_status \
115 vts.title_unit.p_title[p_dvd->i_title_id-1].title.pi_audio_status[i-1]
117 void DVDReadAudio( input_thread_t * p_input )
119 thread_dvd_data_t * p_dvd;
120 es_descriptor_t * p_es;
121 int i_lang;
122 int i_id;
123 int i;
125 p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
126 p_dvd->i_audio_nb = 0;
128 /* Audio ES, in the order they appear in .ifo */
129 for( i = 1 ; i <= vts.manager_inf.i_audio_nb ; i++ )
131 IfoPrintAudio( p_dvd, i );
133 /* audio channel is active if first byte is 0x80 */
134 if( audio_status.i_available )
136 p_dvd->i_audio_nb++;
137 i_lang = vts.manager_inf.p_audio_attr[i-1].i_lang_code;
138 i_id = audio_status.i_position;
140 switch( vts.manager_inf.p_audio_attr[i-1].i_coding_mode )
142 case 0x00: /* AC3 */
143 ADDES( 0xbd, 0x80 + audio_status.i_position,
144 AC3_AUDIO_ES, AUDIO_ES, i_lang, 0 );
145 p_es->b_audio = 1;
146 strcat( p_es->psz_desc, " (ac3)" );
148 break;
149 case 0x02:
150 case 0x03: /* MPEG audio */
151 ADDES( 0xc0 + audio_status.i_position, 0,
152 MPEG2_AUDIO_ES, AUDIO_ES, i_lang, 0 );
153 p_es->b_audio = 1;
154 strcat( p_es->psz_desc, " (mpeg)" );
156 break;
157 case 0x04: /* LPCM */
158 ADDES( 0xbd, 0xa0 + audio_status.i_position,
159 LPCM_AUDIO_ES, AUDIO_ES, i_lang, 0 );
160 p_es->b_audio = 1;
161 strcat( p_es->psz_desc, " (lpcm)" );
163 break;
164 case 0x06: /* DTS */
165 i_id = ( ( 0x88 + audio_status.i_position ) << 8 ) | 0xbd;
166 intf_ErrMsg( "dvd warning: DTS audio not handled yet"
167 "(0x%x)", i_id );
168 break;
169 default:
170 i_id = 0;
171 intf_ErrMsg( "dvd warning: unknown audio type %.2x",
172 vts.manager_inf.p_audio_attr[i-1].i_coding_mode );
177 #undef audio_status
179 /*****************************************************************************
180 * DVDReadSPU: read subpictures ES
181 *****************************************************************************/
182 #define spu_status \
183 vts.title_unit.p_title[p_dvd->i_title_id-1].title.pi_spu_status[i-1]
184 #define palette \
185 vts.title_unit.p_title[p_dvd->i_title_id-1].title.pi_yuv_color
187 void DVDReadSPU( input_thread_t * p_input )
189 thread_dvd_data_t * p_dvd;
190 es_descriptor_t * p_es;
191 int i_id;
192 int i;
194 p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
195 p_dvd->i_spu_nb = 0;
197 for( i = 1 ; i <= vts.manager_inf.i_spu_nb; i++ )
199 IfoPrintSpu( p_dvd, i );
201 if( spu_status.i_available )
203 p_dvd->i_spu_nb++;
205 /* there are several streams for one spu */
206 if( vts.manager_inf.video_attr.i_ratio )
208 /* 16:9 */
209 switch( vts.manager_inf.video_attr.i_perm_displ )
211 case 1:
212 i_id = spu_status.i_position_pan;
213 break;
214 case 2:
215 i_id = spu_status.i_position_letter;
216 break;
217 default:
218 i_id = spu_status.i_position_wide;
219 break;
222 else
224 /* 4:3 */
225 i_id = spu_status.i_position_43;
228 if( vmg.title.pi_yuv_color )
230 ADDES( 0xbd, 0x20 + i_id, DVD_SPU_ES, SPU_ES,
231 vts.manager_inf.p_spu_attr[i-1].i_lang_code,
232 sizeof(int) + 16*sizeof(u32) );
233 *(int*)p_es->p_demux_data = 0xBeeF;
234 memcpy( (void*)p_es->p_demux_data + sizeof(int),
235 palette, 16*sizeof(u32) );
237 else
239 ADDES( 0xbd, 0x20 + i_id, DVD_SPU_ES, SPU_ES,
240 vts.manager_inf.p_spu_attr[i-1].i_lang_code, 0 );
245 #undef palette
246 #undef spu_status
248 #undef vts
249 #undef vmg
251 /*****************************************************************************
252 * DVDLaunchDecoders: select ES for video, audio and spu
253 *****************************************************************************/
254 void DVDLaunchDecoders( input_thread_t * p_input )
256 thread_dvd_data_t * p_dvd;
257 int i_audio;
258 int i_spu;
260 p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
262 /* Select Video stream (always 0) */
263 if( p_main->b_video )
265 input_SelectES( p_input, p_input->stream.pp_es[0] );
268 /* Select audio stream */
269 if( p_main->b_audio && p_dvd->i_audio_nb > 0 )
271 /* For audio: first one if none or a not existing one specified */
272 i_audio = config_GetIntVariable( "audio-channel" );
273 if( i_audio <= 0 || i_audio > p_dvd->i_audio_nb )
275 config_PutIntVariable( "audio-channel", 1 );
276 i_audio = 1;
279 if( ( config_GetIntVariable( "audio-type" ) == REQUESTED_AC3 ) )
281 int i_ac3 = i_audio;
282 while( ( p_input->stream.pp_es[i_ac3]->i_type !=
283 AC3_AUDIO_ES ) && ( i_ac3 <=
284 p_dvd->p_ifo->vts.manager_inf.i_audio_nb ) )
286 i_ac3++;
288 if( p_input->stream.pp_es[i_ac3]->i_type == AC3_AUDIO_ES )
290 input_SelectES( p_input,
291 p_input->stream.pp_es[i_ac3] );
294 else
296 input_SelectES( p_input,
297 p_input->stream.pp_es[i_audio] );
301 /* Select subtitle */
302 if( p_main->b_video && p_dvd->i_spu_nb > 0 )
304 /* for spu, default is none */
305 i_spu = config_GetIntVariable( "spu-channel" );
306 if( i_spu < 0 || i_spu > p_dvd->i_spu_nb )
308 config_PutIntVariable( "spu-channel", 0 );
309 i_spu = 0;
311 if( i_spu > 0 )
313 i_spu += p_dvd->p_ifo->vts.manager_inf.i_audio_nb;
314 input_SelectES( p_input, p_input->stream.pp_es[i_spu] );