[FFmpeg-devel] [PATCH 2/3 v3] libopenmpt: add subsong support

Josh de Kock josh at itanimul.li
Wed Jul 20 00:33:57 EEST 2016


---
 libavformat/libopenmpt.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c
index 17eb611..d52ebd6 100644
--- a/libavformat/libopenmpt.c
+++ b/libavformat/libopenmpt.c
@@ -43,9 +43,12 @@ typedef struct OpenMPTContext {
 #define A AV_OPT_FLAG_AUDIO_PARAM
 #define D AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
-    {"sample_rate", "set sample rate",    OFFSET(sample_rate), AV_OPT_TYPE_INT,    {.i64 = 48000},            1000, INT_MAX,   A | D},
-    {"layout",      "set channel layout", OFFSET(layout),      AV_OPT_TYPE_STRING, {.i64 = .str = "stereo"},     0, INT64_MAX, A | D},
-    {NULL}
+    { "sample_rate", "set sample rate",    OFFSET(sample_rate), AV_OPT_TYPE_INT,    { .i64 = 48000 },    1000, INT_MAX, A | D },
+    { "layout",      "set channel layout", OFFSET(layout),      AV_OPT_TYPE_STRING, { .str = "stereo" }, 0,    0,       A | D },
+    { "subsong",     "set subsong",        OFFSET(subsong),     AV_OPT_TYPE_INT,    { .i64 = -2 },       -2,   INT_MAX, A | D, "layout"},
+    { "all",         "all",                0,                   AV_OPT_TYPE_CONST,  { .i64 = -1},        0,    0,       A | D, "layout" },
+    { "auto",        "auto",               0,                   AV_OPT_TYPE_CONST,  { .i64 = -2},        0,    0,       A | D, "layout" },
+    { NULL }
 };
 
 static void openmpt_logfunc(const char *message, void *userdata)
@@ -72,6 +75,7 @@ static int read_header_openmpt(AVFormatContext *s)
     int64_t size = avio_size(s->pb);
     char *buf = av_malloc(size);
     int64_t layout;
+    int ret;
 
     if (!buf)
         return AVERROR(ENOMEM);
@@ -96,6 +100,22 @@ static int read_header_openmpt(AVFormatContext *s)
     add_meta(s, "encoder", openmpt_module_get_metadata(openmpt->module, "tracker"));
     add_meta(s, "comment", openmpt_module_get_metadata(openmpt->module, "message"));
 
+    if (openmpt->subsong >= openmpt_module_get_num_subsongs(openmpt->module)) {
+        av_log(s, AV_LOG_ERROR, "Invalid subsong index: %d\n", openmpt->subsong);
+        return AVERROR(EINVAL);
+    }
+
+    if (openmpt->subsong != -2) {
+        if (openmpt->subsong >= 0) {
+            av_dict_set_int(&s->metadata, "track", openmpt->subsong + 1, 0);
+        }
+        ret = openmpt_module_select_subsong(openmpt->module, openmpt->subsong);
+        if (!ret){
+            av_log(s, AV_LOG_ERROR, "Could not select requested subsong: %d", openmpt->subsong);
+            return AVERROR(EINVAL);   
+        }
+    }
+
     st = avformat_new_stream(s, NULL);
     if (!st) {
         openmpt_module_destroy(openmpt->module);
-- 
2.7.4 (Apple Git-66)



More information about the ffmpeg-devel mailing list