From 1285128b9ab831e0485e17de2c663dfaecab050d Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Wed, 27 Feb 2019 21:58:33 +0100 Subject: [PATCH] [xcode] Fix incorrect source BPS detection + support for more audio qualities --- src/transcode.c | 64 +++++++++++++++++++++++++++++++++++++++++++++---- src/transcode.h | 5 ++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/transcode.c b/src/transcode.c index 11831822..6de7b51d 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -216,6 +216,16 @@ init_settings(struct settings_ctx *settings, enum transcode_profile profile) settings->sample_format = AV_SAMPLE_FMT_S16; break; + case XCODE_PCM16_96000: + settings->encode_audio = 1; + settings->format = "s16le"; + settings->audio_codec = AV_CODEC_ID_PCM_S16LE; + settings->sample_rate = 96000; + settings->channel_layout = AV_CH_LAYOUT_STEREO; + settings->channels = 2; + settings->sample_format = AV_SAMPLE_FMT_S16; + break; + case XCODE_PCM24_44100: settings->encode_audio = 1; settings->format = "s24le"; @@ -236,6 +246,46 @@ init_settings(struct settings_ctx *settings, enum transcode_profile profile) settings->sample_format = AV_SAMPLE_FMT_S32; break; + case XCODE_PCM24_96000: + settings->encode_audio = 1; + settings->format = "s24le"; + settings->audio_codec = AV_CODEC_ID_PCM_S24LE; + settings->sample_rate = 96000; + settings->channel_layout = AV_CH_LAYOUT_STEREO; + settings->channels = 2; + settings->sample_format = AV_SAMPLE_FMT_S32; + break; + + case XCODE_PCM32_44100: + settings->encode_audio = 1; + settings->format = "s32le"; + settings->audio_codec = AV_CODEC_ID_PCM_S32LE; + settings->sample_rate = 44100; + settings->channel_layout = AV_CH_LAYOUT_STEREO; + settings->channels = 2; + settings->sample_format = AV_SAMPLE_FMT_S32; + break; + + case XCODE_PCM32_48000: + settings->encode_audio = 1; + settings->format = "s32le"; + settings->audio_codec = AV_CODEC_ID_PCM_S32LE; + settings->sample_rate = 48000; + settings->channel_layout = AV_CH_LAYOUT_STEREO; + settings->channels = 2; + settings->sample_format = AV_SAMPLE_FMT_S32; + break; + + case XCODE_PCM32_96000: + settings->encode_audio = 1; + settings->format = "s32le"; + settings->audio_codec = AV_CODEC_ID_PCM_S32LE; + settings->sample_rate = 96000; + settings->channel_layout = AV_CH_LAYOUT_STEREO; + settings->channels = 2; + settings->sample_format = AV_SAMPLE_FMT_S32; + break; + case XCODE_MP3: settings->encode_audio = 1; settings->format = "mp3"; @@ -1198,17 +1248,19 @@ transcode_encode_setup(enum transcode_profile profile, struct decode_ctx *src_ct ctx->settings.width = width; ctx->settings.height = height; + // Profile does not specify a sample rate -> use same as source if (!ctx->settings.sample_rate && ctx->settings.encode_audio) ctx->settings.sample_rate = src_ctx->audio_stream.codec->sample_rate; + // Profile does not specify a sample format -> use same as source if (!ctx->settings.sample_format && ctx->settings.encode_audio) { - bps = av_get_bits_per_sample(src_ctx->audio_stream.codec->codec_id); - if (bps >= 24) + bps = av_get_bytes_per_sample(src_ctx->audio_stream.codec->sample_fmt); + if (bps == 4) { ctx->settings.sample_format = AV_SAMPLE_FMT_S32; - ctx->settings.audio_codec = AV_CODEC_ID_PCM_S24LE; - ctx->settings.format = "s24le"; + ctx->settings.audio_codec = AV_CODEC_ID_PCM_S32LE; + ctx->settings.format = "s32le"; } else { @@ -1582,6 +1634,10 @@ transcode_frame_new(void *data, size_t size, int nsamples, int sample_rate, int { f->format = AV_SAMPLE_FMT_S32; } + else if (bits_per_sample == 32) + { + f->format = AV_SAMPLE_FMT_S32; + } else { DPRINTF(E_LOG, L_XCODE, "transcode_frame_new() called with unsupported bps (%d)\n", bits_per_sample); diff --git a/src/transcode.h b/src/transcode.h index 3ce05d26..3db09ae2 100644 --- a/src/transcode.h +++ b/src/transcode.h @@ -17,8 +17,13 @@ enum transcode_profile // Decodes/resamples the best audio stream (no wav headers) XCODE_PCM16_44100, XCODE_PCM16_48000, + XCODE_PCM16_96000, XCODE_PCM24_44100, XCODE_PCM24_48000, + XCODE_PCM24_96000, + XCODE_PCM32_44100, + XCODE_PCM32_48000, + XCODE_PCM32_96000, // Transcodes the best audio stream into MP3 XCODE_MP3, // Transcodes the best audio stream into OPUS