4

I have created a WebRTC session from one device to another, the device should be able to control the volume for music stream, but WebRTC is originally designed to stream voice_call so is using the voice_call channel and using the call volume control is not good behavior for non-call app.

I tried to change STREAM_VOICE_CALL to STREAM_MUSIC in WebRTC source WebRtcAudioTrack to use the stream music volume but the only change was android is detecting it as music but volume change with call volume.

Rahul
  • 3,293
  • 2
  • 31
  • 43
nima moradi
  • 2,300
  • 21
  • 34

1 Answers1

1

I found the solution to this. You have to change the opensls player for this to happen

change this from here

  // corresponds to android.media.AudioManager.STREAM_VOICE_CALL.
  SLint32 stream_type = SL_ANDROID_STREAM_VOICE;
  RETURN_ON_ERROR(
      (*player_config)
          ->SetConfiguration(player_config, SL_ANDROID_KEY_STREAM_TYPE,
                             &stream_type, sizeof(SLint32)),
      false);

to this

  // corresponds to android.media.AudioManager.STREAM_MUSIC.
  SLint32 stream_type = SL_ANDROID_STREAM_MEDIA;
  RETURN_ON_ERROR(
      (*player_config)
          ->SetConfiguration(player_config, SL_ANDROID_KEY_STREAM_TYPE,
                             &stream_type, sizeof(SLint32)),
      false);

do this here too

nima moradi
  • 2,300
  • 21
  • 34
  • I'm also looking for a fix for this issue, and I implemented this as you suggested @nima-moradi and found it made no difference. I noted that on this repo you made further changes -> [https://github.com/nimamoradi/webrtc-audio-fix](https://github.com/nimamoradi/webrtc-audio-fix). Is it possible that there are other code changes required other than the changes in `sdk/android/src/jni/audio_device/opensles_player.cc` and `modules/audio_device/android/opensles_player.cc`? – forty9er Oct 29 '21 at 12:06
  • @forty9er as i said in question i did change the values in java files for webrtc and it was not enough so i made some change too to sles player too. look in webrtc source and change STREAM_VOICE_CALL to STREAM_MUSIC. look in other class too some are loging which do not need any change – nima moradi Oct 29 '21 at 14:38
  • Thanks @nima moradi. I found the Java files that also needed updating and it works - much appreciated. Now the only issue I have is that that the audio is mono, hopefully I can find a fix for that in the same area of the code. – forty9er Oct 29 '21 at 22:41
  • This will change nothing after compiling the aar and changed each `stream_voice_call` to `stream_music` also changing the 2 files of opensles_player.cc the voice remains `stream_voice_call` this answer is misleading and invalid. – DelphiStudent Nov 20 '22 at 11:54
  • @DelphiStudent, it did work for me I think you missed some place, have you replace SL_ANDROID_STREAM_VOICE? the comment up forty9er said it worked for him – nima moradi Nov 21 '22 at 00:09
  • @nimamoradi i mentioned that i have changed `SL_Android_Voice` in `opensles_player.cc` files. and the volume is still voice call not stream music. tested on webrtc version 5414. https://webrtc.googlesource.com/src.git/+log/refs/branch-heads/5414 – DelphiStudent Nov 21 '22 at 11:00
  • @nimamoradi also i have recompiled the source to aar and checked the 'webrtcaudiotrack' class and it was set `audioManager.setStreamVolume(3, volume, 0);` `audioManager.getStreamMaxVolume(3);` and so on.. tested on official example And IT DOES NOT Change Stream_voice_call to stream_music. https://webrtc.googlesource.com/src.git/+/a3e51df5f3377bee71b4dcdd1ee8f50c520a9ea8/examples/androidapp/src/org/appspot/apprtc – DelphiStudent Nov 21 '22 at 11:08
  • @DelphiStudent idk it work for me and some other guy, make sure you change everything you probably miss something fix recorder too if you missed https://chromium.googlesource.com/external/webrtc/+/refs/heads/master/modules/audio_device/android/opensles_recorder.cc – nima moradi Nov 21 '22 at 15:10
  • @nimamoradi so your app volume button is set to volume music? The recorder isn't a part of the player and it hasn't any input for voice_call – DelphiStudent Nov 21 '22 at 21:13
  • yes, the audio was coming out of call speaker and it can be controlled through audio stream(via volume up and down) and can not be muted since it counted as call – nima moradi Nov 22 '22 at 17:55