1 /* dvd_es.c: functions to find and select ES
2 *****************************************************************************
3 * Copyright (C) 1998-2001 VideoLAN
4 * $Id: dvd_es.c,v 1.12 2002/06/01 12:31:58 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 /*****************************************************************************
25 *****************************************************************************/
31 #include <vlc/input.h>
38 #include <sys/types.h>
43 #ifdef STRNCASECMP_IN_STRINGS_H
48 # include "dummy_dvdcss.h"
50 # include <dvdcss/dvdcss.h>
55 #include "dvd_summary.h"
58 /*****************************************************************************
60 *****************************************************************************/
62 void DVDLaunchDecoders( input_thread_t * p_input );
64 #define vmg p_dvd->p_ifo->vmg
65 #define vts p_dvd->p_ifo->vts
67 #define ADDES( stream_id, private_id, type, cat, lang, size ) \
68 i_id = ( (private_id) << 8 ) | (stream_id); \
69 p_es = input_AddES( p_input, NULL, i_id, size ); \
70 p_es->i_stream_id = (stream_id); \
71 p_es->i_type = (type); \
72 p_es->i_cat = (cat); \
75 strcpy( p_es->psz_desc, DecodeLanguage( lang ) ); \
79 /*****************************************************************************
80 * DVDReadVideo: read video ES
81 *****************************************************************************/
82 void DVDReadVideo( input_thread_t * p_input )
84 thread_dvd_data_t * p_dvd;
85 es_descriptor_t * p_es;
89 p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
91 /* ES 0 -> video MPEG2 */
92 IfoPrintVideo( p_dvd );
93 i_ratio = vts.manager_inf.video_attr.i_ratio;
97 ADDES( 0xe0, 0, MPEG2_VIDEO_ES, VIDEO_ES, 0, sizeof(int) );
98 *(int*)(p_es->p_demux_data) = i_ratio;
102 ADDES( 0xe0, 0, MPEG2_VIDEO_ES, VIDEO_ES, 0, 0 );
107 /*****************************************************************************
108 * DVDReadAudio: read audio ES
109 *****************************************************************************/
110 #define audio_status \
111 vts.title_unit.p_title[p_dvd->i_title_id-1].title.pi_audio_status[i-1]
113 void DVDReadAudio( input_thread_t * p_input )
115 thread_dvd_data_t * p_dvd;
116 es_descriptor_t * p_es;
121 p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
122 p_dvd->i_audio_nb = 0;
124 /* Audio ES, in the order they appear in .ifo */
125 for( i = 1 ; i <= vts.manager_inf.i_audio_nb ; i++ )
127 IfoPrintAudio( p_dvd, i );
129 /* audio channel is active if first byte is 0x80 */
130 if( audio_status.i_available )
133 i_lang = vts.manager_inf.p_audio_attr[i-1].i_lang_code;
134 i_id = audio_status.i_position;
136 switch( vts.manager_inf.p_audio_attr[i-1].i_coding_mode )
139 ADDES( 0xbd, 0x80 + audio_status.i_position,
140 AC3_AUDIO_ES, AUDIO_ES, i_lang, 0 );
142 strcat( p_es->psz_desc, " (ac3)" );
146 case 0x03: /* MPEG audio */
147 ADDES( 0xc0 + audio_status.i_position, 0,
148 MPEG2_AUDIO_ES, AUDIO_ES, i_lang, 0 );
150 strcat( p_es->psz_desc, " (mpeg)" );
153 case 0x04: /* LPCM */
154 ADDES( 0xbd, 0xa0 + audio_status.i_position,
155 LPCM_AUDIO_ES, AUDIO_ES, i_lang, 0 );
157 strcat( p_es->psz_desc, " (lpcm)" );
161 i_id = ( ( 0x88 + audio_status.i_position ) << 8 ) | 0xbd;
162 msg_Err( p_input, "DTS audio not handled yet (0x%x)", i_id );
166 msg_Err( p_input, "unknown audio type %.2x",
167 vts.manager_inf.p_audio_attr[i-1].i_coding_mode );
174 /*****************************************************************************
175 * DVDReadSPU: read subpictures ES
176 *****************************************************************************/
178 vts.title_unit.p_title[p_dvd->i_title_id-1].title.pi_spu_status[i-1]
180 vts.title_unit.p_title[p_dvd->i_title_id-1].title.pi_yuv_color
182 void DVDReadSPU( input_thread_t * p_input )
184 thread_dvd_data_t * p_dvd;
185 es_descriptor_t * p_es;
189 p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
192 for( i = 1 ; i <= vts.manager_inf.i_spu_nb; i++ )
194 IfoPrintSpu( p_dvd, i );
196 if( spu_status.i_available )
200 /* there are several streams for one spu */
201 if( vts.manager_inf.video_attr.i_ratio )
204 switch( vts.manager_inf.video_attr.i_perm_displ )
207 i_id = spu_status.i_position_pan;
210 i_id = spu_status.i_position_letter;
213 i_id = spu_status.i_position_wide;
220 i_id = spu_status.i_position_43;
223 if( vmg.title.pi_yuv_color )
225 ADDES( 0xbd, 0x20 + i_id, DVD_SPU_ES, SPU_ES,
226 vts.manager_inf.p_spu_attr[i-1].i_lang_code,
227 sizeof(int) + 16*sizeof(u32) );
228 *(int*)p_es->p_demux_data = 0xBeeF;
229 memcpy( (char*)p_es->p_demux_data + sizeof(int),
230 palette, 16*sizeof(u32) );
234 ADDES( 0xbd, 0x20 + i_id, DVD_SPU_ES, SPU_ES,
235 vts.manager_inf.p_spu_attr[i-1].i_lang_code, 0 );
246 /*****************************************************************************
247 * DVDLaunchDecoders: select ES for video, audio and spu
248 *****************************************************************************/
249 void DVDLaunchDecoders( input_thread_t * p_input )
251 thread_dvd_data_t * p_dvd;
255 p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
257 /* Select Video stream (always 0) */
258 if( !config_GetInt( p_input, "novideo" ) )
260 input_SelectES( p_input, p_input->stream.pp_es[0] );
263 /* Select audio stream */
264 if( p_dvd->i_audio_nb > 0 && !config_GetInt( p_input, "noaudio" ) )
266 /* For audio: first one if none or a not existing one specified */
267 i_audio = config_GetInt( p_input, "audio-channel" );
268 if( i_audio <= 0 || i_audio > p_dvd->i_audio_nb )
270 config_PutInt( p_input, "audio-channel", 1 );
274 if( ( config_GetInt( p_input, "audio-type" )
278 while( ( p_input->stream.pp_es[i_ac3]->i_type !=
279 AC3_AUDIO_ES ) && ( i_ac3 <=
280 p_dvd->p_ifo->vts.manager_inf.i_audio_nb ) )
284 if( p_input->stream.pp_es[i_ac3]->i_type == AC3_AUDIO_ES )
286 input_SelectES( p_input,
287 p_input->stream.pp_es[i_ac3] );
292 input_SelectES( p_input,
293 p_input->stream.pp_es[i_audio] );
297 /* Select subtitle */
298 if( p_dvd->i_spu_nb > 0 && !config_GetInt( p_input, "novideo" ) )
300 /* for spu, default is none */
301 i_spu = config_GetInt( p_input, "spu-channel" );
302 if( i_spu < 0 || i_spu > p_dvd->i_spu_nb )
304 config_PutInt( p_input, "spu-channel", 0 );
309 i_spu += p_dvd->p_ifo->vts.manager_inf.i_audio_nb;
310 input_SelectES( p_input, p_input->stream.pp_es[i_spu] );