[MPlayer-dev-eng] [PATCH] combine vobsub_lang with sub_select
Joey Parrish
joey at nicewarrior.org
Thu Aug 12 02:22:25 CEST 2004
Hello,
I don't like having vobsub_lang and sub_select as two different keys in
my input config file. So I suggest we combine them. I also think this
would be useful for adding other kinds of dynamic sub selection. All of
them should be done with one input event.
The first patch moves vobsub_lang into sub_select. I have also attached
patches to add dynamic sub selection for dvds and ogg files. Apply
these three patches in order and you can use sub_select event to cycle
through subtitles from -sub option, dvd, vobsubs, or ogg text streams,
whichever is appropriate.
This is easily the most radical of the patch mails I'm sending today, so
I welcome comments and criticisms. :)
--Joey
--
Me: "Isn't Kennedy as real as Colonel Sanders?"
Chad: "... Which Kennedy?"
-------------- next part --------------
combine vobsub_lang into sub_select
change osd_show_vobsub_changed to sh_video->fps
diff -ur main.sofar/input/input.c main.dev/input/input.c
--- main.sofar/input/input.c 2004-08-11 21:26:57.909641600 +0000
+++ main.dev/input/input.c 2004-08-11 21:27:28.233244800 +0000
@@ -77,7 +77,7 @@
{ MP_CMD_SUB_POS, "sub_pos", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_SUB_ALIGNMENT, "sub_alignment",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_SUB_VISIBILITY, "sub_visibility", 0, { {-1,{0}} } },
- { MP_CMD_VOBSUB_LANG, "vobsub_lang", 0, { {-1,{0}} } },
+ { MP_CMD_SUB_SELECT, "vobsub_lang", 0, { {-1,{0}} } }, // for compatibility
{ MP_CMD_SUB_SELECT, "sub_select", 0, { {-1,{0}} } },
{ MP_CMD_GET_PERCENT_POS, "get_percent_pos", 0, { {-1,{0}} } },
{ MP_CMD_GET_TIME_LENGTH, "get_time_length", 0, { {-1,{0}} } },
diff -ur main.sofar/input/input.h main.dev/input/input.h
--- main.sofar/input/input.h 2004-08-11 21:26:57.939684800 +0000
+++ main.dev/input/input.h 2004-08-11 21:27:28.263288000 +0000
@@ -30,7 +30,7 @@
#define MP_CMD_VF_CHANGE_RECTANGLE 28
#define MP_CMD_GAMMA 29
#define MP_CMD_SUB_VISIBILITY 30
-#define MP_CMD_VOBSUB_LANG 31
+// #define MP_CMD_VOBSUB_LANG 31 // combined with SUB_SELECT
#define MP_CMD_MENU 32
#define MP_CMD_SET_MENU 33
#define MP_CMD_GET_TIME_LENGTH 34
diff -ur main.sofar/mplayer.c main.dev/mplayer.c
--- main.sofar/mplayer.c 2004-08-11 21:26:57.969728000 +0000
+++ main.dev/mplayer.c 2004-08-11 21:28:58.342816000 +0000
@@ -3115,19 +3115,6 @@
}
#endif
} break;
- case MP_CMD_VOBSUB_LANG:
- if (vo_vobsub)
- {
- int new_id = vobsub_id + 1;
- if (vobsub_id < 0)
- new_id = 0;
- if ((unsigned int) new_id >= vobsub_get_indexes_count(vo_vobsub))
- new_id = -1;
- if(new_id != vobsub_id)
- osd_show_vobsub_changed = 9;
- vobsub_id = new_id;
- }
- break;
case MP_CMD_SUB_SELECT:
#ifdef USE_SUB
if (set_of_sub_size > 0){ //change subtitle file
@@ -3138,6 +3125,17 @@
vo_osd_changed(OSDTYPE_SUBTITLE);
}
#endif
+ if (vo_vobsub)
+ {
+ int new_id = vobsub_id + 1;
+ if (vobsub_id < 0)
+ new_id = 0;
+ if ((unsigned int) new_id >= vobsub_get_indexes_count(vo_vobsub))
+ new_id = -1;
+ if(new_id != vobsub_id)
+ osd_show_vobsub_changed = sh_video->fps;
+ vobsub_id = new_id;
+ }
break;
case MP_CMD_SUB_FORCED_ONLY:
if (vo_spudec) {
-------------- next part --------------
allow runtime selection of dvd subtitle language (including 'none')
diff -ur main.sofar/libmpdemux/open.c main.dev/libmpdemux/open.c
--- main.sofar/libmpdemux/open.c 2004-06-25 15:19:11.000000000 +0000
+++ main.dev/libmpdemux/open.c 2004-08-11 21:36:09.853297600 +0000
@@ -636,6 +636,25 @@
return d->nr_of_channels ? d->audio_streams[0].id : -1;
}
+int dvd_number_of_subs(stream_t *stream)
+{
+ dvd_priv_t *d;
+ if (!stream) return -1;
+ d = stream->priv;
+ if (!d) return -1;
+ return d->nr_of_subtitles;
+}
+
+int dvd_lang_from_sid(stream_t *stream, int id)
+{
+ dvd_priv_t *d;
+ if (!stream) return 0;
+ d = stream->priv;
+ if (!d) return 0;
+ if (id >= d->nr_of_subtitles) return 0;
+ return d->subtitles[id].language;
+}
+
int dvd_sid_from_lang(stream_t *stream, unsigned char* lang){
dvd_priv_t *d=stream->priv;
int code,i;
diff -ur main.sofar/libmpdemux/stream.h main.dev/libmpdemux/stream.h
--- main.sofar/libmpdemux/stream.h 2004-08-11 21:14:41.200305600 +0000
+++ main.dev/libmpdemux/stream.h 2004-08-11 21:36:09.883340800 +0000
@@ -336,6 +336,8 @@
stream_language_t subtitles[32];
} dvd_priv_t;
+int dvd_number_of_subs(stream_t *stream);
+int dvd_lang_from_sid(stream_t *stream, int id);
int dvd_aid_from_lang(stream_t *stream, unsigned char* lang);
int dvd_sid_from_lang(stream_t *stream, unsigned char* lang);
int dvd_chapter_from_cell(dvd_priv_t *dvd,int title,int cell);
diff -ur main.sofar/mplayer.c main.dev/mplayer.c
--- main.sofar/mplayer.c 2004-08-11 21:31:04.634414400 +0000
+++ main.dev/mplayer.c 2004-08-11 21:36:09.903369600 +0000
@@ -1587,7 +1587,7 @@
demux_info_print(demuxer);
//================== Read SUBTITLES (DVD & TEXT) ==========================
-if(d_dvdsub->id >= 0 && vo_spudec==NULL && sh_video){
+if(vo_spudec==NULL && sh_video && stream->type==STREAMTYPE_DVD){
if (spudec_ifo) {
unsigned int palette[16], width, height;
@@ -3136,6 +3136,18 @@
osd_show_vobsub_changed = sh_video->fps;
vobsub_id = new_id;
}
+ if (vo_spudec && stream->type == STREAMTYPE_DVD)
+ {
+ int new_id = dvdsub_id + 1;
+ if (dvdsub_id < 0)
+ new_id = 0;
+ if ((unsigned int) new_id >= dvd_number_of_subs(stream))
+ new_id = -1;
+ if(new_id != dvdsub_id)
+ osd_show_vobsub_changed = sh_video->fps;
+ d_dvdsub->id = dvdsub_id = new_id;
+ spudec_reset(vo_spudec);
+ }
break;
case MP_CMD_SUB_FORCED_ONLY:
if (vo_spudec) {
@@ -3558,10 +3570,22 @@
osd_show_sub_visibility--;
} else
if (osd_show_vobsub_changed) {
- const char *language = "none";
- if (vo_vobsub && vobsub_id >= 0)
+ if (vo_vobsub && vobsub_id >= 0) {
+ const char *language = "none";
language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
+ }
+ if (vo_spudec) {
+ char lang[5] = "none";
+ int code = 0;
+ if (dvdsub_id >= 0) code = dvd_lang_from_sid(stream, dvdsub_id);
+ if (code) {
+ lang[0] = code >> 8;
+ lang[1] = code;
+ lang[2] = 0;
+ }
+ snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
+ }
osd_show_vobsub_changed--;
} else
#ifdef USE_SUB
-------------- next part --------------
support switching ogg text subtitle streams during runtime
diff -ur main.sofar/libmpdemux/demux_ogg.c main.dev/libmpdemux/demux_ogg.c
--- main.sofar/libmpdemux/demux_ogg.c 2004-08-11 21:48:25.711409600 +0000
+++ main.dev/libmpdemux/demux_ogg.c 2004-08-11 21:48:44.007718400 +0000
@@ -655,12 +655,18 @@
extern void print_wave_header(WAVEFORMATEX *h);
extern void print_video_header(BITMAPINFOHEADER *h);
+static int n_text = 0;
+static int *text_ids = NULL;
+
+int demux_ogg_num_subs() { return n_text; }
+int demux_ogg_sub_id(int index) { return (index < 0) ? index : text_ids[index]; }
+
/// Open an ogg physical stream
int demux_ogg_open(demuxer_t* demuxer) {
ogg_demuxer_t* ogg_d;
stream_t *s;
char* buf;
- int np,s_no, n_audio = 0, n_video = 0, n_text = 0;
+ int np,s_no, n_audio = 0, n_video = 0;
int audio_id = -1, video_id = -1, text_id = -1;
ogg_sync_state* sync;
ogg_page* page;
@@ -902,6 +908,8 @@
if (demuxer->sub->id == n_text)
text_id = ogg_d->num_sub;
n_text++;
+ text_ids = (int *)realloc(text_ids, sizeof(int) * n_text);
+ text_ids[n_text - 1] = ogg_d->num_sub;
demux_ogg_init_sub();
//// Unknown header type
} else
diff -ur main.sofar/mplayer.c main.dev/mplayer.c
--- main.sofar/mplayer.c 2004-08-11 21:48:25.751467200 +0000
+++ main.dev/mplayer.c 2004-08-11 21:47:28.298854400 +0000
@@ -3161,6 +3161,18 @@
d_dvdsub->id = dvdsub_id = new_id;
spudec_reset(vo_spudec);
}
+ if (d_dvdsub && demuxer->type == DEMUXER_TYPE_OGG)
+ {
+ int new_id = dvdsub_id + 1;
+ if (dvdsub_id < 0)
+ new_id = 0;
+ if ((unsigned int) new_id >= demux_ogg_num_subs())
+ new_id = -1;
+ if (new_id != dvdsub_id)
+ osd_show_vobsub_changed = sh_video->fps;
+ dvdsub_id = new_id;
+ d_dvdsub->id = demux_ogg_sub_id(new_id);
+ }
break;
case MP_CMD_AUDIO_SELECT:
if (sh_audio && stream->type == STREAMTYPE_DVD)
@@ -3615,6 +3627,12 @@
language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
}
+ if (d_dvdsub && demuxer->type == DEMUXER_TYPE_OGG) {
+ if (dvdsub_id < 0)
+ snprintf(osd_text_tmp, 63, "Subtitles: (off)");
+ else
+ snprintf(osd_text_tmp, 63, "Subtitles: (%d)", dvdsub_id);
+ }
if (vo_spudec) {
char lang[5] = "none";
int code = 0;
More information about the MPlayer-dev-eng
mailing list