From 64364cf0e6b62d822175ba028e2635620e701dc1 Mon Sep 17 00:00:00 2001 From: Dmitry Vedenko Date: Thu, 18 Jan 2024 14:09:34 +0300 Subject: [PATCH] Mixdowns use MP3 --- .../lib-cloud-audiocom/ServiceConfig.cpp | 29 ++++++++++++++----- libraries/lib-cloud-audiocom/ServiceConfig.h | 2 +- .../sync/LocalProjectSnapshot.cpp | 2 +- .../sync/MixdownUploader.cpp | 7 +++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libraries/lib-cloud-audiocom/ServiceConfig.cpp b/libraries/lib-cloud-audiocom/ServiceConfig.cpp index cdbe4afea8b7..ed92ff68b4e8 100644 --- a/libraries/lib-cloud-audiocom/ServiceConfig.cpp +++ b/libraries/lib-cloud-audiocom/ServiceConfig.cpp @@ -152,14 +152,19 @@ std::chrono::milliseconds ServiceConfig::GetProgressCallbackTimeout() const return std::chrono::seconds(3); } -std::vector ServiceConfig::GetPreferredAudioFormats() const +std::vector +ServiceConfig::GetPreferredAudioFormats(bool preferLossless) const { - return { "audio/x-wavpack", "audio/x-flac", "audio/x-wav" }; + if (preferLossless) + return { "audio/x-wavpack", "audio/x-flac", "audio/x-wav" }; + else + return { "audio/mpeg" }; } -rapidjson::Document ServiceConfig::GetExportConfig(const std::string& mimeType) const +rapidjson::Document +ServiceConfig::GetExportConfig(const std::string& mimeType) const { - if(mimeType == "audio/x-wavpack") + if (mimeType == "audio/x-wavpack") { rapidjson::Document config; config.SetObject(); @@ -169,17 +174,27 @@ rapidjson::Document ServiceConfig::GetExportConfig(const std::string& mimeType) config.AddMember("hybrid_mode", false, config.GetAllocator()); return config; } - if(mimeType == "audio/x-flac") + else if (mimeType == "audio/x-flac") { rapidjson::Document config; config.SetObject(); - config.AddMember("bit_depth", rapidjson::Value(24), config.GetAllocator()); + config.AddMember( + "bit_depth", rapidjson::Value(24), config.GetAllocator()); config.AddMember("level", rapidjson::Value(5), config.GetAllocator()); } - if(mimeType == "audio/x-wav") + else if (mimeType == "audio/x-wav") { return {}; } + else if (mimeType == "audio/mpeg") + { + rapidjson::Document config; + config.SetObject(); + config.AddMember("mode", rapidjson::Value("VBR"), config.GetAllocator()); + config.AddMember("quality", rapidjson::Value(5), config.GetAllocator()); + return config; + } + throw std::invalid_argument("unknown mime-type"); } diff --git a/libraries/lib-cloud-audiocom/ServiceConfig.h b/libraries/lib-cloud-audiocom/ServiceConfig.h index 41c319495720..f366bc6d24d5 100644 --- a/libraries/lib-cloud-audiocom/ServiceConfig.h +++ b/libraries/lib-cloud-audiocom/ServiceConfig.h @@ -42,7 +42,7 @@ class CLOUD_AUDIOCOM_API ServiceConfig final //! Timeout between progress callbacks std::chrono::milliseconds GetProgressCallbackTimeout() const; //! Preferred audio format - std::vector GetPreferredAudioFormats() const; + std::vector GetPreferredAudioFormats(bool preferLossless = true) const; //! Export configuration suitable for the mime type provided rapidjson::Document GetExportConfig(const std::string& exporterName) const; //! Return the mime type server should store the file. This is a requirement diff --git a/libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp b/libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp index 5dec18bf3733..c0dffc479df9 100644 --- a/libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp +++ b/libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp @@ -467,6 +467,7 @@ void LocalProjectSnapshot::OnSnapshotCreated( if (mProjectCloudExtension.NeedsMixdownSync()) { mMixdownUploadInProgress.store(true, std::memory_order_release); + mMixdownUploader = MixdownUploader::Upload( mCloudSyncUI, mServiceConfig, *project, mixdownUrls, [this](std::string, bool success) @@ -474,7 +475,6 @@ void LocalProjectSnapshot::OnSnapshotCreated( if (success) mProjectCloudExtension.MixdownSynced(); - mMixdownUploader.reset(); mMixdownUploadInProgress.store( false, std::memory_order_release); }); diff --git a/libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp b/libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp index f73f66a43cf3..aa7c2c51e794 100644 --- a/libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp +++ b/libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp @@ -272,7 +272,7 @@ void MixdownUploader::ExportProject() const auto& registry = ExportPluginRegistry::Get(); for (const auto& preferredMimeType : - GetServiceConfig().GetPreferredAudioFormats()) + GetServiceConfig().GetPreferredAudioFormats(false)) { auto config = GetServiceConfig().GetExportConfig(preferredMimeType); ExportProcessor::Parameters parameters; @@ -325,7 +325,10 @@ void MixdownUploader::UploadMixdown() [this](UploadResult result) { BasicUI::CallAfter([this, result = std::move(result)] - { mCloudSyncUI.OnMixdownFinished(); }); + { + mCloudSyncUI.OnMixdownFinished(); + mOnComplete(result.ErrorMessage, result.Code == UploadResultCode::Success); + }); }, {}); }