Skip to content

Commit

Permalink
Fixes audacity#5969: upload with no audio data
Browse files Browse the repository at this point in the history
  • Loading branch information
crsib committed Feb 21, 2024
1 parent 53b57a9 commit 45a9e28
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
18 changes: 11 additions & 7 deletions libraries/lib-cloud-audiocom/sync/LocalProjectSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ std::shared_ptr<LocalProjectSnapshot> LocalProjectSnapshot::Create(
auto snapshot = std::make_shared<LocalProjectSnapshot>(
Tag {}, config, oauthService, extension);

snapshot->mProjectCloudExtension.OnUploadOperationCreated(snapshot);

snapshot->mProjectBlocksLock = std::make_unique<ProjectBlocksLock>(
extension, *project,
[weakSnapshot = std::weak_ptr(snapshot)]
Expand All @@ -246,8 +248,6 @@ std::shared_ptr<LocalProjectSnapshot> LocalProjectSnapshot::Create(
snapshot->mProjectCloudExtension.OnBlocksHashed(*snapshot);
});

snapshot->mProjectCloudExtension.OnUploadOperationCreated(snapshot);

return snapshot;
}

Expand Down Expand Up @@ -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;

Expand Down
27 changes: 25 additions & 2 deletions libraries/lib-cloud-audiocom/sync/MixdownUploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudacityProject&>(project))
.Any<PlayableTrack>())
{
if (track->GetStartTime() != track->GetEndTime())
return true;
}

return false;
}

} // namespace

class MixdownUploader::DataExporter final : public ExportProcessorDelegate
Expand Down Expand Up @@ -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 });
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions libraries/lib-cloud-audiocom/sync/MixdownUploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum class MixdownState
Succeeded,
Cancelled,
Failed,
Empty,
};

struct CLOUD_AUDIOCOM_API MixdownResult final
Expand Down
1 change: 1 addition & 0 deletions modules/mod-cloud-audiocom/CloudProjectUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ bool HandleProjectLink(std::string_view uri)

return true;
}

void UploadMixdownForSnapshot(
AudacityProject& project, std::shared_ptr<LocalProjectSnapshot> snapshot)
{
Expand Down

0 comments on commit 45a9e28

Please sign in to comment.