libbluray
 All Classes Files Functions Macros
bluray.h
Go to the documentation of this file.
1 /*
2  * This file is part of libbluray
3  * Copyright (C) 2009-2010 Obliter0n
4  * Copyright (C) 2009-2010 John Stebbins
5  * Copyright (C) 2010 hpi1
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef BLURAY_H_
23 #define BLURAY_H_
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
34 #include <stdint.h>
35 
36 #define TITLES_ALL 0
37 #define TITLES_FILTER_DUP_TITLE 0x01
38 #define TITLES_FILTER_DUP_CLIP 0x02
40 #define TITLES_RELEVANT \
41  (TITLES_FILTER_DUP_TITLE | TITLES_FILTER_DUP_CLIP)
44 typedef struct bluray BLURAY;
45 
46 typedef enum {
47  BLURAY_STREAM_TYPE_VIDEO_MPEG1 = 0x01,
48  BLURAY_STREAM_TYPE_VIDEO_MPEG2 = 0x02,
49  BLURAY_STREAM_TYPE_AUDIO_MPEG1 = 0x03,
50  BLURAY_STREAM_TYPE_AUDIO_MPEG2 = 0x04,
51  BLURAY_STREAM_TYPE_AUDIO_LPCM = 0x80,
52  BLURAY_STREAM_TYPE_AUDIO_AC3 = 0x81,
53  BLURAY_STREAM_TYPE_AUDIO_DTS = 0x82,
54  BLURAY_STREAM_TYPE_AUDIO_TRUHD = 0x83,
55  BLURAY_STREAM_TYPE_AUDIO_AC3PLUS = 0x84,
56  BLURAY_STREAM_TYPE_AUDIO_DTSHD = 0x85,
57  BLURAY_STREAM_TYPE_AUDIO_DTSHD_MASTER = 0x86,
58  BLURAY_STREAM_TYPE_VIDEO_VC1 = 0xea,
59  BLURAY_STREAM_TYPE_VIDEO_H264 = 0x1b,
60  BLURAY_STREAM_TYPE_SUB_PG = 0x90,
61  BLURAY_STREAM_TYPE_SUB_IG = 0x91,
62  BLURAY_STREAM_TYPE_SUB_TEXT = 0x92,
63  BLURAY_STREAM_TYPE_AUDIO_AC3PLUS_SECONDARY = 0xa1,
64  BLURAY_STREAM_TYPE_AUDIO_DTSHD_SECONDARY = 0xa2
65 } bd_stream_type_e;
66 
67 typedef enum {
68  BLURAY_VIDEO_FORMAT_480I = 1, // ITU-R BT.601-5
69  BLURAY_VIDEO_FORMAT_576I = 2, // ITU-R BT.601-4
70  BLURAY_VIDEO_FORMAT_480P = 3, // SMPTE 293M
71  BLURAY_VIDEO_FORMAT_1080I = 4, // SMPTE 274M
72  BLURAY_VIDEO_FORMAT_720P = 5, // SMPTE 296M
73  BLURAY_VIDEO_FORMAT_1080P = 6, // SMPTE 274M
74  BLURAY_VIDEO_FORMAT_576P = 7 // ITU-R BT.1358
75 } bd_video_format_e;
76 
77 typedef enum {
78  BLURAY_VIDEO_RATE_24000_1001 = 1, // 23.976
79  BLURAY_VIDEO_RATE_24 = 2,
80  BLURAY_VIDEO_RATE_25 = 3,
81  BLURAY_VIDEO_RATE_30000_1001 = 4, // 29.97
82  BLURAY_VIDEO_RATE_50 = 6,
83  BLURAY_VIDEO_RATE_60000_1001 = 7 // 59.94
84 } bd_video_rate_e;
85 
86 typedef enum {
87  BLURAY_ASPECT_RATIO_4_3 = 2,
88  BLURAY_ASPECT_RATIO_16_9 = 3
89 } bd_video_aspect_e;
90 
91 typedef enum {
92  BLURAY_AUDIO_FORMAT_MONO = 1,
93  BLURAY_AUDIO_FORMAT_STEREO = 3,
94  BLURAY_AUDIO_FORMAT_MULTI_CHAN = 6,
95  BLURAY_AUDIO_FORMAT_COMBO = 12 // Stereo ac3/dts,
96 } bd_audio_format_e;
97  // multi mlp/dts-hd
98 
99 typedef enum {
100  BLURAY_AUDIO_RATE_48 = 1,
101  BLURAY_AUDIO_RATE_96 = 4,
102  BLURAY_AUDIO_RATE_192 = 5,
103  BLURAY_AUDIO_RATE_192_COMBO = 12, // 48 or 96 ac3/dts
104  // 192 mpl/dts-hd
105  BLURAY_AUDIO_RATE_96_COMBO = 14 // 48 ac3/dts
106  // 96 mpl/dts-hd
107 } bd_audio_rate_e;
108 
109 typedef enum {
110  BLURAY_TEXT_CHAR_CODE_UTF8 = 0x01,
111  BLURAY_TEXT_CHAR_CODE_UTF16BE = 0x02,
112  BLURAY_TEXT_CHAR_CODE_SHIFT_JIS = 0x03,
113  BLURAY_TEXT_CHAR_CODE_EUC_KR = 0x04,
114  BLURAY_TEXT_CHAR_CODE_GB18030_20001 = 0x05,
115  BLURAY_TEXT_CHAR_CODE_CN_GB = 0x06,
116  BLURAY_TEXT_CHAR_CODE_BIG5 = 0x07
117 } bd_char_code_e;
118 
119 typedef enum {
120  BLURAY_STILL_NONE = 0x00,
121  BLURAY_STILL_TIME = 0x01,
122  BLURAY_STILL_INFINITE = 0x02,
123 } bd_still_mode_e;
124 
125 typedef struct bd_stream_info {
126  uint8_t coding_type;
127  uint8_t format;
128  uint8_t rate;
129  uint8_t char_code;
130  uint8_t lang[4];
131  uint16_t pid;
132  uint8_t aspect;
134 
135 typedef struct bd_clip {
136  uint32_t pkt_count;
137  uint8_t still_mode;
138  uint16_t still_time; /* seconds */
139  uint8_t video_stream_count;
140  uint8_t audio_stream_count;
141  uint8_t pg_stream_count;
142  uint8_t ig_stream_count;
143  uint8_t sec_audio_stream_count;
144  uint8_t sec_video_stream_count;
145  BLURAY_STREAM_INFO *video_streams;
146  BLURAY_STREAM_INFO *audio_streams;
147  BLURAY_STREAM_INFO *pg_streams;
148  BLURAY_STREAM_INFO *ig_streams;
149  BLURAY_STREAM_INFO *sec_audio_streams;
150  BLURAY_STREAM_INFO *sec_video_streams;
152 
153 typedef struct bd_chapter {
154  uint32_t idx;
155  uint64_t start;
156  uint64_t duration;
157  uint64_t offset;
159 
160 typedef struct bd_title_info {
161  uint32_t idx;
162  uint32_t playlist;
163  uint64_t duration;
164  uint32_t clip_count;
165  uint8_t angle_count;
166  uint32_t chapter_count;
167  BLURAY_CLIP_INFO *clips;
168  BLURAY_TITLE_CHAPTER *chapters;
170 
171 typedef struct bd_sound_effect {
172  uint8_t num_channels; /* 1 - mono, 2 - stereo */
173  uint32_t num_frames;
174  const int16_t *samples; /* 48000 Hz, 16 bit LPCM. interleaved if stereo */
176 
181 void bd_get_version(int *major, int *minor, int *micro);
182 
194 uint32_t bd_get_titles(BLURAY *bd, uint8_t flags, uint32_t min_title_length);
195 
205 BLURAY_TITLE_INFO* bd_get_title_info(BLURAY *bd, uint32_t title_idx, unsigned angle);
206 
216 BLURAY_TITLE_INFO* bd_get_playlist_info(BLURAY *bd, uint32_t playlist, unsigned angle);
217 
224 void bd_free_title_info(BLURAY_TITLE_INFO *title_info);
225 
233 BLURAY *bd_open(const char* device_path, const char* keyfile_path);
234 
240 void bd_close(BLURAY *bd);
241 
249 int64_t bd_seek(BLURAY *bd, uint64_t pos);
250 
259 int64_t bd_seek_time(BLURAY *bd, uint64_t tick);
260 
270 int bd_read(BLURAY *bd, unsigned char *buf, int len);
271 
279 int bd_read_skip_still(BLURAY *bd);
280 
289 int64_t bd_seek_chapter(BLURAY *bd, unsigned chapter);
290 
299 int64_t bd_chapter_pos(BLURAY *bd, unsigned chapter);
300 
308 uint32_t bd_get_current_chapter(BLURAY *bd);
309 
318 int64_t bd_seek_mark(BLURAY *bd, unsigned mark);
319 
328 int bd_select_playlist(BLURAY *bd, uint32_t playlist);
329 
338 int bd_select_title(BLURAY *bd, uint32_t title);
339 
348 int bd_select_angle(BLURAY *bd, unsigned angle);
349 
357 void bd_seamless_angle_change(BLURAY *bd, unsigned angle);
358 
368 uint64_t bd_get_title_size(BLURAY *bd);
369 
377 uint32_t bd_get_current_title(BLURAY *bd);
378 
386 unsigned bd_get_current_angle(BLURAY *bd);
387 
395 uint64_t bd_tell(BLURAY *bd);
396 
404 uint64_t bd_tell_time(BLURAY *bd);
405 
406 /*
407  * Disc info
408  */
409 
410 /* AACS error codes */
411 #define BD_AACS_CORRUPTED_DISC -1
412 #define BD_AACS_NO_CONFIG -2
413 #define BD_AACS_NO_PK -3
414 #define BD_AACS_NO_CERT -4
415 #define BD_AACS_CERT_REVOKED -5
416 #define BD_AACS_MMC_FAILED -6
417 
418 typedef struct {
419  uint8_t bluray_detected;
420 
421  uint8_t first_play_supported;
422  uint8_t top_menu_supported;
423 
424  uint32_t num_hdmv_titles;
425  uint32_t num_bdj_titles;
426  uint32_t num_unsupported_titles;
427 
428  uint8_t aacs_detected;
429  uint8_t libaacs_detected;
430  uint8_t aacs_handled;
431 
432  uint8_t bdplus_detected;
433  uint8_t libbdplus_detected;
434  uint8_t bdplus_handled;
435 
436  /* aacs error code */
437  int aacs_error_code;
438  /* aacs MKB version */
439  int aacs_mkbv;
440 
441  /* Disc ID */
442  uint8_t disc_id[20];
443 
445 
453 const BLURAY_DISC_INFO *bd_get_disc_info(BLURAY*);
454 
455 /*
456  * player settings
457  */
458 
459 typedef enum {
460  BLURAY_PLAYER_SETTING_PARENTAL = 13, /* Age for parental control (years) */
461  BLURAY_PLAYER_SETTING_AUDIO_CAP = 15, /* Player capability for audio (bit mask) */
462  BLURAY_PLAYER_SETTING_AUDIO_LANG = 16, /* Initial audio language: ISO 639-2 string, ex. "eng" */
463  BLURAY_PLAYER_SETTING_PG_LANG = 17, /* Initial PG/SPU language: ISO 639-2 string, ex. "eng" */
464  BLURAY_PLAYER_SETTING_MENU_LANG = 18, /* Initial menu language: ISO 639-2 string, ex. "eng" */
465  BLURAY_PLAYER_SETTING_COUNTRY_CODE = 19, /* Player country code: ISO 3166-1 string, ex. "de" */
466  BLURAY_PLAYER_SETTING_REGION_CODE = 20, /* Player region code: 1 - region A, 2 - B, 4 - C */
467  BLURAY_PLAYER_SETTING_VIDEO_CAP = 29, /* Player capability for video (bit mask) */
468  BLURAY_PLAYER_SETTING_TEXT_CAP = 30, /* Player capability for text subtitle (bit mask) */
469  BLURAY_PLAYER_SETTING_PLAYER_PROFILE = 31, /* Profile1: 0, Profile1+: 1, Profile2: 3, Profile3: 8 */
470 } bd_player_setting;
471 
482 int bd_set_player_setting(BLURAY *bd, uint32_t idx, uint32_t value);
483 int bd_set_player_setting_str(BLURAY *bd, uint32_t idx, const char *s);
484 
485 /*
486  * Java
487  */
488 int bd_start_bdj(BLURAY *bd, const char* start_object); // start BD-J from the specified BD-J object (should be a 5 character string)
489 void bd_stop_bdj(BLURAY *bd); // shutdown BD-J and clean up resources
490 
491 /*
492  * events
493  */
494 
495 typedef enum {
496  BD_EVENT_NONE = 0,
497  BD_EVENT_ERROR, /* Fatal error. Playback can't be continued. */
498  BD_EVENT_READ_ERROR, /* Reading of .m2ts aligned unit failed. Next call to read will try next block. */
499  BD_EVENT_ENCRYPTED, /* .m2ts file is encrypted and can't be played */
500 
501  /* current playback position */
502  BD_EVENT_ANGLE, /* current angle, 1...N */
503  BD_EVENT_TITLE, /* current title, 1...N (0 = top menu) */
504  BD_EVENT_PLAYLIST, /* current playlist (xxxxx.mpls) */
505  BD_EVENT_PLAYITEM, /* current play item, 0...N-1 */
506  BD_EVENT_CHAPTER, /* current chapter, 1...N */
507  BD_EVENT_END_OF_TITLE,
508 
509  /* stream selection */
510  BD_EVENT_AUDIO_STREAM, /* 1..32, 0xff = none */
511  BD_EVENT_IG_STREAM, /* 1..32 */
512  BD_EVENT_PG_TEXTST_STREAM, /* 1..255, 0xfff = none */
513  BD_EVENT_PIP_PG_TEXTST_STREAM, /* 1..255, 0xfff = none */
514  BD_EVENT_SECONDARY_AUDIO_STREAM, /* 1..32, 0xff = none */
515  BD_EVENT_SECONDARY_VIDEO_STREAM, /* 1..32, 0xff = none */
516 
517  BD_EVENT_PG_TEXTST, /* 0 - disable, 1 - enable */
518  BD_EVENT_PIP_PG_TEXTST, /* 0 - disable, 1 - enable */
519  BD_EVENT_SECONDARY_AUDIO, /* 0 - disable, 1 - enable */
520  BD_EVENT_SECONDARY_VIDEO, /* 0 - disable, 1 - enable */
521  BD_EVENT_SECONDARY_VIDEO_SIZE, /* 0 - PIP, 0xf - fullscreen */
522 
523  /* HDMV VM or JVM seeked the stream. Next read() will return data from new position. */
524  BD_EVENT_SEEK,
525 
526  /* still playback (pause) */
527  BD_EVENT_STILL, /* 0 - off, 1 - on */
528 
529  /* Still playback for n seconds (reached end of still mode play item) */
530  BD_EVENT_STILL_TIME, /* 0 = infinite ; 1...300 = seconds */
531 
532  /* Play sound effect */
533  BD_EVENT_SOUND_EFFECT, /* effect ID */
534 
535  /* Pop-Up menu available */
536  BD_EVENT_POPUP, /* 0 - no, 1 - yes */
537 
538  /* Interactive menu visible */
539  BD_EVENT_MENU, /* 0 - no, 1 - yes */
540 } bd_event_e;
541 
542 typedef struct {
543  uint32_t event; /* bd_event_e */
544  uint32_t param;
545 } BD_EVENT;
546 
547 #define BLURAY_TITLE_FIRST_PLAY 0xffff
548 #define BLURAY_TITLE_TOP_MENU 0
549 
557 int bd_get_event(BLURAY *bd, BD_EVENT *event);
558 
559 /*
560  * navigaton mode
561  */
562 
572 int bd_play(BLURAY *bd);
573 
586 int bd_read_ext(BLURAY *bd, unsigned char *buf, int len, BD_EVENT *event);
587 
600 int bd_play_title(BLURAY *bd, unsigned title);
601 
612 int bd_menu_call(BLURAY *bd, int64_t pts);
613 
614 /*
615  * User interaction and On-screen display controller
616  */
617 
618 struct bd_overlay_s; /* defined in overlay.h */
619 typedef void (*bd_overlay_proc_f)(void *, const struct bd_overlay_s * const);
620 
630 void bd_register_overlay_proc(BLURAY *bd, void *handle, bd_overlay_proc_f func);
631 
643 int bd_user_input(BLURAY *bd, int64_t pts, uint32_t key);
644 
655 int bd_mouse_select(BLURAY *bd, int64_t pts, uint16_t x, uint16_t y);
656 
666 int bd_get_sound_effect(BLURAY *bd, unsigned sound_id, struct bd_sound_effect *effect);
667 
668 /*
669  *
670  */
671 
672 struct meta_dl;
680 const struct meta_dl *bd_get_meta(BLURAY *bd);
681 
682 
683 struct clpi_cl;
692 struct clpi_cl *bd_get_clpi(BLURAY *bd, unsigned clip_ref);
693 
700 void bd_free_clpi(struct clpi_cl *cl);
701 
702 #ifdef __cplusplus
703 };
704 #endif
705 
706 #endif /* BLURAY_H_ */