Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
audacity::cloud::audiocom::sync::MixdownUploader Class Referencefinal

#include <MixdownUploader.h>

Inheritance diagram for audacity::cloud::audiocom::sync::MixdownUploader:
[legend]
Collaboration diagram for audacity::cloud::audiocom::sync::MixdownUploader:
[legend]

Classes

class  DataExporter
 
struct  Tag
 

Public Member Functions

 MixdownUploader (Tag, concurrency::CancellationContextPtr cancellationContext, const ServiceConfig &config, const AudacityProject &project, MixdownProgressCallback progressCallback)
 
 ~MixdownUploader ()
 
void SetUrls (const UploadUrls &urls)
 
std::future< MixdownResultGetResultFuture ()
 
- Public Member Functions inherited from audacity::concurrency::ICancellable
virtual ~ICancellable ()=default
 
virtual void Cancel ()=0
 

Static Public Member Functions

static std::shared_ptr< MixdownUploaderUpload (concurrency::CancellationContextPtr cancellationContext, const ServiceConfig &config, const AudacityProject &project, MixdownProgressCallback progressCallback)
 

Private Member Functions

void Cancel ()
 
void ReportProgress (MixdownState state, double progress, ResponseResult uploadResult)
 
void ExportProject ()
 
void UploadMixdown ()
 

Private Attributes

const ServiceConfigmServiceConfig
 
const AudacityProjectmProject
 
std::mutex mUploadUrlsMutex
 
std::condition_variable mUploadUrlsSet
 
std::optional< UploadUrlsmUploadUrls
 
MixdownProgressCallback mProgressCallback
 
std::unique_ptr< DataExportermDataExporter
 
std::string mExportedFilePath
 
std::atomic< double > mProgress {}
 
bool mProgressUpdateQueued { false }
 
std::atomic< bool > mUploadCancelled { false }
 
std::atomic< bool > mFinished { false }
 
std::promise< MixdownResultmPromise
 
concurrency::CancellationContextPtr mCancellationContext
 

Detailed Description

Definition at line 59 of file MixdownUploader.h.

Constructor & Destructor Documentation

◆ MixdownUploader()

audacity::cloud::audiocom::sync::MixdownUploader::MixdownUploader ( Tag  ,
concurrency::CancellationContextPtr  cancellationContext,
const ServiceConfig config,
const AudacityProject project,
MixdownProgressCallback  progressCallback 
)

Definition at line 221 of file MixdownUploader.cpp.

224 : mServiceConfig { config }
225 , mProject { project }
226 , mProgressCallback { std::move(progressCallback) }
227 , mCancellationContext { std::move(cancellationContext) }
228{
230}
const auto project
concurrency::CancellationContextPtr mCancellationContext

References ExportProject().

Here is the call graph for this function:

◆ ~MixdownUploader()

audacity::cloud::audiocom::sync::MixdownUploader::~MixdownUploader ( )

Definition at line 232 of file MixdownUploader.cpp.

233{
234 if (wxFileExists(mExportedFilePath))
235 wxRemoveFile(mExportedFilePath);
236}

References mExportedFilePath.

Member Function Documentation

◆ Cancel()

void audacity::cloud::audiocom::sync::MixdownUploader::Cancel ( )
privatevirtual

Implements audacity::concurrency::ICancellable.

Definition at line 267 of file MixdownUploader.cpp.

268{
269 if (!mDataExporter)
270 return;
271
272 if (mUploadCancelled.exchange(true, std::memory_order_acq_rel))
273 return;
274
275 // To be on a safe side, we cancel both operations
276 mDataExporter->Cancel();
277 // And ensure that WaitingForUrls is interrupted too
278 mUploadUrlsSet.notify_all();
279}
std::unique_ptr< DataExporter > mDataExporter

References mDataExporter, mUploadCancelled, and mUploadUrlsSet.

◆ ExportProject()

void audacity::cloud::audiocom::sync::MixdownUploader::ExportProject ( )
private

Definition at line 326 of file MixdownUploader.cpp.

327{
329 {
330 mFinished.store(true);
331 mPromise.set_value({ MixdownState::Empty });
332 return;
333 }
334
336
337 const double t0 = 0.0;
338 const double t1 = tracks.GetEndTime();
339
340 const int nChannels = CalculateChannels(tracks);
341
342 auto hasMimeType = [](const auto&& mimeTypes, const std::string& mimeType)
343 {
344 return std::find(mimeTypes.begin(), mimeTypes.end(), mimeType) !=
345 mimeTypes.end();
346 };
347
348 const auto& registry = ExportPluginRegistry::Get();
349
350 for (const auto& preferredMimeType :
351 GetServiceConfig().GetPreferredAudioFormats(false))
352 {
353 auto config = GetServiceConfig().GetExportConfig(preferredMimeType);
354
356 auto pluginIt = std::find_if(
357 registry.begin(), registry.end(),
358 [&](auto t)
359 {
360 auto [plugin, formatIndex] = t;
361 parameters.clear();
362 return hasMimeType(
363 plugin->GetMimeTypes(formatIndex), preferredMimeType) &&
364 plugin->ParseConfig(formatIndex, config, parameters);
365 });
366
367 if (pluginIt == registry.end())
368 continue;
369
370 const auto [plugin, formatIndex] = *pluginIt;
371
372 const auto formatInfo = plugin->GetFormatInfo(formatIndex);
373 const auto path = GenerateTempPath(formatInfo.extensions[0]);
374
375 if (path.empty())
376 continue;
377
378 auto builder = ExportTaskBuilder {}
379 .SetParameters(parameters)
380 .SetNumChannels(nChannels)
382 .SetPlugin(plugin)
384 .SetRange(t0, t1, false);
385
386 mExportedFilePath = path;
387
388 mDataExporter = std::make_unique<DataExporter>(
389 *this, builder.Build(const_cast<AudacityProject&>(mProject)));
390
391 return;
392 }
393
394 if (!mDataExporter)
395 {
396 mFinished.store(true);
397 mPromise.set_value({ MixdownState::Failed });
398 }
399}
const auto tracks
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static ExportPluginRegistry & Get()
std::vector< std::tuple< ExportOptionID, ExportValue > > Parameters
Definition: ExportPlugin.h:93
ExportTaskBuilder & SetPlugin(const ExportPlugin *plugin, int format=0) noexcept
Definition: Export.cpp:59
ExportTaskBuilder & SetParameters(ExportProcessor::Parameters parameters) noexcept
Definition: Export.cpp:47
ExportTaskBuilder & SetNumChannels(unsigned numChannels) noexcept
Definition: Export.cpp:53
ExportTaskBuilder & SetSampleRate(double sampleRate) noexcept
Definition: Export.cpp:72
ExportTaskBuilder & SetFileName(const wxFileName &filename)
Definition: Export.cpp:33
ExportTaskBuilder & SetRange(double t0, double t1, bool selectedOnly=false) noexcept
Definition: Export.cpp:39
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
rapidjson::Document GetExportConfig(const std::string &exporterName) const
Export configuration suitable for the mime type provided.
double GetRate(const Track &track)
Definition: TimeTrack.cpp:182
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.
wxString ToWXString(const std::string &str)

References audacity::cloud::audiocom::sync::anonymous_namespace{MixdownUploader.cpp}::CalculateChannels(), audacity::cloud::audiocom::sync::Empty, audacity::cloud::audiocom::sync::Failed, audacity::cloud::audiocom::sync::anonymous_namespace{MixdownUploader.cpp}::GenerateTempPath(), ExportPluginRegistry::Get(), ProjectRate::Get(), TrackList::Get(), audacity::cloud::audiocom::ServiceConfig::GetExportConfig(), anonymous_namespace{TimeTrack.cpp}::GetRate(), audacity::cloud::audiocom::GetServiceConfig(), audacity::cloud::audiocom::sync::anonymous_namespace{MixdownUploader.cpp}::HasPlayableTracks(), mDataExporter, mExportedFilePath, mFinished, mProject, mPromise, ExportTaskBuilder::SetFileName(), ExportTaskBuilder::SetNumChannels(), ExportTaskBuilder::SetParameters(), ExportTaskBuilder::SetPlugin(), ExportTaskBuilder::SetRange(), ExportTaskBuilder::SetSampleRate(), audacity::ToWXString(), and tracks.

Referenced by MixdownUploader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetResultFuture()

std::future< MixdownResult > audacity::cloud::audiocom::sync::MixdownUploader::GetResultFuture ( )

Definition at line 281 of file MixdownUploader.cpp.

282{
283 return mPromise.get_future();
284}

References mPromise.

◆ ReportProgress()

void audacity::cloud::audiocom::sync::MixdownUploader::ReportProgress ( MixdownState  state,
double  progress,
ResponseResult  uploadResult 
)
private

Definition at line 286 of file MixdownUploader.cpp.

288{
289 mProgress.store(progress);
290
292 {
293 mProgressUpdateQueued = false;
294 mProgressCallback(progress);
295 }
296 else if (!mProgressUpdateQueued)
297 {
299
301 [weakThis = weak_from_this(), this]
302 {
303 auto lock = weakThis.lock();
304
305 if (!lock)
306 return;
307
308 if (mFinished.load())
309 return;
310
312
313 mProgressUpdateQueued = false;
314 });
315 }
316
317 if (
318 state == MixdownState::Succeeded || state == MixdownState::Failed ||
320 {
321 mFinished.store(true);
322 mPromise.set_value({ state, uploadResult });
323 }
324}
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:214
bool IsUiThread()
Whether the current thread is the UI thread.
Definition: BasicUI.h:407

References BasicUI::CallAfter(), audacity::cloud::audiocom::sync::Cancelled, audacity::cloud::audiocom::sync::Failed, BasicUI::IsUiThread(), mFinished, mProgress, mProgressCallback, mProgressUpdateQueued, mPromise, and audacity::cloud::audiocom::sync::Succeeded.

Referenced by UploadMixdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetUrls()

void audacity::cloud::audiocom::sync::MixdownUploader::SetUrls ( const UploadUrls urls)

Definition at line 257 of file MixdownUploader.cpp.

258{
259 auto lock = std::lock_guard { mUploadUrlsMutex };
260
261 assert(!mUploadUrls);
262 mUploadUrls = urls;
263
264 mUploadUrlsSet.notify_one();
265}

References mUploadUrls, mUploadUrlsMutex, and mUploadUrlsSet.

◆ Upload()

std::shared_ptr< MixdownUploader > audacity::cloud::audiocom::sync::MixdownUploader::Upload ( concurrency::CancellationContextPtr  cancellationContext,
const ServiceConfig config,
const AudacityProject project,
MixdownProgressCallback  progressCallback 
)
static

Definition at line 238 of file MixdownUploader.cpp.

241{
242 if (!progressCallback)
243 progressCallback = [](auto...) { return true; };
244
245 if (!cancellationContext)
246 cancellationContext =
248
249 auto uploader = std::make_shared<MixdownUploader>(
250 Tag {}, cancellationContext, config, project, std::move(progressCallback));
251
252 cancellationContext->OnCancelled(uploader);
253
254 return uploader;
255}

References audacity::concurrency::CancellationContext::Create(), and project.

Referenced by audacity::cloud::audiocom::sync::UploadMixdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UploadMixdown()

void audacity::cloud::audiocom::sync::MixdownUploader::UploadMixdown ( )
private

Definition at line 401 of file MixdownUploader.cpp.

402{
404
405 {
406 auto lock = std::unique_lock { mUploadUrlsMutex };
407 mUploadUrlsSet.wait(
408 lock, [this] { return mUploadCancelled.load() || !!mUploadUrls; });
409 }
410
411 if (mUploadCancelled.load(std::memory_order_acquire))
412 {
414 return;
415 }
416
418
421 [this, strongThis = shared_from_this()](ResponseResult result)
422 {
423 const auto state = [code = result.Code]
424 {
425 if (code == SyncResultCode::Success)
427 else if (code == SyncResultCode::Cancelled)
429 else
431 }();
432
433 ReportProgress(state, 1.0, result);
434 },
435 [this, strongThis = shared_from_this()](double progress)
436 { ReportProgress(MixdownState::Uploading, progress, {}); });
437}
void Upload(CancellationContextPtr cancellationContex, const ServiceConfig &config, const UploadUrls &target, std::vector< uint8_t > data, std::function< void(ResponseResult)> callback, std::function< void(double)> progressCallback={})
void ReportProgress(MixdownState state, double progress, ResponseResult uploadResult)

References audacity::cloud::audiocom::Cancelled, audacity::cloud::audiocom::sync::Cancelled, audacity::cloud::audiocom::ResponseResult::Code, audacity::cloud::audiocom::sync::Failed, audacity::cloud::audiocom::sync::DataUploader::Get(), mCancellationContext, mExportedFilePath, mServiceConfig, mUploadCancelled, mUploadUrls, mUploadUrlsMutex, mUploadUrlsSet, ReportProgress(), audacity::cloud::audiocom::sync::Succeeded, audacity::cloud::audiocom::Success, audacity::cloud::audiocom::sync::DataUploader::Upload(), audacity::cloud::audiocom::sync::Uploading, and audacity::cloud::audiocom::sync::WaitingForUrls.

Here is the call graph for this function:

Member Data Documentation

◆ mCancellationContext

concurrency::CancellationContextPtr audacity::cloud::audiocom::sync::MixdownUploader::mCancellationContext
private

Definition at line 115 of file MixdownUploader.h.

Referenced by UploadMixdown().

◆ mDataExporter

std::unique_ptr<DataExporter> audacity::cloud::audiocom::sync::MixdownUploader::mDataExporter
private

Definition at line 102 of file MixdownUploader.h.

Referenced by Cancel(), and ExportProject().

◆ mExportedFilePath

std::string audacity::cloud::audiocom::sync::MixdownUploader::mExportedFilePath
private

Definition at line 104 of file MixdownUploader.h.

Referenced by ExportProject(), UploadMixdown(), and ~MixdownUploader().

◆ mFinished

std::atomic<bool> audacity::cloud::audiocom::sync::MixdownUploader::mFinished { false }
private

Definition at line 111 of file MixdownUploader.h.

Referenced by ExportProject(), and ReportProgress().

◆ mProgress

std::atomic<double> audacity::cloud::audiocom::sync::MixdownUploader::mProgress {}
private

Definition at line 106 of file MixdownUploader.h.

Referenced by ReportProgress().

◆ mProgressCallback

MixdownProgressCallback audacity::cloud::audiocom::sync::MixdownUploader::mProgressCallback
private

Definition at line 99 of file MixdownUploader.h.

Referenced by ReportProgress().

◆ mProgressUpdateQueued

bool audacity::cloud::audiocom::sync::MixdownUploader::mProgressUpdateQueued { false }
private

Definition at line 108 of file MixdownUploader.h.

Referenced by ReportProgress().

◆ mProject

const AudacityProject& audacity::cloud::audiocom::sync::MixdownUploader::mProject
private

Definition at line 93 of file MixdownUploader.h.

Referenced by ExportProject().

◆ mPromise

std::promise<MixdownResult> audacity::cloud::audiocom::sync::MixdownUploader::mPromise
private

Definition at line 113 of file MixdownUploader.h.

Referenced by ExportProject(), GetResultFuture(), and ReportProgress().

◆ mServiceConfig

const ServiceConfig& audacity::cloud::audiocom::sync::MixdownUploader::mServiceConfig
private

Definition at line 92 of file MixdownUploader.h.

Referenced by UploadMixdown().

◆ mUploadCancelled

std::atomic<bool> audacity::cloud::audiocom::sync::MixdownUploader::mUploadCancelled { false }
private

Definition at line 110 of file MixdownUploader.h.

Referenced by Cancel(), and UploadMixdown().

◆ mUploadUrls

std::optional<UploadUrls> audacity::cloud::audiocom::sync::MixdownUploader::mUploadUrls
private

Definition at line 97 of file MixdownUploader.h.

Referenced by SetUrls(), and UploadMixdown().

◆ mUploadUrlsMutex

std::mutex audacity::cloud::audiocom::sync::MixdownUploader::mUploadUrlsMutex
private

Definition at line 95 of file MixdownUploader.h.

Referenced by SetUrls(), and UploadMixdown().

◆ mUploadUrlsSet

std::condition_variable audacity::cloud::audiocom::sync::MixdownUploader::mUploadUrlsSet
private

Definition at line 96 of file MixdownUploader.h.

Referenced by Cancel(), SetUrls(), and UploadMixdown().


The documentation for this class was generated from the following files: