Commit c86a2a4b authored by Adrien Béraud's avatar Adrien Béraud

multi-device: misc fixes

Change-Id: I2a69b5b59ae8ee2e6ceedbb448148872c0d55fd4
parent f6ffeb90
......@@ -421,6 +421,7 @@ Call::addSubCall(const std::shared_ptr<Call>& call)
sub->hangup(0);
}
this_.merge(call);
Manager::instance().peerAnsweredCall(this_);
}
RING_WARN("[call %s] Remaining %d subcalls", this_.getCallId().c_str(), this_.subcalls.size());
} else {
......
......@@ -102,6 +102,15 @@ void VideoInput::processAndroid()
std::unique_lock<std::mutex> lck(mutex_);
frame_cv_.wait(lck, [this] { return waitForBufferFull(); });
std::weak_ptr<VideoInput> wthis;
// shared_from_this throws in destructor
// assumes C++17
try {
wthis = shared_from_this();
} catch (...) {
return;
}
for (auto& buffer : buffers_) {
if (buffer.status == BUFFER_FULL && buffer.index == publish_index_) {
auto& frame = getNewFrame();
......@@ -109,7 +118,12 @@ void VideoInput::processAndroid()
buffer.status = BUFFER_PUBLISHED;
frame.setFromMemory((uint8_t*)buffer.data, format, decOpts_.width, decOpts_.height,
std::bind(&VideoInput::releaseBufferCb, this, std::placeholders::_1));
[wthis](uint8_t* ptr) {
if (auto sthis = wthis.lock())
sthis->releaseBufferCb(ptr);
else
std::free(ptr);
});
publish_index_++;
lck.unlock();
publishFrame();
......
......@@ -61,7 +61,7 @@ struct VideoFrameBuffer {
status(BUFFER_NOT_ALLOCATED), index(0) {}
};
class VideoInput : public VideoGenerator
class VideoInput : public VideoGenerator, public std::enable_shared_from_this<VideoInput>
{
public:
VideoInput();
......
......@@ -1038,11 +1038,12 @@ RingAccount::createAccount(const std::string& archive_password)
a.ca_key = std::move(*ca.first);
}
this_.ringAccountId_ = a.id.second->getId().toString();
this_.createRingDevice(a.id);
this_.username_ = RING_URI_PREFIX+this_.ringAccountId_;
auto keypair = future_keypair.get();
this_.ethAccount_ = keypair.address().hex();
a.eth_key = keypair.secret().makeInsecure().asBytes();
this_.createRingDevice(a.id);
this_.saveArchive(a, archive_password);
} catch (...) {
this_.setRegistrationState(RegistrationState::ERROR_GENERIC);
......@@ -1515,14 +1516,14 @@ RingAccount::doRegister_()
// Put device annoucement
if (announce_) {
auto h = dht::InfoHash(ringAccountId_);
RING_DBG("Announcing device at %s: %s", h.toString().c_str(), announce_->toString().c_str());
RING_WARN("Announcing device at %s: %s", h.toString().c_str(), announce_->toString().c_str());
loadKnownDevices();
dht_.put(h, announce_, dht::DoneCallback{}, {}, true);
dht_.listen<DeviceAnnouncement>(h, [shared](DeviceAnnouncement&& dev) {
shared->findCertificate(dev.dev, [shared](const std::shared_ptr<dht::crypto::Certificate> crt) {
auto& this_ = *shared;
if (this_.knownDevices_.emplace(crt->getId(), crt).second) {
RING_DBG("[Account %s] Found known account device: %s", this_.getAccountID().c_str(), crt->getId().toString().c_str());
RING_WARN("[Account %s] Found known account device: %s", this_.getAccountID().c_str(), crt->getId().toString().c_str());
tls::CertificateStore::instance().pinCertificate(crt);
this_.saveKnownDevices();
emitSignal<DRing::ConfigurationSignal::KnownDevicesChanged>(this_.getAccountID(), this_.getKnownDevices());
......@@ -1530,6 +1531,8 @@ RingAccount::doRegister_()
});
return true;
});
} else {
RING_WARN("Can't announce device: no annoucement...");
}
// Listen for incoming calls
......
......@@ -367,35 +367,26 @@ SIPCall::answer()
void
SIPCall::hangup(int reason)
{
// Stop all RTP streams
stopAllMedia();
if (not inv or not inv->dlg) {
removeCall();
throw VoipLinkException("[call:" + getCallId() + "] hangup: no invite session for this call");
}
pjsip_route_hdr *route = inv->dlg->route_set.next;
while (route and route != &inv->dlg->route_set) {
char buf[1024];
int printed = pjsip_hdr_print_on(route, buf, sizeof(buf));
if (printed >= 0) {
buf[printed] = '\0';
RING_DBG("[call:%s] Route header %s", getCallId().c_str(), buf);
if (inv and inv->dlg) {
pjsip_route_hdr *route = inv->dlg->route_set.next;
while (route and route != &inv->dlg->route_set) {
char buf[1024];
int printed = pjsip_hdr_print_on(route, buf, sizeof(buf));
if (printed >= 0) {
buf[printed] = '\0';
RING_DBG("[call:%s] Route header %s", getCallId().c_str(), buf);
}
route = route->next;
}
route = route->next;
const int status = reason ? reason :
inv->state <= PJSIP_INV_STATE_EARLY and inv->role != PJSIP_ROLE_UAC ?
PJSIP_SC_CALL_TSX_DOES_NOT_EXIST :
inv->state >= PJSIP_INV_STATE_DISCONNECTED ? PJSIP_SC_DECLINE : 0;
// Notify the peer
terminateSipSession(status);
}
const int status = reason ? reason :
inv->state <= PJSIP_INV_STATE_EARLY and inv->role != PJSIP_ROLE_UAC ?
PJSIP_SC_CALL_TSX_DOES_NOT_EXIST :
inv->state >= PJSIP_INV_STATE_DISCONNECTED ? PJSIP_SC_DECLINE : 0;
// Notify the peer
terminateSipSession(status);
// Stop all RTP streams
stopAllMedia();
setState(Call::ConnectionState::DISCONNECTED, reason);
removeCall();
}
......@@ -704,9 +695,11 @@ SIPCall::onClosed()
void
SIPCall::onAnswered()
{
RING_WARN("[call:%s] onAnswered()", getCallId().c_str());
if (getConnectionState() != ConnectionState::CONNECTED) {
setState(CallState::ACTIVE, ConnectionState::CONNECTED);
Manager::instance().peerAnsweredCall(*this);
if (not quiet)
Manager::instance().peerAnsweredCall(*this);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment