webrtc-java icon indicating copy to clipboard operation
webrtc-java copied to clipboard

Fatal error in audio_send_stream.cc

Open Charles92011 opened this issue 2 years ago • 6 comments

Describe the bug I've had my experimental project working for a while now: https://github.com/Charles92011/webrtc-java-experimental-server It was working great, but I put it away for a couple of months until we're ready to transition to it. When I started it up today, it gets this error upon connecting two connections together:

#
# Fatal error in: ../../audio/audio_send_stream.cc, line 387
# last system error: 0
# Check failed: !race_checker.RaceDetected()
# 

I updated my pom file to get the latest version of the library and it still fails. This error is untrappable, so I can't recover from it

To Reproduce Steps to reproduce the behavior:

  1. clone https://github.com/Charles92011/webrtc-java-experimental-server
  2. run main.java
  3. browse to wsclient.html
  4. click start
  5. click mirror
  6. Server will crash

Expected behavior You should get two videos working fine

Desktop (please complete the following information): Windows 10

Additional context This was working fine when I last used it a few months ago.

Charles92011 avatar Mar 30 '23 18:03 Charles92011

This error only appears when transmitting an audio track. Video tracks alone do not throw this error.

Charles92011 avatar Mar 31 '23 16:03 Charles92011

hey i am also getting this same error wheni am trying to add mediastreamtrack of another party

Map<String, RTCPeerConnection> savedMapOfConnection = list_of_connected_user
		                .get(roomUserResponse.getRoomId());
		        	savedMapOfConnection.forEach((key, connection) -> {
		        	final int receivers = connection.getReceivers().length;
		    		if (receivers == 0)
                                      {return;}
		    		try {
		    			for (int index = 0; index < receivers; index++) {
			    			
			    			final RTCRtpReceiver receiver = connection.getReceivers()[index];
			    			if (receiver != null) {
			    				
			    				final MediaStreamTrack track = receiver.getTrack();
			    				if (track != null) {
			    							    					
			    					List<String> streamIds = new ArrayList<String>();
			    					streamIds.add(receiver.getTrack().getId());
			    					
			    					@SuppressWarnings("unused")
			    					RTCRtpSender sender = connection.addTrack(track, streamIds);
			    				}
			    			}
			    		}
		    			
		    		}
		    		catch(Exception e) {
		    			System.out.println("someting went wrong "+e.getMessage());
		    			
		    		}
		    		
		            
		        });
		}

so help

naveenSaini1 avatar Apr 10 '24 17:04 naveenSaini1

@naveenSaini1 I was never able to get past this error, and in a year there's been no update that mentions it. I had to abandon it.

Charles92011 avatar Apr 10 '24 18:04 Charles92011

@Charles92011 hey i saw your project and that is really amazing most of the things i learn from there and about this error i need to resolve this because i am trying to make sfu server in webrtc and now i have been stuck at this point if you want we can figure out on this

naveenSaini1 avatar Apr 11 '24 18:04 naveenSaini1

@naveenSaini1 I'm in the same situation. My goal was to build a server with this library, but I had to abandon it because of this error.

You could always download the library source, and see if you can trap the error.

From my research, the error is actually occurring in the WebRTC code itself, not the java RTC library. So you could try to modify JavaRTC to trap the exception or try to debug Google's WebRTC code to fix it. I don't have the resources available to do either one.

Charles92011 avatar Apr 11 '24 18:04 Charles92011

@Charles92011 hi i noticed something in this , like whenever we send the audioTrack like this

 AudioTrackSource audioSource = peerConnectionFactory.createAudioSource(new AudioOptions());
		AudioTrack audioTrack = peerConnectionFactory.createAudioTrack("audioTrack", audioSource);
			audioTrack.addSink(new AudioTrackSink() {
				@Override
				public void onData(byte[] data, int bitsPerSample, int sampleRate, int channels, int frames) {
					System.out.println(data);
				}
			});
			
			List<String> streamIds = new ArrayList<>();
			streamIds.add("stream-0");

			RTCRtpSender audioSender = peer_connection.addTrack(audioTrack, streamIds);

we will not get the error so i change this way to puting the track in diffrent way

AudioTrack audioTrack = (AudioTrack)allTheTracks.get("a");
			audioTrack.addSink(new AudioTrackSink() {
				@Override
				public void onData(byte[] data, int bitsPerSample, int sampleRate, int channels, int frames) {
					System.out.println(data);
				}
			});
			
			List<String> streamIds = new ArrayList<>();
			streamIds.add(allTheTracks.get("a").getId());

			RTCRtpSender audioSender = peer_connection.addTrack(audioTrack, streamIds);

but guess what same thing that same issue

 #
# Fatal error in: ../../audio/audio_send_stream.cc, line 387
# last system error: 11
# Check failed: !race_checker.RaceDetected()

@devopvoid can you please look into this , i really don't know like how to resolve this or can you gave little hint

naveenSaini1 avatar Apr 12 '24 10:04 naveenSaini1

WebRTC has detected that multiple threads are accessing the same audio send stream object concurrently without proper synchronization. Or it is improper stream lifecycle management when the stream is closed but still accessed. Try to wrap your peer-connection control flow into one managing thread.

devopvoid avatar Aug 28 '25 10:08 devopvoid

I managed to resolve the issue using static mutex:

                private static final Object LOCK = new Object();


                synchronized (LOCK) {
                    customAudioSource.pushAudio(
                            audioData,
                            DEFAULT_BITS_PER_SAMPLE,
                            DEFAULT_SAMPLE_RATE,
                            DEFAULT_CHANNELS,
                            DEFAULT_FRAME_COUNT
                    );
                }

turbo-hammer avatar Aug 28 '25 11:08 turbo-hammer

I managed to resolve the issue using static mutex:

            private static final Object LOCK = new Object();


            synchronized (LOCK) {
                customAudioSource.pushAudio(
                        audioData,
                        DEFAULT_BITS_PER_SAMPLE,
                        DEFAULT_SAMPLE_RATE,
                        DEFAULT_CHANNELS,
                        DEFAULT_FRAME_COUNT
                );
            }

I have done that still that error persist @turbo-hammer can u give the full exxample of connection + signaling + customAudioSource usage, if possible?

sc-sityad avatar Oct 19 '25 18:10 sc-sityad

I managed to resolve the issue using static mutex:

            private static final Object LOCK = new Object();


            synchronized (LOCK) {
                customAudioSource.pushAudio(
                        audioData,
                        DEFAULT_BITS_PER_SAMPLE,
                        DEFAULT_SAMPLE_RATE,
                        DEFAULT_CHANNELS,
                        DEFAULT_FRAME_COUNT
                );
            }

I have done that still that error persist @turbo-hammer can u give the full exxample of connection + signaling + customAudioSource usage, if possible?

This is not working for me. Some times passed but then happened again.

turbo-hammer avatar Oct 22 '25 11:10 turbo-hammer

Then , how u resolved it or u haven't?

sc-sityad avatar Oct 22 '25 11:10 sc-sityad