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
|
/*
* Copyright (C) 2000-2005 the xine project
*
* Copyright (C) 2009 Petri Hintukainen <phintuka@users.sourceforge.net>
*
* This file is part of xine, a free 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
* Input plugin for BluRay discs / images
*
* Requires libbluray from http://www.assembla.com/spaces/libbluray/
* Tested with revision 97
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <dlfcn.h>
#include <bluray.h>
#define LOG_MODULE "input_bluray"
#define LOG_VERBOSE
/*
#define LOG
*/
#ifdef HAVE_CONFIG_H
# include "xine_internal.h"
# include "input_plugin.h"
#else
# include <xine/xine_internal.h>
# include <xine/input_plugin.h>
#endif
#ifndef EXPORTED
# define EXPORTED __attribute__((visibility("default")))
#endif
#ifndef MIN
# define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#define ALIGNED_UNIT_SIZE (6144)
typedef struct {
input_class_t input_class;
xine_t *xine;
/* config */
char *mountpoint;
char *keyfile;
char *device;
} bluray_input_class_t;
typedef struct {
input_plugin_t input_plugin;
xine_stream_t *stream;
bluray_input_class_t *class;
char *mrl;
BLURAY *bdh;
} bluray_input_plugin_t;
static uint32_t bluray_plugin_get_capabilities (input_plugin_t *this_gen)
{
return INPUT_CAP_SEEKABLE /*| INPUT_CAP_BLOCK*/;
}
static off_t bluray_plugin_read (input_plugin_t *this_gen, char *buf, off_t len)
{
bluray_input_plugin_t *this = (bluray_input_plugin_t *) this_gen;
if (len < 0)
return -1;
int got = bd_read (this->bdh, (unsigned char *)buf, len);
#ifdef LOG
if (got != len) {
fprintf(stderr, "input_bluray: bd_read() failed: %s (%d of %d)\n",
strerror(errno), got, (int)len);
}
if (buf[4] != 0x47) {
fprintf(stderr, "input_bluray: %02x %02x %02x %02x %02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4]);
}
#endif
return got;
}
static buf_element_t *bluray_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo, off_t todo)
{
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
if (todo < 0) {
buf->free_buffer (buf);
return NULL;
}
if (todo > (off_t)buf->max_size)
todo = buf->max_size;
if (todo > ALIGNED_UNIT_SIZE)
todo = ALIGNED_UNIT_SIZE;
buf->type = BUF_DEMUX_BLOCK;
buf->size = bluray_plugin_read(this_gen, (char*)buf->content, todo);
if (buf->size <= 0) {
buf->free_buffer (buf);
return NULL;
}
return buf;
}
static off_t bluray_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin)
{
bluray_input_plugin_t *this = (bluray_input_plugin_t *) this_gen;
if (!this->bdh)
return -1;
if (origin == SEEK_CUR) {
offset = this->bdh->s_pos + offset;
origin = SEEK_SET;
}
if (origin != SEEK_SET)
return this->bdh->s_pos;
return bd_seek (this->bdh, offset);
}
static off_t bluray_plugin_get_current_pos (input_plugin_t *this_gen)
{
bluray_input_plugin_t *this = (bluray_input_plugin_t *) this_gen;
return this->bdh ? this->bdh->s_pos : 0;
}
static off_t bluray_plugin_get_length (input_plugin_t *this_gen)
{
bluray_input_plugin_t *this = (bluray_input_plugin_t *) this_gen;
return this->bdh ? this->bdh->s_size : -1;
}
static uint32_t bluray_plugin_get_blocksize (input_plugin_t *this_gen)
{
return ALIGNED_UNIT_SIZE;
}
static const char* bluray_plugin_get_mrl (input_plugin_t *this_gen)
{
bluray_input_plugin_t *this = (bluray_input_plugin_t *) this_gen;
return this->mrl;
}
static int bluray_plugin_get_optional_data (input_plugin_t *this_gen, void *data, int data_type)
{
return INPUT_OPTIONAL_UNSUPPORTED;
}
static void bluray_plugin_dispose (input_plugin_t *this_gen)
{
bluray_input_plugin_t *this = (bluray_input_plugin_t *) this_gen;
if (this->bdh)
bd_close(this->bdh);
free (this->mrl);
free (this);
}
static int bluray_plugin_open (input_plugin_t *this_gen)
{
bluray_input_plugin_t *this = (bluray_input_plugin_t *) this_gen;
int title = 0;
char *filename;
lprintf("bluray_plugin_open\n");
if (strncasecmp (this->mrl, "bluray:", 7))
return -1;
if (!strcasecmp (this->mrl, "bluray:") ||
!strcasecmp (this->mrl, "bluray:/") ||
!strcasecmp (this->mrl, "bluray://") ||
!strcasecmp (this->mrl, "bluray:///")) {
filename = strdup(this->class->mountpoint);
} else if (!strncasecmp (this->mrl, "bluray:/", 8)) {
if (!strncasecmp (this->mrl, "bluray:///", 10))
filename = strdup(this->mrl + 9);
else if (!strncasecmp (this->mrl, "bluray://", 9))
filename = strdup(this->mrl + 8);
else
filename = strdup(this->mrl + 7);
_x_mrl_unescape(filename);
if (filename[strlen(filename)-1] != '/') {
char *end = strrchr(filename, '/');
if (end && end[1])
if (sscanf(end, "/%d", &title) != 1)
title = 0;
*end = 0;
}
} else {
return -1;
}
if (! (this->bdh = bd_open (filename, this->class->keyfile))) {
fprintf(stderr, "input_bluray: bd_open(\'%s\') failed: %s\n", filename, strerror(errno));
free(filename);
return -1;
}
fprintf(stderr, "input_bluray: bd_open(\'%s\') OK\n", filename);
if (!bd_select_title(this->bdh, title)) {
fprintf(stderr, "input_bluray: bd_select_title(%d) failed: %s\n", title, strerror(errno));
free(filename);
return -1;
}
fprintf(stderr, "input_bluray: bd_select_title(%d) OK\n", title);
fprintf(stderr, "input_bluray: title length: %"PRIu64" bytes\n", this->bdh->s_size);
//_x_meta_info_set(this->stream, XINE_META_INFO_TITLE, this->dvd_name);
_x_stream_info_set(this->stream, XINE_STREAM_INFO_DVD_TITLE_NUMBER, title);
//_x_stream_info_set(this->stream,XINE_STREAM_INFO_DVD_TITLE_COUNT,num_tt);
free(filename);
return 1;
}
static input_plugin_t *bluray_class_get_instance (input_class_t *cls_gen, xine_stream_t *stream,
const char *mrl)
{
bluray_input_plugin_t *this;
lprintf("bluray_class_get_instance\n");
if (strncasecmp (mrl, "bluray:", 7))
return NULL;
this = (bluray_input_plugin_t *) calloc(1, sizeof (bluray_input_plugin_t));
this->stream = stream;
this->class = (bluray_input_class_t*)cls_gen;
this->mrl = strdup(mrl);
this->input_plugin.open = bluray_plugin_open;
this->input_plugin.get_capabilities = bluray_plugin_get_capabilities;
this->input_plugin.read = bluray_plugin_read;
this->input_plugin.read_block = bluray_plugin_read_block;
this->input_plugin.seek = bluray_plugin_seek;
this->input_plugin.get_current_pos = bluray_plugin_get_current_pos;
this->input_plugin.get_length = bluray_plugin_get_length;
this->input_plugin.get_blocksize = bluray_plugin_get_blocksize;
this->input_plugin.get_mrl = bluray_plugin_get_mrl;
this->input_plugin.get_optional_data = bluray_plugin_get_optional_data;
this->input_plugin.dispose = bluray_plugin_dispose;
this->input_plugin.input_class = cls_gen;
return &this->input_plugin;
}
/*
* plugin class
*/
static void mountpoint_change_cb(void *data, xine_cfg_entry_t *cfg)
{
bluray_input_class_t *this = (bluray_input_class_t *) data;
this->mountpoint = cfg->str_value;
}
static void device_change_cb(void *data, xine_cfg_entry_t *cfg)
{
bluray_input_class_t *this = (bluray_input_class_t *) data;
this->device = cfg->str_value;
}
static void keyfile_change_cb(void *data, xine_cfg_entry_t *cfg)
{
bluray_input_class_t *this = (bluray_input_class_t *) data;
this->keyfile = cfg->str_value;
}
static const char *bluray_class_get_description (input_class_t *this_gen)
{
return _("BluRay input plugin");
}
static const char *bluray_class_get_identifier (input_class_t *this_gen)
{
return "bluray";
}
static char **bluray_class_get_autoplay_list (input_class_t *this_gen, int *num_files)
{
static char *autoplay_list[] = { "bluray:/", NULL };
*num_files = 1;
return autoplay_list;
}
static int bluray_class_eject_media (input_class_t *this_gen)
{
#if 0
bluray_input_class_t *this = (bluray_input_class_t*) this_gen;
return media_eject_media (this->xine, this->device);
#endif
return 1;
}
static void bluray_class_dispose (input_class_t *this_gen)
{
bluray_input_class_t *this = (bluray_input_class_t *) this_gen;
config_values_t *config = this->xine->config;
config->unregister_callback(config, "media.bluray.mountpoint");
config->unregister_callback(config, "media.bluray.device");
config->unregister_callback(config, "media.bluray.keyfile");
free (this);
}
static void *bluray_init_plugin (xine_t *xine, void *data)
{
config_values_t *config = xine->config;
bluray_input_class_t *this = (bluray_input_class_t *) calloc(1, sizeof (bluray_input_class_t));
this->xine = xine;
this->input_class.get_instance = bluray_class_get_instance;
this->input_class.get_identifier = bluray_class_get_identifier;
this->input_class.get_description = bluray_class_get_description;
this->input_class.get_dir = NULL;
this->input_class.get_autoplay_list = bluray_class_get_autoplay_list;
this->input_class.dispose = bluray_class_dispose;
this->input_class.eject_media = bluray_class_eject_media;
this->mountpoint = config->register_filename(config, "media.bluray.mountpoint",
"/mnt/bluray", XINE_CONFIG_STRING_IS_DIRECTORY_NAME,
_("BluRay mount point"),
_("Default mount location for BluRay discs."),
0, mountpoint_change_cb, (void *) this);
return this;
}
/*
* exported plugin catalog entry
*/
const plugin_info_t xine_plugin_info[] EXPORTED = {
/* type, API, "name", version, special_info, init_function */
{ PLUGIN_INPUT | PLUGIN_MUST_PRELOAD, 17, "BLURAY", XINE_VERSION_CODE, NULL, bluray_init_plugin },
{ PLUGIN_NONE, 0, "", 0, NULL, NULL }
};
|