improve src filling with lookup table

This commit is contained in:
Green Sky 2024-09-30 12:37:40 +02:00
parent 0886e9c8ef
commit a1d3e0a480
No known key found for this signature in database
2 changed files with 27 additions and 30 deletions

View File

@ -23,10 +23,12 @@ namespace Components {
ObjectHandle o; ObjectHandle o;
// ptr? // ptr?
}; };
// vid
struct ToxAVAudioSource { struct ToxAVAudioSource {
ObjectHandle o; ObjectHandle o;
// ptr? // ptr?
}; };
// vid
} // Components } // Components
// TODO: make proper adapter // TODO: make proper adapter
@ -181,6 +183,20 @@ void ToxAVVoIPModel::destroySession(ObjectHandle session) {
return; return;
} }
// 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);
}
}
// destory sources // destory sources
if (auto* ss = session.try_get<Components::VoIP::StreamSources>(); ss != nullptr) { if (auto* ss = session.try_get<Components::VoIP::StreamSources>(); ss != nullptr) {
for (const auto ssov : ss->streams) { for (const auto ssov : ss->streams) {
@ -405,6 +421,8 @@ bool ToxAVVoIPModel::onEvent(const Events::FriendCallState& e) {
o.emplace<Components::ToxAVAudioSource>(incoming_audio); o.emplace<Components::ToxAVAudioSource>(incoming_audio);
// TODO: tie session to stream // TODO: tie session to stream
_audio_sources[e.friend_number] = incoming_audio;
_os.throwEventConstruct(incoming_audio); _os.throwEventConstruct(incoming_audio);
} else if (!s.is_sending_a() && o.all_of<Components::ToxAVAudioSource>()) { } else if (!s.is_sending_a() && o.all_of<Components::ToxAVAudioSource>()) {
// remove asrc? // remove asrc?
@ -427,46 +445,20 @@ bool ToxAVVoIPModel::onEvent(const Events::FriendVideoBitrate&) {
} }
bool ToxAVVoIPModel::onEvent(const Events::FriendAudioFrame& e) { bool ToxAVVoIPModel::onEvent(const Events::FriendAudioFrame& e) {
//auto& call = _calls[e.friend_number]; auto asrc_it = _audio_sources.find(e.friend_number);
if (asrc_it == _audio_sources.cend()) {
// get session? // missing src from lookup table
// get asrc (directly instead?) this is pretty hot
const auto session_contact = _tcm.getContactFriend(e.friend_number);
if (!_cr.valid(session_contact)) {
return false; return false;
} }
// jesus this is bad auto asrc = asrc_it->second;
ObjectHandle asrc;
for (const auto& [ov, voipmodel] : _os.registry().view<VoIPModelI*>().each()) {
if (voipmodel != this) {
continue;
}
auto o = _os.objectHandle(ov);
if (!o.all_of<Components::VoIP::SessionContact>()) {
continue;
}
if (session_contact != o.get<Components::VoIP::SessionContact>().c) {
continue;
}
if (!o.all_of<Components::ToxAVAudioSource>()) {
continue;
}
asrc = o.get<Components::ToxAVAudioSource>().o;
break;
}
if (!static_cast<bool>(asrc)) { if (!static_cast<bool>(asrc)) {
// missing src to put frame into ?? // missing src to put frame into ??
return false; return false;
} }
//assert(call.incoming_asrc.all_of<AudioFrameStream2MultiSource*>());
assert(asrc.all_of<FrameStream2MultiSource<AudioFrame2>*>()); assert(asrc.all_of<FrameStream2MultiSource<AudioFrame2>*>());
//assert(call.incoming_asrc.all_of<Components::FrameStream2Source<AudioFrame>>());
assert(asrc.all_of<Components::FrameStream2Source<AudioFrame2>>()); assert(asrc.all_of<Components::FrameStream2Source<AudioFrame2>>());
asrc.get<FrameStream2MultiSource<AudioFrame2>*>()->push(AudioFrame2{ asrc.get<FrameStream2MultiSource<AudioFrame2>*>()->push(AudioFrame2{

View File

@ -6,12 +6,17 @@
#include "./frame_streams/voip_model.hpp" #include "./frame_streams/voip_model.hpp"
#include "./tox_av.hpp" #include "./tox_av.hpp"
#include <unordered_map>
struct ToxAVVoIPModel : protected ToxAVEventI, public VoIPModelI { struct ToxAVVoIPModel : protected ToxAVEventI, public VoIPModelI {
ObjectStore2& _os; ObjectStore2& _os;
ToxAVI& _av; ToxAVI& _av;
Contact3Registry& _cr; Contact3Registry& _cr;
ToxContactModel2& _tcm; ToxContactModel2& _tcm;
// for faster lookup
std::unordered_map<uint32_t, ObjectHandle> _audio_sources;
ToxAVVoIPModel(ObjectStore2& os, ToxAVI& av, Contact3Registry& cr, ToxContactModel2& tcm); ToxAVVoIPModel(ObjectStore2& os, ToxAVI& av, Contact3Registry& cr, ToxContactModel2& tcm);
~ToxAVVoIPModel(void); ~ToxAVVoIPModel(void);