Skip to content

Commit

Permalink
[FFmpeg] Add .dsf to extension list (DSD support)
Browse files Browse the repository at this point in the history
+ resample to a lower sample rate if needed, as some variants of DSD
exceed the 524kHz we support internally -- and the 384kHz limit of at
least some outputs (pulse).

Fixes cmus#796.
  • Loading branch information
gavtroy committed Sep 18, 2024
1 parent 3af94b7 commit 353ab99
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ip/ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ static int ffmpeg_open(struct input_plugin_data *ip_data)
int err = 0;
int i;
int stream_index = -1;
int out_sample_rate;
AVCodec const *codec;
AVCodecContext *cc = NULL;
AVFormatContext *ic = NULL;
Expand Down Expand Up @@ -237,6 +238,7 @@ static int ffmpeg_open(struct input_plugin_data *ip_data)
priv->output = ffmpeg_output_create();

/* Prepare for resampling. */
out_sample_rate = min_u(cc->sample_rate, 384000);
swr = swr_alloc();
#if LIBAVCODEC_VERSION_MAJOR >= 60
if (cc->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
Expand All @@ -248,15 +250,15 @@ static int ffmpeg_open(struct input_plugin_data *ip_data)
av_opt_set_int(swr, "out_channel_layout", av_get_default_channel_layout(cc->channels), 0);
#endif
av_opt_set_int(swr, "in_sample_rate", cc->sample_rate, 0);
av_opt_set_int(swr, "out_sample_rate", cc->sample_rate, 0);
av_opt_set_int(swr, "out_sample_rate", out_sample_rate, 0);
av_opt_set_sample_fmt(swr, "in_sample_fmt", cc->sample_fmt, 0);
priv->swr = swr;

ip_data->private = priv;
#if LIBAVCODEC_VERSION_MAJOR >= 60
ip_data->sf = sf_rate(cc->sample_rate) | sf_channels(cc->ch_layout.nb_channels);
ip_data->sf = sf_rate(out_sample_rate) | sf_channels(cc->ch_layout.nb_channels);
#else
ip_data->sf = sf_rate(cc->sample_rate) | sf_channels(cc->channels);
ip_data->sf = sf_rate(out_sample_rate) | sf_channels(cc->channels);
#endif
switch (cc->sample_fmt) {
case AV_SAMPLE_FMT_U8:
Expand Down Expand Up @@ -542,9 +544,9 @@ const struct input_plugin_ops ip_ops = {

const int ip_priority = 30;
const char *const ip_extensions[] = {
"aa", "aac", "ac3", "aif", "aifc", "aiff", "ape", "au", "fla", "flac",
"m4a", "m4b", "mka", "mkv", "mp+", "mp2", "mp3", "mp4", "mpc", "mpp",
"ogg", "opus", "shn", "tak", "tta", "wav", "webm", "wma", "wv",
"aa", "aac", "ac3", "aif", "aifc", "aiff", "ape", "au", "dsf", "fla",
"flac", "m4a", "m4b", "mka", "mkv", "mp+", "mp2", "mp3", "mp4", "mpc",
"mpp", "ogg", "opus", "shn", "tak", "tta", "wav", "webm", "wma", "wv",
#ifdef USE_FALLBACK_IP
"*",
#endif
Expand Down

0 comments on commit 353ab99

Please sign in to comment.