annotate libmpdvdkit2/libdvdcss.c @ 19998:b1cebdd78625

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