1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
/*
* Copyright (C) 2000-2001 the xine project
*
* This file is part of xine, a unix video player.
*
* xine is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* xine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* $Id: input_dvd.c,v 1.18 2001/07/28 13:23:24 guenter Exp $
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dlfcn.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#ifdef HAVE_SYS_CDIO_H
# include <sys/cdio.h>
#endif
#ifdef HAVE_LINUX_CDROM_H
# include <linux/cdrom.h>
#endif
#if ! defined (HAVE_LINUX_CDROM_H) && ! defined (HAVE_SYS_CDIO_H)
#error "you need to add cdrom / VCD support for your platform to input_vcd and configure.in"
#endif
#include "xine_internal.h"
#include "monitor.h"
#include "input_plugin.h"
#include "dvd_udf.h"
static uint32_t xine_debug;
#if defined(__sun)
#define RDVD "/vol/dev/aliases/cdrom0"
#define DVD RDVD
#else
#define DVD "/dev/dvd"
#define RDVD "/dev/rdvd"
#endif
typedef struct {
input_plugin_t input_plugin;
char *mrl;
config_values_t *config;
int dvd_fd;
int raw_fd;
off_t file_size;
off_t file_size_left;
int file_lbstart;
int file_lbcur;
int gVTSMinor;
int gVTSMajor;
const char *device;
const char *raw_device;
/*
* udf dir function
*/
#define MAX_DIR_ENTRIES 250
char *filelist[MAX_DIR_ENTRIES];
char *filelist2[MAX_DIR_ENTRIES];
int mrls_allocated_entries;
mrl_t **mrls;
} dvd_input_plugin_t;
/* ***************************************************************** */
/* Private functions */
/* ***************************************************************** */
static int openDrive (dvd_input_plugin_t *this) {
this->dvd_fd = open(this->device, O_RDONLY /* | O_NONBLOCK */ );
if (this->dvd_fd < 0) {
printf ("input_dvd: unable to open dvd drive (%s): %s\n",
this->device, strerror(errno));
return -1;
}
this->raw_fd = open(this->raw_device, O_RDONLY /* | O_NONBLOCK */ );
if (this->raw_fd < 0) {
this->raw_fd = this->dvd_fd;
}
return this->raw_fd;
}
static void closeDrive (dvd_input_plugin_t *this) {
if (this->dvd_fd < 0)
return;
close (this->dvd_fd);
if (this->raw_fd != this->dvd_fd)
close (this->raw_fd);
this->dvd_fd = -1;
}
/*
* try to open dvd and prepare to read >filename<
*
* returns lbnum on success, 0 otherwise
*/
static int openDVDFile (dvd_input_plugin_t *this,
char *filename, off_t *size) {
char str[256];
int lbnum;
xprintf (VERBOSE|INPUT, "input_dvd : openDVDFile >%s<\n", filename);
if (openDrive(this) < 0) {
printf ("input_dvd: cannot open dvd drive >%s<\n", this->device);
return 0;
}
snprintf (str, sizeof(str), "/VIDEO_TS/%s", filename);
xprintf (VERBOSE|INPUT, "UDFFindFile %s\n", str);
if (!(lbnum = UDFFindFile(this->dvd_fd, str, size))) {
printf ("input_dvd: cannot open file >%s<\n", filename);
closeDrive (this);
return 0;
}
lseek (this->raw_fd, lbnum * (off_t) DVD_VIDEO_LB_LEN, SEEK_SET) ;
return lbnum;
}
/* ***************************************************************** */
/* END OF PRIVATES */
/* ***************************************************************** */
/*
*
*/
static uint32_t dvd_plugin_get_capabilities (input_plugin_t *this) {
return INPUT_CAP_SEEKABLE | INPUT_CAP_BLOCK | INPUT_CAP_AUTOPLAY | INPUT_CAP_GET_DIR;
}
/*
*
*/
static int dvd_plugin_open (input_plugin_t *this_gen, char *mrl) {
char *filename;
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
this->mrl = mrl;
xprintf (VERBOSE|INPUT, "input dvd : input_plugin_open >%s<\n", mrl);
/*
* do we handle this kind of MRL ?
*/
if (strncasecmp (mrl, "dvd://", 6))
return 0;
filename = (char *) &mrl[6];
xprintf (VERBOSE|INPUT, "input dvd : dvd_plugin_open media type correct."
" file name is %s\n", filename);
sscanf (filename, "VTS_%d_%d.VOB", &this->gVTSMajor, &this->gVTSMinor);
this->file_lbstart = openDVDFile (this, filename, &this->file_size) ;
this->file_lbcur = this->file_lbstart;
if (!this->file_lbstart) {
fprintf (stderr, "Unable to find >%s< on dvd.\n", filename);
return 0;
}
this->file_size_left = this->file_size;
return 1 ;
}
/*
*
*/
static off_t dvd_plugin_read (input_plugin_t *this_gen,
char *buf, off_t nlen) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
if (nlen != DVD_VIDEO_LB_LEN) {
/*
* Hide the error reporting now, demuxer try to read 6 bytes
* at STAGE_BY_CONTENT probe stage
*/
fprintf (stderr, "ERROR in input_dvd plugin read: %Ld bytes "
"is not a sector!\n", nlen);
return 0;
}
if (this->file_size_left < nlen)
return 0;
if (read (this->raw_fd, buf, DVD_VIDEO_LB_LEN)) {
this->file_lbcur++;
this->file_size_left -= DVD_VIDEO_LB_LEN;
return DVD_VIDEO_LB_LEN;
} else
fprintf (stderr, "read error in input_dvd plugin\n");
return 0;
}
/*
*
*/
static buf_element_t *dvd_plugin_read_block (input_plugin_t *this_gen,
fifo_buffer_t *fifo, off_t nlen) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
if (nlen != DVD_VIDEO_LB_LEN) {
/*
* Hide the error reporting now, demuxer try to read 6 bytes
* at STAGE_BY_CONTENT probe stage
*/
fprintf (stderr, "ERROR in input_dvd plugin read: %Ld bytes "
"is not a sector!\n", nlen);
goto read_block_failure;
}
if (this->file_size_left < nlen)
goto read_block_failure;
buf->content = buf->mem;
if ((buf->size = read (this->raw_fd, buf->mem, DVD_VIDEO_LB_LEN)) > 0) {
this->file_lbcur++;
this->file_size_left -= DVD_VIDEO_LB_LEN;
return buf;
} else
fprintf (stderr, "read error in input_dvd plugin\n");
read_block_failure:
buf->free_buffer (buf);
return NULL;
}
/*
*
*/
static off_t dvd_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
offset /= DVD_VIDEO_LB_LEN;
switch (origin) {
case SEEK_END:
offset = (this->file_size / DVD_VIDEO_LB_LEN) - offset;
case SEEK_SET:
this->file_lbcur = this->file_lbstart + offset;
this->file_size_left = this->file_size - (offset * DVD_VIDEO_LB_LEN);
break;
case SEEK_CUR:
if (offset) {
this->file_lbcur += offset;
this->file_size_left = this->file_size -
((this->file_lbcur - this->file_lbstart) * DVD_VIDEO_LB_LEN);
} else {
return (this->file_lbcur - this->file_lbstart) *
(off_t) DVD_VIDEO_LB_LEN;
}
break;
default:
fprintf (stderr, "error in input dvd plugin seek: %d is an unknown "
"origin\n", origin);
}
return lseek (this->raw_fd,
this->file_lbcur * (off_t) DVD_VIDEO_LB_LEN, SEEK_SET)
- this->file_lbstart * (off_t) DVD_VIDEO_LB_LEN;
}
/*
*
*/
static off_t dvd_plugin_get_current_pos (input_plugin_t *this_gen){
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
return ((this->file_lbcur - this->file_lbstart) * DVD_VIDEO_LB_LEN);
}
/*
*
*/
static off_t dvd_plugin_get_length (input_plugin_t *this_gen) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
return this->file_size;
}
/*
*
*/
static uint32_t dvd_plugin_get_blocksize (input_plugin_t *this_gen) {
return DVD_VIDEO_LB_LEN;
}
/*
*
*/
static int dvd_plugin_eject_media (input_plugin_t *this_gen) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
int ret, status;
int fd;
if((fd = open(this->device, O_RDONLY|O_NONBLOCK)) > -1) {
#if defined (HAVE_LINUX_CDROM_H)
if((status = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT)) > 0) {
switch(status) {
case CDS_TRAY_OPEN:
if((ret = ioctl(fd, CDROMCLOSETRAY)) != 0) {
xprintf(VERBOSE|INPUT, "CDROMCLOSETRAY failed: %s\n",
strerror(errno));
}
break;
case CDS_DISC_OK:
if((ret = ioctl(fd, CDROMEJECT)) != 0) {
xprintf(VERBOSE|INPUT, "CDROMEJECT failed: %s\n", strerror(errno));
}
break;
}
}
else {
xprintf(VERBOSE|INPUT, "CDROM_DRIVE_STATUS failed: %s\n",
strerror(errno));
close(fd);
return 0;
}
#elif defined (HAVE_CDIO_H)
# if defined (__sun)
status = 0;
if ((ret = ioctl(fd, CDROMEJECT)) != 0) {
xprintf(VERBOSE|INPUT, "CDROMEJECT failed: %s\n", strerror(errno));
}
# else
if (ioctl(fd, CDIOCALLOW) == -1) {
perror("ioctl(cdromallow)");
} else {
if (ioctl(fd, CDIOCEJECT) == -1) {
perror("ioctl(cdromeject)");
}
}
# endif
#endif
close(fd);
}
return 1;
}
/*
*
*/
static void dvd_plugin_close (input_plugin_t *this_gen) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
closeDrive (this);
}
/*
*
*/
static char *dvd_plugin_get_description (input_plugin_t *this_gen) {
return "dvd device input plugin as shipped with xine";
}
/*
*
*/
static char *dvd_plugin_get_identifier (input_plugin_t *this_gen) {
return "DVD";
}
/*
*
*/
static mrl_t **dvd_plugin_get_dir (input_plugin_t *this_gen,
char *filename, int *nEntries) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
int i, fd;
*nEntries = 0;
if (filename)
return NULL;
if((fd = open(this->device, O_RDONLY /* | O_NONBLOCK */ )) > -1) {
int nFiles, nFiles2;
UDFListDir (fd, "/VIDEO_TS", MAX_DIR_ENTRIES, this->filelist, &nFiles);
nFiles2 = 0;
for (i=0; i<nFiles; i++) {
int nLen;
nLen = strlen (this->filelist[i]);
if (nLen<4)
continue;
if (!strcasecmp (&this->filelist[i][nLen-4], ".VOB")) {
char str[1024];
if(nFiles2 >= this->mrls_allocated_entries
|| this->mrls_allocated_entries == 0) {
this->mrls[nFiles2] = (mrl_t *) xmalloc(sizeof(mrl_t));
}
else {
memset(this->mrls[nFiles2], 0, sizeof(mrl_t));
}
if(this->mrls[nFiles2]->mrl) {
this->mrls[nFiles2]->mrl = (char *)
realloc(this->mrls[nFiles2]->mrl, strlen(this->filelist[i]) + 7);
}
else {
this->mrls[nFiles2]->mrl = (char *)
xmalloc(strlen(this->filelist[i]) + 7);
}
this->mrls[nFiles2]->origin = NULL;
sprintf(this->mrls[nFiles2]->mrl, "dvd://%s", this->filelist[i]);
this->mrls[nFiles2]->link = NULL;
this->mrls[nFiles2]->type = (0 | mrl_dvd);
/* determine size */
memset(&str, 0, strlen(str));
sprintf (str, "/VIDEO_TS/%s", this->filelist[i]);
UDFFindFile(fd, str, &this->mrls[nFiles2]->size);
nFiles2++;
}
}
*nEntries = nFiles2;
close (fd);
}
else {
printf ("input_dvd: unable to open dvd drive (%s): %s\n",
this->device, strerror(errno));
return NULL;
}
/*
* Freeing exceeded mrls if exists.
*/
if(*nEntries > this->mrls_allocated_entries)
this->mrls_allocated_entries = *nEntries;
else if(this->mrls_allocated_entries > *nEntries) {
while(this->mrls_allocated_entries > *nEntries) {
MRL_ZERO(this->mrls[this->mrls_allocated_entries - 1]);
free(this->mrls[this->mrls_allocated_entries--]);
}
}
/*
* This is useful to let UI know where it should stops ;-).
*/
this->mrls[*nEntries] = NULL;
return this->mrls;
}
/*
*
*/
static char **dvd_plugin_get_autoplay_list (input_plugin_t *this_gen,
int *nFiles) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
int i, fd;
if((fd = open(this->device, O_RDONLY /* | O_NONBLOCK */ )) > -1) {
int nFiles3, nFiles2;
UDFListDir (fd, "/VIDEO_TS", MAX_DIR_ENTRIES, this->filelist, &nFiles3);
nFiles2 = 0;
for (i=0; i<nFiles3; i++) {
int nLen;
nLen = strlen (this->filelist[i]);
if (nLen<4)
continue;
if (!strcasecmp (&this->filelist[i][nLen-4], ".VOB")) {
sprintf (this->filelist2[nFiles2], "dvd://%s", this->filelist[i]);
nFiles2++;
}
}
*nFiles = nFiles2;
this->filelist2[*nFiles] = NULL;
close (fd);
} else {
printf ("input_dvd: unable to open dvd drive (%s): %s\n",
this->device, strerror(errno));
*nFiles = 0;
return NULL;
}
return this->filelist2;
}
/*
*
*/
static char* dvd_plugin_get_mrl (input_plugin_t *this_gen) {
dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen;
return this->mrl;
}
static int dvd_plugin_get_optional_data (input_plugin_t *this_gen,
void *data, int data_type) {
/*
switch(data_type) {
case INPUT_OPTIONAL_DATA_CLUT:
...
return INPUT_OPTIONAL_SUCCESS;
break;
case INPUT_OPTIONAL_DATA_AUDIOLANG:
...
return INPUT_OPTIONAL_SUCCESS;
break;
}
*/
return INPUT_OPTIONAL_UNSUPPORTED;
}
/*
*
*/
input_plugin_t *init_input_plugin (int iface, config_values_t *config) {
dvd_input_plugin_t *this;
int i;
xine_debug = config->lookup_int (config, "xine_debug", 0);
if (iface != 2) {
printf("vcd input plugin doesn't support plugin API version %d.\n"
"PLUGIN DISABLED.\n"
"This means there's a version mismatch between xine and this input"
"plugin.\nInstalling current input plugins should help.\n",
iface);
return NULL;
}
this = (dvd_input_plugin_t *) xmalloc (sizeof (dvd_input_plugin_t));
for (i = 0; i < MAX_DIR_ENTRIES; i++) {
this->filelist[i] = (char *) xmalloc (256);
this->filelist2[i] = (char *) xmalloc (256);
}
this->input_plugin.interface_version = INPUT_PLUGIN_IFACE_VERSION;
this->input_plugin.get_capabilities = dvd_plugin_get_capabilities;
this->input_plugin.open = dvd_plugin_open;
this->input_plugin.read = dvd_plugin_read;
this->input_plugin.read_block = dvd_plugin_read_block;
this->input_plugin.seek = dvd_plugin_seek;
this->input_plugin.get_current_pos = dvd_plugin_get_current_pos;
this->input_plugin.get_length = dvd_plugin_get_length;
this->input_plugin.get_blocksize = dvd_plugin_get_blocksize;
this->input_plugin.eject_media = dvd_plugin_eject_media;
this->input_plugin.close = dvd_plugin_close;
this->input_plugin.get_identifier = dvd_plugin_get_identifier;
this->input_plugin.get_description = dvd_plugin_get_description;
this->input_plugin.get_dir = dvd_plugin_get_dir;
this->input_plugin.get_mrl = dvd_plugin_get_mrl;
this->input_plugin.get_autoplay_list = dvd_plugin_get_autoplay_list;
this->input_plugin.get_optional_data = dvd_plugin_get_optional_data;
this->input_plugin.handle_input_event= NULL;
this->input_plugin.is_branch_possible= NULL;
this->device = config->lookup_str(config, "dvd_device", DVD);
this->raw_device = config->lookup_str(config, "dvd_raw_device", RDVD);
this->mrls = (mrl_t **) xmalloc(sizeof(mrl_t));
this->mrls_allocated_entries = 0;
this->mrl = NULL;
this->config = config;
this->dvd_fd = -1;
this->raw_fd = -1;
return (input_plugin_t *) this;
}
|