22#include <libopenmpt/libopenmpt.h>
23#include <libopenmpt/libopenmpt_stream_callbacks_file.h>
24#include <libopenmpt/libopenmpt_version.h>
26#if !defined(OPENMPT_API_VERSION_MAKE)
27#define OPENMPT_API_VERSION_MAKE(major, minor, patch) (((major)<<24)|((minor)<<16)|((patch)<<0))
29#if !defined(OPENMPT_API_VERSION_AT_LEAST)
30#define OPENMPT_API_VERSION_AT_LEAST(major, minor, patch) (OPENMPT_API_VERSION >= OPENMPT_API_VERSION_MAKE((major), (minor), (patch)))
51#define OFFSET(x) offsetof(OpenMPTContext, x)
52#define A AV_OPT_FLAG_AUDIO_PARAM
53#define D AV_OPT_FLAG_DECODING_PARAM
55 {
"sample_rate",
"set sample rate",
OFFSET(sample_rate),
AV_OPT_TYPE_INT, { .i64 = 48000 }, 1000, INT_MAX,
A |
D },
57 {
"subsong",
"set subsong",
OFFSET(subsong),
AV_OPT_TYPE_INT, { .i64 = -2 }, -2, INT_MAX,
A |
D, .unit =
"subsong"},
72#define add_meta(s, name, meta) \
74 const char *value = meta; \
75 if (value && value[0]) \
76 av_dict_set(&s->metadata, name, value, 0); \
77 openmpt_free_string(value); \
86#if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
104#if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
105 error = OPENMPT_ERROR_OK;
109 if (
error == OPENMPT_ERROR_OUT_OF_MEMORY)
111 else if (
error >= OPENMPT_ERROR_GENERAL)
123 if (openmpt->
subsong >= openmpt_module_get_num_subsongs(openmpt->
module)) {
132 ret = openmpt_module_select_subsong(openmpt->
module, openmpt->
subsong);
139 openmpt->
duration = openmpt_module_get_duration_seconds(openmpt->
module);
141 add_meta(
s,
"artist", openmpt_module_get_metadata(openmpt->
module,
"artist"));
142 add_meta(
s,
"title", openmpt_module_get_metadata(openmpt->
module,
"title"));
143 add_meta(
s,
"encoder", openmpt_module_get_metadata(openmpt->
module,
"tracker"));
144 add_meta(
s,
"comment", openmpt_module_get_metadata(openmpt->
module,
"message"));
145 add_meta(
s,
"date", openmpt_module_get_metadata(openmpt->
module,
"date"));
164#define AUDIO_PKT_SIZE 2048
175 double pos = openmpt_module_get_position_seconds(openmpt->
module);
180 n_samples, (
float *)
pkt->data);
183 ret = openmpt_module_read_interleaved_float_stereo(openmpt->
module, openmpt->
sample_rate,
184 n_samples, (
float *)
pkt->data);
187 ret = openmpt_module_read_interleaved_float_quad(openmpt->
module, openmpt->
sample_rate,
188 n_samples, (
float *)
pkt->data);
212 openmpt_module_destroy(openmpt->
module);
231 ext = strrchr(p->filename,
'.');
232 if (ext && strlen(ext + 1) > 0) {
234 if (openmpt_is_extension_supported(ext) == 1)
243#if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
245 if (p->buf && p->buf_size > 0) {
246 probe_result = openmpt_probe_file_header_without_filesize(
247 OPENMPT_PROBE_FILE_HEADER_FLAGS_DEFAULT,
250 if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_SUCCESS) {
256 }
else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA) {
260 if (p->buf_size >= openmpt_probe_file_header_get_recommended_size()) {
274 }
else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_FAILURE) {
284 .class_name =
"libopenmpt",
291 .p.name =
"libopenmpt",
294#if OPENMPT_API_VERSION_AT_LEAST(0,3,0)
295 .p.extensions =
"669,amf,ams,dbm,digi,dmf,dsm,dtm,far,gdm,ice,imf,it,j2b,m15,mdl,med,mmcmp,mms,mo3,mod,mptm,mt2,mtm,nst,okt,plm,ppm,psm,pt36,ptm,s3m,sfx,sfx2,st26,stk,stm,stp,ult,umx,wow,xm,xpk",
297 .p.extensions =
"669,amf,ams,dbm,digi,dmf,dsm,far,gdm,ice,imf,it,j2b,m15,mdl,med,mmcmp,mms,mo3,mod,mptm,mt2,mtm,nst,okt,plm,ppm,psm,pt36,ptm,s3m,sfx,sfx2,st26,stk,stm,ult,umx,wow,xm,xpk",
int64_t avio_size(AVIOContext *s)
Get the filesize.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define flags(name, subs,...)
static int read_probe(const AVProbeData *p)
Public libavutil channel layout APIs header.
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
static int read_header(FFV1Context *f, RangeCoder *c)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_CHLAYOUT
Underlying C type is AVChannelLayout.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define AV_TIME_BASE
Internal time base represented as integer.
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
static int read_close_openmpt(AVFormatContext *s)
static void openmpt_logfunc(const char *message, void *userdata)
#define add_meta(s, name, meta)
static int read_header_openmpt(AVFormatContext *s)
static int probe_openmpt_extension(const AVProbeData *p)
static const AVClass class_openmpt
static int read_seek_openmpt(AVFormatContext *s, int stream_idx, int64_t ts, int flags)
static int read_probe_openmpt(const AVProbeData *p)
static int read_packet_openmpt(AVFormatContext *s, AVPacket *pkt)
Memory handling functions.
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
AVChannelLayout ch_layout
The channel layout and number of channels.
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
This structure stores compressed data.
This structure contains the data a format has to probe a file.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t duration
Decoding: duration of the stream, in stream time base.
AVChannelLayout ch_layout
static void error(const char *err)