]> git.sesse.net Git - vlc/blob - extras/libdvdread/nav_read.c
Support for libdvdread.
[vlc] / extras / libdvdread / nav_read.c
1 /**
2  * Copyright (C) 2000 HÃ¥kan Hjort <d95hjort@dtek.chalmers.se>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <inttypes.h>
22 #include <assert.h>
23
24 #include "config.h" // Needed for WORDS_BIGENDIAN
25 #include "bswap.h"
26 #include "nav_types.h"
27 #include "nav_read.h"
28
29 void navRead_PCI(pci_t *pci, unsigned char *buffer) {
30   int i, j;
31
32   assert(sizeof(pci_t) == PCI_BYTES - 1); // -1 for substream id
33   
34   memcpy(pci, buffer, sizeof(pci_t));
35
36   /* Endian conversions  */
37
38   /* pci pci_gi */
39   B2N_32(pci->pci_gi.nv_pck_lbn);
40   B2N_16(pci->pci_gi.vobu_cat);
41   B2N_32(pci->pci_gi.vobu_s_ptm);
42   B2N_32(pci->pci_gi.vobu_e_ptm);
43   B2N_32(pci->pci_gi.vobu_se_e_ptm);
44
45   /* pci nsml_agli */
46   for(i = 0; i < 9; i++)
47     B2N_32(pci->nsml_agli.nsml_agl_dsta[i]);
48
49   /* pci hli hli_gi */
50   B2N_16(pci->hli.hl_gi.hli_ss);
51   B2N_32(pci->hli.hl_gi.hli_s_ptm);
52   B2N_32(pci->hli.hl_gi.hli_e_ptm);
53   B2N_32(pci->hli.hl_gi.btn_se_e_ptm);
54
55   /* pci hli btn_colit */
56   for(i = 0; i < 3; i++)
57     for(j = 0; j < 2; j++)
58       B2N_32(pci->hli.btn_colit.btn_coli[i][j]);
59
60
61   /* pci hli btni */
62   /* There are some issues with this bitfiled with some compilers 
63      because they stradle word boundaries. */
64   
65 #if !defined(WORDS_BIGENDIAN)
66   for(i = 0; i < 36; i++) {
67 #if 0 /* Wierd Sun CC code that does not work */
68     unsigned char m[6];
69     memcpy(m, &pci->hli.btnit[i], 6);
70     pci->hli.btnit[i].zero1   = (m[1] >> 2);
71     pci->hli.btnit[i].x_start = (m[0] << 4) | (m[1] >> 4);
72     pci->hli.btnit[i].x_end   = (m[1] << 8) | m[2];
73     pci->hli.btnit[i].y_start = (m[3] << 4) | (m[4] >> 4);
74     pci->hli.btnit[i].y_end   = (m[4] << 8) | m[5];
75     pci->hli.btnit[i].zero2   = (m[4] >> 2);
76     pci->hli.btnit[i].btn_coln = (m[0] >> 6);
77     pci->hli.btnit[i].auto_action_mode = (m[3] >> 6);
78 #else
79     char tmp[6], swap;
80     memcpy(tmp, &(pci->hli.btnit[i]), 6);
81     /* This is a B2N_24() */
82     swap = tmp[0]; tmp[0] = tmp[2]; tmp[2] = swap;
83     /* This is a B2N_24() */
84     swap = tmp[3]; tmp[3] = tmp[5]; tmp[5] = swap;
85     memcpy(&(pci->hli.btnit[i]), tmp, 6);
86 #endif
87   }
88 #endif
89
90
91   /* Asserts */
92
93   /* pci pci gi */ 
94   assert(pci->pci_gi.zero1 == 0);
95
96   /* pci hli hli_gi */
97   assert(pci->hli.hl_gi.zero1 == 0);
98   assert(pci->hli.hl_gi.zero2 == 0);
99   assert(pci->hli.hl_gi.zero3 == 0);
100   assert(pci->hli.hl_gi.zero4 == 0);
101   assert(pci->hli.hl_gi.zero5 == 0);
102
103   /* Are there buttons defined here? */
104   if((pci->hli.hl_gi.hli_ss & 0x03) != 0) {
105     assert(pci->hli.hl_gi.btn_ns != 0); 
106     assert(pci->hli.hl_gi.btngr_ns != 0); 
107   } else {
108     assert((pci->hli.hl_gi.btn_ns != 0 && pci->hli.hl_gi.btngr_ns != 0) 
109            || (pci->hli.hl_gi.btn_ns == 0 && pci->hli.hl_gi.btngr_ns == 0));
110   }
111
112   /* pci hli btnit */
113   
114 #if NDEBUG
115   for(i = 0; i < pci->hli.hl_gi.btngr_ns; i++) {
116     for(j = 0; j < (36 / pci->hli.hl_gi.btngr_ns); j++) {
117       int n = (36 / pci->hli.hl_gi.btngr_ns) * i + j;
118       assert(pci->hli.btnit[n].zero1 == 0);
119       assert(pci->hli.btnit[n].zero2 == 0);
120       assert(pci->hli.btnit[n].zero3 == 0);
121       assert(pci->hli.btnit[n].zero4 == 0);
122       assert(pci->hli.btnit[n].zero5 == 0);
123       assert(pci->hli.btnit[n].zero6 == 0);
124       
125       if (j < pci->hli.hl_gi.btn_ns) {  
126         assert(pci->hli.btnit[n].x_start <= pci->hli.btnit[n].x_end);
127         assert(pci->hli.btnit[n].y_start <= pci->hli.btnit[n].y_end);
128         assert(pci->hli.btnit[n].up <= pci->hli.hl_gi.btn_ns);
129         assert(pci->hli.btnit[n].down <= pci->hli.hl_gi.btn_ns);
130         assert(pci->hli.btnit[n].left <= pci->hli.hl_gi.btn_ns);
131         assert(pci->hli.btnit[n].right <= pci->hli.hl_gi.btn_ns);
132         //vmcmd_verify(pci->hli.btnit[n].cmd);
133       } else {
134         int k;
135         assert(pci->hli.btnit[n].btn_coln == 0);
136         assert(pci->hli.btnit[n].auto_action_mode == 0);
137         assert(pci->hli.btnit[n].x_start == 0);
138         assert(pci->hli.btnit[n].y_start == 0);
139         assert(pci->hli.btnit[n].x_end == 0);
140         assert(pci->hli.btnit[n].y_end == 0);
141         assert(pci->hli.btnit[n].up == 0);
142         assert(pci->hli.btnit[n].down == 0);
143         assert(pci->hli.btnit[n].left == 0);
144         assert(pci->hli.btnit[n].right == 0);
145         for (k = 0; k < 8; k++)
146           assert(pci->hli.btnit[n].cmd.bytes[k] == 0); //CHECK_ZERO?
147       }
148     }
149   }
150 #endif
151 }
152
153 void navRead_DSI(dsi_t *dsi, unsigned char *buffer) {
154   int i;
155
156   assert(sizeof(dsi_t) == DSI_BYTES - 1); // -1 for substream id
157   
158   memcpy(dsi, buffer, sizeof(dsi_t));
159
160   /* Endian conversions */
161
162   /* dsi dsi gi */
163   B2N_32(dsi->dsi_gi.nv_pck_scr);
164   B2N_32(dsi->dsi_gi.nv_pck_lbn);
165   B2N_32(dsi->dsi_gi.vobu_ea);
166   B2N_32(dsi->dsi_gi.vobu_1stref_ea);
167   B2N_32(dsi->dsi_gi.vobu_2ndref_ea);
168   B2N_32(dsi->dsi_gi.vobu_3rdref_ea);
169   B2N_16(dsi->dsi_gi.vobu_vob_idn);
170
171   /* dsi sml pbi */
172   B2N_16(dsi->sml_pbi.category);
173   B2N_32(dsi->sml_pbi.ilvu_ea);
174   B2N_32(dsi->sml_pbi.ilvu_sa);
175   B2N_16(dsi->sml_pbi.size);
176   B2N_32(dsi->sml_pbi.vob_v_s_s_ptm);
177   B2N_32(dsi->sml_pbi.vob_v_e_e_ptm);
178
179   /* dsi sml agli */
180   for(i = 0; i < 9; i++) {
181     B2N_32(dsi->sml_agli.data[ i ].address);
182     B2N_16(dsi->sml_agli.data[ i ].size);
183   }
184
185   /* dsi vobu sri */
186   B2N_32(dsi->vobu_sri.next_video);
187   for(i = 0; i < 19; i++)
188     B2N_32(dsi->vobu_sri.fwda[i]);
189   B2N_32(dsi->vobu_sri.next_vobu);
190   B2N_32(dsi->vobu_sri.prev_vobu);
191   for(i = 0; i < 19; i++)
192     B2N_32(dsi->vobu_sri.bwda[i]);
193   B2N_32(dsi->vobu_sri.prev_video);
194
195   /* dsi synci */
196   for(i = 0; i < 8; i++)
197     B2N_16(dsi->synci.a_synca[i]);
198   for(i = 0; i < 32; i++)
199     B2N_32(dsi->synci.sp_synca[i]);
200
201   
202   /* Asserts */
203
204   /* dsi dsi gi */
205   assert(dsi->dsi_gi.zero1 == 0);
206 }
207