MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open()

bool MayaFlux::IO::SoundFileWriter::open ( const std::string &  filepath,
uint32_t  channels,
uint32_t  sample_rate,
AVCodecID  explicit_codec 
)

Open the output file and spawn the worker thread.

Format is inferred from the filepath extension (wav, flac, ogg, mp4, mkv…). Pass explicit_codec to override the container's default audio codec.

Parameters
filepathDestination file path. Extension determines container.
channelsNumber of interleaved channels in all submitted data.
sample_ratePCM sample rate in Hz.
explicit_codecEncoder override; AV_CODEC_ID_NONE = container default.
Returns
True if the worker started successfully.

Definition at line 46 of file SoundFileWriter.cpp.

50{
51 if (m_open.load(std::memory_order_acquire)) {
52 set_error("open() called while already open");
53 return false;
54 }
55
56 m_channels = channels;
57 m_close_promise = std::promise<bool> {};
58 m_close_future = m_close_promise.get_future().share();
59 m_closing.store(false, std::memory_order_release);
60
61 m_worker = std::thread(&SoundFileWriter::worker_loop, this,
62 filepath, channels, sample_rate, explicit_codec);
63
64 constexpr int k_spin_ms = 500;
65 constexpr int k_sleep_us = 500;
66 for (int i = 0; i < (k_spin_ms * 1000 / k_sleep_us); ++i) {
67 if (m_open.load(std::memory_order_acquire))
68 return true;
69 std::this_thread::sleep_for(std::chrono::microseconds(k_sleep_us));
70 }
71
72 if (m_worker.joinable())
73 m_worker.join();
74 return false;
75}
std::promise< bool > m_close_promise
void set_error(std::string msg)
std::shared_future< bool > m_close_future
void worker_loop(const std::string &filepath, uint32_t channels, uint32_t sample_rate, AVCodecID codec_id)

References m_channels, m_close_future, m_close_promise, m_closing, m_open, m_worker, set_error(), and worker_loop().

+ Here is the call graph for this function: