Skip to main content

Recording internal audio the right way

By August 31, 2019June 12th, 2021No Comments

You probably used screencam for recording your game play or an important task with the internal audio but was stumbled when you couldn’t hear the audio play back to you while recording? So, it is a bug right? Worth to be reported? NO! Read further to know why and a elegant work around to the problem for the folks running custom Roms!

1. The implementation:

Have you ever wondered how a screencast from your android phone also streams the audio but apps could not capture the audio? And how the audio is played only on your chromecast or your TV but not on your phone?

The Reason:

All the audio sources (music player, apps like youtube, audio call) are called sources and the destination where it is routed is called a Sink (yes, just like your kitchen, the water from your tap flowing down to your sink). Now, just like how there could be multiple sources (taps), there could be any number of sinks. One such sink is called the R_SUBMIX.

2. R_SUBMIX and its significance:

R_submix is a peculiar sink since, at one end it acts like a sink. But on the other, it behaves like the source. When an app requests the android system for R_SUBMIX source, the system essentially treats the app as a audio output device and redirectly all and any audio to the app. Now the app, if is a screen cast, becomes the source for the audio on the TV end.

Now, that you know how the R_SUBMIX helps in capturing the internal audio for screen casting and why you cannot hear the audio while an app uses R_SUBMIX, you might also be wondering why not any app could use the stream then? And why ScreenCam requires magisk module to use R_SUBMIX?

3. Reason for root and magisk:

In order to use the R_SUBMIX source, the app requires android.permission.CAPTURE_AUDIO_OUTPUT permission. And this permission is protected by system|signature. That means, the app has to be either a system app (not just root) or signed by the same signature used to sign the frameworks. Hence, if an app has to use R_SUBMIX, it has to be either a system app or signed with the same certificate as that of the system frameworks.

Great! Now you know why screencam requires magisk and why internal recording is not possible with systemizing the app. The next frequent question users ask is, how do I hear the audio via speaker while recording the audio? Well, the answer is tricky.

4. Fixing the internal audio recording:

First, this is not exactly a fix. Second, this is not something to be done by a average user. You could theoretically “fix” this problem if you are on a custom ROM and your ROM developer is interested in fixing it for you.

Thanks to PixelExperience team, the above commit brings in internal audio recording for the ROM using R_SUBMIX but also allows the audio to be routed via the speaker at the same time. Voila!

If you are interested in getting this for your phone, ask your ROM developer to cherry pick the above commit in their ROM.

Leave a Reply