[MPlayer-cvslog] r25392 - in trunk: access_mpcontext.h etc/menu.conf libmenu/Makefile libmenu/menu.c libmenu/menu_chapsel.c mplayer.c
ulion
subversion at mplayerhq.hu
Fri Dec 14 09:39:46 CET 2007
Author: ulion
Date: Fri Dec 14 09:39:45 2007
New Revision: 25392
Log:
Support chapter in OSD menu.
Added:
trunk/libmenu/menu_chapsel.c
Modified:
trunk/access_mpcontext.h
trunk/etc/menu.conf
trunk/libmenu/Makefile
trunk/libmenu/menu.c
trunk/mplayer.c
Modified: trunk/access_mpcontext.h
==============================================================================
--- trunk/access_mpcontext.h (original)
+++ trunk/access_mpcontext.h Fri Dec 14 09:39:45 2007
@@ -1,6 +1,7 @@
struct MPContext;
void *mpctx_get_video_out(struct MPContext *mpctx);
void *mpctx_get_audio_out(struct MPContext *mpctx);
+void *mpctx_get_demuxer(struct MPContext *mpctx);
void *mpctx_get_playtree_iter(struct MPContext *mpctx);
void *mpctx_get_mixer(struct MPContext *mpctx);
int mpctx_get_global_sub_size(struct MPContext *mpctx);
Modified: trunk/etc/menu.conf
==============================================================================
--- trunk/etc/menu.conf (original)
+++ trunk/etc/menu.conf Fri Dec 14 09:39:45 2007
@@ -31,6 +31,7 @@
<keybindings name="filesel" parent="list">
<binding key="BS" cmd="menu left" />
</keybindings>
+<keybindings name="chapsel" parent="list" />
<keybindings name="cmdlist" parent="list">
<binding key="AR_PREV" cmd="menu left" />
<binding key="AR_NEXT" cmd="menu right" />
@@ -52,6 +53,8 @@
filter="/etc/mplayer/extensions_filter"
actions="d:run 'mp_loader \'%p\' d',c:run 'mp_loader \'%p\' c'" />
+<chapsel name="select_chapter" />
+
<pt name="jump_to"/>
<console name="console0" height="80" vspace="0">Welcome to MPlayer</console>
@@ -132,6 +135,8 @@
<cmdlist name="main" title="MPlayer OSD menu" ptr="<>" >
<e name="Pause" ok="pause"/>
+ <e name="Chapter ..." ok="set_menu select_chapter"
+ left="seek_chapter -1" right="seek_chapter +1"/>
<e name="Prev/Next" ok="pt_step 1" cancel="pt_step -1"/>
<e name="Jump to ..." ok="set_menu jump_to"/>
<e name="Open ..." ok="set_menu open_file"/>
Modified: trunk/libmenu/Makefile
==============================================================================
--- trunk/libmenu/Makefile (original)
+++ trunk/libmenu/Makefile Fri Dec 14 09:39:45 2007
@@ -4,6 +4,7 @@ LIBNAME_MPLAYER = libmenu.a
SRCS_MPLAYER = menu.c \
vf_menu.c \
+ menu_chapsel.c \
menu_cmdlist.c \
menu_pt.c \
menu_list.c \
Modified: trunk/libmenu/menu.c
==============================================================================
--- trunk/libmenu/menu.c (original)
+++ trunk/libmenu/menu.c Fri Dec 14 09:39:45 2007
@@ -24,6 +24,7 @@
#include "menu.h"
extern menu_info_t menu_info_cmdlist;
+extern menu_info_t menu_info_chapsel;
extern menu_info_t menu_info_pt;
extern menu_info_t menu_info_filesel;
extern menu_info_t menu_info_txt;
@@ -37,6 +38,7 @@ extern menu_info_t menu_info_dvbsel;
menu_info_t* menu_info_list[] = {
&menu_info_pt,
&menu_info_cmdlist,
+ &menu_info_chapsel,
&menu_info_filesel,
&menu_info_txt,
&menu_info_console,
Added: trunk/libmenu/menu_chapsel.c
==============================================================================
--- (empty file)
+++ trunk/libmenu/menu_chapsel.c Fri Dec 14 09:39:45 2007
@@ -0,0 +1,183 @@
+/*
+ * Support chapter list and selection.
+ *
+ * Copyright (C) 2006-2007 Benjamin Zores <ben A geexbox P org>
+ * Copyright (C) 2007 Ulion <ulion A gmail P com>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer 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.
+ *
+ * MPlayer 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 MPlayer; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "config.h"
+
+#include "m_struct.h"
+#include "m_option.h"
+#include "input/input.h"
+
+#include "stream/stream.h"
+#include "libmpdemux/demuxer.h"
+#include "access_mpcontext.h"
+
+#include "libmpcodecs/mp_image.h"
+
+#include "menu.h"
+#include "menu_list.h"
+
+struct list_entry_s {
+ struct list_entry p;
+ int cid;
+};
+
+struct menu_priv_s {
+ menu_list_priv_t p;
+ char* title;
+ int auto_close;
+ char* fmt_with_time;
+};
+
+static struct menu_priv_s cfg_dflt = {
+ MENU_LIST_PRIV_DFLT,
+ "Select chapter",
+ 0,
+ "${chapter_name} [${start}]"
+};
+
+#define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
+
+static m_option_t cfg_fields[] = {
+ MENU_LIST_PRIV_FIELDS,
+ { "title", ST_OFF (title), CONF_TYPE_STRING, 0, 0, 0, NULL },
+ { "auto-close", ST_OFF (auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
+ { "fmt_with_time", ST_OFF (fmt_with_time), CONF_TYPE_STRING, 0, 0, 0, NULL },
+ { NULL, NULL, NULL, 0, 0, 0, NULL }
+};
+
+static char *fmt_replace(const char *fmt, const char *chapter_name,
+ const char *start) {
+ static const char ctag[] = "${chapter_name}";
+ static const char stag[] = "${start}";
+ int l = strlen(fmt);
+ int cl = strlen(chapter_name);
+ int sl = strlen(start);
+ char *str = malloc(l + cl + sl);
+ char *p;
+ strcpy(str, fmt);
+ p = strstr(str, ctag);
+ if (p) {
+ memmove(p+cl, p+sizeof(ctag)-1, str+l+1 - (p+sizeof(ctag)-1));
+ memcpy(p, chapter_name, cl);
+ l -= sizeof(ctag) + 1;
+ l += cl;
+ }
+ p = strstr(str, stag);
+ if (p) {
+ memmove(p+sl, p+sizeof(stag)-1, str+l+1 - (p+sizeof(stag)-1));
+ memcpy(p, start, sl);
+ l -= sizeof(stag) + 1;
+ l += sl;
+ }
+ return str;
+}
+
+static int fill_menu (menu_t* menu)
+{
+ list_entry_t* e;
+ int cid, chapter_num = 0;
+ int start_time;
+ demuxer_t* demuxer = mpctx_get_demuxer(menu->ctx);
+
+ if (demuxer)
+ chapter_num = demuxer_chapter_count(demuxer);
+ if (chapter_num > 0) {
+ menu_list_init (menu);
+ for (cid = 0; cid < chapter_num; ++cid)
+ if ((e = calloc (1, sizeof (list_entry_t))) != NULL) {
+ e->cid = cid + 1;
+ e->p.next = NULL;
+ e->p.txt = demuxer_chapter_display_name(demuxer, cid);
+ start_time = demuxer_chapter_time(demuxer, cid, NULL);
+ if (start_time >= 0) {
+ char timestr[13];
+ char *tmp;
+ int hour = start_time / 3600;
+ int minute = (start_time / 60) % 60;
+ int seconds = start_time % 60;
+ sprintf(timestr,"%02d:%02d:%02d", hour, minute, seconds);
+
+ tmp = fmt_replace(menu->priv->fmt_with_time, e->p.txt, timestr);
+ free(e->p.txt);
+ e->p.txt = tmp;
+ }
+ menu_list_add_entry(menu, e);
+ }
+ }
+ else
+ menu_list_read_cmd(menu, MENU_CMD_CANCEL);
+
+ return 1;
+}
+
+static void read_cmd (menu_t* menu, int cmd)
+{
+ switch (cmd) {
+ case MENU_CMD_RIGHT:
+ case MENU_CMD_OK: {
+ char cmdbuf[26];
+ sprintf(cmdbuf, "seek_chapter %d 1", menu->priv->p.current->cid);
+ mp_input_queue_cmd(mp_input_parse_cmd(cmdbuf));
+ if (menu->priv->auto_close)
+ mp_input_queue_cmd(mp_input_parse_cmd("menu hide"));
+ break;
+ }
+ default:
+ menu_list_read_cmd (menu, cmd);
+ }
+}
+
+static void close_cs (menu_t* menu)
+{
+ menu_list_uninit (menu, NULL);
+}
+
+static int open_cs (menu_t* menu, char* args)
+{
+ args = NULL;
+
+ menu->draw = menu_list_draw;
+ menu->read_cmd = read_cmd;
+ menu->close = close_cs;
+ menu->priv->p.title = menu->priv->title;
+
+ return fill_menu (menu);
+}
+
+const menu_info_t menu_info_chapsel = {
+ "Chapter selector menu",
+ "chapsel",
+ "Benjamin Zores & Ulion",
+ "",
+ {
+ "chapsel_cfg",
+ sizeof(struct menu_priv_s),
+ &cfg_dflt,
+ cfg_fields
+ },
+ open_cs
+};
Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c (original)
+++ trunk/mplayer.c Fri Dec 14 09:39:45 2007
@@ -387,6 +387,11 @@ void *mpctx_get_audio_out(MPContext *mpc
return mpctx->audio_out;
}
+void *mpctx_get_demuxer(MPContext *mpctx)
+{
+ return mpctx->demuxer;
+}
+
void *mpctx_get_playtree_iter(MPContext *mpctx)
{
return mpctx->playtree_iter;
More information about the MPlayer-cvslog
mailing list