49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#include "stream_wrapper.h"
|
|
|
|
pwstream::pwstream(uint32_t rate, uint32_t channels, int direction,
|
|
pw_loop* lp, const char* name, pw_properties* props):
|
|
events{PW_VERSION_STREAM_EVENTS,.process = on_process_generic}
|
|
{
|
|
strm = pw_stream_new_simple(lp, name, props, &events, (void*)this);
|
|
|
|
b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
|
|
|
|
spa_audio_info_raw fmt = {
|
|
.format = SPA_AUDIO_FORMAT_F32,
|
|
.rate = rate,
|
|
.channels = channels,
|
|
.position = {SPA_AUDIO_CHANNEL_MONO}
|
|
};
|
|
|
|
if(channels==2) {
|
|
fmt.position[0] = SPA_AUDIO_CHANNEL_FL;
|
|
fmt.position[1] = SPA_AUDIO_CHANNEL_FR;
|
|
}
|
|
|
|
params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &fmt);
|
|
|
|
pw_stream_connect(strm,
|
|
(direction ? PW_DIRECTION_OUTPUT : PW_DIRECTION_INPUT),
|
|
PW_ID_ANY,
|
|
(pw_stream_flags) (
|
|
PW_STREAM_FLAG_MAP_BUFFERS |
|
|
PW_STREAM_FLAG_RT_PROCESS), params, 1);
|
|
}
|
|
|
|
pwstream::~pwstream() {
|
|
pw_stream_destroy(strm);
|
|
}
|
|
|
|
void pwstream::on_process() {
|
|
pw_buffer* buf;
|
|
if((buf = pw_stream_dequeue_buffer(strm)) == nullptr) {
|
|
pw_log_warn("Out of buffers %m"); return;
|
|
}
|
|
|
|
pw_stream_queue_buffer(strm, buf);
|
|
}
|
|
|
|
void on_process_generic(void* indirection) {
|
|
auto* ptr = (pwstream*)(indirection);
|
|
ptr->on_process();
|
|
}
|