MythTV  0.26-pre
nav_read.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2000, 2001, 2002, 2003 HÃ¥kan Hjort <d95hjort@dtek.chalmers.se>
00003  *
00004  * This file is part of libdvdread.
00005  *
00006  * libdvdread is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * libdvdread is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with libdvdread; if not, write to the Free Software Foundation, Inc.,
00018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019  */
00020 
00021 #include "config.h"
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <inttypes.h>
00027 
00028 #include "bswap.h"
00029 #include "dvdread/nav_types.h"
00030 #include "dvdread/nav_read.h"
00031 #include "dvdread_internal.h"
00032 #include "dvdread/bitreader.h"
00033 
00034 #define getbits_init dvdread_getbits_init
00035 #define getbits dvdread_getbits
00036 
00037 void navRead_PCI(pci_t *pci, unsigned char *buffer) {
00038   int32_t i, j;
00039   getbits_state_t state;
00040   if (!getbits_init(&state, buffer)) abort(); /* Passed NULL pointers */
00041 
00042   /* pci pci_gi */
00043   pci->pci_gi.nv_pck_lbn = getbits(&state, 32 );
00044   pci->pci_gi.vobu_cat = getbits(&state, 16 );
00045   pci->pci_gi.zero1 = getbits(&state, 16 );
00046   pci->pci_gi.vobu_uop_ctl.zero = getbits(&state, 7 );
00047   pci->pci_gi.vobu_uop_ctl.video_pres_mode_change         = getbits(&state, 1 );
00048 
00049   pci->pci_gi.vobu_uop_ctl.karaoke_audio_pres_mode_change = getbits(&state, 1 );
00050   pci->pci_gi.vobu_uop_ctl.angle_change                   = getbits(&state, 1 );
00051   pci->pci_gi.vobu_uop_ctl.subpic_stream_change           = getbits(&state, 1 );
00052   pci->pci_gi.vobu_uop_ctl.audio_stream_change            = getbits(&state, 1 );
00053   pci->pci_gi.vobu_uop_ctl.pause_on                       = getbits(&state, 1 );
00054   pci->pci_gi.vobu_uop_ctl.still_off                      = getbits(&state, 1 );
00055   pci->pci_gi.vobu_uop_ctl.button_select_or_activate      = getbits(&state, 1 );
00056   pci->pci_gi.vobu_uop_ctl.resume                         = getbits(&state, 1 );
00057 
00058   pci->pci_gi.vobu_uop_ctl.chapter_menu_call              = getbits(&state, 1 );
00059   pci->pci_gi.vobu_uop_ctl.angle_menu_call                = getbits(&state, 1 );
00060   pci->pci_gi.vobu_uop_ctl.audio_menu_call                = getbits(&state, 1 );
00061   pci->pci_gi.vobu_uop_ctl.subpic_menu_call               = getbits(&state, 1 );
00062   pci->pci_gi.vobu_uop_ctl.root_menu_call                 = getbits(&state, 1 );
00063   pci->pci_gi.vobu_uop_ctl.title_menu_call                = getbits(&state, 1 );
00064   pci->pci_gi.vobu_uop_ctl.backward_scan                  = getbits(&state, 1 );
00065   pci->pci_gi.vobu_uop_ctl.forward_scan                   = getbits(&state, 1 );
00066 
00067   pci->pci_gi.vobu_uop_ctl.next_pg_search                 = getbits(&state, 1 );
00068   pci->pci_gi.vobu_uop_ctl.prev_or_top_pg_search          = getbits(&state, 1 );
00069   pci->pci_gi.vobu_uop_ctl.time_or_chapter_search         = getbits(&state, 1 );
00070   pci->pci_gi.vobu_uop_ctl.go_up                          = getbits(&state, 1 );
00071   pci->pci_gi.vobu_uop_ctl.stop                           = getbits(&state, 1 );
00072   pci->pci_gi.vobu_uop_ctl.title_play                     = getbits(&state, 1 );
00073   pci->pci_gi.vobu_uop_ctl.chapter_search_or_play         = getbits(&state, 1 );
00074   pci->pci_gi.vobu_uop_ctl.title_or_time_play             = getbits(&state, 1 );
00075   pci->pci_gi.vobu_s_ptm = getbits(&state, 32 );
00076   pci->pci_gi.vobu_e_ptm = getbits(&state, 32 );
00077   pci->pci_gi.vobu_se_e_ptm = getbits(&state, 32 );
00078   pci->pci_gi.e_eltm.hour   = getbits(&state, 8 );
00079   pci->pci_gi.e_eltm.minute = getbits(&state, 8 );
00080   pci->pci_gi.e_eltm.second = getbits(&state, 8 );
00081   pci->pci_gi.e_eltm.frame_u = getbits(&state, 8 );
00082   for(i = 0; i < 32; i++)
00083     pci->pci_gi.vobu_isrc[i] = getbits(&state, 8 );
00084 
00085   /* pci nsml_agli */
00086   for(i = 0; i < 9; i++)
00087     pci->nsml_agli.nsml_agl_dsta[i] = getbits(&state, 32 );
00088 
00089   /* pci hli hli_gi */
00090   pci->hli.hl_gi.hli_ss = getbits(&state, 16 );
00091   pci->hli.hl_gi.hli_s_ptm = getbits(&state, 32 );
00092   pci->hli.hl_gi.hli_e_ptm = getbits(&state, 32 );
00093   pci->hli.hl_gi.btn_se_e_ptm = getbits(&state, 32 );
00094   pci->hli.hl_gi.zero1 = getbits(&state, 2 );
00095   pci->hli.hl_gi.btngr_ns = getbits(&state, 2 );
00096   pci->hli.hl_gi.zero2 = getbits(&state, 1 );
00097   pci->hli.hl_gi.btngr1_dsp_ty = getbits(&state, 3 );
00098   pci->hli.hl_gi.zero3 = getbits(&state, 1 );
00099   pci->hli.hl_gi.btngr2_dsp_ty = getbits(&state, 3 );
00100   pci->hli.hl_gi.zero4 = getbits(&state, 1 );
00101   pci->hli.hl_gi.btngr3_dsp_ty = getbits(&state, 3 );
00102   pci->hli.hl_gi.btn_ofn = getbits(&state, 8 );
00103   pci->hli.hl_gi.btn_ns = getbits(&state, 8 );
00104   pci->hli.hl_gi.nsl_btn_ns = getbits(&state, 8 );
00105   pci->hli.hl_gi.zero5 = getbits(&state, 8 );
00106   pci->hli.hl_gi.fosl_btnn = getbits(&state, 8 );
00107   pci->hli.hl_gi.foac_btnn = getbits(&state, 8 );
00108 
00109   /* pci hli btn_colit */
00110   for(i = 0; i < 3; i++)
00111     for(j = 0; j < 2; j++)
00112       pci->hli.btn_colit.btn_coli[i][j] = getbits(&state, 32 );
00113 
00114   /* NOTE: I've had to change the structure from the disk layout to get
00115    * the packing to work with Sun's Forte C compiler. */
00116 
00117   /* pci hli btni */
00118   for(i = 0; i < 36; i++) {
00119     pci->hli.btnit[i].btn_coln = getbits(&state, 2 );
00120     pci->hli.btnit[i].x_start = getbits(&state, 10 );
00121     pci->hli.btnit[i].zero1 = getbits(&state, 2 );
00122     pci->hli.btnit[i].x_end = getbits(&state, 10 );
00123 
00124     pci->hli.btnit[i].auto_action_mode = getbits(&state, 2 );
00125     pci->hli.btnit[i].y_start = getbits(&state, 10 );
00126     pci->hli.btnit[i].zero2 = getbits(&state, 2 );
00127     pci->hli.btnit[i].y_end = getbits(&state, 10 );
00128 
00129     pci->hli.btnit[i].zero3 = getbits(&state, 2 );
00130     pci->hli.btnit[i].up = getbits(&state, 6 );
00131     pci->hli.btnit[i].zero4 = getbits(&state, 2 );
00132     pci->hli.btnit[i].down = getbits(&state, 6 );
00133     pci->hli.btnit[i].zero5 = getbits(&state, 2 );
00134     pci->hli.btnit[i].left = getbits(&state, 6 );
00135     pci->hli.btnit[i].zero6 = getbits(&state, 2 );
00136     pci->hli.btnit[i].right = getbits(&state, 6 );
00137     /* pci vm_cmd */
00138     for(j = 0; j < 8; j++)
00139       pci->hli.btnit[i].cmd.bytes[j] = getbits(&state, 8 );
00140   }
00141 
00142 
00143 #ifndef NDEBUG
00144   /* Asserts */
00145 
00146   /* pci pci gi */
00147   CHECK_VALUE(pci->pci_gi.zero1 == 0);
00148 
00149   /* pci hli hli_gi */
00150   CHECK_VALUE(pci->hli.hl_gi.zero1 == 0);
00151   CHECK_VALUE(pci->hli.hl_gi.zero2 == 0);
00152   CHECK_VALUE(pci->hli.hl_gi.zero3 == 0);
00153   CHECK_VALUE(pci->hli.hl_gi.zero4 == 0);
00154   CHECK_VALUE(pci->hli.hl_gi.zero5 == 0);
00155 
00156   /* Are there buttons defined here? */
00157   if((pci->hli.hl_gi.hli_ss & 0x03) != 0) {
00158     CHECK_VALUE(pci->hli.hl_gi.btn_ns != 0);
00159     CHECK_VALUE(pci->hli.hl_gi.btngr_ns != 0);
00160   } else {
00161     CHECK_VALUE((pci->hli.hl_gi.btn_ns != 0 && pci->hli.hl_gi.btngr_ns != 0)
00162                 || (pci->hli.hl_gi.btn_ns == 0 && pci->hli.hl_gi.btngr_ns == 0));
00163   }
00164 
00165   /* pci hli btnit */
00166   for(i = 0; i < pci->hli.hl_gi.btngr_ns; i++) {
00167     for(j = 0; j < (36 / pci->hli.hl_gi.btngr_ns); j++) {
00168       int n = (36 / pci->hli.hl_gi.btngr_ns) * i + j;
00169       CHECK_VALUE(pci->hli.btnit[n].zero1 == 0);
00170       CHECK_VALUE(pci->hli.btnit[n].zero2 == 0);
00171       CHECK_VALUE(pci->hli.btnit[n].zero3 == 0);
00172       CHECK_VALUE(pci->hli.btnit[n].zero4 == 0);
00173       CHECK_VALUE(pci->hli.btnit[n].zero5 == 0);
00174       CHECK_VALUE(pci->hli.btnit[n].zero6 == 0);
00175 
00176       if (j < pci->hli.hl_gi.btn_ns) {
00177         CHECK_VALUE(pci->hli.btnit[n].x_start <= pci->hli.btnit[n].x_end);
00178         CHECK_VALUE(pci->hli.btnit[n].y_start <= pci->hli.btnit[n].y_end);
00179         CHECK_VALUE(pci->hli.btnit[n].up <= pci->hli.hl_gi.btn_ns);
00180         CHECK_VALUE(pci->hli.btnit[n].down <= pci->hli.hl_gi.btn_ns);
00181         CHECK_VALUE(pci->hli.btnit[n].left <= pci->hli.hl_gi.btn_ns);
00182         CHECK_VALUE(pci->hli.btnit[n].right <= pci->hli.hl_gi.btn_ns);
00183         /* vmcmd_verify(pci->hli.btnit[n].cmd); */
00184       } else {
00185         int k;
00186         CHECK_VALUE(pci->hli.btnit[n].btn_coln == 0);
00187         CHECK_VALUE(pci->hli.btnit[n].auto_action_mode == 0);
00188         CHECK_VALUE(pci->hli.btnit[n].x_start == 0);
00189         CHECK_VALUE(pci->hli.btnit[n].y_start == 0);
00190         CHECK_VALUE(pci->hli.btnit[n].x_end == 0);
00191         CHECK_VALUE(pci->hli.btnit[n].y_end == 0);
00192         CHECK_VALUE(pci->hli.btnit[n].up == 0);
00193         CHECK_VALUE(pci->hli.btnit[n].down == 0);
00194         CHECK_VALUE(pci->hli.btnit[n].left == 0);
00195         CHECK_VALUE(pci->hli.btnit[n].right == 0);
00196         for (k = 0; k < 8; k++)
00197           CHECK_VALUE(pci->hli.btnit[n].cmd.bytes[k] == 0); /* CHECK_ZERO? */
00198       }
00199     }
00200   }
00201 #endif /* !NDEBUG */
00202 }
00203 
00204 void navRead_DSI(dsi_t *dsi, unsigned char *buffer) {
00205   int i;
00206   getbits_state_t state;
00207   if (!getbits_init(&state, buffer)) abort(); /* Passed NULL pointers */
00208 
00209   /* dsi dsi gi */
00210   dsi->dsi_gi.nv_pck_scr = getbits(&state, 32 );
00211   dsi->dsi_gi.nv_pck_lbn = getbits(&state, 32 );
00212   dsi->dsi_gi.vobu_ea = getbits(&state, 32 );
00213   dsi->dsi_gi.vobu_1stref_ea = getbits(&state, 32 );
00214   dsi->dsi_gi.vobu_2ndref_ea = getbits(&state, 32 );
00215   dsi->dsi_gi.vobu_3rdref_ea = getbits(&state, 32 );
00216   dsi->dsi_gi.vobu_vob_idn = getbits(&state, 16 );
00217   dsi->dsi_gi.zero1 = getbits(&state, 8 );
00218   dsi->dsi_gi.vobu_c_idn = getbits(&state, 8 );
00219   dsi->dsi_gi.c_eltm.hour   = getbits(&state, 8 );
00220   dsi->dsi_gi.c_eltm.minute = getbits(&state, 8 );
00221   dsi->dsi_gi.c_eltm.second = getbits(&state, 8 );
00222   dsi->dsi_gi.c_eltm.frame_u = getbits(&state, 8 );
00223 
00224   /* dsi sml pbi */
00225   dsi->sml_pbi.category = getbits(&state, 16 );
00226   dsi->sml_pbi.ilvu_ea = getbits(&state, 32 );
00227   dsi->sml_pbi.ilvu_sa = getbits(&state, 32 );
00228   dsi->sml_pbi.size = getbits(&state, 16 );
00229   dsi->sml_pbi.vob_v_s_s_ptm = getbits(&state, 32 );
00230   dsi->sml_pbi.vob_v_e_e_ptm = getbits(&state, 32 );
00231   for(i = 0; i < 8; i++) {
00232     dsi->sml_pbi.vob_a[i].stp_ptm1 = getbits(&state, 32 );
00233     dsi->sml_pbi.vob_a[i].stp_ptm2 = getbits(&state, 32 );
00234     dsi->sml_pbi.vob_a[i].gap_len1 = getbits(&state, 32 );
00235     dsi->sml_pbi.vob_a[i].gap_len2 = getbits(&state, 32 );
00236   }
00237 
00238   /* dsi sml agli */
00239   for(i = 0; i < 9; i++) {
00240     dsi->sml_agli.data[ i ].address = getbits(&state, 32 );
00241     dsi->sml_agli.data[ i ].size = getbits(&state, 16 );
00242   }
00243 
00244   /* dsi vobu sri */
00245   dsi->vobu_sri.next_video = getbits(&state, 32 );
00246   for(i = 0; i < 19; i++)
00247     dsi->vobu_sri.fwda[i] = getbits(&state, 32 );
00248   dsi->vobu_sri.next_vobu = getbits(&state, 32 );
00249   dsi->vobu_sri.prev_vobu = getbits(&state, 32 );
00250   for(i = 0; i < 19; i++)
00251     dsi->vobu_sri.bwda[i] = getbits(&state, 32 );
00252   dsi->vobu_sri.prev_video = getbits(&state, 32 );
00253 
00254   /* dsi synci */
00255   for(i = 0; i < 8; i++)
00256     dsi->synci.a_synca[i] = getbits(&state, 16 );
00257   for(i = 0; i < 32; i++)
00258     dsi->synci.sp_synca[i] = getbits(&state, 32 );
00259 
00260 
00261   /* Asserts */
00262 
00263   /* dsi dsi gi */
00264   CHECK_VALUE(dsi->dsi_gi.zero1 == 0);
00265 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends