2 * Copyright (C) 2005-2009 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 #include "DynamicDll.h"
30 #include <libbluray/bluray.h>
31 #include <libbluray/filesystem.h>
32 #include <libbluray/log_control.h>
35 class DllLibblurayInterface
38 virtual ~DllLibblurayInterface() {};
39 virtual uint32_t bd_get_titles(BLURAY *bd, uint8_t flags, uint32_t min_title_length)=0;
40 virtual BLURAY_TITLE_INFO* bd_get_title_info(BLURAY *bd, uint32_t title_idx, unsigned angle)=0;
41 virtual BLURAY_TITLE_INFO* bd_get_playlist_info(BLURAY *bd, uint32_t playlist, unsigned angle)=0;
42 virtual void bd_free_title_info(BLURAY_TITLE_INFO *title_info)=0;
43 virtual BLURAY *bd_open(const char* device_path, const char* keyfile_path)=0;
44 virtual void bd_close(BLURAY *bd)=0;
45 virtual int64_t bd_seek(BLURAY *bd, uint64_t pos)=0;
46 virtual int64_t bd_seek_time(BLURAY *bd, uint64_t tick)=0;
47 virtual int bd_read(BLURAY *bd, unsigned char *buf, int len)=0;
48 virtual int64_t bd_seek_chapter(BLURAY *bd, unsigned chapter)=0;
49 virtual int64_t bd_chapter_pos(BLURAY *bd, unsigned chapter)=0;
50 virtual uint32_t bd_get_current_chapter(BLURAY *bd)=0;
51 virtual int64_t bd_seek_mark(BLURAY *bd, unsigned mark)=0;
52 virtual int bd_select_playlist(BLURAY *bd, uint32_t playlist)=0;
53 virtual int bd_select_title(BLURAY *bd, uint32_t title)=0;
54 virtual int bd_select_angle(BLURAY *bd, unsigned angle)=0;
55 virtual void bd_seamless_angle_change(BLURAY *bd, unsigned angle)=0;
56 virtual uint64_t bd_get_title_size(BLURAY *bd)=0;
57 virtual uint32_t bd_get_current_title(BLURAY *bd)=0;
58 virtual unsigned bd_get_current_angle(BLURAY *bd)=0;
59 virtual uint64_t bd_tell(BLURAY *bd)=0;
60 virtual uint64_t bd_tell_time(BLURAY *bd)=0;
61 virtual BD_FILE_OPEN bd_register_file(BD_FILE_OPEN p)=0;
62 virtual BD_DIR_OPEN bd_register_dir(BD_DIR_OPEN p)=0;
64 virtual void bd_set_debug_handler(BD_LOG_FUNC)=0;
65 virtual void bd_set_debug_mask(uint32_t mask)=0;
66 virtual uint32_t bd_get_debug_mask(void)=0;
67 virtual const BLURAY_DISC_INFO *bd_get_disc_info(BLURAY *bd)=0;
70 class DllLibbluray : public DllDynamic, DllLibblurayInterface
72 DECLARE_DLL_WRAPPER(DllLibbluray, DLL_PATH_LIBBLURAY)
73 DEFINE_METHOD3(uint32_t, bd_get_titles, (BLURAY *p1, uint8_t p2, uint32_t p3))
74 DEFINE_METHOD3(BLURAY_TITLE_INFO*, bd_get_title_info, (BLURAY *p1, uint32_t p2, unsigned p3))
75 DEFINE_METHOD3(BLURAY_TITLE_INFO*, bd_get_playlist_info, (BLURAY *p1, uint32_t p2, unsigned p3))
76 DEFINE_METHOD1(void, bd_free_title_info, (BLURAY_TITLE_INFO *p1))
77 DEFINE_METHOD2(BLURAY*, bd_open, (const char* p1, const char* p2))
78 DEFINE_METHOD1(void, bd_close, (BLURAY *p1))
79 DEFINE_METHOD2(int64_t, bd_seek, (BLURAY *p1, uint64_t p2))
80 DEFINE_METHOD2(int64_t, bd_seek_time, (BLURAY *p1, uint64_t p2))
81 DEFINE_METHOD3(int, bd_read, (BLURAY *p1, unsigned char *p2, int p3))
82 DEFINE_METHOD2(int64_t, bd_seek_chapter, (BLURAY *p1, unsigned p2))
83 DEFINE_METHOD2(int64_t, bd_chapter_pos, (BLURAY *p1, unsigned p2))
84 DEFINE_METHOD1(uint32_t, bd_get_current_chapter, (BLURAY *p1))
85 DEFINE_METHOD2(int64_t, bd_seek_mark, (BLURAY *p1, unsigned p2))
86 DEFINE_METHOD2(int, bd_select_playlist, (BLURAY *p1, uint32_t p2))
87 DEFINE_METHOD2(int, bd_select_title, (BLURAY *p1, uint32_t p2))
88 DEFINE_METHOD2(int, bd_select_angle, (BLURAY *p1, unsigned p2))
89 DEFINE_METHOD2(void, bd_seamless_angle_change,(BLURAY *p1, unsigned p2))
90 DEFINE_METHOD1(uint64_t, bd_get_title_size, (BLURAY *p1))
91 DEFINE_METHOD1(uint32_t, bd_get_current_title, (BLURAY *p1))
92 DEFINE_METHOD1(unsigned, bd_get_current_angle, (BLURAY *p1))
93 DEFINE_METHOD1(uint64_t, bd_tell, (BLURAY *p1))
94 DEFINE_METHOD1(uint64_t, bd_tell_time, (BLURAY *p1))
95 DEFINE_METHOD1(BD_FILE_OPEN, bd_register_file, (BD_FILE_OPEN p1))
96 DEFINE_METHOD1(BD_DIR_OPEN, bd_register_dir, (BD_DIR_OPEN p1))
98 DEFINE_METHOD1(void, bd_set_debug_handler, (BD_LOG_FUNC p1))
99 DEFINE_METHOD1(void, bd_set_debug_mask, (uint32_t p1))
100 DEFINE_METHOD0(uint32_t, bd_get_debug_mask)
101 DEFINE_METHOD1(const BLURAY_DISC_INFO*, bd_get_disc_info, (BLURAY *p1))
103 BEGIN_METHOD_RESOLVE()
104 RESOLVE_METHOD(bd_get_titles)
105 RESOLVE_METHOD(bd_get_title_info)
106 RESOLVE_METHOD(bd_get_playlist_info)
107 RESOLVE_METHOD_RENAME(bd_free_title_info, bd_free_title_info)
108 RESOLVE_METHOD_RENAME(bd_open, bd_open)
109 RESOLVE_METHOD_RENAME(bd_close, bd_close)
110 RESOLVE_METHOD_RENAME(bd_seek, bd_seek)
111 RESOLVE_METHOD_RENAME(bd_seek_time, bd_seek_time)
112 RESOLVE_METHOD_RENAME(bd_read, bd_read)
113 RESOLVE_METHOD_RENAME(bd_seek_chapter, bd_seek_chapter)
114 RESOLVE_METHOD_RENAME(bd_chapter_pos, bd_chapter_pos)
115 RESOLVE_METHOD_RENAME(bd_get_current_chapter, bd_get_current_chapter)
116 RESOLVE_METHOD_RENAME(bd_seek_mark, bd_seek_mark)
117 RESOLVE_METHOD_RENAME(bd_select_playlist, bd_select_playlist)
118 RESOLVE_METHOD_RENAME(bd_select_title, bd_select_title)
119 RESOLVE_METHOD_RENAME(bd_select_angle, bd_select_angle)
120 RESOLVE_METHOD_RENAME(bd_seamless_angle_change, bd_seamless_angle_change)
121 RESOLVE_METHOD_RENAME(bd_get_title_size, bd_get_title_size)
122 RESOLVE_METHOD_RENAME(bd_get_current_title, bd_get_current_title)
123 RESOLVE_METHOD_RENAME(bd_get_current_angle, bd_get_current_angle)
124 RESOLVE_METHOD_RENAME(bd_tell, bd_tell)
125 RESOLVE_METHOD_RENAME(bd_tell_time, bd_tell_time)
126 RESOLVE_METHOD_RENAME(bd_register_file, bd_register_file)
127 RESOLVE_METHOD_RENAME(bd_register_dir, bd_register_dir)
128 RESOLVE_METHOD(bd_set_debug_handler)
129 RESOLVE_METHOD(bd_set_debug_mask)
130 RESOLVE_METHOD(bd_get_debug_mask)
131 RESOLVE_METHOD(bd_get_disc_info)
135 static void file_close(BD_FILE_H *file);
136 static int64_t file_seek(BD_FILE_H *file, int64_t offset, int32_t origin);
137 static int64_t file_tell(BD_FILE_H *file);
138 static int file_eof(BD_FILE_H *file);
139 static int64_t file_read(BD_FILE_H *file, uint8_t *buf, int64_t size);
140 static int64_t file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size);
141 static BD_FILE_H *file_open(const char* filename, const char *mode);
142 static void dir_close(BD_DIR_H *dir);
143 static int dir_read(BD_DIR_H *dir, BD_DIRENT *entry);
144 static BD_DIR_H *dir_open(const char* dirname);
145 static void bluray_logger(const char* msg);