[FFmpeg-devel] [PATCH] Read ogg stream language
Reimar Döffinger
Reimar.Doeffinger
Thu Jan 31 23:57:35 CET 2008
Hello,
attached patch makes vorbis_comment (which lacks a ff_ prefix btw) parse
the language tag into AVStream.language (if a mapping is known).
It also adds vorbis comment parsing to oggparseogm.c (I would apply as a
second step).
The code is probably improvable, the mapping list even more so.
Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: oggparsevorbis.c
===================================================================
--- oggparsevorbis.c (revision 11697)
+++ oggparsevorbis.c (working copy)
@@ -30,8 +30,24 @@
#include "oggdec.h"
#include "avstring.h"
+static const struct {
+ const char langid[4];
+ const char * const name;
+} langmap [] = {
+ {"eng", "English"},
+ {"und", NULL}
+};
+
+static void setlang(char langid[4], const char *name) {
+ int i;
+ for (i = 0; langmap[i].name; i++)
+ if (!strcasecmp(name, langmap[i].name))
+ break;
+ memcpy(langid, langmap[i].langid, 4);
+}
+
extern int
-vorbis_comment(AVFormatContext * as, uint8_t *buf, int size)
+vorbis_comment(AVFormatContext * as, uint8_t *buf, int size, AVStream *st)
{
uint8_t *p = buf;
uint8_t *end = buf + size;
@@ -96,6 +112,8 @@
as->track = atoi(ct);
else if (!strcmp(tt, "ALBUM"))
av_strlcpy(as->album, ct, sizeof(as->album));
+ else if (st && !strcmp(tt, "LANGUAGE"))
+ setlang(st->language, ct);
}
}
@@ -210,7 +228,7 @@
st->time_base.den = st->codec->sample_rate;
} else if (os->buf[os->pstart] == 3) {
if (os->psize > 8)
- vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
+ vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8, st);
} else {
st->codec->extradata_size =
fixup_vorbis_headers(s, priv, &st->codec->extradata);
Index: oggdec.h
===================================================================
--- oggdec.h (revision 11698)
+++ oggdec.h (working copy)
@@ -84,6 +84,6 @@
extern ogg_codec_t ogm_text_codec;
extern ogg_codec_t ogm_old_codec;
-extern int vorbis_comment(AVFormatContext *ms, uint8_t *buf, int size);
+extern int vorbis_comment(AVFormatContext *ms, uint8_t *buf, int size, AVStream *st);
#endif /* FFMPEG_OGGDEC_H */
Index: oggparseflac.c
===================================================================
--- oggparseflac.c (revision 11697)
+++ oggparseflac.c (working copy)
@@ -69,7 +69,7 @@
st->time_base.num = 1;
st->time_base.den = st->codec->sample_rate;
} else if (mdt == 4) {
- vorbis_comment (s, os->buf + os->pstart + 4, os->psize - 4);
+ vorbis_comment (s, os->buf + os->pstart + 4, os->psize - 4, st);
}
return 1;
Index: oggparsetheora.c
===================================================================
--- oggparsetheora.c (revision 11697)
+++ oggparsetheora.c (working copy)
@@ -102,7 +102,7 @@
st->codec->codec_id = CODEC_ID_THEORA;
} else if (os->buf[os->pstart] == 0x83) {
- vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
+ vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8, st);
}
st->codec->extradata = av_realloc (st->codec->extradata, cds);
Index: oggparseogm.c
===================================================================
--- oggparseogm.c (revision 11698)
+++ oggparseogm.c (working copy)
@@ -43,6 +43,9 @@
if(!(*p & 1))
return 0;
+ if (*p == 3)
+ if (os->psize > 8)
+ vorbis_comment (s, p + 7, os->psize - 8, st);
if(*p != 1)
return 1;
More information about the ffmpeg-devel
mailing list