25 #define MODPLUG_STATIC
26 #include <libmodplug/modplug.h>
67 "speed",
"tempo",
"order",
"pattern",
"row",
79 #define FF_MODPLUG_MAX_FILE_SIZE (100 * 1<<20)
80 #define FF_MODPLUG_DEF_FILE_SIZE ( 5 * 1<<20)
82 #define OFFSET(x) offsetof(ModPlugContext, x)
83 #define D AV_OPT_FLAG_DECODING_PARAM
85 {
"noise_reduction",
"Enable noise reduction 0(off)-1(on)",
OFFSET(noise_reduction),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
D},
86 {
"reverb_depth",
"Reverb level 0(quiet)-100(loud)",
OFFSET(reverb_depth),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 100,
D},
87 {
"reverb_delay",
"Reverb delay in ms, usually 40-200ms",
OFFSET(reverb_delay),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
D},
88 {
"bass_amount",
"XBass level 0(quiet)-100(loud)",
OFFSET(bass_amount),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 100,
D},
90 {
"surround_depth",
"Surround level 0(quiet)-100(heavy)",
OFFSET(surround_depth),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 100,
D},
91 {
"surround_delay",
"Surround delay in ms, usually 5-40ms",
OFFSET(surround_delay),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
D},
92 {
"max_size",
"Max file size supported (in bytes). Default is 5MB. Set to 0 for no limit (not recommended)",
96 {
"video_stream_w",
"Video stream width in char (one char = 8x8px)",
OFFSET(
w),
AV_OPT_TYPE_INT, {.i64 = 30}, 20, 512,
D},
97 {
"video_stream_h",
"Video stream height in char (one char = 8x8px)",
OFFSET(
h),
AV_OPT_TYPE_INT, {.i64 = 30}, 20, 512,
D},
98 {
"video_stream_ptxt",
"Print speed, tempo, order, ... in video stream",
OFFSET(print_textinfo),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1,
D},
105 ModPlug_Unload(modplug->
f);
110 #define SET_OPT_IF_REQUESTED(libopt, opt, flag) do { \
111 if (modplug->opt) { \
112 settings.libopt = modplug->opt; \
113 settings.mFlags |= flag; \
117 #define ADD_META_MULTIPLE_ENTRIES(entry_name, fname) do { \
118 if (n_## entry_name ##s) { \
121 for (i = 0; i < n_## entry_name ##s; i++) { \
122 char item_name[64] = {0}; \
123 fname(f, i, item_name); \
127 av_dict_set(&s->metadata, #entry_name, "\n", AV_DICT_APPEND); \
128 av_dict_set(&s->metadata, #entry_name, item_name, AV_DICT_APPEND); \
132 extra = av_asprintf(", %u/%u " #entry_name "%s", \
133 n, n_## entry_name ##s, n > 1 ? "s" : ""); \
135 return AVERROR(ENOMEM); \
136 av_dict_set(&s->metadata, "extra info", extra, AV_DICT_APPEND); \
144 ModPlugFile *
f = modplug->
f;
146 const char *
name = ModPlug_GetName(
f);
147 const char *msg = ModPlug_GetMessage(
f);
149 unsigned n_instruments = ModPlug_NumInstruments(
f);
150 unsigned n_samples = ModPlug_NumSamples(
f);
151 unsigned n_patterns = ModPlug_NumPatterns(
f);
152 unsigned n_channels = ModPlug_NumChannels(
f);
155 if (msg && *msg)
av_dict_set(&
s->metadata,
"message", msg, 0);
158 n_patterns, n_patterns > 1 ?
"s" :
"",
159 n_channels, n_channels > 1 ?
"s" :
"");
170 #define AUDIO_PKT_SIZE 512
176 ModPlug_Settings settings;
187 "but demuxing is likely to fail due to incomplete buffer\n",
203 ModPlug_GetSettings(&settings);
204 settings.mChannels = 2;
206 settings.mFrequency = 44100;
207 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
208 settings.mLoopCount = 0;
210 if (modplug->
noise_reduction) settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION;
225 ModPlug_SetSettings(&settings);
227 modplug->
f = ModPlug_Load(modplug->
buf, sz);
238 st->
duration = ModPlug_GetLength(modplug->
f);
275 dst += y*linesize + x*3;
276 for (
i = 0;
s[
i];
i++, dst += 3) {
283 #define PRINT_INFO(line, name, idvalue) do { \
284 snprintf(intbuf, sizeof(intbuf), "%.0f", var_values[idvalue]); \
285 write_text(pkt->data, name ":", modplug->linesize, 0+1, line+1); \
286 write_text(pkt->data, intbuf, modplug->linesize, 10+1, line+1); \
299 var_values[
VAR_W ] = modplug->
w;
300 var_values[
VAR_H ] = modplug->
h;
302 var_values[
VAR_SPEED ] = ModPlug_GetCurrentSpeed (modplug->
f);
303 var_values[
VAR_TEMPO ] = ModPlug_GetCurrentTempo (modplug->
f);
304 var_values[
VAR_ORDER ] = ModPlug_GetCurrentOrder (modplug->
f);
305 var_values[
VAR_PATTERN] = ModPlug_GetCurrentPattern(modplug->
f);
306 var_values[
VAR_ROW ] = ModPlug_GetCurrentRow (modplug->
f);
325 for (y = 0; y < modplug->
h; y++) {
326 for (x = 0; x < modplug->
w; x++) {
328 var_values[
VAR_X] = x;
329 var_values[
VAR_Y] = y;
357 ModPlug_Seek(modplug->
f, (
int)ts);
363 static const char modplug_extensions[] =
"669,abc,amf,ams,dbm,dmf,dsm,far,it,mdl,med,mid,mod,mt2,mtm,okt,psm,ptm,s3m,stm,ult,umx,xm,itgz,itr,itz,mdgz,mdr,mdz,s3gz,s3r,s3z,xmgz,xmr,xmz";
384 .
name =
"libmodplug",
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)
char * av_asprintf(const char *fmt,...)
#define flags(name, subs,...)
static AVStream * video_stream
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
simple arithmetic expression evaluator
static int read_header(FFV1Context *f)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
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 AVCodec *c)
Add a new stream to a media file.
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_WARNING
Something somehow does not look correct.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
common internal API header
#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 modplug_read_header(AVFormatContext *s)
static const char modplug_extensions[]
static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt)
static const AVOption options[]
static int modplug_read_close(AVFormatContext *s)
#define PRINT_INFO(line, name, idvalue)
static int modplug_read_seek(AVFormatContext *s, int stream_idx, int64_t ts, int flags)
#define SET_OPT_IF_REQUESTED(libopt, opt, flag)
static void write_text(uint8_t *dst, const char *s, int linesize, int x, int y)
static const AVClass modplug_class
#define FF_MODPLUG_MAX_FILE_SIZE
static const char *const var_names[]
static int modplug_load_metadata(AVFormatContext *s)
static int modplug_probe(const AVProbeData *p)
#define ADD_META_MULTIPLE_ENTRIES(entry_name, fname)
AVInputFormat ff_libmodplug_demuxer
#define FF_MODPLUG_DEF_FILE_SIZE
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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
Audio only.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
This structure contains the data a format has to probe a file.
int buf_size
Size of buf except extra allocated bytes.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t duration
Decoding: duration of the stream, in stream time base.
int print_textinfo
bool flag for printing speed, tempo, order, ...
double ts_per_packet
used to define the pts/dts using packet_count;
AVExpr * expr
parsed color eval expression
int h
video stream height in char (one char = 8x8px)
int linesize
line size in bytes
char * color_eval
color eval user input expression
int w
video stream width in char (one char = 8x8px)
int max_size
max file size to allocate
int fsize
constant frame size
int video_switch
1 if current packet is video, otherwise 0
int packet_count
total number of audio packets
uint8_t * buf
input file content
int video_stream
1 if the user want a video stream, otherwise 0