[FFmpeg-devel] [PATCH 1/2 v3] libopenmpt: add subsong support
Josh de Kock
josh at itanimul.li
Tue Jul 19 18:39:11 EEST 2016
---
libavformat/libopenmpt.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c
index 58a02be..670866f 100644
--- a/libavformat/libopenmpt.c
+++ b/libavformat/libopenmpt.c
@@ -36,14 +36,19 @@ typedef struct OpenMPTContext {
/* options */
int sample_rate;
int64_t layout;
+ int subsong;
} OpenMPTContext;
+
+#define LIBOPENMPT_SUBSONG_DEFAULT -2
+
#define OFFSET(x) offsetof(OpenMPTContext, x)
#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_CHANNEL_LAYOUT, {.i64 = AV_CH_LAYOUT_STEREO}, 0, INT64_MAX, A|D},
+ {"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_CHANNEL_LAYOUT, {.i64 = AV_CH_LAYOUT_STEREO}, 0, INT64_MAX, A|D},
+ {"subsong", "set subsong", OFFSET(subsong), AV_OPT_TYPE_INT, {.i64 = LIBOPENMPT_SUBSONG_DEFAULT}, -2, INT_MAX, A|D},
{NULL}
};
@@ -88,6 +93,18 @@ 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 != LIBOPENMPT_SUBSONG_DEFAULT) {
+ if (openmpt->subsong >= 0) {
+ av_dict_set_int(&s->metadata, "track", openmpt->subsong + 1, 0);
+ }
+ openmpt_module_select_subsong(openmpt->module, openmpt->subsong);
+ }
+
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