[MPlayer-dev-eng] [PATCH] show ogg subtitle language
Joey Parrish
joey at nicewarrior.org
Fri Sep 24 07:49:24 CEST 2004
On Thu, Sep 23, 2004 at 09:21:30PM -0500, Joey Parrish wrote:
> Attached is a patch to demux_ogg to cache the subtitle languages and to
> main to show them on OSD. OK to commit?
No! Not okay! :)
I sent the wrong version, that one didn't compile. Oops.
Here's the right one.
--Joey
--
"There's no blood in your brain? You're one of the lucky ones." --Chad
-------------- next part --------------
diff -ur main.sofar/libmpdemux/demux_ogg.c main.dev/libmpdemux/demux_ogg.c
--- main.sofar/libmpdemux/demux_ogg.c 2004-09-24 00:36:30.690745600 -0500
+++ main.dev/libmpdemux/demux_ogg.c 2004-09-23 22:42:49.602502400 -0500
@@ -132,6 +132,7 @@
/* Used for subtitle switching. */
int n_text;
int *text_ids;
+ char **text_langs;
} ogg_demuxer_t;
#define NUM_VORBIS_HDR_PACKETS 3
@@ -428,6 +429,8 @@
{
char *hdr, *val;
char **cmt = vc->user_comments;
+ int index;
+ ogg_demuxer_t *ogg_d = (ogg_demuxer_t *)d->priv;
while(*cmt)
{
@@ -440,6 +443,9 @@
else if (!strncasecmp(*cmt, "LANGUAGE=", 9))
{
val = *cmt + 9;
+ // copy this language name into the array
+ index = demux_ogg_sub_reverse_id(d, id);
+ if (index >= 0) ogg_d->text_langs[index] = strdup(val);
// check for -slang if subs are uninitialized yet
if (os->text && d->sub->id == -1 && demux_ogg_check_lang(val, dvdsub_lang))
{
@@ -683,6 +689,19 @@
return (index < 0) ? index : (index >= ogg_d->n_text) ? -1 : ogg_d->text_ids[index];
}
+static int demux_ogg_sub_reverse_id(demuxer_t *demuxer, int id) {
+ ogg_demuxer_t *ogg_d = (ogg_demuxer_t *)demuxer->priv;
+ int i;
+ for (i = 0; i < ogg_d->n_text; i++)
+ if (ogg_d->text_ids[i] == id) return i;
+ return -1;
+}
+
+int demux_ogg_sub_lang(demuxer_t *demuxer, int index) {
+ ogg_demuxer_t *ogg_d = (ogg_demuxer_t *)demuxer->priv;
+ return (index < 0) ? NULL : (index >= ogg_d->n_text) ? NULL : ogg_d->text_langs[index];
+}
+
/// Open an ogg physical stream
int demux_ogg_open(demuxer_t* demuxer) {
ogg_demuxer_t* ogg_d;
@@ -932,6 +951,8 @@
ogg_d->n_text++;
ogg_d->text_ids = (int *)realloc(ogg_d->text_ids, sizeof(int) * ogg_d->n_text);
ogg_d->text_ids[ogg_d->n_text - 1] = ogg_d->num_sub;
+ ogg_d->text_langs = (char **)realloc(ogg_d->text_langs, sizeof(char *) * ogg_d->n_text);
+ ogg_d->text_langs[ogg_d->n_text - 1] = NULL;
demux_ogg_init_sub();
//// Unknown header type
} else
@@ -1380,6 +1401,7 @@
void demux_close_ogg(demuxer_t* demuxer) {
ogg_demuxer_t* ogg_d = demuxer->priv;
+ int i;
if(!ogg_d)
return;
@@ -1394,6 +1416,11 @@
free(ogg_d->syncpoints);
if (ogg_d->text_ids)
free(ogg_d->text_ids);
+ if (ogg_d->text_langs) {
+ for (i = 0; i < ogg_d->n_text; i++)
+ if (ogg_d->text_langs[i]) free(ogg_d->text_langs[i]);
+ free(ogg_d->text_langs);
+ }
free(ogg_d);
}
diff -ur main.sofar/libmpdemux/demuxer.h main.dev/libmpdemux/demuxer.h
--- main.sofar/libmpdemux/demuxer.h 2004-09-24 00:36:30.700760000 -0500
+++ main.dev/libmpdemux/demuxer.h 2004-09-23 21:11:06.980120000 -0500
@@ -282,6 +282,7 @@
/* Found in demux_ogg.c */
int demux_ogg_num_subs(demuxer_t *demuxer);
int demux_ogg_sub_id(demuxer_t *demuxer, int index);
+int demux_ogg_sub_lang(demuxer_t *demuxer, int index);
#endif
#endif
More information about the MPlayer-dev-eng
mailing list