From 09ece262005df910ed9c9d7ad3ebcaa85f66c545 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Mar 2019 11:02:17 +0100 Subject: [PATCH] lib/ffmpeg/SampleFormat: add ToFfmpegSampleFormat() --- src/lib/ffmpeg/SampleFormat.hxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/ffmpeg/SampleFormat.hxx b/src/lib/ffmpeg/SampleFormat.hxx index bc5bde054..febeeb0f6 100644 --- a/src/lib/ffmpeg/SampleFormat.hxx +++ b/src/lib/ffmpeg/SampleFormat.hxx @@ -53,6 +53,28 @@ FromFfmpegSampleFormat(AVSampleFormat sample_fmt) noexcept } } +/** + * Convert a MPD #SampleFormat to a FFmpeg #AVSampleFormat. Returns + * AV_SAMPLE_FMT_NONE if there is no direct mapping. + */ +constexpr AVSampleFormat +ToFfmpegSampleFormat(SampleFormat f) noexcept +{ + switch (f) { + case SampleFormat::S16: + return AV_SAMPLE_FMT_S16; + + case SampleFormat::S32: + return AV_SAMPLE_FMT_S32; + + case SampleFormat::FLOAT: + return AV_SAMPLE_FMT_FLT; + + default: + return AV_SAMPLE_FMT_NONE; + } +} + } // namespace Ffmpeg #endif