annotate libmenu/menu_chapsel.c @ 33593:835841f89315

Use the proper type for the palette, fixes compiler warning.
author reimar
date Sun, 19 Jun 2011 19:15:26 +0000
parents 45b93bea8082
children 38a5d56c389c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25364
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
1 /*
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
2 * Support chapter list and selection.
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
3 *
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
4 * Copyright (C) 2006-2007 Benjamin Zores <ben A geexbox P org>
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
5 * Copyright (C) 2007 Ulion <ulion A gmail P com>
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
6 *
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
7 * This file is part of MPlayer.
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
8 *
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
9 * MPlayer is free software; you can redistribute it and/or modify
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
12 * (at your option) any later version.
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
13 *
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
14 * MPlayer is distributed in the hope that it will be useful,
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
17 * GNU General Public License for more details.
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
18 *
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 25499
diff changeset
19 * You should have received a copy of the GNU General Public License along
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 25499
diff changeset
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 25499
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25364
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
22 */
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
23
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
24 #include <stdlib.h>
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
25 #include <stdio.h>
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
26 #include <string.h>
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
27
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
28 #include "config.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
29
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
30 #include "m_struct.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
31 #include "m_option.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
32 #include "input/input.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
33
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
34 #include "stream/stream.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
35 #include "libmpdemux/demuxer.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
36 #include "access_mpcontext.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
37
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
38 #include "libmpcodecs/mp_image.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
39
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
40 #include "menu.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
41 #include "menu_list.h"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
42
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
43 struct list_entry_s {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
44 struct list_entry p;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
45 int cid;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
46 };
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
47
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
48 struct menu_priv_s {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
49 menu_list_priv_t p;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
50 char* title;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
51 int auto_close;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
52 char* fmt_with_time;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
53 };
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
54
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
55 static struct menu_priv_s cfg_dflt = {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
56 MENU_LIST_PRIV_DFLT,
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
57 "Select chapter",
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
58 0,
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
59 "${chapter_name} [${start}]"
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
60 };
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
61
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
62 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
63
30957
45b93bea8082 Mark cfg_fields m_option_t array as const.
diego
parents: 29263
diff changeset
64 static const m_option_t cfg_fields[] = {
25364
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
65 MENU_LIST_PRIV_FIELDS,
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
66 { "title", ST_OFF (title), CONF_TYPE_STRING, 0, 0, 0, NULL },
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
67 { "auto-close", ST_OFF (auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
25499
0846480d1a50 Use '-' instead of '_' in option name.
ulion
parents: 25364
diff changeset
68 { "fmt-with-time", ST_OFF (fmt_with_time), CONF_TYPE_STRING, 0, 0, 0, NULL },
25364
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
69 { NULL, NULL, NULL, 0, 0, 0, NULL }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
70 };
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
71
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
72 static char *fmt_replace(const char *fmt, const char *chapter_name,
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
73 const char *start) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26743
diff changeset
74 static const char ctag[] = "${chapter_name}";
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26743
diff changeset
75 static const char stag[] = "${start}";
25364
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
76 int l = strlen(fmt);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
77 int cl = strlen(chapter_name);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
78 int sl = strlen(start);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
79 char *str = malloc(l + cl + sl);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
80 char *p;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
81 strcpy(str, fmt);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
82 p = strstr(str, ctag);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
83 if (p) {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
84 memmove(p+cl, p+sizeof(ctag)-1, str+l+1 - (p+sizeof(ctag)-1));
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
85 memcpy(p, chapter_name, cl);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
86 l -= sizeof(ctag) + 1;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
87 l += cl;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
88 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
89 p = strstr(str, stag);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
90 if (p) {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
91 memmove(p+sl, p+sizeof(stag)-1, str+l+1 - (p+sizeof(stag)-1));
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
92 memcpy(p, start, sl);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
93 l -= sizeof(stag) + 1;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
94 l += sl;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
95 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
96 return str;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
97 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
98
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
99 static int fill_menu (menu_t* menu)
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
100 {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
101 list_entry_t* e;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
102 int cid, chapter_num = 0;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
103 int start_time;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
104 demuxer_t* demuxer = mpctx_get_demuxer(menu->ctx);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
105
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
106 if (demuxer)
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
107 chapter_num = demuxer_chapter_count(demuxer);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
108 if (chapter_num > 0) {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
109 menu_list_init (menu);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
110 for (cid = 0; cid < chapter_num; ++cid)
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
111 if ((e = calloc (1, sizeof (list_entry_t))) != NULL) {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
112 e->cid = cid + 1;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
113 e->p.next = NULL;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
114 e->p.txt = demuxer_chapter_display_name(demuxer, cid);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
115 start_time = demuxer_chapter_time(demuxer, cid, NULL);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
116 if (start_time >= 0) {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
117 char timestr[13];
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
118 char *tmp;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
119 int hour = start_time / 3600;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
120 int minute = (start_time / 60) % 60;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
121 int seconds = start_time % 60;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
122 sprintf(timestr,"%02d:%02d:%02d", hour, minute, seconds);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
123
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
124 tmp = fmt_replace(menu->priv->fmt_with_time, e->p.txt, timestr);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
125 free(e->p.txt);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
126 e->p.txt = tmp;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
127 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
128 menu_list_add_entry(menu, e);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
129 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
130 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
131 else
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
132 menu_list_read_cmd(menu, MENU_CMD_CANCEL);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
133
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
134 return 1;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
135 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
136
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
137 static void read_cmd (menu_t* menu, int cmd)
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
138 {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
139 switch (cmd) {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
140 case MENU_CMD_RIGHT:
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
141 case MENU_CMD_OK: {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
142 char cmdbuf[26];
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
143 sprintf(cmdbuf, "seek_chapter %d 1", menu->priv->p.current->cid);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
144 mp_input_queue_cmd(mp_input_parse_cmd(cmdbuf));
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
145 if (menu->priv->auto_close)
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
146 mp_input_queue_cmd(mp_input_parse_cmd("menu hide"));
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
147 break;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
148 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
149 default:
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
150 menu_list_read_cmd (menu, cmd);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
151 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
152 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
153
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
154 static void close_cs (menu_t* menu)
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
155 {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
156 menu_list_uninit (menu, NULL);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
157 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
158
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
159 static int open_cs (menu_t* menu, char* args)
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
160 {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
161 args = NULL;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
162
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
163 menu->draw = menu_list_draw;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
164 menu->read_cmd = read_cmd;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
165 menu->close = close_cs;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
166 menu->priv->p.title = menu->priv->title;
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
167
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
168 return fill_menu (menu);
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
169 }
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
170
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
171 const menu_info_t menu_info_chapsel = {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
172 "Chapter selector menu",
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
173 "chapsel",
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
174 "Benjamin Zores & Ulion",
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
175 "",
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
176 {
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
177 "chapsel_cfg",
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
178 sizeof(struct menu_priv_s),
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
179 &cfg_dflt,
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
180 cfg_fields
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
181 },
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
182 open_cs
fec8936c8079 Support chapter in OSD menu.
ulion
parents:
diff changeset
183 };