]> git.sesse.net Git - vlc/blob - modules/access/dvd/ifo.h
* include/vlc_common.h:
[vlc] / modules / access / dvd / ifo.h
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 $
6  *
7  * Author: Stéphane Borel <stef@via.ecp.fr>
8  *
9  * based on:
10  *  - libifo by Thomas Mirlacher <dent@cosy.sbg.ac.at>
11  *  - IFO structure documentation by Thomas Mirlacher, Björn Englund,
12  *  Håkan Hjort
13  *
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.
18  *
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.
23  *
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  *****************************************************************************/
28
29 /*****************************************************************************
30  * Common structures for Video Management and Video Title sets
31  *****************************************************************************/
32
33 /*
34  * Program Chain structures
35  */
36 typedef struct ifo_video_s
37 {
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; */
42
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; */
48 } ifo_video_t;
49
50 /* Audio type information */
51 typedef struct ifo_audio_s
52 {
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; */
57
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 ? */
66 } ifo_audio_t;
67
68 /* Audio Status */
69 typedef struct audio_status_s
70 {
71     uint8_t i_available;        /* 1 */
72     uint8_t i_position;         /* 7 */
73     uint8_t i_foo;              /* 8 */
74 } audio_status_t;
75
76 typedef struct ifo_spu_t
77 {
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 ? */
82 } ifo_spu_t;
83
84 /* Subpicture status */
85 typedef struct spu_status_s
86 {
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*/
92 } spu_status_t;
93
94
95 /* Ifo vitual machine Commands */
96 typedef struct command_desc_s
97 {
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;
104     union
105     {
106         uint8_t     pi_8[6];
107         uint16_t    pi_16[3];
108     } data;
109 } command_desc_t;
110
111 /* Program Chain Command Table
112   - start at i_pgc_com_tab_sbyte */
113 typedef struct command_s
114 {
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 */
118 /*    char[2]         ??? */
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 */
122
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 */
126 } command_t;
127
128 /* Program Chain Map Table
129  * - start at "i_pgc_prg_map_sbyte" */
130 typedef struct chapter_map_s
131 {
132     uint8_t *       pi_start_cell;              /* i_prg_nb * 1 byte  */
133 } chapter_map_t;
134
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
139 {
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 */
149 } cell_play_t;
150
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
155 {
156     /* This information concerns the currently selected cell */
157     uint16_t        i_vob_id;                   /* 2 bytes */
158 /*    char            ??? */
159     uint8_t         i_cell_id;                  /* 1 byte */
160 } cell_pos_t;
161
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
166 {
167     /* Global features of program chain */
168 /*    char[2]         ??? */
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 */
189     command_t       command;
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 */
193 } title_t;
194
195 /*
196  * Menu PGCI Unit Table
197  */
198
199 /* Menu PGCI Language unit Descriptor */
200 typedef struct unit_s
201 {
202     uint16_t        i_lang_code;            /* 2 bytes (ISO-xx) */
203 /*    char            ??? */
204     uint8_t         i_existence_mask;           /* 1 byte */
205     uint32_t        i_unit_inf_start_byte;                 /* 4 bytes */
206 } unit_t;
207
208 typedef struct unit_title_s
209 {
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 */
214     title_t         title;
215 } unit_title_t;
216
217 /* Menu PGCI Language Unit Table
218  * - start at i_lu_sbyte */
219 typedef struct unit_inf_s
220 {
221     uint16_t        i_title_nb;                   /* 2 bytes */
222 /*    char[2]         ??? */
223     uint32_t        i_last_byte;                /* 4 bytes */
224     unit_title_t *  p_title;                      /* i_srp_nb * 8 bytes */
225 } unit_inf_t;
226
227 /* Main Struct for Menu PGCI
228  * - start at i_*_pgci_ut_ssector */
229 typedef struct title_unit_s
230 {
231     uint16_t        i_unit_nb;                    /* 2 bytes; ??? */
232 /*    char[2]         ??? */
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 */
236 } title_unit_t;
237
238 /*
239  * Cell Adress Table Information
240  */
241 typedef struct cell_map_s
242 {
243     uint16_t        i_vob_id;                   /* 2 bytes */
244     uint8_t         i_cell_id;                  /* 1 byte */
245 /*    char            ??? */
246     uint32_t        i_first_sector;             /* 4 bytes */
247     uint32_t        i_last_sector;              /* 4 bytes */
248 } cell_map_t;
249
250 typedef struct cell_inf_s
251 {
252     uint16_t        i_vob_nb;                   /* 2 bytes */
253 /*    char[2]         ??? */
254     uint32_t        i_last_byte;                /* 4 bytes */
255     uint16_t        i_cell_nb;                  /* not in ifo; computed */
256                                                 /* with e_byte */
257     cell_map_t*     p_cell_map;
258 } cell_inf_t;
259
260
261 /*
262  * VOBU Adress Map Table
263  */
264 typedef struct vobu_map_s
265 {
266     uint32_t        i_last_byte;                   /* 4 bytes */
267     uint32_t *      pi_vobu_start_sector;            /* (nb of vobu) * 4 bytes */
268 } vobu_map_t;
269
270 /*****************************************************************************
271  * Structures for Video Management (cf video_ts.ifo)
272  *****************************************************************************/
273
274 /*
275  * Video Manager Information Management Table
276  */
277 typedef struct manager_inf_s
278 {
279     byte_t          psz_id[13];                 /* 12 bytes (DVDVIDEO-VMG) */
280     uint32_t        i_vmg_end_sector;                  /* 4 bytes */
281 /*    char[12]        ??? */
282     uint32_t        i_vmg_inf_end_sector;                /* 4 bytes */
283 /*    char            ??? */
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 */
289 /*    char[20]        ??? */
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 */
293 /*    char[24]        ??? */
294     uint32_t        i_vmg_inf_end_byte;              /* 4 bytes */
295     uint32_t        i_first_play_title_start_byte;             /* 4 bytes */
296 /*    char[56]        ??? */
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 */
305 /*    char[2]         ??? */
306     ifo_video_t     video_attr;                 /* 2 bytes */
307 /*    char            ??? */
308     uint8_t         i_audio_nb;                 /* 1 byte */
309     ifo_audio_t     p_audio_attr[8];            /* i_vmgm_audio_nb * 8 bytes */
310 /*    char[16]        ??? */
311     uint8_t         i_spu_nb;                /* 1 byte */
312     ifo_spu_t       p_spu_attr[32];          /* i_subpic_nb * 6 bytes */
313 } manager_inf_t;
314
315
316 /*
317  * Part Of Title Search Pointer Table Information
318  */
319
320 /* Title sets structure
321  * we have a pointer to this structure for each tts */
322 typedef struct title_attr_s
323 {
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 */
331 } title_attr_t;
332
333 /* Main struct for tts
334  * - start at "i_vmg_ptt_srpt_ssector" */
335 typedef struct title_inf_s
336 {
337     uint16_t        i_title_nb;                   /* 2 bytes */
338 /*    char[2]         ??? */
339     uint32_t        i_last_byte;                   /* 4 bytes */
340     title_attr_t *  p_attr;                     /* i_ttu_nb * 12 bytes */
341 } title_inf_t;
342
343 /*
344  * Parental Management Information Table
345  */
346 typedef struct parental_desc_s
347 {
348     byte_t          ps_country_code[2];         /* 2 bytes */
349 /*    char[2]         ??? */
350     uint16_t        i_parental_mask_start_byte;            /* 2 bytes */
351 /*    char[2]         ??? */
352 } parental_desc_t;
353
354 typedef struct parental_mask_s
355 {
356     uint16_t *      ppi_mask[8];            /* (i_vts_nb +1) * 8 * 2 bytes */
357 } parental_mask_t;
358
359 /* Main struct for parental management
360  * - start at i_vmg_ptl_mait_ssector */
361 typedef struct parental_inf_s
362 {
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) */
368 } parental_inf_t;
369
370 /*
371  * Video Title Set Attribute Table
372  */
373
374 /* Attribute structure : one for each vts
375  * - start at pi_atrt_sbyte */
376 typedef struct vts_attr_s
377 {
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 */
381 /*    char            ??? */
382     uint8_t         i_vts_menu_audio_nb;            /* 1 byte */
383     ifo_audio_t     p_vts_menu_audio_attr[8];       /* 8 * 8 bytes */
384 /*    char[17]        ??? */
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 */
387 /*    char[2]         ??? */
388     ifo_video_t     vts_title_video_attr;         /* 2 bytes */
389 /*    char            ??? */
390     uint8_t         i_vts_title_audio_nb;           /* 1 byte */
391     ifo_audio_t     p_vts_title_audio_attr[8];      /* 8 * 8 bytes */
392 /*    char[17]        ??? */
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 */
395 } vts_attr_t;
396
397 /* Main struct for vts attributes
398  * - start at i_vmg_vts_atrt_ssector */
399 typedef struct vts_inf_s
400 {
401     uint16_t        i_vts_nb;                   /* 2 bytes */
402 /*    char[2]         ??? */
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;
406 } vts_inf_t;
407
408 /*
409  * Global Structure for Video Manager
410  */
411 typedef struct vmg_s
412 {
413     manager_inf_t       manager_inf;
414     title_t             title;
415     title_inf_t         title_inf;
416     title_unit_t        title_unit;
417     parental_inf_t      parental_inf;
418     vts_inf_t           vts_inf;
419     cell_inf_t          cell_inf;
420     vobu_map_t          vobu_map;
421 } vmg_t;
422
423 /*****************************************************************************
424  * Structures for Video Title Sets (cf vts_*.ifo)
425  ****************************************************************************/
426
427 /*
428  * Video Title Sets Information Management Table
429  */
430 typedef struct vts_manager_s
431 {
432     byte_t          psz_id[13];                 /* 12 bytes (DVDVIDEO-VTS) */
433     uint32_t        i_last_sector;              /* 4 bytes */
434 /*    char[12]        ??? */
435     uint32_t        i_inf_last_sector;          /* 4 bytes */
436 /*    char            ??? */
437     uint8_t         i_spec_ver;                 /* 1 byte */
438     uint32_t        i_cat;                      /* 4 bytes */
439 /*    char[90]        ??? */
440     uint32_t        i_inf_end_byte;                /* 4 bytes */
441 /*    char[60]        ??? */
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 */
452 /*    char[24]        ??? */
453     ifo_video_t     menu_video_attr;               /* 2 bytes */
454 /*    char            ??? */
455     uint8_t         i_menu_audio_nb;               /* 1 byte */
456     ifo_audio_t     p_menu_audio_attr[8];          /* i_vmgm_audio_nb * 8 bytes */
457 /*    char[16]        ??? */
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 ??? */
461 /*    char[2]         ??? */
462     ifo_video_t     video_attr;                 /* 2 bytes */
463 /*    char            ??? */
464     uint8_t         i_audio_nb;                 /* 1 byte */
465     ifo_audio_t     p_audio_attr[8];            /* i_vmgm_audio_nb * 8 bytes */
466 /*    char[16]        ??? */
467     uint8_t         i_spu_nb;                /* 1 byte */
468     ifo_spu_t       p_spu_attr[32];          /* i_subpic_nb * 6 bytes */
469 } vts_manager_t;
470
471 /*
472  * Part Of Title Search Pointer Table Information
473  */
474
475 /* Title sets structure
476  * we have a pointer to this structure for each tts */
477 typedef struct title_start_s
478 {
479     uint16_t        i_title_id;         /* 2 bytes; Chapters/PGs */
480     uint16_t        i_chapter;                   /* 2 bytes */
481 } title_start_t;
482
483 /* Main struct for tts
484  * - start at "i_vts_ptt_srpt_ssector" */
485 typedef struct vts_title_s
486 {
487     uint16_t        i_title_nb;                   /* 2 bytes */
488 /*    char[2]         ??? */
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 */
492 } vts_title_t;
493
494 /*
495  * Time Map table information
496  */
497
498 /* Time Map structure */
499 typedef struct time_map_s
500 {
501     uint8_t         i_time_unit;                /* 1 byte */
502 /*    char            ??? */
503     uint16_t        i_entry_nb;                 /* 2 bytes */
504     uint32_t *      pi_sector;                  /* i_entry_nb * 4 bytes */
505 } time_map_t;
506
507 /* Main structure for tmap_ti
508  * - start at "i_tmap_ti_ssector" */
509 typedef struct time_inf_s
510 {
511     uint16_t        i_nb;                       /* 2 bytes */
512 /*    char[2]         ??? */
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;
516 } time_inf_t;
517
518 /*
519  * Video Title Set
520  */
521 typedef struct vts_s
522 {
523     vlc_bool_t      b_initialized;
524     int             i_pos;
525     vts_manager_t   manager_inf;
526     vts_title_t     title_inf;
527     title_unit_t    menu_unit;
528     unit_inf_t      title_unit;
529     time_inf_t      time_inf;
530     cell_inf_t      menu_cell_inf;
531     vobu_map_t      menu_vobu_map;
532     cell_inf_t      cell_inf;
533     vobu_map_t      vobu_map;
534 } vts_t;
535
536 /*
537  *  Global Ifo Structure
538  */
539 typedef struct ifo_s
540 {
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 */
547
548     /* Remap buffer for unaligned reads */
549     uint8_t         p_remap[ 2 * DVD_LB_SIZE ];
550
551 } ifo_t;
552
553
554 /*****************************************************************************
555  * Prototypes in dvd_ifo.c
556  *****************************************************************************/
557 struct thread_dvd_data_s;
558
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 * );
563