MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / modplug_read_header

Function modplug_read_header

libavformat/libmodplug.c:174–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172#define AUDIO_PKT_SIZE 512
173
174static int modplug_read_header(AVFormatContext *s)
175{
176 AVStream *st;
177 AVIOContext *pb = s->pb;
178 ModPlug_Settings settings;
179 ModPlugContext *modplug = s->priv_data;
180 int64_t sz = avio_size(pb);
181 int ret;
182
183 if (sz < 0) {
184 av_log(s, AV_LOG_WARNING, "Could not determine file size\n");
185 sz = modplug->max_size;
186 } else if (modplug->max_size && sz > modplug->max_size) {
187 sz = modplug->max_size;
188 av_log(s, AV_LOG_WARNING, "Max file size reach%s, allocating %"PRIi64"B "
189 "but demuxing is likely to fail due to incomplete buffer\n",
190 sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz);
191 }
192
193 if (modplug->color_eval) {
194 int r = av_expr_parse(&modplug->expr, modplug->color_eval, var_names,
195 NULL, NULL, NULL, NULL, 0, s);
196 if (r < 0)
197 return r;
198 }
199
200 modplug->buf = av_malloc(modplug->max_size);
201 if (!modplug->buf)
202 return AVERROR(ENOMEM);
203 sz = avio_read(pb, modplug->buf, sz);
204
205 ModPlug_GetSettings(&settings);
206 settings.mChannels = 2;
207 settings.mBits = 16;
208 settings.mFrequency = 44100;
209 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; // best quality
210 settings.mLoopCount = 0; // prevents looping forever
211
212 if (modplug->noise_reduction) settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION;
213 SET_OPT_IF_REQUESTED(mReverbDepth, reverb_depth, MODPLUG_ENABLE_REVERB);
214 SET_OPT_IF_REQUESTED(mReverbDelay, reverb_delay, MODPLUG_ENABLE_REVERB);
215 SET_OPT_IF_REQUESTED(mBassAmount, bass_amount, MODPLUG_ENABLE_MEGABASS);
216 SET_OPT_IF_REQUESTED(mBassRange, bass_range, MODPLUG_ENABLE_MEGABASS);
217 SET_OPT_IF_REQUESTED(mSurroundDepth, surround_depth, MODPLUG_ENABLE_SURROUND);
218 SET_OPT_IF_REQUESTED(mSurroundDelay, surround_delay, MODPLUG_ENABLE_SURROUND);
219
220 if (modplug->reverb_depth) settings.mReverbDepth = modplug->reverb_depth;
221 if (modplug->reverb_delay) settings.mReverbDelay = modplug->reverb_delay;
222 if (modplug->bass_amount) settings.mBassAmount = modplug->bass_amount;
223 if (modplug->bass_range) settings.mBassRange = modplug->bass_range;
224 if (modplug->surround_depth) settings.mSurroundDepth = modplug->surround_depth;
225 if (modplug->surround_delay) settings.mSurroundDelay = modplug->surround_delay;
226
227 ModPlug_SetSettings(&settings);
228
229 modplug->f = ModPlug_Load(modplug->buf, sz);
230 if (!modplug->f) {
231 av_freep(&modplug->buf);

Callers

nothing calls this directly

Calls 10

avio_sizeFunction · 0.85
av_logFunction · 0.85
av_expr_parseFunction · 0.85
avio_readFunction · 0.85
av_freepFunction · 0.85
avformat_new_streamFunction · 0.85
avpriv_set_pts_infoFunction · 0.85
modplug_load_metadataFunction · 0.85
modplug_read_closeFunction · 0.85
av_mallocFunction · 0.50

Tested by

no test coverage detected