Debian Codegraph @

src/dvdread/dvd_reader.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2001, 2002 Billy Biggs <[email protected]>,
3 * Håkan Hjort <[email protected]>,
4 * Björn Englund <[email protected]>
5 *
6 * This file is part of libdvdread.
7 *
8 * libdvdread is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * libdvdread is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with libdvdread; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #ifndef LIBDVDREAD_DVD_READER_H
24 #define LIBDVDREAD_DVD_READER_H
25
26 /* dvd_filesystem.h exposes off64_t in the public filesystem callbacks. */
27 #ifndef _LARGEFILE64_SOURCE
28 #define _LARGEFILE64_SOURCE
29 #endif
30
31 #include <sys/types.h>
32 #include <inttypes.h>
33 #include <stdarg.h>
34
35 #if defined(_MSC_VER) && !defined(ssize_t)
36 #include <basetsd.h>
37 typedef SSIZE_T ssize_t;
38 #endif
39
40 #include <dvdread/attributes.h>
41
42 /**
43 * The DVD access interface.
44 *
45 * This file contains the functions that form the interface for
46 * reading files located on a DVD.
47 */
48
49 /**
50 * The current version.
51 */
52 #include <dvdread/version.h>
53
54 /**
55 * Filesystem types
56 */
57 #include "dvd_filesystem.h"
58
59
60 /**
61 * The length of one Logical Block of a DVD.
62 */
63 #define DVD_VIDEO_LB_LEN 2048
64
65 /**
66 * Maximum length of filenames allowed in UDF.
67 */
68 #define MAX_UDF_FILE_NAME_LEN 2048
69
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73
74 /**
75 * Opaque type that is used as a handle for one instance of an opened DVD.
76 */
77 typedef struct dvd_reader_s dvd_reader_t;
78 typedef struct dvd_reader_device_s dvd_reader_device_t;
79
80 /**
81 * Opaque type for a file read handle, much like a normal fd or FILE *.
82 */
83 typedef struct dvd_file_s dvd_file_t;
84
85 struct dvd_reader_stream_cb
86 {
87 int ( *pf_seek ) ( void *p_stream, uint64_t i_pos);
88 int ( *pf_read ) ( void *p_stream, void* buffer, int i_read);
89 int ( *pf_readv ) ( void *p_stream, void *p_iovec, int i_blocks);
90 };
91 typedef struct dvd_reader_stream_cb dvd_reader_stream_cb;
92
93 /**
94 * Custom logger callback for DVDOpen[Stream]2
95 * @param private Handle as provided in Open functions
96 * @param level Log level
97 * @param fmt Format string
98 * @param args Arguments list
99 * pf_log(priv, level, fmt, args);
100 */
101 typedef enum
102 {
103 DVD_LOGGER_LEVEL_INFO,
104 DVD_LOGGER_LEVEL_ERROR,
105 DVD_LOGGER_LEVEL_WARN,
106 DVD_LOGGER_LEVEL_DEBUG,
107 } dvd_logger_level_t;
108
109 typedef struct
110 {
111 void ( *pf_log ) ( void *, dvd_logger_level_t, const char *, va_list );
112 } dvd_logger_cb;
113
114 /**
115 * Public type that is used to provide statistics on a handle.
116 */
117 typedef struct {
118 off_t size; /**< Total size of file in bytes */
119 int nr_parts; /**< Number of file parts */
120 off_t parts_size[9]; /**< Size of each part in bytes */
121 } dvd_stat_t;
122
123 /**
124 * Opens a block device of a DVD-ROM file, or an image file, or a directory
125 * name for a mounted DVD or HD copy of a DVD.
126 * The second form of Open function (DVDOpenStream) can be used to
127 * provide custom stream_cb functions to access the DVD (see libdvdcss).
128 *
129 * If the given file is a block device, or is the mountpoint for a block
130 * device, then that device is used for CSS authentication using libdvdcss.
131 * If no device is available, then no CSS authentication is performed,
132 * and we hope that the image is decrypted.
133 *
134 * If the path given is a directory, then the files in that directory may be
135 * in any one of these formats:
136 *
137 * path/VIDEO_TS/VTS_01_1.VOB
138 * path/video_ts/vts_01_1.vob
139 * path/VTS_01_1.VOB
140 * path/vts_01_1.vob
141 *
142 * @param path Specifies the device, file or directory to be used.
143 * @param stream is a private handle used by stream_cb
144 * @param stream_cb is a struct containing seek and read functions
145 * @return If successful a read handle is returned. Otherwise 0 is returned.
146 *
147 * dvd = DVDOpen(path);
148 * dvd = DVDOpenStream(stream, &stream_cb);
149 */
150 DVDREAD_API dvd_reader_t *DVDOpen( const char * );
151 DVDREAD_API dvd_reader_t *DVDOpenStream( void *, dvd_reader_stream_cb * );
152
153 /**
154 * Same as DVDOpen, but with private handle to be passed back on callbacks
155 *
156 * @param path Specifies the device, file or directory to be used.
157 * @param priv is a private handle
158 * @param logcb is a custom logger callback struct, or NULL if none needed
159 * @param stream_cb is a struct containing seek and read functions
160 * @return If successful a read handle is returned. Otherwise 0 is returned.
161 *
162 * dvd = DVDOpen2(priv, logcb, path);
163 * dvd = DVDOpenStream2(priv, logcb, &stream_cb);
164 */
165 DVDREAD_API dvd_reader_t *DVDOpen2( void *, const dvd_logger_cb *, const char *);
166 DVDREAD_API dvd_reader_t *DVDOpenStream2( void *, const dvd_logger_cb *, dvd_reader_stream_cb *);
167
168 /* in the case the the type was autodetected, can check with dvd->dvd_type */
169 /* To explicitly open the disc as DVD-Audio */
170 DVDREAD_API dvd_reader_t *DVDOpenAudio( void *, const dvd_logger_cb *, const char *);
171 DVDREAD_API dvd_reader_t *DVDOpenStreamAudio( void *, const dvd_logger_cb *, dvd_reader_stream_cb *);
172
173 /* To explicitly open the disc as DVD-VR*/
174 DVDREAD_API dvd_reader_t *DVDOpenVideoRecording( void *, const dvd_logger_cb *, const char *);
175 DVDREAD_API dvd_reader_t *DVDOpenStreamVideoRecording( void *, const dvd_logger_cb *, dvd_reader_stream_cb *);
176
177 /**
178 * Open unencrypted DVD files providing the respective filesystem implementation
179 * Useful to open files located on virtual file systems
180 *
181 * @param priv is a private handle
182 * @param logcb is a custom logger callback struct, or NULL if none needed
183 * @param path Specifies the directory to use
184 * @param fs is a struct containing the filesystem implementation
185 * @return If successful a read handle is returned. Otherwise NULL is returned.
186 *
187 * on success the reader owns fs and closes it in DVDClose
188 * on failure the caller keeps fs and must free it
189 *
190 * do not mix this with a css reader in the same process
191 * it switches all readers to the builtin input
192 */
193 DVDREAD_API dvd_reader_t *DVDOpenFiles( void *priv, const dvd_logger_cb *logcb, const char * path, dvd_reader_filesystem_h *fs);
194
195 /**
196 * Closes and cleans up the DVD reader object.
197 *
198 * You must close all open files before calling this function.
199 *
200 * @param dvd A read handle that should be closed.
201 *
202 * DVDClose(dvd);
203 */
204 DVDREAD_API void DVDClose( dvd_reader_t * );
205
206 /**
207 *
208 */
209 typedef enum {
210 DVD_READ_INFO_FILE, /**< VIDEO_TS.IFO or VTS_XX_0.IFO (title) */
211 DVD_READ_INFO_BACKUP_FILE, /**< VIDEO_TS.BUP or VTS_XX_0.BUP (title) */
212 DVD_READ_MENU_VOBS, /**< VIDEO_TS.VOB or VTS_XX_0.VOB (title) */
213 DVD_READ_TITLE_VOBS, /**< VTS_XX_[1-9].VOB (title). All files in
214 the title set are opened and read as a
215 single file. */
216 DVD_READ_SAMG_INFO, /* for the AUDIO_PP.IFO */
217 DVD_READ_ASVS_INFO, /* for the AUDIO_SV.IFO */
218 DVD_READ_ASVS_INFO_BACKUP, /* for the AUDIO_SV.BUP */
219 } dvd_read_domain_t;
220
221 /**
222 * Stats a file on the DVD given the title number and domain.
223 * The information about the file is stored in a dvd_stat_t
224 * which contains information about the size of the file and
225 * the number of parts in case of a multipart file and the respective
226 * sizes of the parts.
227 * A multipart file is for instance VTS_02_1.VOB, VTS_02_2.VOB, VTS_02_3.VOB
228 * The size of VTS_02_1.VOB will be stored in stat->parts_size[0],
229 * VTS_02_2.VOB in stat->parts_size[1], ...
230 * The total size (sum of all parts) is stored in stat->size and
231 * stat->nr_parts will hold the number of parts.
232 * Only DVD_READ_TITLE_VOBS (VTS_??_[1-9].VOB) can be multipart files.
233 *
234 * This function is only of use if you want to get the size of each file
235 * in the filesystem. These sizes are not needed to use any other
236 * functions in libdvdread.
237 *
238 * @param dvd A dvd read handle.
239 * @param titlenum Which Video Title Set should be used, VIDEO_TS is 0.
240 * @param domain Which domain.
241 * @param stat Pointer to where the result is stored.
242 * @return If successful 0, otherwise -1.
243 *
244 * int DVDFileStat(dvd, titlenum, domain, stat);
245 */
246 DVDREAD_API int DVDFileStat(dvd_reader_t *, int, dvd_read_domain_t, dvd_stat_t *);
247
248 /**
249 * Opens a file on the DVD given the title number and domain.
250 *
251 * If the title number is 0, the video manager information is opened
252 * (VIDEO_TS.[IFO,BUP,VOB]). Returns a file structure which may be
253 * used for reads, or 0 if the file was not found.
254 *
255 * @param dvd A dvd read handle.
256 * @param titlenum Which Video Title Set should be used, VIDEO_TS is 0.
257 * @param domain Which domain.
258 * @return If successful a a file read handle is returned, otherwise 0.
259 *
260 * dvd_file = DVDOpenFile(dvd, titlenum, domain); */
261 DVDREAD_API dvd_file_t *DVDOpenFile( dvd_reader_t *, int, dvd_read_domain_t );
262
263 /**
264 * Closes a file and frees the associated structure.
265 *
266 * @param dvd_file The file read handle to be closed.
267 *
268 * DVDCloseFile(dvd_file);
269 */
270 DVDREAD_API void DVDCloseFile( dvd_file_t * );
271
272 /**
273 * Reads block_count number of blocks from the file at the given block offset.
274 * Returns number of blocks read on success, -1 on error. This call is only
275 * for reading VOB data, and should not be used when reading the IFO files.
276 * When reading from an encrypted drive, blocks are decrypted using libdvdcss
277 * where required.
278 *
279 * @param dvd_file A file read handle.
280 * @param offset Block offset from the start of the file to start reading at.
281 * @param block_count Number of block to read.
282 * @param data Pointer to a buffer to write the data into.
283 * @return Returns number of blocks read on success, -1 on error.
284 *
285 * blocks_read = DVDReadBlocks(dvd_file, offset, block_count, data);
286 */
287 DVDREAD_API ssize_t DVDReadBlocks( dvd_file_t *, int, size_t, unsigned char * );
288
289 /**
290 * Seek to the given position in the file. Returns the resulting position in
291 * bytes from the beginning of the file. The seek position is only used for
292 * byte reads from the file, the block read call always reads from the given
293 * offset.
294 *
295 * @param dvd_file A file read handle.
296 * @param seek_offset Byte offset from the start of the file to seek to.
297 * @return The resulting position in bytes from the beginning of the file.
298 *
299 * offset_set = DVDFileSeek(dvd_file, seek_offset);
300 */
301 DVDREAD_API int32_t DVDFileSeek( dvd_file_t *, int32_t );
302
303 /**
304 * Reads the given number of bytes from the file. This call can only be used
305 * on the information files, and may not be used for reading from a VOB. This
306 * reads from and increments the current seek position for the file.
307 *
308 * @param dvd_file A file read handle.
309 * @param data Pointer to a buffer to write the data into.
310 * @param bytes Number of bytes to read.
311 * @return Returns number of bytes read on success, -1 on error.
312 *
313 * bytes_read = DVDReadBytes(dvd_file, data, bytes);
314 */
315 DVDREAD_API ssize_t DVDReadBytes( dvd_file_t *, void *, size_t );
316
317 /**
318 * Returns the file size in blocks.
319 *
320 * @param dvd_file A file read handle.
321 * @return The size of the file in blocks, -1 on error.
322 *
323 * blocks = DVDFileSize(dvd_file);
324 */
325 DVDREAD_API ssize_t DVDFileSize( dvd_file_t * );
326
327 /**
328 * Get a unique 128 bit disc ID.
329 * This is the MD5 sum of VIDEO_TS.IFO and the VTS_0?_0.IFO files
330 * in title order (those that exist).
331 * If you need a 'text' representation of the id, print it as a
332 * hexadecimal number, using lowercase letters, discid[0] first.
333 * I.e. the same format as the command-line 'md5sum' program uses.
334 *
335 * @param dvd A read handle to get the disc ID from
336 * @param discid The buffer to put the disc ID into. The buffer must
337 * have room for 128 bits (16 chars).
338 * @return 0 on success, -1 on error.
339 */
340 DVDREAD_API int DVDDiscID( dvd_reader_t *, unsigned char * );
341
342 /**
343 * Get the UDF VolumeIdentifier and VolumeSetIdentifier
344 * from the PrimaryVolumeDescriptor.
345 *
346 * @param dvd A read handle to get the disc ID from
347 * @param volid The buffer to put the VolumeIdentifier into.
348 * The VolumeIdentifier is latin-1 encoded (8bit unicode)
349 * null terminated and max 32 bytes (including '\0')
350 * @param volid_size No more than volid_size bytes will be copied to volid.
351 * If the VolumeIdentifier is truncated because of this
352 * it will still be null terminated.
353 * @param volsetid The buffer to put the VolumeSetIdentifier into.
354 * The VolumeIdentifier is 128 bytes as
355 * stored in the UDF PrimaryVolumeDescriptor.
356 * Note that this is not a null terminated string.
357 * @param volsetid_size At most volsetid_size bytes will be copied to volsetid.
358 * @return 0 on success, -1 on error.
359 */
360 DVDREAD_API int DVDUDFVolumeInfo( dvd_reader_t *, char *, unsigned int,
361 unsigned char *, unsigned int );
362
363 DVDREAD_API int DVDFileSeekForce( dvd_file_t *, int offset, int force_size);
364
365 /**
366 * Get the ISO9660 VolumeIdentifier and VolumeSetIdentifier
367 *
368 * * Only use this function as fallback if DVDUDFVolumeInfo returns -1 *
369 * * this will happen on a disc mastered only with a iso9660 filesystem *
370 * * All video DVD discs have UDF filesystem *
371 *
372 * @param dvd A read handle to get the disc ID from
373 * @param volid The buffer to put the VolumeIdentifier into.
374 * The VolumeIdentifier is coded with '0-9','A-Z','_'
375 * null terminated and max 33 bytes (including '\0')
376 * @param volid_size No more than volid_size bytes will be copied to volid.
377 * If the VolumeIdentifier is truncated because of this
378 * it will still be null terminated.
379 * @param volsetid The buffer to put the VolumeSetIdentifier into.
380 * The VolumeIdentifier is 128 bytes as
381 * stored in the ISO9660 PrimaryVolumeDescriptor.
382 * Note that this is not a null terminated string.
383 * @param volsetid_size At most volsetid_size bytes will be copied to volsetid.
384 * @return 0 on success, -1 on error.
385 */
386 DVDREAD_API int DVDISOVolumeInfo( dvd_reader_t *, char *, unsigned int,
387 unsigned char *, unsigned int );
388
389 /**
390 * Sets the level of caching that is done when reading from a device
391 *
392 * @param dvd A read handle to get the disc ID from
393 * @param level The level of caching wanted.
394 * -1 - returns the current setting.
395 * 0 - UDF Cache turned off.
396 * 1 - (default level) Pointers to IFO files and some data from
397 * PrimaryVolumeDescriptor are cached.
398 *
399 * @return The level of caching.
400 */
401 DVDREAD_API int DVDUDFCacheLevel( dvd_reader_t *, int );
402
403 #ifdef __cplusplus
404 };
405 #endif
406 #endif /* LIBDVDREAD_DVD_READER_H */