annotate libdvdcss/libdvdcss.c @ 31399:a12626be522c

100l, never just ignore a backwards skip, even if the stream is not seekable it might still be in a buffer. Fixes piping of yuv4mpeg files.
author reimar
date Fri, 18 Jun 2010 16:36:39 +0000
parents b470391059f3
children 383f17e1ef2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
1 /* libdvdcss.c: DVD reading library.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
2 *
27442
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
3 * Authors: Stéphane Borel <stef@via.ecp.fr>
27462
60bd1a7f3fc6 Sync libdvdcss with upstream version 1.2.10.
diego
parents: 27442
diff changeset
4 * Sam Hocevar <sam@zoy.org>
27442
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
5 * Håkan Hjort <d95hjort@dtek.chalmers.se>
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
6 *
27462
60bd1a7f3fc6 Sync libdvdcss with upstream version 1.2.10.
diego
parents: 27442
diff changeset
7 * Copyright (C) 1998-2008 VideoLAN
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
8 * $Id$
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
9 *
31098
9e9595c779cf libdvdcss: cosmetics: Fix FSF address and program name in license headers.
diego
parents: 27462
diff changeset
10 * This library is free software; you can redistribute it and/or modify
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
13 * (at your option) any later version.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
14 *
31098
9e9595c779cf libdvdcss: cosmetics: Fix FSF address and program name in license headers.
diego
parents: 27462
diff changeset
15 * This library is distributed in the hope that it will be useful,
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
18 * GNU General Public License for more details.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
19 *
31098
9e9595c779cf libdvdcss: cosmetics: Fix FSF address and program name in license headers.
diego
parents: 27462
diff changeset
20 * You should have received a copy of the GNU General Public License along
9e9595c779cf libdvdcss: cosmetics: Fix FSF address and program name in license headers.
diego
parents: 27462
diff changeset
21 * with this library; if not, write to the Free Software Foundation, Inc.,
9e9595c779cf libdvdcss: cosmetics: Fix FSF address and program name in license headers.
diego
parents: 27462
diff changeset
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
23 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
24
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
25 /**
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
26 * \mainpage libdvdcss developer documentation
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
27 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
28 * \section intro Introduction
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
29 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
30 * \e libdvdcss is a simple library designed for accessing DVDs like a block
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
31 * device without having to bother about the decryption. The important features
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
32 * are:
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
33 * \li portability: currently supported platforms are GNU/Linux, FreeBSD,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
34 * NetBSD, OpenBSD, BSD/OS, BeOS, Windows 95/98, Windows NT/2000, MacOS X,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
35 * Solaris, HP-UX and OS/2.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
36 * \li adaptability: unlike most similar projects, libdvdcss doesn't require
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
37 * the region of your drive to be set and will try its best to read from
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
38 * the disc even in the case of a region mismatch.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
39 * \li simplicity: a DVD player can be built around the \e libdvdcss API using
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
40 * no more than 4 or 5 library calls.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
41 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
42 * \e libdvdcss is free software, released under the General Public License.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
43 * This ensures that \e libdvdcss remains free and used only with free
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
44 * software.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
45 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
46 * \section api The libdvdcss API
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
47 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
48 * The complete \e libdvdcss programming interface is documented in the
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
49 * dvdcss.h file.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
50 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
51 * \section env Environment variables
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
52 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
53 * Some environment variables can be used to change the behaviour of
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
54 * \e libdvdcss without having to modify the program which uses it. These
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
55 * variables are:
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
56 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
57 * \li \b DVDCSS_VERBOSE: sets the verbosity level.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
58 * - \c 0 outputs no messages at all.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
59 * - \c 1 outputs error messages to stderr.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
60 * - \c 2 outputs error messages and debug messages to stderr.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
61 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
62 * \li \b DVDCSS_METHOD: sets the authentication and decryption method
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
63 * that \e libdvdcss will use to read scrambled discs. Can be one
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
64 * of \c title, \c key or \c disc.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
65 * - \c key is the default method. \e libdvdcss will use a set of
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
66 * calculated player keys to try and get the disc key. This can fail
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
67 * if the drive does not recognize any of the player keys.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
68 * - \c disc is a fallback method when \c key has failed. Instead of
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
69 * using player keys, \e libdvdcss will crack the disc key using
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
70 * a brute force algorithm. This process is CPU intensive and requires
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
71 * 64 MB of memory to store temporary data.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
72 * - \c title is the fallback when all other methods have failed. It does
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
73 * not rely on a key exchange with the DVD drive, but rather uses a
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
74 * crypto attack to guess the title key. On rare cases this may fail
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
75 * because there is not enough encrypted data on the disc to perform
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
76 * a statistical attack, but in the other hand it is the only way to
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
77 * decrypt a DVD stored on a hard disc, or a DVD with the wrong region
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
78 * on an RPC2 drive.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
79 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
80 * \li \b DVDCSS_RAW_DEVICE: specify the raw device to use. Exact usage will
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
81 * depend on your operating system, the Linux utility to set up raw devices
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
82 * is \c raw(8) for instance. Please note that on most operating systems,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
83 * using a raw device requires highly aligned buffers: Linux requires a
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
84 * 2048 bytes alignment (which is the size of a DVD sector).
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
85 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
86 * \li \b DVDCSS_CACHE: specify a directory in which to store title key
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
87 * values. This will speed up descrambling of DVDs which are in the
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
88 * cache. The DVDCSS_CACHE directory is created if it does not exist,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
89 * and a subdirectory is created named after the DVD's title or
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
90 * manufacturing date. If DVDCSS_CACHE is not set or is empty, \e libdvdcss
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
91 * will use the default value which is "${HOME}/.dvdcss/" under Unix and
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
92 * "C:\Documents and Settings\$USER\Application Data\dvdcss\" under Win32.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
93 * The special value "off" disables caching.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
94 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
95
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
96 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
97 * Preamble
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
98 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
99 #include "config.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
100
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
101 #include <stdio.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
102 #include <stdlib.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
103 #include <string.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
104 #include <sys/types.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
105 #include <sys/stat.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
106 #ifdef HAVE_SYS_PARAM_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
107 # include <sys/param.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
108 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
109 #ifdef HAVE_PWD_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
110 # include <pwd.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
111 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
112 #include <fcntl.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
113 #include <errno.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
114
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
115 #ifdef HAVE_UNISTD_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
116 # include <unistd.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
117 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
118
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
119 #ifdef HAVE_LIMITS_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
120 # include <limits.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
121 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
122
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
123 #ifdef HAVE_DIRECT_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
124 # include <direct.h>
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
125 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
126
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
127 #include "dvdcss/dvdcss.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
128
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
129 #include "common.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
130 #include "css.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
131 #include "libdvdcss.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
132 #include "ioctl.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
133 #include "device.h"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
134
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
135 /**
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
136 * \brief Symbol for version checks.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
137 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
138 * The name of this symbol contains the library major number, which makes it
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
139 * easy to check which \e libdvdcss development headers are installed on the
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
140 * system with tools such as autoconf.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
141 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
142 * The variable itself contains the exact version number of the library,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
143 * which can be useful for specific feature needs.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
144 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
145 char * dvdcss_interface_2 = VERSION;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
146
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
147 /**
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
148 * \brief Open a DVD device or directory and return a dvdcss instance.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
149 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
150 * \param psz_target a string containing the target name, for instance
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
151 * "/dev/hdc" or "E:".
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
152 * \return a handle to a dvdcss instance or NULL on error.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
153 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
154 * Initialize the \e libdvdcss library and open the requested DVD device or
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
155 * directory. \e libdvdcss checks whether ioctls can be performed on the disc,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
156 * and when possible, the disc key is retrieved.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
157 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
158 * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
159 * calls. If an error occurred, NULL is returned.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
160 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
161 LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( char *psz_target )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
162 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
163 char psz_buffer[PATH_MAX];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
164 int i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
165
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
166 char *psz_method = getenv( "DVDCSS_METHOD" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
167 char *psz_verbose = getenv( "DVDCSS_VERBOSE" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
168 char *psz_cache = getenv( "DVDCSS_CACHE" );
31099
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
169 #if !defined(WIN32) && !defined(SYS_OS2)
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
170 char *psz_raw_device = getenv( "DVDCSS_RAW_DEVICE" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
171 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
172
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
173 dvdcss_t dvdcss;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
174
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
175 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
176 * Allocate the library structure
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
177 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
178 dvdcss = malloc( sizeof( struct dvdcss_s ) );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
179 if( dvdcss == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
180 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
181 return NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
182 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
183
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
184 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
185 * Initialize structure with default values
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
186 */
31099
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
187 #if !defined(WIN32) && !defined(SYS_OS2)
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
188 dvdcss->i_raw_fd = -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
189 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
190 dvdcss->p_titles = NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
191 dvdcss->psz_device = (char *)strdup( psz_target );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
192 dvdcss->psz_error = "no error";
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
193 dvdcss->i_method = DVDCSS_METHOD_KEY;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
194 dvdcss->psz_cachefile[0] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
195 dvdcss->b_debug = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
196 dvdcss->b_errors = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
197
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
198 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
199 * Find verbosity from DVDCSS_VERBOSE environment variable
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
200 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
201 if( psz_verbose != NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
202 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
203 int i = atoi( psz_verbose );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
204
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
205 if( i >= 2 ) dvdcss->b_debug = i;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
206 if( i >= 1 ) dvdcss->b_errors = 1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
207 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
208
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
209 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
210 * Find method from DVDCSS_METHOD environment variable
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
211 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
212 if( psz_method != NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
213 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
214 if( !strncmp( psz_method, "key", 4 ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
215 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
216 dvdcss->i_method = DVDCSS_METHOD_KEY;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
217 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
218 else if( !strncmp( psz_method, "disc", 5 ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
219 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
220 dvdcss->i_method = DVDCSS_METHOD_DISC;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
221 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
222 else if( !strncmp( psz_method, "title", 5 ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
223 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
224 dvdcss->i_method = DVDCSS_METHOD_TITLE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
225 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
226 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
227 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
228 print_error( dvdcss, "unknown decrypt method, please choose "
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
229 "from 'title', 'key' or 'disc'" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
230 free( dvdcss->psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
231 free( dvdcss );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
232 return NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
233 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
234 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
235
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
236 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
237 * If DVDCSS_CACHE was not set, try to guess a default value
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
238 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
239 if( psz_cache == NULL || psz_cache[0] == '\0' )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
240 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
241 #ifdef HAVE_DIRECT_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
242 typedef HRESULT( WINAPI *SHGETFOLDERPATH )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
243 ( HWND, int, HANDLE, DWORD, LPTSTR );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
244
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
245 # define CSIDL_FLAG_CREATE 0x8000
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
246 # define CSIDL_APPDATA 0x1A
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
247 # define SHGFP_TYPE_CURRENT 0
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
248
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
249 char psz_home[MAX_PATH];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
250 HINSTANCE p_dll;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
251 SHGETFOLDERPATH p_getpath;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
252
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
253 *psz_home = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
254
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
255 /* Load the shfolder dll to retrieve SHGetFolderPath */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
256 p_dll = LoadLibrary( "shfolder.dll" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
257 if( p_dll )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
258 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
259 p_getpath = (void*)GetProcAddress( p_dll, "SHGetFolderPathA" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
260 if( p_getpath )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
261 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
262 /* Get the "Application Data" folder for the current user */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
263 if( p_getpath( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
264 NULL, SHGFP_TYPE_CURRENT, psz_home ) == S_OK )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
265 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
266 FreeLibrary( p_dll );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
267 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
268 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
269 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
270 *psz_home = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
271 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
272 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
273 FreeLibrary( p_dll );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
274 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
275
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
276 /* Cache our keys in
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
277 * C:\Documents and Settings\$USER\Application Data\dvdcss\ */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
278 if( *psz_home )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
279 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
280 snprintf( psz_buffer, PATH_MAX, "%s/dvdcss", psz_home );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
281 psz_buffer[PATH_MAX-1] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
282 psz_cache = psz_buffer;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
283 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
284 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
285 char *psz_home = NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
286 # ifdef HAVE_PWD_H
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
287 struct passwd *p_pwd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
288
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
289 /* Try looking in password file for home dir. */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
290 p_pwd = getpwuid(getuid());
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
291 if( p_pwd )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
292 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
293 psz_home = p_pwd->pw_dir;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
294 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
295 # endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
296
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
297 if( psz_home == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
298 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
299 psz_home = getenv( "HOME" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
300 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
301 if( psz_home == NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
302 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
303 psz_home = getenv( "USERPROFILE" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
304 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
305
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
306 /* Cache our keys in ${HOME}/.dvdcss/ */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
307 if( psz_home )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
308 {
31099
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
309 int home_pos = 0;
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
310
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
311 #ifdef SYS_OS2
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
312 if( *psz_home == '/' || *psz_home == '\\')
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
313 {
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
314 char *psz_unixroot = getenv("UNIXROOT");
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
315
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
316 if( psz_unixroot &&
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
317 psz_unixroot[0] &&
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
318 psz_unixroot[1] == ':' &&
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
319 psz_unixroot[2] == '\0')
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
320 {
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
321 strcpy( psz_buffer, psz_unixroot );
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
322 home_pos = 2;
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
323 }
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
324 }
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
325 #endif
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
326 snprintf( psz_buffer + home_pos, PATH_MAX - home_pos,
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
327 "%s/.dvdcss", psz_home );
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
328 psz_buffer[PATH_MAX-1] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
329 psz_cache = psz_buffer;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
330 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
331 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
332 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
333
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
334 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
335 * Find cache dir from the DVDCSS_CACHE environment variable
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
336 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
337 if( psz_cache != NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
338 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
339 if( psz_cache[0] == '\0' || !strcmp( psz_cache, "off" ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
340 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
341 psz_cache = NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
342 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
343 /* Check that we can add the ID directory and the block filename */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
344 else if( strlen( psz_cache ) + 1 + 32 + 1 + (KEY_SIZE * 2) + 10 + 1
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
345 > PATH_MAX )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
346 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
347 print_error( dvdcss, "cache directory name is too long" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
348 psz_cache = NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
349 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
350 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
351
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
352 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
353 * Open device
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
354 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
355 _dvdcss_check( dvdcss );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
356 i_ret = _dvdcss_open( dvdcss );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
357 if( i_ret < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
358 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
359 free( dvdcss->psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
360 free( dvdcss );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
361 return NULL;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
362 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
363
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
364 dvdcss->b_scrambled = 1; /* Assume the worst */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
365 dvdcss->b_ioctls = _dvdcss_use_ioctls( dvdcss );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
366
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
367 if( dvdcss->b_ioctls )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
368 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
369 i_ret = _dvdcss_test( dvdcss );
31253
b470391059f3 Sync libdvdcss with their latest SVN.
reimar
parents: 31100
diff changeset
370
b470391059f3 Sync libdvdcss with their latest SVN.
reimar
parents: 31100
diff changeset
371 if( i_ret == -3 )
31100
45159a4b8815 libdvdcss: Fix potential format string crash; check RPC status on disc access.
diego
parents: 31099
diff changeset
372 {
31253
b470391059f3 Sync libdvdcss with their latest SVN.
reimar
parents: 31100
diff changeset
373 print_debug( dvdcss, "scrambled disc on a region-free RPC-II "
b470391059f3 Sync libdvdcss with their latest SVN.
reimar
parents: 31100
diff changeset
374 "drive: possible failure, but continuing "
b470391059f3 Sync libdvdcss with their latest SVN.
reimar
parents: 31100
diff changeset
375 "anyway" );
31100
45159a4b8815 libdvdcss: Fix potential format string crash; check RPC status on disc access.
diego
parents: 31099
diff changeset
376 }
45159a4b8815 libdvdcss: Fix potential format string crash; check RPC status on disc access.
diego
parents: 31099
diff changeset
377 else if( i_ret < 0 )
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
378 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
379 /* Disable the CSS ioctls and hope that it works? */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
380 print_debug( dvdcss,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
381 "could not check whether the disc was scrambled" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
382 dvdcss->b_ioctls = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
383 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
384 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
385 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
386 print_debug( dvdcss, i_ret ? "disc is scrambled"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
387 : "disc is unscrambled" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
388 dvdcss->b_scrambled = i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
389 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
390 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
391
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
392 /* If disc is CSS protected and the ioctls work, authenticate the drive */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
393 if( dvdcss->b_scrambled && dvdcss->b_ioctls )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
394 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
395 i_ret = _dvdcss_disckey( dvdcss );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
396
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
397 if( i_ret < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
398 {
27462
60bd1a7f3fc6 Sync libdvdcss with upstream version 1.2.10.
diego
parents: 27442
diff changeset
399 print_debug( dvdcss, "could not get disc key" );
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
400 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
401 }
27442
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
402 else
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
403 {
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
404 memset( dvdcss->css.p_disc_key, 0, KEY_SIZE );
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
405 }
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
406
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
407 /* If the cache is enabled, write the cache directory tag */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
408 if( psz_cache )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
409 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
410 char *psz_tag = "Signature: 8a477f597d28d172789f06886806bc55\r\n"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
411 "# This file is a cache directory tag created by libdvdcss.\r\n"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
412 "# For information about cache directory tags, see:\r\n"
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
413 "# http://www.brynosaurus.com/cachedir/\r\n";
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
414 char psz_tagfile[PATH_MAX + 1 + 12 + 1];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
415 int i_fd;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
416
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
417 sprintf( psz_tagfile, "%s/CACHEDIR.TAG", psz_cache );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
418 i_fd = open( psz_tagfile, O_RDWR|O_CREAT, 0644 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
419 if( i_fd >= 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
420 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
421 write( i_fd, psz_tag, strlen(psz_tag) );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
422 close( i_fd );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
423 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
424 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
425
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
426 /* If the cache is enabled, extract a unique disc ID */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
427 if( psz_cache )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
428 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
429 uint8_t p_sector[DVDCSS_BLOCK_SIZE];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
430 char psz_key[1 + KEY_SIZE * 2 + 1];
23708
1fb5f0b13a1a Fix crash on some DVDs
iive
parents: 23707
diff changeset
431 char *psz_title;
1fb5f0b13a1a Fix crash on some DVDs
iive
parents: 23707
diff changeset
432 uint8_t *psz_serial;
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
433 int i;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
434
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
435 /* We read sector 0. If it starts with 0x000001ba (BE), we are
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
436 * reading a VOB file, and we should not cache anything. */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
437
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
438 i_ret = dvdcss->pf_seek( dvdcss, 0 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
439 if( i_ret != 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
440 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
441 goto nocache;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
442 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
443
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
444 i_ret = dvdcss->pf_read( dvdcss, p_sector, 1 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
445 if( i_ret != 1 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
446 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
447 goto nocache;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
448 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
449
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
450 if( p_sector[0] == 0x00 && p_sector[1] == 0x00
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
451 && p_sector[2] == 0x01 && p_sector[3] == 0xba )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
452 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
453 goto nocache;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
454 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
455
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
456 /* The data we are looking for is at sector 16 (32768 bytes):
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
457 * - offset 40: disc title (32 uppercase chars)
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
458 * - offset 813: manufacturing date + serial no (16 digits) */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
459
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
460 i_ret = dvdcss->pf_seek( dvdcss, 16 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
461 if( i_ret != 16 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
462 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
463 goto nocache;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
464 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
465
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
466 i_ret = dvdcss->pf_read( dvdcss, p_sector, 1 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
467 if( i_ret != 1 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
468 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
469 goto nocache;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
470 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
471
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
472 /* Get the disc title */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
473 psz_title = (char *)p_sector + 40;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
474 psz_title[32] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
475
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
476 for( i = 0 ; i < 32 ; i++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
477 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
478 if( psz_title[i] <= ' ' )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
479 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
480 psz_title[i] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
481 break;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
482 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
483 else if( psz_title[i] == '/' || psz_title[i] == '\\' )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
484 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
485 psz_title[i] = '-';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
486 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
487 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
488
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
489 /* Get the date + serial */
23708
1fb5f0b13a1a Fix crash on some DVDs
iive
parents: 23707
diff changeset
490 psz_serial = p_sector + 813;
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
491 psz_serial[16] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
492
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
493 /* Check that all characters are digits, otherwise convert. */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
494 for( i = 0 ; i < 16 ; i++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
495 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
496 if( psz_serial[i] < '0' || psz_serial[i] > '9' )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
497 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
498 char psz_tmp[16 + 1];
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
499 sprintf( psz_tmp,
27462
60bd1a7f3fc6 Sync libdvdcss with upstream version 1.2.10.
diego
parents: 27442
diff changeset
500 "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
501 psz_serial[0], psz_serial[1], psz_serial[2],
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
502 psz_serial[3], psz_serial[4], psz_serial[5],
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
503 psz_serial[6], psz_serial[7] );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
504 memcpy( psz_serial, psz_tmp, 16 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
505 break;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
506 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
507 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
508
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
509 /* Get disk key, since some discs have got same title, manufacturing
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
510 * date and serial number, but different keys */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
511 if( dvdcss->b_scrambled )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
512 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
513 psz_key[0] = '-';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
514 for( i = 0; i < KEY_SIZE; i++ )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
515 {
27462
60bd1a7f3fc6 Sync libdvdcss with upstream version 1.2.10.
diego
parents: 27442
diff changeset
516 sprintf( &psz_key[1+i*2], "%.2x", dvdcss->css.p_disc_key[i] );
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
517 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
518 psz_key[1 + KEY_SIZE * 2] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
519 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
520 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
521 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
522 psz_key[0] = 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
523 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
524
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
525 /* We have a disc name or ID, we can create the cache dir */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
526 i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
527 #if !defined( WIN32 ) || defined( SYS_CYGWIN )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
528 i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
529 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
530 i_ret = mkdir( dvdcss->psz_cachefile );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
531 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
532 if( i_ret < 0 && errno != EEXIST )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
533 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
534 print_error( dvdcss, "failed creating cache directory" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
535 dvdcss->psz_cachefile[0] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
536 goto nocache;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
537 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
538
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
539 i += sprintf( dvdcss->psz_cachefile + i, "/%s-%s%s", psz_title,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
540 psz_serial, psz_key );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
541 #if !defined( WIN32 ) || defined( SYS_CYGWIN )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
542 i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
543 #else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
544 i_ret = mkdir( dvdcss->psz_cachefile );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
545 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
546 if( i_ret < 0 && errno != EEXIST )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
547 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
548 print_error( dvdcss, "failed creating cache subdirectory" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
549 dvdcss->psz_cachefile[0] = '\0';
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
550 goto nocache;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
551 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
552 i += sprintf( dvdcss->psz_cachefile + i, "/");
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
553
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
554 /* Pointer to the filename we will use. */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
555 dvdcss->psz_block = dvdcss->psz_cachefile + i;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
556
31100
45159a4b8815 libdvdcss: Fix potential format string crash; check RPC status on disc access.
diego
parents: 31099
diff changeset
557 print_debug( dvdcss, "using CSS key cache dir: %s",
45159a4b8815 libdvdcss: Fix potential format string crash; check RPC status on disc access.
diego
parents: 31099
diff changeset
558 dvdcss->psz_cachefile );
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
559 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
560 nocache:
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
561
31099
f43e87f69590 libdvdcss: OS/2 support; this merges upstream revisions 220 and 229.
diego
parents: 31098
diff changeset
562 #if !defined(WIN32) && !defined(SYS_OS2)
20613
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
563 if( psz_raw_device != NULL )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
564 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
565 _dvdcss_raw_open( dvdcss, psz_raw_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
566 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
567 #endif
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
568
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
569 /* Seek at the beginning, just for safety. */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
570 dvdcss->pf_seek( dvdcss, 0 );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
571
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
572 return dvdcss;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
573 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
574
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
575 /**
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
576 * \brief Return a string containing the latest error that occurred in the
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
577 * given \e libdvdcss instance.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
578 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
579 * \param dvdcss a \e libdvdcss instance.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
580 * \return a null-terminated string containing the latest error message.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
581 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
582 * This function returns a constant string containing the latest error that
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
583 * occurred in \e libdvdcss. It can be used to format error messages at your
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
584 * convenience in your application.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
585 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
586 LIBDVDCSS_EXPORT char * dvdcss_error ( dvdcss_t dvdcss )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
587 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
588 return dvdcss->psz_error;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
589 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
590
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
591 /**
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
592 * \brief Seek in the disc and change the current key if requested.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
593 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
594 * \param dvdcss a \e libdvdcss instance.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
595 * \param i_blocks an absolute block offset to seek to.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
596 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with one of #DVDCSS_SEEK_KEY
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
597 * or #DVDCSS_SEEK_MPEG.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
598 * \return the new position in blocks, or a negative value in case an error
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
599 * happened.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
600 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
601 * This function seeks to the requested position, in logical blocks.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
602 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
603 * You typically set \p i_flags to #DVDCSS_NOFLAGS when seeking in a .IFO.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
604 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
605 * If #DVDCSS_SEEK_MPEG is specified in \p i_flags and if \e libdvdcss finds it
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
606 * reasonable to do so (ie, if the dvdcss method is not "title"), the current
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
607 * title key will be checked and a new one will be calculated if necessary.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
608 * This flag is typically used when reading data from a VOB.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
609 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
610 * If #DVDCSS_SEEK_KEY is specified, the title key will be always checked,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
611 * even with the "title" method. This is equivalent to using the now
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
612 * deprecated dvdcss_title() call. This flag is typically used when seeking
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
613 * in a new title.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
614 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
615 LIBDVDCSS_EXPORT int dvdcss_seek ( dvdcss_t dvdcss, int i_blocks, int i_flags )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
616 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
617 /* title cracking method is too slow to be used at each seek */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
618 if( ( ( i_flags & DVDCSS_SEEK_MPEG )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
619 && ( dvdcss->i_method != DVDCSS_METHOD_TITLE ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
620 || ( i_flags & DVDCSS_SEEK_KEY ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
621 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
622 /* check the title key */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
623 if( _dvdcss_title( dvdcss, i_blocks ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
624 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
625 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
626 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
627 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
628
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
629 return dvdcss->pf_seek( dvdcss, i_blocks );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
630 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
631
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
632 /**
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
633 * \brief Read from the disc and decrypt data if requested.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
634 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
635 * \param dvdcss a \e libdvdcss instance.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
636 * \param p_buffer a buffer that will contain the data read from the disc.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
637 * \param i_blocks the amount of blocks to read.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
638 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
639 * \return the amount of blocks read, or a negative value in case an
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
640 * error happened.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
641 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
642 * This function reads \p i_blocks logical blocks from the DVD.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
643 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
644 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
645 * .IFO file on the DVD.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
646 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
647 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_read() will
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
648 * automatically decrypt scrambled sectors. This flag is typically used when
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
649 * reading data from a .VOB file on the DVD. It has no effect on unscrambled
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
650 * discs or unscrambled sectors, and can be safely used on those.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
651 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
652 * \warning dvdcss_read() expects to be able to write \p i_blocks *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
653 * #DVDCSS_BLOCK_SIZE bytes in \p p_buffer.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
654 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
655 LIBDVDCSS_EXPORT int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
656 int i_blocks,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
657 int i_flags )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
658 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
659 int i_ret, i_index;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
660
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
661 i_ret = dvdcss->pf_read( dvdcss, p_buffer, i_blocks );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
662
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
663 if( i_ret <= 0
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
664 || !dvdcss->b_scrambled
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
665 || !(i_flags & DVDCSS_READ_DECRYPT) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
666 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
667 return i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
668 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
669
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
670 if( ! memcmp( dvdcss->css.p_title_key, "\0\0\0\0\0", 5 ) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
671 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
672 /* For what we believe is an unencrypted title,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
673 * check that there are no encrypted blocks */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
674 for( i_index = i_ret; i_index; i_index-- )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
675 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
676 if( ((uint8_t*)p_buffer)[0x14] & 0x30 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
677 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
678 print_error( dvdcss, "no key but found encrypted block" );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
679 /* Only return the initial range of unscrambled blocks? */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
680 /* or fail completely? return 0; */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
681 break;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
682 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
683 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE);
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
684 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
685 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
686 else
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
687 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
688 /* Decrypt the blocks we managed to read */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
689 for( i_index = i_ret; i_index; i_index-- )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
690 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
691 _dvdcss_unscramble( dvdcss->css.p_title_key, p_buffer );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
692 ((uint8_t*)p_buffer)[0x14] &= 0x8f;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
693 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE);
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
694 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
695 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
696
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
697 return i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
698 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
699
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
700 /**
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
701 * \brief Read from the disc into multiple buffers and decrypt data if
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
702 * requested.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
703 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
704 * \param dvdcss a \e libdvdcss instance.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
705 * \param p_iovec a pointer to an array of iovec structures that will contain
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
706 * the data read from the disc.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
707 * \param i_blocks the amount of blocks to read.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
708 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
709 * \return the amount of blocks read, or a negative value in case an
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
710 * error happened.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
711 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
712 * This function reads \p i_blocks logical blocks from the DVD and writes them
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
713 * to an array of iovec structures.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
714 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
715 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
716 * .IFO file on the DVD.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
717 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
718 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_readv() will
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
719 * automatically decrypt scrambled sectors. This flag is typically used when
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
720 * reading data from a .VOB file on the DVD. It has no effect on unscrambled
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
721 * discs or unscrambled sectors, and can be safely used on those.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
722 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
723 * \warning dvdcss_readv() expects to be able to write \p i_blocks *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
724 * #DVDCSS_BLOCK_SIZE bytes in the buffers pointed by \p p_iovec.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
725 * Moreover, all iov_len members of the iovec structures should be
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
726 * multiples of #DVDCSS_BLOCK_SIZE.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
727 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
728 LIBDVDCSS_EXPORT int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
729 int i_blocks,
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
730 int i_flags )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
731 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
732 struct iovec *_p_iovec = (struct iovec *)p_iovec;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
733 int i_ret, i_index;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
734 void *iov_base;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
735 size_t iov_len;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
736
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
737 i_ret = dvdcss->pf_readv( dvdcss, _p_iovec, i_blocks );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
738
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
739 if( i_ret <= 0
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
740 || !dvdcss->b_scrambled
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
741 || !(i_flags & DVDCSS_READ_DECRYPT) )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
742 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
743 return i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
744 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
745
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
746 /* Initialize loop for decryption */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
747 iov_base = _p_iovec->iov_base;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
748 iov_len = _p_iovec->iov_len;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
749
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
750 /* Decrypt the blocks we managed to read */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
751 for( i_index = i_ret; i_index; i_index-- )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
752 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
753 /* Check that iov_len is a multiple of 2048 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
754 if( iov_len & 0x7ff )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
755 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
756 return -1;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
757 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
758
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
759 while( iov_len == 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
760 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
761 _p_iovec++;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
762 iov_base = _p_iovec->iov_base;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
763 iov_len = _p_iovec->iov_len;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
764 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
765
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
766 _dvdcss_unscramble( dvdcss->css.p_title_key, iov_base );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
767 ((uint8_t*)iov_base)[0x14] &= 0x8f;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
768
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
769 iov_base = (void *) ((uint8_t*)iov_base + DVDCSS_BLOCK_SIZE);
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
770 iov_len -= DVDCSS_BLOCK_SIZE;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
771 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
772
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
773 return i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
774 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
775
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
776 /**
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
777 * \brief Close the DVD and clean up the library.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
778 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
779 * \param dvdcss a \e libdvdcss instance.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
780 * \return zero in case of success, a negative value otherwise.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
781 *
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
782 * This function closes the DVD device and frees all the memory allocated
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
783 * by \e libdvdcss. On return, the #dvdcss_t is invalidated and may not be
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
784 * used again.
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
785 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
786 LIBDVDCSS_EXPORT int dvdcss_close ( dvdcss_t dvdcss )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
787 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
788 dvd_title_t *p_title;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
789 int i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
790
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
791 /* Free our list of keys */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
792 p_title = dvdcss->p_titles;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
793 while( p_title )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
794 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
795 dvd_title_t *p_tmptitle = p_title->p_next;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
796 free( p_title );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
797 p_title = p_tmptitle;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
798 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
799
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
800 i_ret = _dvdcss_close( dvdcss );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
801
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
802 if( i_ret < 0 )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
803 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
804 return i_ret;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
805 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
806
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
807 free( dvdcss->psz_device );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
808 free( dvdcss );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
809
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
810 return 0;
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
811 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
812
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
813 /*
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
814 * Deprecated. See dvdcss_seek().
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
815 */
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
816 #undef dvdcss_title
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
817 LIBDVDCSS_EXPORT int dvdcss_title ( dvdcss_t dvdcss, int i_block )
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
818 {
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
819 return _dvdcss_title( dvdcss, i_block );
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
820 }
e68f255d7d64 Move libdvdcss into its own subdirectory.
diego
parents:
diff changeset
821
27442
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
822 /**
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
823 * \brief Return 1 if the DVD is scrambled, 0 otherwise.
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
824 *
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
825 * \param dvdcss a \e libdvdcss instance.
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
826 * \return 1 if the DVD is scrambled, 0 otherwise.
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
827 *
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
828 * This function returns whether the DVD is scrambled.
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
829 */
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
830 LIBDVDCSS_EXPORT int dvdcss_is_scrambled ( dvdcss_t dvdcss )
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
831 {
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
832 return dvdcss->b_scrambled;
afa2cc0166be Sync libdvdcss with upstream version r212.
diego
parents: 26234
diff changeset
833 }
27462
60bd1a7f3fc6 Sync libdvdcss with upstream version 1.2.10.
diego
parents: 27442
diff changeset
834