I want to call PeerConnectionInterface::GetStats() every N milliseconds, within the native example app `peerconnection`.
Currently, I am attempting to do this in the following way, in examples/peerconnection/client/conductor.cc
std::make_unique<StatsCollectorTask>(
my_interval_ms, peer_connection_.get(), stats_observer_.get()),
0);
- StatsCollectorTask is a subclass of webrtc::QueuedTask whose run() does something like
peer_connection_->GetStats(stats_collector_callback_); webrtc::TaskQueueBase::Current()->PostDelayedTask(absl::WrapUnique(this), my_interval_ms)
- stats_observer_ is an object of a subclass of webrtc::RTCStatsCollectorCallback, which implements OnStatsDelivered()
The problem I am facing right now is that after streaming a while (1 / 2 mins) this seems to cause a deadlock. I.e., the GetStats calls gets blocked at WebRtcVideoChannel::FillReceiverStats. This only happens if the peerconnection app calls GetStats() periodically, also constantly sending data via the Data Channel.
Looking at RTCStatsCollector seems GetStats is supposed to be invoked from the signaling thread. But I don't know how to get the signaling thread (not seeing such method from PeerConnectionInterface).
I have tried a few alternatives but no luck so far, such as
- Call GetStats in my own pthread which has a loop and sleep logic
- Explicitly creating a rtc::Thread signaling thread, passing it to a CreatePeerConnectionFactory, and do something like
g_signaling_thread->PostTask(
RTC_FROM_HERE, rtc::Bind(&Conductor::TestGetStats, this));
where TestGetStats will make the GetStats() call
Please help! Please provide suggestion on what is a right way of calling GetStats every N milliseconds in such a native app.
Thank a lot in advance!