Support replacing a mixing channel stream
This commit is contained in:
parent
bb31fe79c9
commit
cab34558ce
2 changed files with 12 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/audio/stream.hpp>
|
||||
#include <psemek/util/function.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -16,6 +17,8 @@ namespace psemek::audio
|
|||
|
||||
virtual bool is_stopped() const = 0;
|
||||
|
||||
virtual void replace(util::function<stream_ptr(stream_ptr)> modifier) = 0;
|
||||
|
||||
virtual ~channel() {}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ namespace psemek::audio
|
|||
void stop() override;
|
||||
|
||||
bool is_stopped() const override;
|
||||
|
||||
void replace(util::function<stream_ptr(stream_ptr)> modifier) override;
|
||||
};
|
||||
|
||||
void channel_impl::stop()
|
||||
|
|
@ -30,6 +32,13 @@ namespace psemek::audio
|
|||
return std::atomic_load(&stream) != nullptr;
|
||||
}
|
||||
|
||||
void channel_impl::replace(util::function<stream_ptr(stream_ptr)> modifier)
|
||||
{
|
||||
stream_ptr stream = std::atomic_load(&(this->stream));
|
||||
stream = modifier(std::move(stream));
|
||||
std::atomic_store(&(this->stream), std::move(stream));
|
||||
}
|
||||
|
||||
struct mixer_impl final
|
||||
: mixer
|
||||
, std::enable_shared_from_this<mixer_impl>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue