2024-09-29 18:23:17 +02:00
|
|
|
#include "./tox_av_voip_model.hpp"
|
|
|
|
|
|
|
|
#include <solanaceae/object_store/object_store.hpp>
|
|
|
|
#include <solanaceae/tox_contacts/components.hpp>
|
|
|
|
|
|
|
|
#include "./frame_streams/stream_manager.hpp"
|
|
|
|
#include "./frame_streams/audio_stream2.hpp"
|
|
|
|
#include "./frame_streams/locked_frame_stream.hpp"
|
2024-09-30 00:07:33 +02:00
|
|
|
#include "./frame_streams/multi_source.hpp"
|
2024-10-01 11:39:26 +02:00
|
|
|
#include "./frame_streams/audio_stream_pop_reframer.hpp"
|
2024-09-29 18:23:17 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
namespace Components {
|
|
|
|
struct ToxAVIncomingAV {
|
2024-09-29 18:23:17 +02:00
|
|
|
bool incoming_audio {false};
|
|
|
|
bool incoming_video {false};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ToxAVAudioSink {
|
|
|
|
ObjectHandle o;
|
|
|
|
// ptr?
|
|
|
|
};
|
2024-09-30 12:37:40 +02:00
|
|
|
// vid
|
2024-09-29 18:23:17 +02:00
|
|
|
struct ToxAVAudioSource {
|
|
|
|
ObjectHandle o;
|
|
|
|
// ptr?
|
|
|
|
};
|
2024-09-30 12:37:40 +02:00
|
|
|
// vid
|
2024-09-29 18:23:17 +02:00
|
|
|
} // Components
|
|
|
|
|
|
|
|
struct ToxAVCallAudioSink : public FrameStream2SinkI<AudioFrame2> {
|
|
|
|
ToxAVI& _toxav;
|
|
|
|
|
|
|
|
// bitrate for enabled state
|
|
|
|
uint32_t _audio_bitrate {32};
|
|
|
|
|
|
|
|
uint32_t _fid;
|
2024-10-01 11:39:26 +02:00
|
|
|
std::shared_ptr<AudioStreamPopReFramer<LockedFrameStream2<AudioFrame2>>> _writer;
|
2024-09-29 18:23:17 +02:00
|
|
|
|
|
|
|
ToxAVCallAudioSink(ToxAVI& toxav, uint32_t fid) : _toxav(toxav), _fid(fid) {}
|
|
|
|
~ToxAVCallAudioSink(void) {
|
|
|
|
if (_writer) {
|
|
|
|
_writer = nullptr;
|
|
|
|
_toxav.toxavAudioSetBitRate(_fid, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// sink
|
|
|
|
std::shared_ptr<FrameStream2I<AudioFrame2>> subscribe(void) override {
|
|
|
|
if (_writer) {
|
|
|
|
// max 1 (exclusive for now)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto err = _toxav.toxavAudioSetBitRate(_fid, _audio_bitrate);
|
|
|
|
if (err != TOXAV_ERR_BIT_RATE_SET_OK) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-10-01 18:30:20 +02:00
|
|
|
// 20ms for now, 10ms would work too, further investigate stutters at 5ms (probably too slow interval rate)
|
|
|
|
_writer = std::make_shared<AudioStreamPopReFramer<LockedFrameStream2<AudioFrame2>>>(20);
|
2024-09-29 18:23:17 +02:00
|
|
|
|
|
|
|
return _writer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool unsubscribe(const std::shared_ptr<FrameStream2I<AudioFrame2>>& sub) override {
|
|
|
|
if (!sub || !_writer) {
|
|
|
|
// nah
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sub == _writer) {
|
|
|
|
_writer = nullptr;
|
|
|
|
|
|
|
|
/*auto err = */_toxav.toxavAudioSetBitRate(_fid, 0);
|
|
|
|
// print warning? on error?
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// what
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
void ToxAVVoIPModel::addAudioSource(ObjectHandle session, uint32_t friend_number) {
|
|
|
|
auto& stream_source = session.get_or_emplace<Components::VoIP::StreamSources>().streams;
|
2024-09-29 18:23:17 +02:00
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
ObjectHandle incoming_audio {_os.registry(), _os.registry().create()};
|
2024-09-29 18:23:17 +02:00
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
auto new_asrc = std::make_unique<FrameStream2MultiSource<AudioFrame2>>();
|
|
|
|
incoming_audio.emplace<FrameStream2MultiSource<AudioFrame2>*>(new_asrc.get());
|
|
|
|
incoming_audio.emplace<Components::FrameStream2Source<AudioFrame2>>(std::move(new_asrc));
|
|
|
|
incoming_audio.emplace<Components::StreamSource>(Components::StreamSource::create<AudioFrame2>("ToxAV Friend Call Incoming Audio"));
|
|
|
|
|
|
|
|
std::cout << "new incoming audio\n";
|
|
|
|
if (
|
|
|
|
const auto* defaults = session.try_get<Components::VoIP::DefaultConfig>();
|
|
|
|
defaults != nullptr && defaults->incoming_audio
|
|
|
|
) {
|
|
|
|
incoming_audio.emplace<Components::TagConnectToDefault>(); // depends on what was specified in enter()
|
|
|
|
std::cout << "with default\n";
|
2024-09-29 18:23:17 +02:00
|
|
|
}
|
2024-10-01 11:13:27 +02:00
|
|
|
|
|
|
|
stream_source.push_back(incoming_audio);
|
|
|
|
session.emplace<Components::ToxAVAudioSource>(incoming_audio);
|
|
|
|
// TODO: tie session to stream
|
|
|
|
|
|
|
|
_audio_sources[friend_number] = incoming_audio;
|
|
|
|
|
|
|
|
_os.throwEventConstruct(incoming_audio);
|
2024-09-29 18:23:17 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
void ToxAVVoIPModel::addAudioSink(ObjectHandle session, uint32_t friend_number) {
|
|
|
|
auto& stream_sinks = session.get_or_emplace<Components::VoIP::StreamSinks>().streams;
|
|
|
|
ObjectHandle outgoing_audio {_os.registry(), _os.registry().create()};
|
|
|
|
|
|
|
|
auto new_asink = std::make_unique<ToxAVCallAudioSink>(_av, friend_number);
|
|
|
|
outgoing_audio.emplace<ToxAVCallAudioSink*>(new_asink.get());
|
|
|
|
outgoing_audio.emplace<Components::FrameStream2Sink<AudioFrame2>>(std::move(new_asink));
|
|
|
|
outgoing_audio.emplace<Components::StreamSink>(Components::StreamSink::create<AudioFrame2>("ToxAV Friend Call Outgoing Audio"));
|
|
|
|
|
|
|
|
if (
|
|
|
|
const auto* defaults = session.try_get<Components::VoIP::DefaultConfig>();
|
|
|
|
defaults != nullptr && defaults->outgoing_audio
|
|
|
|
) {
|
|
|
|
outgoing_audio.emplace<Components::TagConnectToDefault>(); // depends on what was specified in enter()
|
2024-09-29 18:23:17 +02:00
|
|
|
}
|
2024-10-01 11:13:27 +02:00
|
|
|
|
|
|
|
stream_sinks.push_back(outgoing_audio);
|
|
|
|
session.emplace<Components::ToxAVAudioSink>(outgoing_audio);
|
|
|
|
// TODO: tie session to stream
|
|
|
|
|
|
|
|
_os.throwEventConstruct(outgoing_audio);
|
2024-09-29 18:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToxAVVoIPModel::destroySession(ObjectHandle session) {
|
|
|
|
if (!static_cast<bool>(session)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-30 12:37:40 +02:00
|
|
|
// remove lookup
|
|
|
|
if (session.all_of<Components::ToxAVAudioSource>()) {
|
|
|
|
auto it_asrc = std::find_if(
|
|
|
|
_audio_sources.cbegin(), _audio_sources.cend(),
|
|
|
|
[o = session.get<Components::ToxAVAudioSource>().o](const auto& it) {
|
|
|
|
return it.second == o;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (it_asrc != _audio_sources.cend()) {
|
|
|
|
_audio_sources.erase(it_asrc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-29 18:23:17 +02:00
|
|
|
// destory sources
|
|
|
|
if (auto* ss = session.try_get<Components::VoIP::StreamSources>(); ss != nullptr) {
|
|
|
|
for (const auto ssov : ss->streams) {
|
|
|
|
|
|
|
|
_os.throwEventDestroy(ssov);
|
|
|
|
_os.registry().destroy(ssov);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// destory sinks
|
|
|
|
if (auto* ss = session.try_get<Components::VoIP::StreamSinks>(); ss != nullptr) {
|
|
|
|
for (const auto ssov : ss->streams) {
|
|
|
|
|
|
|
|
_os.throwEventDestroy(ssov);
|
|
|
|
_os.registry().destroy(ssov);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// destory session
|
|
|
|
_os.throwEventDestroy(session);
|
|
|
|
_os.registry().destroy(session);
|
|
|
|
}
|
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
ToxAVVoIPModel::ToxAVVoIPModel(ObjectStore2& os, ToxAVI& av, Contact3Registry& cr, ToxContactModel2& tcm) :
|
|
|
|
_os(os), _av(av), _cr(cr), _tcm(tcm)
|
|
|
|
{
|
|
|
|
_av.subscribe(this, ToxAV_Event::friend_call);
|
|
|
|
_av.subscribe(this, ToxAV_Event::friend_call_state);
|
|
|
|
_av.subscribe(this, ToxAV_Event::friend_audio_bitrate);
|
|
|
|
_av.subscribe(this, ToxAV_Event::friend_video_bitrate);
|
|
|
|
_av.subscribe(this, ToxAV_Event::friend_audio_frame);
|
|
|
|
_av.subscribe(this, ToxAV_Event::friend_video_frame);
|
|
|
|
|
|
|
|
// attach to all tox friend contacts
|
|
|
|
|
|
|
|
for (const auto& [cv, _] : _cr.view<Contact::Components::ToxFriendPersistent>().each()) {
|
|
|
|
_cr.emplace<VoIPModelI*>(cv, this);
|
|
|
|
}
|
|
|
|
// TODO: events
|
|
|
|
}
|
|
|
|
|
|
|
|
ToxAVVoIPModel::~ToxAVVoIPModel(void) {
|
|
|
|
for (const auto& [ov, voipmodel] : _os.registry().view<VoIPModelI*>().each()) {
|
|
|
|
if (voipmodel == this) {
|
|
|
|
destroySession(_os.objectHandle(ov));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-29 18:23:17 +02:00
|
|
|
void ToxAVVoIPModel::tick(void) {
|
2024-10-01 11:39:26 +02:00
|
|
|
for (const auto& [oc, asink] : _os.registry().view<ToxAVCallAudioSink*>().each()) {
|
2024-09-29 18:23:17 +02:00
|
|
|
if (!asink->_writer) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-09-29 22:10:20 +02:00
|
|
|
for (size_t i = 0; i < 100; i++) {
|
2024-10-01 11:39:26 +02:00
|
|
|
auto new_frame_opt = asink->_writer->pop();
|
2024-09-29 18:23:17 +02:00
|
|
|
if (!new_frame_opt.has_value()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const auto& new_frame = new_frame_opt.value();
|
|
|
|
|
|
|
|
//* @param sample_count Number of samples in this frame. Valid numbers here are
|
|
|
|
//* `((sample rate) * (audio length) / 1000)`, where audio length can be
|
|
|
|
//* 2.5, 5, 10, 20, 40 or 60 milliseconds.
|
|
|
|
|
|
|
|
// we likely needs to subdivide/repackage
|
|
|
|
// frame size should be an option exposed to the user
|
|
|
|
// with 10ms as a default ?
|
|
|
|
// the larger the frame size, the less overhead but the more delay
|
|
|
|
|
|
|
|
auto err = _av.toxavAudioSendFrame(
|
|
|
|
asink->_fid,
|
|
|
|
new_frame.getSpan().ptr,
|
|
|
|
new_frame.getSpan().size / new_frame.channels,
|
|
|
|
new_frame.channels,
|
|
|
|
new_frame.sample_rate
|
|
|
|
);
|
|
|
|
if (err != TOXAV_ERR_SEND_FRAME_OK) {
|
|
|
|
std::cerr << "DTC: failed to send audio frame " << err << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-29 22:10:20 +02:00
|
|
|
ObjectHandle ToxAVVoIPModel::enter(const Contact3 c, const Components::VoIP::DefaultConfig& defaults) {
|
2024-09-29 18:23:17 +02:00
|
|
|
if (!_cr.all_of<Contact::Components::ToxFriendEphemeral>(c)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto friend_number = _cr.get<Contact::Components::ToxFriendEphemeral>(c).friend_number;
|
|
|
|
|
|
|
|
const auto err = _av.toxavCall(friend_number, 0, 0);
|
|
|
|
if (err != TOXAV_ERR_CALL_OK) {
|
|
|
|
std::cerr << "TAVVOIP error: failed to start call: " << err << "\n";
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectHandle new_session {_os.registry(), _os.registry().create()};
|
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
new_session.emplace<VoIPModelI*>(this);
|
2024-09-29 18:23:17 +02:00
|
|
|
new_session.emplace<Components::VoIP::TagVoIPSession>(); // ??
|
2024-10-01 11:13:27 +02:00
|
|
|
new_session.emplace<Components::VoIP::SessionContact>(c);
|
2024-09-29 18:23:17 +02:00
|
|
|
new_session.emplace<Components::VoIP::SessionState>().state = Components::VoIP::SessionState::State::RINGING;
|
2024-09-29 22:10:20 +02:00
|
|
|
new_session.emplace<Components::VoIP::DefaultConfig>(defaults);
|
2024-09-29 18:23:17 +02:00
|
|
|
|
|
|
|
_os.throwEventConstruct(new_session);
|
|
|
|
return new_session;
|
|
|
|
}
|
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
bool ToxAVVoIPModel::accept(ObjectHandle session, const Components::VoIP::DefaultConfig& defaults) {
|
|
|
|
if (!static_cast<bool>(session)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!session.all_of<
|
|
|
|
Components::VoIP::TagVoIPSession,
|
|
|
|
VoIPModelI*,
|
|
|
|
Components::VoIP::SessionContact,
|
|
|
|
Components::VoIP::Incoming
|
|
|
|
>()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if self
|
|
|
|
if (session.get<VoIPModelI*>() != this) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto session_contact = session.get<Components::VoIP::SessionContact>().c;
|
|
|
|
if (!_cr.all_of<Contact::Components::ToxFriendEphemeral>(session_contact)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto friend_number = _cr.get<Contact::Components::ToxFriendEphemeral>(session_contact).friend_number;
|
|
|
|
auto err = _av.toxavAnswer(friend_number, 0, 0);
|
|
|
|
if (err != TOXAV_ERR_ANSWER_OK) {
|
|
|
|
std::cerr << "TOXAVVOIP error: ansering call failed: " << err << "\n";
|
|
|
|
// we simply let it be for now, it apears we can try ansering later again
|
|
|
|
// we also get an error here when the call is already in progress (:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.emplace<Components::VoIP::DefaultConfig>(defaults);
|
|
|
|
|
|
|
|
// answer defaults to enabled receiving audio and video
|
|
|
|
// TODO: think about how we should handle this
|
|
|
|
// set to disabled? and enable on src connection?
|
|
|
|
// we already default disabled send and enabled on sink connection
|
|
|
|
//_av.toxavCallControl(friend_number, TOXAV_CALL_CONTROL_HIDE_VIDEO);
|
|
|
|
//_av.toxavCallControl(friend_number, TOXAV_CALL_CONTROL_MUTE_AUDIO);
|
|
|
|
|
|
|
|
|
|
|
|
// how do we know the other side is accepting audio
|
|
|
|
// bitrate cb or what?
|
|
|
|
assert(!session.all_of<Components::ToxAVAudioSink>());
|
|
|
|
addAudioSink(session, friend_number);
|
|
|
|
|
|
|
|
if (const auto* i_av = session.try_get<Components::ToxAVIncomingAV>(); i_av != nullptr) {
|
|
|
|
// create audio src
|
|
|
|
if (i_av->incoming_audio) {
|
|
|
|
assert(!session.all_of<Components::ToxAVAudioSource>());
|
|
|
|
addAudioSource(session, friend_number);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create video src
|
|
|
|
if (i_av->incoming_video) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
session.get_or_emplace<Components::VoIP::SessionState>().state = Components::VoIP::SessionState::State::CONNECTED;
|
|
|
|
_os.throwEventUpdate(session);
|
|
|
|
return true;
|
2024-09-29 18:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxAVVoIPModel::leave(ObjectHandle session) {
|
|
|
|
// rename to end?
|
|
|
|
|
|
|
|
if (!static_cast<bool>(session)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
if (!session.all_of<
|
|
|
|
Components::VoIP::TagVoIPSession,
|
|
|
|
VoIPModelI*,
|
|
|
|
Components::VoIP::SessionContact
|
|
|
|
>()) {
|
2024-09-29 18:23:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if self
|
|
|
|
if (session.get<VoIPModelI*>() != this) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto session_contact = session.get<Components::VoIP::SessionContact>().c;
|
|
|
|
if (!_cr.all_of<Contact::Components::ToxFriendEphemeral>(session_contact)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto friend_number = _cr.get<Contact::Components::ToxFriendEphemeral>(session_contact).friend_number;
|
|
|
|
// check error? (we delete anyway)
|
|
|
|
_av.toxavCallControl(friend_number, Toxav_Call_Control::TOXAV_CALL_CONTROL_CANCEL);
|
|
|
|
|
|
|
|
destroySession(session);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxAVVoIPModel::onEvent(const Events::FriendCall& e) {
|
|
|
|
// new incoming call, create voip session, ready to be accepted
|
|
|
|
// (or rejected...)
|
|
|
|
|
|
|
|
const auto session_contact = _tcm.getContactFriend(e.friend_number);
|
|
|
|
if (!_cr.valid(session_contact)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectHandle new_session {_os.registry(), _os.registry().create()};
|
|
|
|
|
2024-10-01 11:13:27 +02:00
|
|
|
new_session.emplace<VoIPModelI*>(this);
|
2024-09-29 18:23:17 +02:00
|
|
|
new_session.emplace<Components::VoIP::TagVoIPSession>(); // ??
|
2024-10-01 11:13:27 +02:00
|
|
|
new_session.emplace<Components::VoIP::Incoming>(session_contact); // in 1on1 its always the same contact, might leave blank
|
|
|
|
new_session.emplace<Components::VoIP::SessionContact>(session_contact);
|
2024-09-29 18:23:17 +02:00
|
|
|
new_session.emplace<Components::VoIP::SessionState>().state = Components::VoIP::SessionState::State::RINGING;
|
2024-10-01 11:13:27 +02:00
|
|
|
new_session.emplace<Components::ToxAVIncomingAV>(e.audio_enabled, e.video_enabled);
|
2024-09-29 18:23:17 +02:00
|
|
|
|
|
|
|
_os.throwEventConstruct(new_session);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxAVVoIPModel::onEvent(const Events::FriendCallState& e) {
|
|
|
|
const auto session_contact = _tcm.getContactFriend(e.friend_number);
|
|
|
|
if (!_cr.valid(session_contact)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToxAVFriendCallState s{e.state};
|
|
|
|
|
|
|
|
// find session(s?)
|
|
|
|
// TODO: keep lookup table
|
|
|
|
for (const auto& [ov, voipmodel] : _os.registry().view<VoIPModelI*>().each()) {
|
|
|
|
if (voipmodel == this) {
|
|
|
|
auto o = _os.objectHandle(ov);
|
|
|
|
|
|
|
|
if (!o.all_of<Components::VoIP::SessionContact>()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (session_contact != o.get<Components::VoIP::SessionContact>().c) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.is_error() || s.is_finished()) {
|
|
|
|
// destroy call
|
|
|
|
destroySession(o);
|
|
|
|
} else {
|
|
|
|
// remote accepted our call, or av send/recv conditions changed?
|
2024-09-29 22:10:20 +02:00
|
|
|
o.get<Components::VoIP::SessionState>().state = Components::VoIP::SessionState::State::CONNECTED; // set to in call ??
|
2024-09-29 18:23:17 +02:00
|
|
|
|
|
|
|
if (s.is_accepting_a() && !o.all_of<Components::ToxAVAudioSink>()) {
|
2024-10-01 11:13:27 +02:00
|
|
|
addAudioSink(o, e.friend_number);
|
2024-09-29 18:23:17 +02:00
|
|
|
} else if (!s.is_accepting_a() && o.all_of<Components::ToxAVAudioSink>()) {
|
|
|
|
// remove asink?
|
|
|
|
}
|
|
|
|
|
|
|
|
// video
|
|
|
|
|
|
|
|
// add/update sources
|
|
|
|
// audio
|
2024-09-30 00:07:33 +02:00
|
|
|
if (s.is_sending_a() && !o.all_of<Components::ToxAVAudioSource>()) {
|
2024-10-01 11:13:27 +02:00
|
|
|
addAudioSource(o, e.friend_number);
|
2024-09-30 00:07:33 +02:00
|
|
|
} else if (!s.is_sending_a() && o.all_of<Components::ToxAVAudioSource>()) {
|
|
|
|
// remove asrc?
|
|
|
|
}
|
|
|
|
|
|
|
|
// video
|
2024-09-29 18:23:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxAVVoIPModel::onEvent(const Events::FriendAudioBitrate&) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxAVVoIPModel::onEvent(const Events::FriendVideoBitrate&) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-30 00:07:33 +02:00
|
|
|
bool ToxAVVoIPModel::onEvent(const Events::FriendAudioFrame& e) {
|
2024-09-30 12:37:40 +02:00
|
|
|
auto asrc_it = _audio_sources.find(e.friend_number);
|
|
|
|
if (asrc_it == _audio_sources.cend()) {
|
|
|
|
// missing src from lookup table
|
2024-09-30 00:07:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-30 12:37:40 +02:00
|
|
|
auto asrc = asrc_it->second;
|
2024-09-30 00:07:33 +02:00
|
|
|
|
|
|
|
if (!static_cast<bool>(asrc)) {
|
|
|
|
// missing src to put frame into ??
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(asrc.all_of<FrameStream2MultiSource<AudioFrame2>*>());
|
|
|
|
assert(asrc.all_of<Components::FrameStream2Source<AudioFrame2>>());
|
|
|
|
|
|
|
|
asrc.get<FrameStream2MultiSource<AudioFrame2>*>()->push(AudioFrame2{
|
|
|
|
e.sampling_rate,
|
|
|
|
e.channels,
|
|
|
|
std::vector<int16_t>(e.pcm.begin(), e.pcm.end()) // copy
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
2024-09-29 18:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxAVVoIPModel::onEvent(const Events::FriendVideoFrame&) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|