1 /*****************************************************************************
2 * dvd_ifo.h: Structures for ifo parsing
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: ifo.h,v 1.4 2003/10/25 00:49:13 sam Exp $
7 * Author: Stéphane Borel <stef@via.ecp.fr>
10 * - libifo by Thomas Mirlacher <dent@cosy.sbg.ac.at>
11 * - IFO structure documentation by Thomas Mirlacher, Björn Englund,
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
27 *****************************************************************************/
29 /*****************************************************************************
30 * Common structures for Video Management and Video Title sets
31 *****************************************************************************/
34 * Program Chain structures
36 typedef struct ifo_video_s
38 uint8_t i_compression ;/* 2; */
39 uint8_t i_system ;/* 2; */
40 uint8_t i_ratio ;/* 2; */
41 uint8_t i_perm_displ ;/* 2; */
43 uint8_t i_line21_1 ;/* 1; */
44 uint8_t i_line21_2 ;/* 1; */
45 uint8_t i_source_res ;/* 2; */
46 uint8_t i_letterboxed ;/* 1; */
47 uint8_t i_mode ;/* 1; */
50 /* Audio type information */
51 typedef struct ifo_audio_s
53 uint8_t i_coding_mode ;/* 3; */
54 uint8_t i_multichannel_extension ;/* 1; */
55 uint8_t i_type ;/* 2; */
56 uint8_t i_appl_mode ;/* 2; */
58 uint8_t i_quantization ;/* 2; */
59 uint8_t i_sample_freq ;/* 2; */
60 uint8_t i_test ;/* 1; */
61 uint8_t i_num_channels ;/* 3; */
62 uint16_t i_lang_code ;/* 16; // <char> description */
63 uint8_t i_foo ;/* 8; // 0x00000000 ? */
64 uint8_t i_caption ;/* 8; */
65 uint8_t i_bar ;/* 8; // 0x00000000 ? */
69 typedef struct audio_status_s
71 uint8_t i_available; /* 1 */
72 uint8_t i_position; /* 7 */
73 uint8_t i_foo; /* 8 */
76 typedef struct ifo_spu_t
78 uint16_t i_prefix ;/* 16; // 0x0100 ? */
79 uint16_t i_lang_code ;/* 16; // <char> description */
80 uint8_t i_foo ;/* 8; // dont know */
81 uint8_t i_caption ;/* 8; // 0x00 ? */
84 /* Subpicture status */
85 typedef struct spu_status_s
87 uint8_t i_available; /*1*/
88 uint8_t i_position_43; /*7*/
89 uint8_t i_position_wide; /*8*/
90 uint8_t i_position_letter; /*8*/
91 uint8_t i_position_pan; /*8*/
95 /* Ifo vitual machine Commands */
96 typedef struct command_desc_s
98 unsigned int i_type :3;
99 unsigned int i_direct :1;
100 unsigned int i_cmd :4;
101 unsigned int i_dir_cmp :1;
102 unsigned int i_cmp :3;
103 unsigned int i_sub_cmd :4;
111 /* Program Chain Command Table
112 - start at i_pgc_com_tab_sbyte */
113 typedef struct command_s
115 uint16_t i_pre_command_nb; /* 2 bytes */
116 uint16_t i_post_command_nb; /* 2 bytes */
117 uint16_t i_cell_command_nb; /* 2 bytes */
119 uint64_t * p_pre_command; /* i_pre_com_nb * 8 bytes */
120 uint64_t * p_post_command; /* i_post_com_nb * 8 bytes */
121 uint64_t * p_cell_command; /* i_pre_com_nb * 8 bytes */
123 /* command_desc_t* p_cell_command; // i_cell_com_nb * 8 bytes */
124 /* command_desc_t* p_post_command; // i_post_com_nb * 8 bytes */
125 /* command_desc_t* p_cell_command; // i_cell_com_nb * 8 bytes */
128 /* Program Chain Map Table
129 * - start at "i_pgc_prg_map_sbyte" */
130 typedef struct chapter_map_s
132 uint8_t * pi_start_cell; /* i_prg_nb * 1 byte */
135 /* Cell Playback Information Table
136 * we have a pointer to such a structure for each cell
137 * - first start at "i_cell_play_inf_sbyte" */
138 typedef struct cell_play_s
140 /* This information concerns the currently selected cell */
141 uint16_t i_category; /* 2 bytes */
142 uint8_t i_still_time; /* 1 byte; in seconds; ff=inf */
143 uint8_t i_command_nb; /* 1 byte; 0 = no com */
144 uint32_t i_play_time; /* 4 bytes */
145 uint32_t i_first_sector; /* 4 bytes */
146 uint32_t i_first_ilvu_vobu_esector; /* 4 bytes; ??? */
147 uint32_t i_last_vobu_start_sector; /* 4 bytes */
148 uint32_t i_last_sector; /* 4 bytes */
151 /* Cell Position Information Table
152 * we have a pointer to such a structure for each cell
153 * - first start at "i_cell_pos_inf_sbyte" */
154 typedef struct cell_pos_s
156 /* This information concerns the currently selected cell */
157 uint16_t i_vob_id; /* 2 bytes */
159 uint8_t i_cell_id; /* 1 byte */
162 /* Main structure for Program Chain
163 * - start at i_fp_pgc_sbyte
164 * - or at i_vmgm_pgci_sbyte in vmgm_pgci_srp_t */
165 typedef struct title_s
167 /* Global features of program chain */
169 uint8_t i_chapter_nb; /* 1 byte */
170 uint8_t i_cell_nb; /* 1 byte */
171 uint32_t i_play_time; /* 4 bytes */
172 uint32_t i_prohibited_user_op; /* 4 bytes */
173 audio_status_t pi_audio_status[8]; /* 8*2 bytes */
174 spu_status_t pi_spu_status[32]; /* 32*4 bytes */
175 uint16_t i_next_title_num; /* 2 bytes */
176 uint16_t i_prev_title_num; /* 2 bytes */
177 uint16_t i_go_up_title_num; /* 2 bytes */
178 uint8_t i_still_time; /* 1 byte ; in seconds */
179 uint8_t i_play_mode; /* 1 byte */
180 /* In video_ts.ifo, the 3 significant bytes of each color are
181 * preceded by 1 unsignificant byte */
182 uint32_t pi_yuv_color[16]; /* 16*3 bytes */
183 /* Here come the start bytes of the following structures */
184 uint16_t i_command_start_byte; /* 2 bytes */
185 uint16_t i_chapter_map_start_byte; /* 2 bytes */
186 uint16_t i_cell_play_start_byte; /* 2 bytes */
187 uint16_t i_cell_pos_start_byte; /* 2 bytes */
188 /* Predefined structures */
190 chapter_map_t chapter_map;
191 cell_play_t* p_cell_play; /* i_cell_nb * 24 bytes */
192 cell_pos_t* p_cell_pos; /* i_cell_nb * 4 bytes */
196 * Menu PGCI Unit Table
199 /* Menu PGCI Language unit Descriptor */
200 typedef struct unit_s
202 uint16_t i_lang_code; /* 2 bytes (ISO-xx) */
204 uint8_t i_existence_mask; /* 1 byte */
205 uint32_t i_unit_inf_start_byte; /* 4 bytes */
208 typedef struct unit_title_s
210 uint8_t i_category_mask; /* 1 byte */
211 uint8_t i_category; /* 1 byte */
212 uint16_t i_parental_mask; /* 2 bytes */
213 uint32_t i_title_start_byte; /* 4 bytes */
217 /* Menu PGCI Language Unit Table
218 * - start at i_lu_sbyte */
219 typedef struct unit_inf_s
221 uint16_t i_title_nb; /* 2 bytes */
223 uint32_t i_last_byte; /* 4 bytes */
224 unit_title_t * p_title; /* i_srp_nb * 8 bytes */
227 /* Main Struct for Menu PGCI
228 * - start at i_*_pgci_ut_ssector */
229 typedef struct title_unit_s
231 uint16_t i_unit_nb; /* 2 bytes; ??? */
233 uint32_t i_last_byte; /* 4 bytes */
234 unit_t* p_unit; /* i_lu_nb * 8 bytes */
235 unit_inf_t* p_unit_inf; /* i_lu_nb * 8 bytes */
239 * Cell Adress Table Information
241 typedef struct cell_map_s
243 uint16_t i_vob_id; /* 2 bytes */
244 uint8_t i_cell_id; /* 1 byte */
246 uint32_t i_first_sector; /* 4 bytes */
247 uint32_t i_last_sector; /* 4 bytes */
250 typedef struct cell_inf_s
252 uint16_t i_vob_nb; /* 2 bytes */
254 uint32_t i_last_byte; /* 4 bytes */
255 uint16_t i_cell_nb; /* not in ifo; computed */
257 cell_map_t* p_cell_map;
262 * VOBU Adress Map Table
264 typedef struct vobu_map_s
266 uint32_t i_last_byte; /* 4 bytes */
267 uint32_t * pi_vobu_start_sector; /* (nb of vobu) * 4 bytes */
270 /*****************************************************************************
271 * Structures for Video Management (cf video_ts.ifo)
272 *****************************************************************************/
275 * Video Manager Information Management Table
277 typedef struct manager_inf_s
279 byte_t psz_id[13]; /* 12 bytes (DVDVIDEO-VMG) */
280 uint32_t i_vmg_end_sector; /* 4 bytes */
282 uint32_t i_vmg_inf_end_sector; /* 4 bytes */
284 uint8_t i_spec_ver; /* 1 byte */
285 uint32_t i_cat; /* 4 bytes */
286 uint16_t i_volume_nb; /* 2 bytes */
287 uint16_t i_volume; /* 2 bytes */
288 uint8_t i_disc_side; /* 1 bytes */
290 uint16_t i_title_set_nb; /* 2 bytes */
291 byte_t ps_provider_id[32]; /* 32 bytes */
292 uint64_t i_pos_code; /* 8 bytes */
294 uint32_t i_vmg_inf_end_byte; /* 4 bytes */
295 uint32_t i_first_play_title_start_byte; /* 4 bytes */
297 uint32_t i_vob_start_sector; /* 4 bytes */
298 uint32_t i_title_inf_start_sector; /* 4 bytes */
299 uint32_t i_title_unit_start_sector; /* 4 bytes */
300 uint32_t i_parental_inf_start_sector; /* 4 bytes */
301 uint32_t i_vts_inf_start_sector; /* 4 bytes */
302 uint32_t i_text_data_start_sector; /* 4 bytes */
303 uint32_t i_cell_inf_start_sector; /* 4 bytes */
304 uint32_t i_vobu_map_start_sector; /* 4 bytes */
306 ifo_video_t video_attr; /* 2 bytes */
308 uint8_t i_audio_nb; /* 1 byte */
309 ifo_audio_t p_audio_attr[8]; /* i_vmgm_audio_nb * 8 bytes */
311 uint8_t i_spu_nb; /* 1 byte */
312 ifo_spu_t p_spu_attr[32]; /* i_subpic_nb * 6 bytes */
317 * Part Of Title Search Pointer Table Information
320 /* Title sets structure
321 * we have a pointer to this structure for each tts */
322 typedef struct title_attr_s
324 uint8_t i_play_type; /* 1 byte */
325 uint8_t i_angle_nb; /* 1 byte */
326 uint16_t i_chapter_nb; /* 2 bytes; Chapters/PGs */
327 uint16_t i_parental_id; /* 2 bytes */
328 uint8_t i_title_set_num; /* 1 byte (VTS#) */
329 uint8_t i_title_num; /* 1 byte ??? */
330 uint32_t i_start_sector; /* 4 bytes */
333 /* Main struct for tts
334 * - start at "i_vmg_ptt_srpt_ssector" */
335 typedef struct title_inf_s
337 uint16_t i_title_nb; /* 2 bytes */
339 uint32_t i_last_byte; /* 4 bytes */
340 title_attr_t * p_attr; /* i_ttu_nb * 12 bytes */
344 * Parental Management Information Table
346 typedef struct parental_desc_s
348 byte_t ps_country_code[2]; /* 2 bytes */
350 uint16_t i_parental_mask_start_byte; /* 2 bytes */
354 typedef struct parental_mask_s
356 uint16_t * ppi_mask[8]; /* (i_vts_nb +1) * 8 * 2 bytes */
359 /* Main struct for parental management
360 * - start at i_vmg_ptl_mait_ssector */
361 typedef struct parental_inf_s
363 uint16_t i_country_nb; /* 2 bytes */
364 uint16_t i_vts_nb; /* 2 bytes */
365 uint32_t i_last_byte; /* 4 bytes */
366 parental_desc_t* p_parental_desc; /* i_country_nb * 8 bytes */
367 parental_mask_t* p_parental_mask; /* i_country_nb * sizeof(vmg_ptl_mask_t) */
371 * Video Title Set Attribute Table
374 /* Attribute structure : one for each vts
375 * - start at pi_atrt_sbyte */
376 typedef struct vts_attr_s
378 uint32_t i_last_byte; /* 4 bytes */
379 uint32_t i_cat_app_type; /* 4 bytes */
380 ifo_video_t vts_menu_video_attr; /* 2 bytes */
382 uint8_t i_vts_menu_audio_nb; /* 1 byte */
383 ifo_audio_t p_vts_menu_audio_attr[8]; /* 8 * 8 bytes */
385 uint8_t i_vts_menu_spu_nb; /* 1 byte */
386 ifo_spu_t p_vts_menu_spu_attr[28]; /* i_vtsm_subpic_nb * 6 bytes */
388 ifo_video_t vts_title_video_attr; /* 2 bytes */
390 uint8_t i_vts_title_audio_nb; /* 1 byte */
391 ifo_audio_t p_vts_title_audio_attr[8]; /* 8 * 8 bytes */
393 uint8_t i_vts_title_spu_nb; /* 1 byte */
394 ifo_spu_t p_vts_title_spu_attr[28]; /* i_vtstt_subpic_nb * 6 bytes */
397 /* Main struct for vts attributes
398 * - start at i_vmg_vts_atrt_ssector */
399 typedef struct vts_inf_s
401 uint16_t i_vts_nb; /* 2 bytes */
403 uint32_t i_last_byte; /* 4 bytes */
404 uint32_t * pi_vts_attr_start_byte; /* i_vts_nb * 4 bytes */
405 vts_attr_t* p_vts_attr;
409 * Global Structure for Video Manager
413 manager_inf_t manager_inf;
415 title_inf_t title_inf;
416 title_unit_t title_unit;
417 parental_inf_t parental_inf;
423 /*****************************************************************************
424 * Structures for Video Title Sets (cf vts_*.ifo)
425 ****************************************************************************/
428 * Video Title Sets Information Management Table
430 typedef struct vts_manager_s
432 byte_t psz_id[13]; /* 12 bytes (DVDVIDEO-VTS) */
433 uint32_t i_last_sector; /* 4 bytes */
435 uint32_t i_inf_last_sector; /* 4 bytes */
437 uint8_t i_spec_ver; /* 1 byte */
438 uint32_t i_cat; /* 4 bytes */
440 uint32_t i_inf_end_byte; /* 4 bytes */
442 uint32_t i_menu_vob_start_sector; /* 4 bytes */
443 uint32_t i_title_vob_start_sector; /* 4 bytes */
444 uint32_t i_title_inf_start_sector; /* 4 bytes */
445 uint32_t i_title_unit_start_sector; /* 4 bytes */
446 uint32_t i_menu_unit_start_sector; /* 4 bytes */
447 uint32_t i_time_inf_start_sector; /* 4 bytes */
448 uint32_t i_menu_cell_inf_start_sector; /* 4 bytes */
449 uint32_t i_menu_vobu_map_start_sector; /* 4 bytes */
450 uint32_t i_cell_inf_start_sector; /* 4 bytes */
451 uint32_t i_vobu_map_start_sector; /* 4 bytes */
453 ifo_video_t menu_video_attr; /* 2 bytes */
455 uint8_t i_menu_audio_nb; /* 1 byte */
456 ifo_audio_t p_menu_audio_attr[8]; /* i_vmgm_audio_nb * 8 bytes */
458 uint8_t i_menu_spu_nb; /* 1 byte */
459 ifo_spu_t p_menu_spu_attr[32]; /* i_subpic_nb * 6 bytes */
460 /* !!! only 28 subpics ??? */
462 ifo_video_t video_attr; /* 2 bytes */
464 uint8_t i_audio_nb; /* 1 byte */
465 ifo_audio_t p_audio_attr[8]; /* i_vmgm_audio_nb * 8 bytes */
467 uint8_t i_spu_nb; /* 1 byte */
468 ifo_spu_t p_spu_attr[32]; /* i_subpic_nb * 6 bytes */
472 * Part Of Title Search Pointer Table Information
475 /* Title sets structure
476 * we have a pointer to this structure for each tts */
477 typedef struct title_start_s
479 uint16_t i_title_id; /* 2 bytes; Chapters/PGs */
480 uint16_t i_chapter; /* 2 bytes */
483 /* Main struct for tts
484 * - start at "i_vts_ptt_srpt_ssector" */
485 typedef struct vts_title_s
487 uint16_t i_title_nb; /* 2 bytes */
489 uint32_t i_last_byte; /* 4 bytes */
490 uint32_t * pi_start_byte;
491 title_start_t * p_title_start; /* i_ttu_nb * 4 bytes */
495 * Time Map table information
498 /* Time Map structure */
499 typedef struct time_map_s
501 uint8_t i_time_unit; /* 1 byte */
503 uint16_t i_entry_nb; /* 2 bytes */
504 uint32_t * pi_sector; /* i_entry_nb * 4 bytes */
507 /* Main structure for tmap_ti
508 * - start at "i_tmap_ti_ssector" */
509 typedef struct time_inf_s
511 uint16_t i_nb; /* 2 bytes */
513 uint32_t i_last_byte; /* 4 bytes */
514 uint32_t * pi_start_byte; /* i_tmap_nb * 4 bytes */
515 time_map_t* p_time_map;
523 vlc_bool_t b_initialized;
525 vts_manager_t manager_inf;
526 vts_title_t title_inf;
527 title_unit_t menu_unit;
528 unit_inf_t title_unit;
530 cell_inf_t menu_cell_inf;
531 vobu_map_t menu_vobu_map;
537 * Global Ifo Structure
541 dvdcss_handle dvdhandle; /* File descriptor for the device */
542 int i_start; /* Offset to video_ts.ifo on the device */
543 int i_pos; /* Position of stream pointer */
544 vlc_bool_t b_error; /* Error Management */
545 vmg_t vmg; /* Structure described in video_ts */
546 vts_t vts; /* Vts ifo for current title set */
548 /* Remap buffer for unaligned reads */
549 uint8_t p_remap[ 2 * DVD_LB_SIZE ];
554 /*****************************************************************************
555 * Prototypes in dvd_ifo.c
556 *****************************************************************************/
557 struct thread_dvd_data_s;
559 int IfoCreate ( struct thread_dvd_data_s * );
560 int IfoInit ( struct ifo_s * );
561 int IfoTitleSet ( struct ifo_s *, int );
562 void IfoDestroy ( struct ifo_s * );