diff options
Diffstat (limited to 'libdvdread')
-rw-r--r-- | libdvdread/bswap.h | 16 | ||||
-rw-r--r-- | libdvdread/cmd_print.c | 550 | ||||
-rw-r--r-- | libdvdread/cmd_print.h | 51 | ||||
-rw-r--r-- | libdvdread/dvd_input.c | 414 | ||||
-rw-r--r-- | libdvdread/dvd_input.h | 55 | ||||
-rw-r--r-- | libdvdread/dvd_reader.c | 1612 | ||||
-rw-r--r-- | libdvdread/dvd_reader.h | 344 | ||||
-rw-r--r-- | libdvdread/dvd_udf.c | 1217 | ||||
-rw-r--r-- | libdvdread/dvd_udf.h | 66 | ||||
-rw-r--r-- | libdvdread/dvdread_internal.h | 13 | ||||
-rw-r--r-- | libdvdread/ifo_print.c | 1190 | ||||
-rw-r--r-- | libdvdread/ifo_print.h | 60 | ||||
-rw-r--r-- | libdvdread/ifo_read.c | 2185 | ||||
-rw-r--r-- | libdvdread/ifo_read.h | 228 | ||||
-rw-r--r-- | libdvdread/ifo_types.h | 897 | ||||
-rw-r--r-- | libdvdread/libdvdread_changes.diff | 537 | ||||
-rw-r--r-- | libdvdread/md5.c | 418 | ||||
-rw-r--r-- | libdvdread/md5.h | 162 | ||||
-rw-r--r-- | libdvdread/nav_print.c | 286 | ||||
-rw-r--r-- | libdvdread/nav_print.h | 51 | ||||
-rw-r--r-- | libdvdread/nav_read.c | 331 | ||||
-rw-r--r-- | libdvdread/nav_read.h | 52 | ||||
-rw-r--r-- | libdvdread/nav_types.h | 273 |
23 files changed, 0 insertions, 11008 deletions
diff --git a/libdvdread/bswap.h b/libdvdread/bswap.h deleted file mode 100644 index 92afd07c88..0000000000 --- a/libdvdread/bswap.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef DVDREAD_BSWAP_H -#define DVDREAD_BSWAP_H - -#include "libavutil/bswap.h" - -#ifdef WORDS_BIGENDIAN -#define B2N_16(x) -#define B2N_32(x) -#define B2N_64(x) -#else -#define B2N_16(x) x = bswap_16(x) -#define B2N_32(x) x = bswap_32(x) -#define B2N_64(x) x = bswap_64(x) -#endif - -#endif diff --git a/libdvdread/cmd_print.c b/libdvdread/cmd_print.c deleted file mode 100644 index fd3bdc1382..0000000000 --- a/libdvdread/cmd_print.c +++ /dev/null @@ -1,550 +0,0 @@ -/* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */ -/* - * Copyright (C) 2000, 2001, 2002, 2003 Martin Norbäck, Håkan Hjort - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include <stdio.h> -#include <ctype.h> - -#if defined(HAVE_INTTYPES_H) -#include <inttypes.h> -#elif defined(HAVE_STDINT_H) -#include <stdint.h> -#endif - -#include "cmd_print.h" - - -typedef struct -{ - uint8_t bits[8]; - uint8_t examined[8]; -} cmd_t; - - -static const char *cmp_op_table[] = { - NULL, "&", "==", "!=", ">=", ">", "<=", "<" -}; -static const char *set_op_table[] = { - NULL, "=", "<->", "+=", "-=", "*=", "/=", "%=", "rnd", "&=", "|=", "^=" -}; - -static const char *link_table[] = { - "LinkNoLink", "LinkTopC", "LinkNextC", "LinkPrevC", - NULL, "LinkTopPG", "LinkNextPG", "LinkPrevPG", - NULL, "LinkTopPGC", "LinkNextPGC", "LinkPrevPGC", - "LinkGoUpPGC", "LinkTailPGC", NULL, NULL, - "RSM" -}; - -static const char *system_reg_table[] = { - "Menu Description Language Code", - "Audio Stream Number", - "Sub-picture Stream Number", - "Angle Number", - "Title Track Number", - "VTS Title Track Number", - "VTS PGC Number", - "PTT Number for One_Sequential_PGC_Title", - "Highlighted Button Number", - "Navigation Timer", - "Title PGC Number for Navigation Timer", - "Audio Mixing Mode for Karaoke", - "Country Code for Parental Management", - "Parental Level", - "Player Configurations for Video", - "Player Configurations for Audio", - "Initial Language Code for Audio", - "Initial Language Code Extension for Audio", - "Initial Language Code for Sub-picture", - "Initial Language Code Extension for Sub-picture", - "Player Regional Code", - "Reserved 21", - "Reserved 22", - "Reserved 23" -}; - -static const char *system_reg_abbr_table[] = { - NULL, - "ASTN", - "SPSTN", - "AGLN", - "TTN", - "VTS_TTN", - "TT_PGCN", - "PTTN", - "HL_BTNN", - "NVTMR", - "NV_PGCN", - NULL, - "CC_PLT", - "PLT", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, -}; - - - -static unsigned int bits(cmd_t *cmd, int byte, int bit, int count) { - unsigned int val = 0; - unsigned int bit_mask; - - while(count--) { - if(bit > 7) { - bit = 0; - byte++; - } - bit_mask = 0x01 << (7-bit); - val <<= 1; - if((cmd->bits[byte]) & bit_mask) - val |= 1; - cmd->examined[byte] |= bit_mask; - bit++; - } - return val; -} - - -static void print_system_reg(unsigned int reg) { - if(reg < sizeof(system_reg_abbr_table) / sizeof(char *)) - fprintf(stdout, system_reg_table[reg]); - else - fprintf(stdout, " WARNING: Unknown system register "); -} - -static void print_reg(unsigned int reg) { - if(reg & 0x80) - print_system_reg(reg & 0x7f); - else - if(reg < 16) - fprintf(stdout, "g[%u]", reg); - else - fprintf(stdout, " WARNING: Unknown general register "); -} - -static void print_cmp_op(unsigned int op) { - if(op < sizeof(cmp_op_table) / sizeof(char *) && cmp_op_table[op] != NULL) - fprintf(stdout, " %s ", cmp_op_table[op]); - else - fprintf(stdout, " WARNING: Unknown compare op "); -} - -static void print_set_op(unsigned int op) { - if(op < sizeof(set_op_table) / sizeof(char *) && set_op_table[op] != NULL) - fprintf(stdout, " %s ", set_op_table[op]); - else - fprintf(stdout, " WARNING: Unknown set op "); -} - -static void print_reg_or_data(cmd_t *cmd, unsigned int immediate, int byte) { - if(immediate) { - int i = bits(cmd,byte,0,16); - - fprintf(stdout, "0x%x", i); - if(isprint(i & 0xff) && isprint((i>>8) & 0xff)) - fprintf(stdout, " (\"%c%c\")", (char)((i>>8) & 0xff), (char)(i & 0xff)); - } else { - print_reg(bits(cmd,byte + 1,0,8)); - } -} - -static void print_reg_or_data_2(cmd_t *cmd, unsigned int immediate, int byte) { - if(immediate) - fprintf(stdout, "0x%x", bits(cmd,byte,1,7)); - else - fprintf(stdout, "g[%u]", bits(cmd,byte,4,4)); -} - -static void print_if_version_1(cmd_t *cmd) { - unsigned int op = bits(cmd,1,1,3); - - if(op) { - fprintf(stdout, "if ("); - print_reg(bits(cmd,3,0,8)); - print_cmp_op(op); - print_reg_or_data(cmd,bits(cmd,1,0,1), 4); - fprintf(stdout, ") "); - } -} - -static void print_if_version_2(cmd_t *cmd) { - unsigned int op = bits(cmd,1,1,3); - - if(op) { - fprintf(stdout, "if ("); - print_reg(bits(cmd,6,0,8)); - print_cmp_op(op); - print_reg(bits(cmd,7,0,8)); - fprintf(stdout, ") "); - } -} - -static void print_if_version_3(cmd_t *cmd) { - unsigned int op = bits(cmd,1,1,3); - - if(op) { - fprintf(stdout, "if ("); - print_reg(bits(cmd,2,0,8)); - print_cmp_op(op); - print_reg_or_data(cmd,bits(cmd,1,0,1), 6); - fprintf(stdout, ") "); - } -} - -static void print_if_version_4(cmd_t *cmd) { - unsigned int op = bits(cmd,1,1,3); - - if(op) { - fprintf(stdout, "if ("); - print_reg(bits(cmd,1,4,4)); - print_cmp_op(op); - print_reg_or_data(cmd,bits(cmd,1,0,1), 4); - fprintf(stdout, ") "); - } -} - -static void print_if_version_5(cmd_t *cmd) { - unsigned int op = bits(cmd,1,1,3); - - if(op) { - fprintf(stdout, "if ("); - print_reg(bits(cmd,4,0,8)); - print_cmp_op(op); - print_reg(bits(cmd,5,0,8)); - fprintf(stdout, ") "); - } -} - -static void print_special_instruction(cmd_t *cmd) { - unsigned int op = bits(cmd,1,4,4); - - switch(op) { - case 0: // NOP - fprintf(stdout, "Nop"); - break; - case 1: // Goto line - fprintf(stdout, "Goto %u", bits(cmd,7,0,8)); - break; - case 2: // Break - fprintf(stdout, "Break"); - break; - case 3: // Parental level - fprintf(stdout, "SetTmpPML %u, Goto %u", - bits(cmd,6,4,4), bits(cmd,7,0,8)); - break; - default: - fprintf(stdout, "WARNING: Unknown special instruction (%u)", - bits(cmd,1,4,4)); - } -} - -static void print_linksub_instruction(cmd_t *cmd) { - unsigned int linkop = bits(cmd,7,3,5); - unsigned int button = bits(cmd,6,0,6); - - if(linkop < sizeof(link_table)/sizeof(char *) && link_table[linkop] != NULL) - fprintf(stdout, "%s (button %u)", link_table[linkop], button); - else - fprintf(stdout, "WARNING: Unknown linksub instruction (%u)", linkop); -} - -static void print_link_instruction(cmd_t *cmd, int optional) { - unsigned int op = bits(cmd,1,4,4); - - if(optional && op) - fprintf(stdout, ", "); - - switch(op) { - case 0: - if(!optional) - fprintf(stdout, "WARNING: NOP (link)!"); - break; - case 1: - print_linksub_instruction(cmd); - break; - case 4: - fprintf(stdout, "LinkPGCN %u", bits(cmd,6,1,15)); - break; - case 5: - fprintf(stdout, "LinkPTT %u (button %u)", - bits(cmd,6,6,10), bits(cmd,6,0,6)); - break; - case 6: - fprintf(stdout, "LinkPGN %u (button %u)", - bits(cmd,7,1,7), bits(cmd,6,0,6)); - break; - case 7: - fprintf(stdout, "LinkCN %u (button %u)", - bits(cmd,7,0,8), bits(cmd,6,0,6)); - break; - default: - fprintf(stdout, "WARNING: Unknown link instruction"); - } -} - -static void print_jump_instruction(cmd_t *cmd) { - switch(bits(cmd,1,4,4)) { - case 1: - fprintf(stdout, "Exit"); - break; - case 2: - fprintf(stdout, "JumpTT %u", bits(cmd,5,1,7)); - break; - case 3: - fprintf(stdout, "JumpVTS_TT %u", bits(cmd,5,1,7)); - break; - case 5: - fprintf(stdout, "JumpVTS_PTT %u:%u", bits(cmd,5,1,7), bits(cmd,2,6,10)); - break; - case 6: - switch(bits(cmd,5,0,2)) { - case 0: - fprintf(stdout, "JumpSS FP"); - break; - case 1: - fprintf(stdout, "JumpSS VMGM (menu %u)", bits(cmd,5,4,4)); - break; - case 2: - fprintf(stdout, "JumpSS VTSM (vts %u, title %u, menu %u)", - bits(cmd,4,0,8), bits(cmd,3,0,8), bits(cmd,5,4,4)); - break; - case 3: - fprintf(stdout, "JumpSS VMGM (pgc %u)", bits(cmd,2,1,15)); - break; - } - break; - case 8: - switch(bits(cmd,5,0,2)) { - case 0: - fprintf(stdout, "CallSS FP (rsm_cell %u)", - bits(cmd,4,0,8)); - break; - case 1: - fprintf(stdout, "CallSS VMGM (menu %u, rsm_cell %u)", - bits(cmd,5,4,4), bits(cmd,4,0,8)); - break; - case 2: - fprintf(stdout, "CallSS VTSM (menu %u, rsm_cell %u)", - bits(cmd,5,4,4), bits(cmd,4,0,8)); - break; - case 3: - fprintf(stdout, "CallSS VMGM (pgc %u, rsm_cell %u)", - bits(cmd,2,1,15), bits(cmd,4,0,8)); - break; - } - break; - default: - fprintf(stdout, "WARNING: Unknown Jump/Call instruction"); - } -} - -static void print_system_set(cmd_t *cmd) { - int i; - - switch(bits(cmd,0,4,4)) { - case 1: // Set system reg 1 &| 2 &| 3 (Audio, Subp. Angle) - for(i = 1; i <= 3; i++) { - if(bits(cmd,2+i,0,1)) { - print_system_reg((unsigned int)i); - fprintf(stdout, " = "); - print_reg_or_data_2(cmd,bits(cmd,0,3,1), 2 + i); - fprintf(stdout, " "); - } - } - break; - case 2: // Set system reg 9 & 10 (Navigation timer, Title PGC number) - print_system_reg(9); - fprintf(stdout, " = "); - print_reg_or_data(cmd,bits(cmd,0,3,1), 2); - fprintf(stdout, " "); - print_system_reg(10); - fprintf(stdout, " = %u", bits(cmd,5,0,8)); // ?? - break; - case 3: // Mode: Counter / Register + Set - fprintf(stdout, "SetMode "); - if(bits(cmd,5,0,1)) - fprintf(stdout, "Counter "); - else - fprintf(stdout, "Register "); - print_reg(bits(cmd,5,4,4)); - print_set_op(0x1); // '=' - print_reg_or_data(cmd,bits(cmd,0,3,1), 2); - break; - case 6: // Set system reg 8 (Highlighted button) - print_system_reg(8); - if(bits(cmd,0,3,1)) // immediate - fprintf(stdout, " = 0x%x (button no %u)", - bits(cmd,4,0,16), bits(cmd,4,0,6)); - else - fprintf(stdout, " = g[%u]", bits(cmd,5,4,4)); - break; - default: - fprintf(stdout, "WARNING: Unknown system set instruction (%u)", - bits(cmd,0,4,4)); - } -} - -static void print_set_version_1(cmd_t *cmd) { - unsigned int set_op = bits(cmd,0,4,4); - - if(set_op) { - print_reg(bits(cmd,3,0,8)); - print_set_op(set_op); - print_reg_or_data(cmd,bits(cmd,0,3,1), 4); - } else { - fprintf(stdout, "NOP"); - } -} - -static void print_set_version_2(cmd_t *cmd) { - unsigned int set_op = bits(cmd,0,4,4); - - if(set_op) { - print_reg(bits(cmd,1,4,4)); - print_set_op(set_op); - print_reg_or_data(cmd,bits(cmd,0,3,1), 2); - } else { - fprintf(stdout, "NOP"); - } -} - -static void print_set_version_3(cmd_t *cmd) { - unsigned int set_op = bits(cmd,0,4,4); - - if(set_op) { - print_reg(bits(cmd,1,4,4)); - print_set_op(set_op); - if(bits(cmd,0,3,1)) { // print_reg_or_data - unsigned int i = bits(cmd,2,0,16); - - fprintf(stdout, "0x%x", i); - if(isprint(i & 0xff) && isprint((i>>8) & 0xff)) - fprintf(stdout, " (\"%c%c\")", - (char)((i>>8) & 0xff), (char)(i & 0xff)); - } else { - print_reg(bits(cmd,2,0,8)); - } - } else { - fprintf(stdout, "NOP"); - } -} - -static void print_command(cmd_t *cmd) { - switch(bits(cmd,0,0,3)) { /* three first bits */ - case 0: // Special instructions - print_if_version_1(cmd); - print_special_instruction(cmd); - break; - case 1: // Jump/Call or Link instructions - if(bits(cmd,0,3,1)) { - print_if_version_2(cmd); - print_jump_instruction(cmd); - } else { - print_if_version_1(cmd); - print_link_instruction(cmd,0); // must be pressent - } - break; - case 2: // Set System Parameters instructions - print_if_version_2(cmd); - print_system_set(cmd); - print_link_instruction(cmd,1); // either 'if' or 'link' - break; - case 3: // Set General Parameters instructions - print_if_version_3(cmd); - print_set_version_1(cmd); - print_link_instruction(cmd,1); // either 'if' or 'link' - break; - case 4: // Set, Compare -> LinkSub instructions - print_set_version_2(cmd); - fprintf(stdout, ", "); - print_if_version_4(cmd); - print_linksub_instruction(cmd); - break; - case 5: // Compare -> (Set and LinkSub) instructions - if(bits(cmd,0,3,1)) - print_if_version_5(cmd); - else - print_if_version_1(cmd); - fprintf(stdout, "{ "); - print_set_version_3(cmd); - fprintf(stdout, ", "); - print_linksub_instruction(cmd); - fprintf(stdout, " }"); - break; - case 6: // Compare -> Set, always LinkSub instructions - if(bits(cmd,0,3,1)) - print_if_version_5(cmd); - else - print_if_version_1(cmd); - fprintf(stdout, "{ "); - print_set_version_3(cmd); - fprintf(stdout, " } "); - print_linksub_instruction(cmd); - break; - default: - fprintf(stdout, "WARNING: Unknown instruction type (%i)", - bits(cmd,0,0,3)); - } -} - -void cmdPrint_mnemonic(vm_cmd_t *command) { - int i, extra_bits; - cmd_t cmd; - - for(i = 0; i < 8; i++) { - cmd.bits[i] = command->bytes[i]; - cmd.examined[i] = 0; - } - - print_command(&cmd); - - // Check if there still are bits set that were not examined - extra_bits = 0; - for(i = 0; i < 8; i++) - if(cmd.bits[i] & ~ cmd.examined[i]) { - extra_bits = 1; - break; - } - if(extra_bits) { - fprintf(stdout, " [WARNING, unknown bits:"); - for(i = 0; i < 8; i++) - fprintf(stdout, " %02x", cmd.bits[i] & ~ cmd.examined[i]); - fprintf(stdout, "]"); - } -} - -void cmdPrint_CMD(int row, vm_cmd_t *command) { - int i; - - fprintf(stdout, "(%03d) ", row + 1); - for(i = 0; i < 8; i++) - fprintf(stdout, "%02x ", command->bytes[i]); - fprintf(stdout, "| "); - - cmdPrint_mnemonic(command); - fprintf(stdout, "\n"); -} diff --git a/libdvdread/cmd_print.h b/libdvdread/cmd_print.h deleted file mode 100644 index 0f1ee74ddb..0000000000 --- a/libdvdread/cmd_print.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#ifndef CMD_PRINT_H_INCLUDED -#define CMD_PRINT_H_INCLUDED - -/* - * Copyright (C) 2000, 2001, 2002, 2003 Martin Norbäck, Håkan Hjort - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <libdvdread/ifo_types.h> - -/** - * Pretty printing of the DVD commands (vm instructions). - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Prints a text representation of the commands to stdout. - * - * @param command Pointer to the DVD command to be printed. - */ -void cmdPrint_mnemonic(vm_cmd_t *command); - -/** - * Prints row, then a hex dump of the command followed by the text - * representation of the commands, as given by cmdPrint_mnemonic to - * stdout. - * - * @param command Pointer to the DVD command to be printed. */ -void cmdPrint_CMD(int row, vm_cmd_t *command); - -#ifdef __cplusplus -}; -#endif -#endif /* CMD_PRINT_H_INCLUDED */ diff --git a/libdvdread/dvd_input.c b/libdvdread/dvd_input.c deleted file mode 100644 index 35359821bd..0000000000 --- a/libdvdread/dvd_input.c +++ /dev/null @@ -1,414 +0,0 @@ -/* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */ -/* - * Copyright (C) 2002 Samuel Hocevar <sam@zoy.org>, - * Håkan Hjort <d95hjort@dtek.chalmers.se> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#define __USE_GNU /* to get O_DIRECT in linux */ -#include <fcntl.h> -#include <unistd.h> - -#include "dvd_reader.h" -#include "dvd_input.h" - -#include "dvdread_internal.h" - -/* The function pointers that is the exported interface of this file. */ -dvd_input_t (*dvdinput_open) (const char *); -int (*dvdinput_close) (dvd_input_t); -int (*dvdinput_seek) (dvd_input_t, int); -int (*dvdinput_title) (dvd_input_t, int); -/** - * pointer must be aligned to 2048 bytes - * if reading from a raw/O_DIRECT file - */ -int (*dvdinput_read) (dvd_input_t, void *, int, int); - -char * (*dvdinput_error) (dvd_input_t); - -#ifdef HAVE_DVDCSS_DVDCSS_H -/* linking to libdvdcss */ -#include <dvdcss/dvdcss.h> -#define DVDcss_open(a) dvdcss_open((char*)(a)) -#define DVDcss_close dvdcss_close -#define DVDcss_seek dvdcss_seek -#define DVDcss_title dvdcss_title -#define DVDcss_read dvdcss_read -#define DVDcss_error dvdcss_error -#else -/* dlopening libdvdcss */ -#include <dlfcn.h> -typedef struct dvdcss_s *dvdcss_handle; -static dvdcss_handle (*DVDcss_open) (const char *); -static int (*DVDcss_close) (dvdcss_handle); -static int (*DVDcss_seek) (dvdcss_handle, int, int); -static int (*DVDcss_title) (dvdcss_handle, int); -static int (*DVDcss_read) (dvdcss_handle, void *, int, int); -static char * (*DVDcss_error) (dvdcss_handle); -#endif - -/* The DVDinput handle, add stuff here for new input methods. */ -struct dvd_input_s { - /* libdvdcss handle */ - dvdcss_handle dvdcss; - - /* dummy file input */ - int fd; -}; - - -/** - * initialize and open a DVD device or file. - */ -static dvd_input_t css_open(const char *target) -{ - dvd_input_t dev; - - /* Allocate the handle structure */ - dev = (dvd_input_t) malloc(sizeof(struct dvd_input_s)); - if(dev == NULL) { - /* malloc has set errno to ENOMEM */ - return NULL; - } - - /* Really open it with libdvdcss */ - dev->dvdcss = DVDcss_open(target); - if(dev->dvdcss == 0) { - free(dev); - dev = NULL; - } - - return dev; -} - -/** - * return the last error message - */ -static char *css_error(dvd_input_t dev) -{ - return DVDcss_error(dev->dvdcss); -} - -/** - * seek into the device. - */ -static int css_seek(dvd_input_t dev, int blocks) -{ - /* DVDINPUT_NOFLAGS should match the DVDCSS_NOFLAGS value. */ - return DVDcss_seek(dev->dvdcss, blocks, DVDINPUT_NOFLAGS); -} - -/** - * set the block for the begining of a new title (key). - */ -static int css_title(dvd_input_t dev, int block) -{ - return DVDcss_title(dev->dvdcss, block); -} - -/** - * read data from the device. - */ -static int css_read(dvd_input_t dev, void *buffer, int blocks, int flags) -{ - return DVDcss_read(dev->dvdcss, buffer, blocks, flags); -} - -/** - * close the DVD device and clean up the library. - */ -static int css_close(dvd_input_t dev) -{ - int ret; - - ret = DVDcss_close(dev->dvdcss); - - if(ret < 0) - return ret; - - free(dev); - - return 0; -} - -/* Need to use O_BINARY for WIN32 */ -#ifndef O_BINARY -#ifdef _O_BINARY -#define O_BINARY _O_BINARY -#else -#define O_BINARY 0 -#endif -#endif - -/** - * initialize and open a DVD device or file. - */ -static dvd_input_t file_open(const char *target) -{ - dvd_input_t dev; - char *use_odirect; - int oflags; - - oflags = O_RDONLY | O_BINARY; - use_odirect = getenv("DVDREAD_USE_DIRECT"); - if(use_odirect) { -#ifndef O_DIRECT -#define O_DIRECT 0 -#endif - oflags |= O_DIRECT; - } - /* Allocate the library structure */ - dev = (dvd_input_t) malloc(sizeof(struct dvd_input_s)); - if(dev == NULL) { - return NULL; - } - - /* Open the device */ - dev->fd = open(target, oflags); - if(dev->fd < 0) { - free(dev); - return NULL; - } - - return dev; -} - -/** - * return the last error message - */ -static char *file_error(dvd_input_t dev) -{ - /* use strerror(errno)? */ - return (char *)"unknown error"; -} - -/** - * seek into the device. - */ -static int file_seek(dvd_input_t dev, int blocks) -{ - off_t pos = (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN; - - pos = lseek(dev->fd, pos, SEEK_SET); - if(pos < 0) { - return pos; - } - /* assert pos % DVD_VIDEO_LB_LEN == 0 */ - return (int) (pos / DVD_VIDEO_LB_LEN); -} - -/** - * set the block for the begining of a new title (key). - */ -static int file_title(dvd_input_t dev, int block) -{ - return -1; -} - -/** - * read data from the device. - */ -static int file_read(dvd_input_t dev, void *buffer, int blocks, int flags) -{ - size_t len; - ssize_t ret; - unsigned char *buf = buffer; - - len = (size_t)blocks * DVD_VIDEO_LB_LEN; - - while(len > 0) { - - ret = read(dev->fd, buf, len); - - if(ret < 0) { - /* One of the reads failed, too bad. We won't even bother - * returning the reads that went ok, and as in the posix spec - * the file postition is left unspecified after a failure. */ - return ret; - } - - if(ret == 0) { - /* Nothing more to read. Return the whole blocks, if any, that we got. - and adjust the file possition back to the previous block boundary. */ - size_t bytes = (size_t)blocks * DVD_VIDEO_LB_LEN - len; - off_t over_read = -(bytes % DVD_VIDEO_LB_LEN); - /*off_t pos =*/ lseek(dev->fd, over_read, SEEK_CUR); - /* should have pos % 2048 == 0 */ - return (int) (bytes / DVD_VIDEO_LB_LEN); - } - - buf+=ret; - len -= ret; - } - - return blocks; -} - -/** - * close the DVD device and clean up. - */ -static int file_close(dvd_input_t dev) -{ - int ret; - - ret = close(dev->fd); - - if(ret < 0) - return ret; - - free(dev); - - return 0; -} - - -static void *dvdcss_library = NULL; -static int dvdcss_library_init = 0; - -/** - * Free any objects allocated by dvdinput_setup. - * Should only be called when libdvdread is not to be used any more. - * Closes dlopened libraries. - */ -void dvdinput_free(void) -{ -#ifdef HAVE_DVDCSS_DVDCSS_H - /* linked statically, nothing to free */ - return; -#else - if(dvdcss_library) { - dlclose(dvdcss_library); - dvdcss_library = NULL; - } - dvdcss_library_init = 0; - return; -#endif -} - - -/** - * Setup read functions with either libdvdcss or minimal DVD access. - */ -int dvdinput_setup(void) -{ - char **dvdcss_version = NULL; - int verbose; - - /* dlopening libdvdcss */ - if(dvdcss_library_init) { - /* libdvdcss is already dlopened, function ptrs set */ - if(dvdcss_library) { - return 1; /* css available */ - } else { - return 0; /* css not available */ - } - } - - verbose = get_verbose(); - -#ifdef HAVE_DVDCSS_DVDCSS_H - /* linking to libdvdcss */ - dvdcss_library = &dvdcss_library; /* Give it some value != NULL */ - /* the DVDcss_* functions have been #defined at the top */ - dvdcss_version = &dvdcss_interface_2; - -#else - - dvdcss_library = dlopen("libdvdcss.so.2", RTLD_LAZY); - - if(dvdcss_library != NULL) { -#if defined(__OpenBSD__) && !defined(__ELF__) -#define U_S "_" -#else -#define U_S -#endif - DVDcss_open = (dvdcss_handle (*)(const char*)) - dlsym(dvdcss_library, U_S "dvdcss_open"); - DVDcss_close = (int (*)(dvdcss_handle)) - dlsym(dvdcss_library, U_S "dvdcss_close"); - DVDcss_title = (int (*)(dvdcss_handle, int)) - dlsym(dvdcss_libra |