From 45a9e28cd667a190ef9a6dc0a654268f0af411af Mon Sep 17 00:00:00 2001 From: Dmitry Vedenko Date: Wed, 21 Feb 2024 13:13:14 +0300 Subject: [PATCH] Fixes #5969: upload with no audio data --- .../sync/LocalProjectSnapshot.cpp | 18 ++++++++----- .../sync/MixdownUploader.cpp | 27 +++++++++++++++++-- .../lib-cloud-audiocom/sync/MixdownUploader.h | 1 + .../mod-cloud-audiocom/CloudProjectUtils.cpp | 1 + 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp b/libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp index 6c74a0958695..7c6a41f0238f 100644 --- a/libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp +++ b/libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp @@ -229,6 +229,8 @@ std::shared_ptr LocalProjectSnapshot::Create( auto snapshot = std::make_shared( Tag {}, config, oauthService, extension); + snapshot->mProjectCloudExtension.OnUploadOperationCreated(snapshot); + snapshot->mProjectBlocksLock = std::make_unique( extension, *project, [weakSnapshot = std::weak_ptr(snapshot)] @@ -246,8 +248,6 @@ std::shared_ptr LocalProjectSnapshot::Create( snapshot->mProjectCloudExtension.OnBlocksHashed(*snapshot); }); - snapshot->mProjectCloudExtension.OnUploadOperationCreated(snapshot); - return snapshot; } @@ -391,11 +391,15 @@ void LocalProjectSnapshot::UpdateProjectSnapshot() else projectForm.HeadSnapshotId = mProjectCloudExtension.GetSnapshotId(); - projectForm.Hashes.reserve(mProjectBlocksLock->Blocks.size()); - std::transform( - mProjectBlocksLock->Blocks.begin(), mProjectBlocksLock->Blocks.end(), - std::back_inserter(projectForm.Hashes), - [](const auto& block) { return block.Hash; }); + // For empty projects, mProjectBlocksLock will be nullptr at this point + if (mProjectBlocksLock != nullptr) + { + projectForm.Hashes.reserve(mProjectBlocksLock->Blocks.size()); + std::transform( + mProjectBlocksLock->Blocks.begin(), mProjectBlocksLock->Blocks.end(), + std::back_inserter(projectForm.Hashes), + [](const auto& block) { return block.Hash; }); + } using namespace audacity::network_manager; diff --git a/libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp b/libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp index e7a2ded1a739..404be967e0bf 100644 --- a/libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp +++ b/libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp @@ -64,6 +64,21 @@ int CalculateChannels(const TrackList& trackList) 1 : 2; } + +bool HasPlayableTracks(const AudacityProject& project) +{ + // Why Any requires non const ref??? + for (const auto& track : + TrackList::Get(const_cast(project)) + .Any()) + { + if (track->GetStartTime() != track->GetEndTime()) + return true; + } + + return false; +} + } // namespace class MixdownUploader::DataExporter final : public ExportProcessorDelegate @@ -286,8 +301,9 @@ void MixdownUploader::ReportProgress( }); } - if (state == MixdownState::Succeeded || state == MixdownState::Failed || - state == MixdownState::Cancelled) + if ( + state == MixdownState::Succeeded || state == MixdownState::Failed || + state == MixdownState::Cancelled) { mFinished.store(true); mPromise.set_value({ state, uploadResult }); @@ -296,6 +312,13 @@ void MixdownUploader::ReportProgress( void MixdownUploader::ExportProject() { + if (!HasPlayableTracks(mProject)) + { + mFinished.store(true); + mPromise.set_value({ MixdownState::Empty }); + return; + } + auto& tracks = TrackList::Get(mProject); const double t0 = 0.0; diff --git a/libraries/lib-cloud-audiocom/sync/MixdownUploader.h b/libraries/lib-cloud-audiocom/sync/MixdownUploader.h index c25f6c19606e..e267aaf6898e 100644 --- a/libraries/lib-cloud-audiocom/sync/MixdownUploader.h +++ b/libraries/lib-cloud-audiocom/sync/MixdownUploader.h @@ -41,6 +41,7 @@ enum class MixdownState Succeeded, Cancelled, Failed, + Empty, }; struct CLOUD_AUDIOCOM_API MixdownResult final diff --git a/modules/mod-cloud-audiocom/CloudProjectUtils.cpp b/modules/mod-cloud-audiocom/CloudProjectUtils.cpp index e1209ac12239..270ae382400c 100644 --- a/modules/mod-cloud-audiocom/CloudProjectUtils.cpp +++ b/modules/mod-cloud-audiocom/CloudProjectUtils.cpp @@ -274,6 +274,7 @@ bool HandleProjectLink(std::string_view uri) return true; } + void UploadMixdownForSnapshot( AudacityProject& project, std::shared_ptr snapshot) {