[Android] AudioTrack::set_enabled not called on signaling_thread

217 views
Skip to first unread message

Christophe Chaillon

unread,
Mar 3, 2021, 1:18:07 PM3/3/21
to discuss...@googlegroups.com
Hi,
I am working on c++ applications with WebRTC (M84). They run on Windows and Android.
The applications can send and receive video, audio and data without problem on Windows and Android.
Now, I would like to mute the audio channel of a publisher. So I tried to call set_enabled on the AudioTrack. It works on Windows but it crashes on Android.

Here is the error message:
    # Fatal error in: ../../src/pc/audio_track.cc, line 47
    # last system error: 115
    # Check failed: thread_checker_.IsCurrent()
    #
 
Here is the creation of the PeerConnectionFactory:
  mPeerConnectionFactory = webrtc::CreatePeerConnectionFactory(
nullptr /* network_thread */, nullptr /* worker_thread */,
nullptr /* signaling_thread */, nullptr /* default_adm */,
webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(),
webrtc::CreateBuiltinVideoEncoderFactory(),
webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
nullptr /* audio_processing */);

So if I understand the WebRTC code, the signaling_thread should be the main thread.
If I break in my method before calling set_enabled, I am in the main thread... So I don't understand the error message...

Do you have an idea ?

Thanks,

Christophe




Henrik Andreasson

unread,
Mar 4, 2021, 3:41:11 AM3/4/21
to discuss-webrtc
First of all, compare with the latest WebRTC version; M84 is rather old.

Looks like you are hitting a DCHECK which tells you that the AudioTrack:: GetSource() API is called on another thread than the thread which calls AudioTrack::Create().
You can "avoid" the issue by running in Release mode but that is probably a bad idea going forward.

Can't say for sure what happens in your exact case or why there is a difference between Windows and Android but you might have to do something like this.
Basically, track your three threads (Network, Worker and Signaling) by checking their IDs when they are created. Then, check the ID of the thread that calls AudioTrack::Create() and finally ensure that the thread that calls  AudioTrack:: GetSource() is the same.
If not, check if you must inject the main/creating thread (the fourth thread in your app) to replace Network, Worker or Signaling to fix it.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/CA%2BzMRidmJTOo%2Bb_M5-Dh7__25FU_eEp5tcw1hpeWLfvAkYOmYA%40mail.gmail.com.

Christophe Chaillon

unread,
Mar 9, 2021, 4:34:25 AM3/9/21
to discuss...@googlegroups.com
Hi,

Looks like you are hitting a DCHECK which tells you that the AudioTrack:: GetSource() API is called on another thread than the thread which calls AudioTrack::Create().

You are right, on Android, AudioTrack::Create() was not called on the main thread
Here is the origin of my problem:
  • On Windows: The slots connected to the signals (SignalCloseEvent, SignalConnectEvent and SignalReadEvent) of rtc::AsyncSocket are called on the main thread
  • On Android: The same slots are called on the thread given to the method: rtc::ThreadManager::Instance()->SetCurrentThread(myThread);
Thanks,

Christophe

Filip Bajaník

unread,
Mar 9, 2021, 5:04:54 AM3/9/21
to discuss-webrtc
Isn't that WebRTC responsibility to ensure that methods are called on the appropriate threads? I also had some issues regarding threading and calling some method from the different thread, but is certainly shouldn't be an issue and WebRTC should handle it appropriately.

Dátum: utorok 9. marca 2021, čas: 10:34:25 UTC+1, odosielateľ: hark...@gmail.com

Christophe Chaillon

unread,
Mar 9, 2021, 12:57:49 PM3/9/21
to discuss-webrtc
Hi, 

I still have problems with the threads on Android...
Context:
I have 4 useful threads:
- The main thread (which is also the signaling thread)
- The worker thread
- The network thread
- The server thread (the thread given to rtc::ThreadManager::Instance()->SetCurrentThread)

If I create the peerConnectionFactory, the peerConnections and the tracks (audio and video) on the server thread, everything works but I can't disable the track from the main thread (crash in debug)
If I try to create the peerConnectionFactory and the peerConnections on the main thread, the application freezes (it waits the worker thread forever)

Does someone has an explanation ?
Can someone explain me how to invoke the set_enabled of a track on the server thread from the main thread ?

Thanks,

Christophe

Filip Bajaník

unread,
Mar 18, 2021, 5:34:02 AM3/18/21
to discuss-webrtc
Off the record - why is it important to create the factory or peerconnections on whatever thread or calling methods through the WebRTC API such as manipulating with `RTCAudioTrack.isEnabled`?

As I seen from the implementation, there are checks that ensure that those methods are internally dispatched on threads that they need to be dispatched on.

Only thing that is necessary - as far as I know - is to not block WebRTC threads in the delegates or callbacks? Is my theory right? Otherwise, there should be any best practices guide for integrating WebRTC.
Dátum: utorok 9. marca 2021, čas: 18:57:49 UTC+1, odosielateľ: hark...@gmail.com
Reply all
Reply to author
Forward
0 new messages