1 /*
2 * This file is part of libbluray
3 * Copyright (C) 2010 hpi1
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see
17 * <http://www.gnu.org/licenses/>.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <inttypes.h>
24
25 #include "decoders/overlay.h"
26 #include "util/log_control.h"
27 #include "bluray.h"
28
29
30 #define PRINT_EV0(e) \
31 case BD_EVENT_##e: \
32 printf(#e "\n"); \
33 break
34 #define PRINT_EV1(e,f) \
35 case BD_EVENT_##e: \
36 printf("%-25s " f "\n", #e ":", ev->param); \
37 break
38
_print_event(BD_EVENT * ev)39 static void _print_event(BD_EVENT *ev)
40 {
41 switch ((bd_event_e)ev->event) {
42
43 case BD_EVENT_NONE:
44 break;
45
46 /* errors */
47
48 PRINT_EV1(ERROR, "%u");
49 PRINT_EV1(READ_ERROR, "%u");
50 PRINT_EV1(ENCRYPTED, "%u");
51
52 /* current playback position */
53
54 PRINT_EV1(ANGLE, "%u");
55 PRINT_EV1(TITLE, "%u");
56 PRINT_EV1(PLAYLIST, "%05u.mpls");
57 PRINT_EV1(PLAYITEM, "%u");
58 PRINT_EV1(PLAYMARK, "%u");
59 PRINT_EV1(CHAPTER, "%u");
60 PRINT_EV0(END_OF_TITLE);
61
62 PRINT_EV1(STEREOSCOPIC_STATUS, "%u");
63
64 PRINT_EV1(SEEK, "%u");
65 PRINT_EV0(DISCONTINUITY);
66 PRINT_EV0(PLAYLIST_STOP);
67
68 /* Interactive */
69
70 PRINT_EV1(STILL_TIME, "%u");
71 PRINT_EV1(STILL, "%u");
72 PRINT_EV1(SOUND_EFFECT, "%u");
73 PRINT_EV1(IDLE, "%u");
74 PRINT_EV1(POPUP, "%u");
75 PRINT_EV1(MENU, "%u");
76 PRINT_EV1(UO_MASK_CHANGED, "0x%04x");
77 PRINT_EV1(KEY_INTEREST_TABLE, "0x%04x");
78
79 /* stream selection */
80
81 PRINT_EV1(PG_TEXTST, "%u");
82 PRINT_EV1(SECONDARY_AUDIO, "%u");
83 PRINT_EV1(SECONDARY_VIDEO, "%u");
84 PRINT_EV1(PIP_PG_TEXTST, "%u");
85
86 PRINT_EV1(AUDIO_STREAM, "%u");
87 PRINT_EV1(IG_STREAM, "%u");
88 PRINT_EV1(PG_TEXTST_STREAM, "%u");
89 PRINT_EV1(SECONDARY_AUDIO_STREAM, "%u");
90 PRINT_EV1(SECONDARY_VIDEO_STREAM, "%u");
91 PRINT_EV1(SECONDARY_VIDEO_SIZE, "%u");
92 PRINT_EV1(PIP_PG_TEXTST_STREAM, "%u");
93 }
94
95 fflush(stdout);
96 }
97
_read_to_eof(BLURAY * bd)98 static void _read_to_eof(BLURAY *bd)
99 {
100 BD_EVENT ev;
101 int bytes;
102 uint64_t total = 0;
103 uint8_t buf[6144];
104
105 bd_seek(bd, bd_get_title_size(bd) - 6144);
106
107 do {
108 bytes = bd_read_ext(bd, buf, 6144, &ev);
109 total += bytes < 0 ? 0 : bytes;
110 _print_event(&ev);
111 } while (bytes > 0);
112
113 printf("_read_to_eof(): read %" PRIu64 " bytes\n", total);
114 }
115
_print_events(BLURAY * bd)116 static void _print_events(BLURAY *bd)
117 {
118 BD_EVENT ev;
119
120 do {
121 bd_read_ext(bd, NULL, 0, &ev);
122 _print_event(&ev);
123 } while (ev.event != BD_EVENT_NONE && ev.event != BD_EVENT_ERROR);
124 }
125
_play_pl(BLURAY * bd)126 static void _play_pl(BLURAY *bd)
127 {
128 printf("Playing playlist\n");
129
130 fflush(stdout);
131 _read_to_eof(bd);
132
133 printf("Playing playlist done\n\n");
134
135 _print_events(bd);
136
137 printf("\n");
138 }
139
_overlay_cb(void * h,const struct bd_overlay_s * const ov)140 static void _overlay_cb(void *h, const struct bd_overlay_s * const ov)
141 {
142 (void)h;
143
144 if (ov) {
145 printf("OVERLAY @%ld p%d %d: %d,%d %dx%d\n", (long)ov->pts, ov->plane, ov->cmd, ov->x, ov->y, ov->w, ov->h);
146
147 } else {
148 printf("OVERLAY CLOSE\n");
149 }
150 }
151
_argb_overlay_cb(void * h,const struct bd_argb_overlay_s * const ov)152 static void _argb_overlay_cb(void *h, const struct bd_argb_overlay_s * const ov)
153 {
154 (void)h;
155
156 if (ov) {
157 printf("ARGB OVERLAY @%ld p%d %d: %d,%d %dx%d\n", (long)ov->pts, ov->plane, ov->cmd, ov->x, ov->y, ov->w, ov->h);
158
159 } else {
160 printf("ARGB OVERLAY CLOSE\n");
161 }
162 }
163
main(int argc,char * argv[])164 int main(int argc, char *argv[])
165 {
166 int title = -1;
167 int verbose = 0;
168 int args = 0;
169
170 /*
171 * parse arguments
172 */
173
174 if (argc < 2) {
175 printf("\nUsage:\n %s [-v] [-t <title>] <media_path> [<keyfile_path>]\n\n", argv[0]);
176 return -1;
177 }
178
179 if (!strcmp(argv[1+args], "-v")) {
180 verbose = 1;
181 args++;
182 }
183
184 if (!strcmp(argv[1+args], "-t")) {
185 args++;
186 title = atoi(argv[1+args]);
187 args++;
188 printf("Requested title %d\n", title);
189 }
190
191 if (verbose) {
192 printf("Enabling verbose debug\n");
193 bd_set_debug_mask(bd_get_debug_mask() | DBG_HDMV | DBG_BLURAY);
194 }
195
196 printf("\n");
197
198 /*
199 * open and setup
200 */
201
202 BLURAY *bd = bd_open(argv[1+args], argv[2+args]);
203
204 if (!bd) {
205 printf("bd_open(\'%s\') failed\n", argv[1+args]);
206 return -1;
207 }
208
209 bd_set_player_setting (bd, BLURAY_PLAYER_SETTING_PARENTAL, 99);
210 bd_set_player_setting_str(bd, BLURAY_PLAYER_SETTING_AUDIO_LANG, "eng");
211 bd_set_player_setting_str(bd, BLURAY_PLAYER_SETTING_PG_LANG, "eng");
212 bd_set_player_setting_str(bd, BLURAY_PLAYER_SETTING_MENU_LANG, "eng");
213 bd_set_player_setting_str(bd, BLURAY_PLAYER_SETTING_COUNTRY_CODE, NULL);
214
215 bd_register_overlay_proc(bd, bd, _overlay_cb);
216 bd_register_argb_overlay_proc(bd, bd, _argb_overlay_cb, NULL);
217
218 /*
219 * play
220 */
221
222 printf("Running first play movie object\n");
223
224 fflush(stdout);
225 bd_play(bd);
226
227 _print_events(bd);
228
229 printf("\n");
230
231 /*
232 * play title
233 */
234
235 if (title >= 0) {
236 printf("Playing title %d\n", title);
237
238 fflush(stdout);
239 bd_play_title(bd, title);
240
241 _print_events(bd);
242
243 printf("\n");
244 }
245
246 /*
247 * play playlist
248 */
249
250 _play_pl(bd);
251
252 _play_pl(bd);
253
254 _play_pl(bd);
255
256 /*
257 * clean up
258 */
259
260 bd_close(bd);
261
262 return 0;
263 }
264
265