diff --git a/src/mumble/CMakeLists.txt b/src/mumble/CMakeLists.txt index dbbbada4f46..ad17e81ec96 100644 --- a/src/mumble/CMakeLists.txt +++ b/src/mumble/CMakeLists.txt @@ -519,6 +519,13 @@ else() message(WARNING "libsndfile is missing Opus-support -> No Opus-format recording") endif() +# Check if sndfile version supports mp3 +if("${sndfile_VERSION}" VERSION_GREATER_EQUAL "1.1.0") + target_compile_definitions(mumble_client_object_lib PUBLIC USE_SNDFILE_MP3) +else() + message(WARNING "libsndfile is missing Mp3-support -> No Mp3-format recording") +endif() + # Look for various targets as they are named differently on different platforms if(static AND TARGET sndfile-static) target_link_libraries(mumble_client_object_lib PUBLIC sndfile-static) diff --git a/src/mumble/VoiceRecorder.cpp b/src/mumble/VoiceRecorder.cpp index 58035c8a76f..54deccf489d 100644 --- a/src/mumble/VoiceRecorder.cpp +++ b/src/mumble/VoiceRecorder.cpp @@ -78,7 +78,7 @@ QString VoiceRecorder::sanitizeFilenameOrPathComponent(const QString &str) const } #else // For the rest just make sure the string doesn't contain a \0 or any forward-slashes - res = res.replace(QRegExp(QLatin1String("\\x00|/")), QLatin1String("_")); + res = res.replace(QRegExp(QLatin1String("\\x00|/")), QLatin1String("_")); #endif return res; } @@ -223,6 +223,18 @@ SF_INFO VoiceRecorder::createSoundFileInfo() const { qWarning() << "VoiceRecorder: recording started to" << m_config.fileName << "@" << m_config.sampleRate << "hz in OPUS format"; break; +#endif +#ifdef USE_SNDFILE_MP3 + case VoiceRecorderFormat::MP3: + sfinfo.frames = 0; + sfinfo.samplerate = m_config.sampleRate; + sfinfo.channels = 1; + sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III; + sfinfo.sections = 0; + sfinfo.seekable = 0; + qWarning() << "VoiceRecorder: recording started to" << m_config.fileName << "@" << m_config.sampleRate + << "hz in MP3 format"; + break; #endif } @@ -277,6 +289,16 @@ bool VoiceRecorder::ensureFileIsOpenedFor(SF_INFO &soundFileInfo, boost::shared_ return false; } +#ifdef USE_SNDFILE_MP3 + // Enable constant 320kbps for MP3 formats + if (m_config.recordingFormat == VoiceRecorderFormat::MP3) { + int bitrate = SF_BITRATE_MODE_CONSTANT; + double compression = 0.0; + sf_command(ri->soundFile, SFC_SET_BITRATE_MODE, &bitrate, sizeof(int)); + sf_command(ri->soundFile, SFC_SET_COMPRESSION_LEVEL, &compression, sizeof(double)); + } +#endif + // Store the username in the title attribute of the file (if supported by the format). sf_set_string(ri->soundFile, SF_STR_TITLE, qPrintable(ri->userName)); @@ -445,6 +467,10 @@ QString VoiceRecorderFormat::getFormatDescription(VoiceRecorderFormat::Format fm #ifdef USE_SNDFILE_OPUS case VoiceRecorderFormat::OPUS: return VoiceRecorder::tr(".opus - Lossy compressed"); +#endif +#ifdef USE_SNDFILE_MP3 + case VoiceRecorderFormat::MP3: + return VoiceRecorder::tr(".mp3 - Lossy compressed"); #endif default: return QString(); @@ -466,6 +492,10 @@ QString VoiceRecorderFormat::getFormatDefaultExtension(VoiceRecorderFormat::Form #ifdef USE_SNDFILE_OPUS case VoiceRecorderFormat::OPUS: return QLatin1String("opus"); +#endif +#ifdef USE_SNDFILE_MP3 + case VoiceRecorderFormat::MP3: + return QLatin1String("mp3"); #endif default: return QString(); diff --git a/src/mumble/VoiceRecorder.h b/src/mumble/VoiceRecorder.h index 7d482822524..0778d811553 100644 --- a/src/mumble/VoiceRecorder.h +++ b/src/mumble/VoiceRecorder.h @@ -54,6 +54,9 @@ enum Format { #ifdef USE_SNDFILE_OPUS // OPUS Format OPUS, +#endif +#ifdef USE_SNDFILE_MP3 + MP3, #endif kEnd };