]> git.sesse.net Git - vlc/blob - plugins/dvd/dvd_ifo.h
1f402b223105f211322cebd5fb3b2cee32e93867
[vlc] / plugins / dvd / dvd_ifo.h
1 /*****************************************************************************
2  * dvd_ifo.h: Structures for ifo parsing
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: dvd_ifo.h,v 1.19 2002/05/20 22:45:03 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     u8      i_compression         ;// 2;
39     u8      i_system              ;// 2;
40     u8      i_ratio               ;// 2;
41     u8      i_perm_displ          ;// 2;
42
43     u8      i_line21_1            ;// 1;
44     u8      i_line21_2            ;// 1;
45     u8      i_source_res          ;// 2;
46     u8      i_letterboxed         ;// 1;
47     u8      i_mode                ;// 1;
48 } ifo_video_t;
49
50 /* Audio type information */
51 typedef struct ifo_audio_s
52 {
53     u8      i_coding_mode         ;// 3;
54     u8      i_multichannel_extension  ;// 1;
55     u8      i_type                ;// 2;
56     u8      i_appl_mode           ;// 2;
57
58     u8      i_quantization        ;// 2;
59     u8      i_sample_freq         ;// 2;
60     u8      i_test                ;// 1;
61     u8      i_num_channels        ;// 3;
62     u16     i_lang_code           ;// 16;   // <char> description
63     u8      i_foo                 ;// 8;    // 0x00000000 ?
64     u8      i_caption             ;// 8;
65     u8      i_bar                 ;// 8;    // 0x00000000 ?
66 } ifo_audio_t;
67
68 /* Audio Status */
69 typedef struct audio_status_s
70 {
71     u8      i_available;        // 1
72     u8      i_position;         // 7
73     u8      i_foo;              // 8
74 } audio_status_t;
75
76 typedef struct ifo_spu_t
77 {
78     u16     i_prefix              ;// 16;   // 0x0100 ?
79     u16     i_lang_code           ;// 16;   // <char> description
80     u8      i_foo                 ;// 8;    // dont know
81     u8      i_caption             ;// 8;    // 0x00 ?
82 } ifo_spu_t;
83
84 /* Subpicture status */
85 typedef struct spu_status_s
86 {
87     u8      i_available;        //1
88     u8      i_position_43;      //7
89     u8      i_position_wide;    //8
90     u8      i_position_letter;  //8
91     u8      i_position_pan;     //8
92 } spu_status_t;
93
94
95 /* Ifo vitual machine Commands */
96 typedef struct command_desc_s
97 {
98     u8              i_type      :3;
99     u8              i_direct    :1;
100     u8              i_cmd       :4;
101     u8              i_dir_cmp   :1;
102     u8              i_cmp       :3;
103     u8              i_sub_cmd   :4;
104     union
105     {
106         u8          pi_8[6];
107         u16         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     u16             i_pre_command_nb;               // 2 bytes
116     u16             i_post_command_nb;              // 2 bytes
117     u16             i_cell_command_nb;              // 2 bytes
118 //    char[2]         ???
119     u64* p_pre_command;                  // i_pre_com_nb * 8 bytes
120     u64* p_post_command;                 // i_post_com_nb * 8 bytes
121     u64* 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     u8*             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     u16             i_category;                 // 2 bytes
142     u8              i_still_time;               // 1 byte; in seconds; ff=inf
143     u8              i_command_nb;               // 1 byte; 0 = no com
144     u32             i_play_time;                // 4 bytes
145     u32             i_first_sector;             // 4 bytes
146     u32             i_first_ilvu_vobu_esector;  // 4 bytes; ???
147     u32             i_last_vobu_start_sector;   // 4 bytes
148     u32             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     u16             i_vob_id;                   // 2 bytes
158 //    char            ???
159     u8              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     u8              i_chapter_nb;                   // 1 byte
170     u8              i_cell_nb;                  // 1 byte
171     u32             i_play_time;                // 4 bytes
172     u32             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     u16             i_next_title_num;              // 2 bytes
176     u16             i_prev_title_num;              // 2 bytes
177     u16             i_go_up_title_num;              // 2 bytes
178     u8              i_still_time;               // 1 byte ; in seconds
179     u8              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     u32             pi_yuv_color[16];           // 16*3 bytes
183     /* Here come the start bytes of the following structures */
184     u16             i_command_start_byte;            // 2 bytes
185     u16             i_chapter_map_start_byte;            // 2 bytes
186     u16             i_cell_play_start_byte;      // 2 bytes
187     u16             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     u16             i_lang_code;            // 2 bytes (ISO-xx)
203 //    char            ???
204     u8              i_existence_mask;           // 1 byte
205     u32             i_unit_inf_start_byte;                 // 4 bytes
206 } unit_t;
207
208 typedef struct unit_title_s
209 {
210     u8              i_category_mask;             // 1 byte
211     u8              i_category;                  // 1 byte
212     u16             i_parental_mask;                 // 2 bytes
213     u32             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     u16             i_title_nb;                   // 2 bytes
222 //    char[2]         ???
223     u32             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     u16             i_unit_nb;                    // 2 bytes; ???
232 //    char[2]         ???
233     u32             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     u16             i_vob_id;                   // 2 bytes
244     u8              i_cell_id;                  // 1 byte
245 //    char            ???
246     u32             i_first_sector;             // 4 bytes
247     u32             i_last_sector;              // 4 bytes
248 } cell_map_t;
249
250 typedef struct cell_inf_s
251 {
252     u16             i_vob_nb;                   // 2 bytes
253 //    char[2]         ???
254     u32             i_last_byte;                // 4 bytes
255     u16             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     u32             i_last_byte;                   // 4 bytes
267     u32*            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     char            psz_id[13];                 // 12 bytes (DVDVIDEO-VMG)
280     u32             i_vmg_end_sector;                  // 4 bytes
281 //    char[12]        ???
282     u32             i_vmg_inf_end_sector;                // 4 bytes
283 //    char            ???
284     u8              i_spec_ver;                 // 1 byte
285     u32             i_cat;                      // 4 bytes
286     u16             i_volume_nb;                   // 2 bytes
287     u16             i_volume;                      // 2 bytes
288     u8              i_disc_side;                // 1 bytes
289 //    char[20]        ???
290     u16             i_title_set_nb;                   // 2 bytes
291     char            ps_provider_id[32];         // 32 bytes
292     u64             i_pos_code;                 // 8 bytes
293 //    char[24]        ???
294     u32             i_vmg_inf_end_byte;              // 4 bytes
295     u32             i_first_play_title_start_byte;             // 4 bytes
296 //    char[56]        ???
297     u32             i_vob_start_sector;             // 4 bytes
298     u32             i_title_inf_start_sector;         // 4 bytes
299     u32             i_title_unit_start_sector;          // 4 bytes
300     u32             i_parental_inf_start_sector;         // 4 bytes
301     u32             i_vts_inf_start_sector;         // 4 bytes
302     u32             i_text_data_start_sector;         // 4 bytes
303     u32             i_cell_inf_start_sector;            // 4 bytes
304     u32             i_vobu_map_start_sector;       // 4 bytes
305 //    char[2]         ???
306     ifo_video_t     video_attr;                 // 2 bytes
307 //    char            ???
308     u8              i_audio_nb;                 // 1 byte
309     ifo_audio_t     p_audio_attr[8];            // i_vmgm_audio_nb * 8 bytes
310 //    char[16]        ???
311     u8              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     u8              i_play_type;                // 1 byte
325     u8              i_angle_nb;                 // 1 byte
326     u16             i_chapter_nb;                  // 2 bytes; Chapters/PGs
327     u16             i_parental_id;              // 2 bytes
328     u8              i_title_set_num;            // 1 byte (VTS#)
329     u8              i_title_num;                 // 1 byte ???
330     u32             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     u16             i_title_nb;                   // 2 bytes
338 //    char[2]         ???
339     u32             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     char            ps_country_code[2];         // 2 bytes
349 //    char[2]         ???
350     u16             i_parental_mask_start_byte;            // 2 bytes
351 //    char[2]         ???
352 } parental_desc_t;
353
354 typedef struct parental_mask_s
355 {
356     u16*            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     u16             i_country_nb;               // 2 bytes
364     u16             i_vts_nb;                   // 2 bytes
365     u32             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     u32             i_last_byte;                   // 4 bytes
379     u32             i_cat_app_type;             // 4 bytes
380     ifo_video_t     vts_menu_video_attr;          // 2 bytes
381 //    char            ???
382     u8              i_vts_menu_audio_nb;            // 1 byte
383     ifo_audio_t     p_vts_menu_audio_attr[8];       // 8 * 8 bytes
384 //    char[17]        ???
385     u8              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     u8              i_vts_title_audio_nb;           // 1 byte
391     ifo_audio_t     p_vts_title_audio_attr[8];      // 8 * 8 bytes
392 //    char[17]        ???
393     u8              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     u16             i_vts_nb;                   // 2 bytes
402 //    char[2]         ???
403     u32             i_last_byte;                   // 4 bytes
404     u32*            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     char            psz_id[13];                 // 12 bytes (DVDVIDEO-VTS)
433     u32             i_last_sector;              // 4 bytes
434 //    char[12]        ???
435     u32             i_inf_last_sector;          // 4 bytes
436 //    char            ???
437     u8              i_spec_ver;                 // 1 byte
438     u32             i_cat;                      // 4 bytes
439 //    char[90]        ???
440     u32             i_inf_end_byte;                // 4 bytes
441 //    char[60]        ???
442     u32             i_menu_vob_start_sector;           // 4 bytes
443     u32             i_title_vob_start_sector;          // 4 bytes
444     u32             i_title_inf_start_sector;         // 4 bytes
445     u32             i_title_unit_start_sector;            // 4 bytes
446     u32             i_menu_unit_start_sector;        // 4 bytes
447     u32             i_time_inf_start_sector;          // 4 bytes
448     u32             i_menu_cell_inf_start_sector;          // 4 bytes
449     u32             i_menu_vobu_map_start_sector;     // 4 bytes
450     u32             i_cell_inf_start_sector;            // 4 bytes
451     u32             i_vobu_map_start_sector;       // 4 bytes
452 //    char[24]        ???
453     ifo_video_t     menu_video_attr;               // 2 bytes
454 //    char            ???
455     u8              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     u8              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     u8              i_audio_nb;                 // 1 byte
465     ifo_audio_t     p_audio_attr[8];            // i_vmgm_audio_nb * 8 bytes
466 //    char[16]        ???
467     u8              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     u16             i_title_id;         // 2 bytes; Chapters/PGs
480     u16             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     u16             i_title_nb;                   // 2 bytes
488 //    char[2]         ???
489     u32             i_last_byte;                   // 4 bytes
490     u32*            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     u8              i_time_unit;                // 1 byte
502 //    char            ???
503     u16             i_entry_nb;                 // 2 bytes
504     u32*            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     u16             i_nb;                       // 2 bytes
512 //    char[2]         ???
513     u32             i_last_byte;                   // 4 bytes
514     u32*            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     boolean_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     boolean_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     u8              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