Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ffmpeg-kit with libopus and libopusenc #6208

Merged
merged 7 commits into from
Jun 15, 2022

Conversation

jmartinesp
Copy link
Member

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

This replaces ffmpeg-kit, which was used to convert audio files to and from ogg files with opus codec with libopus and a JNI wrapper. This change is only noticeable on devices with Android version < 10, as >= 10 can use Android's own implementation. This also removes the need for converting these files in the first place, as received audio files will already be in ogg format and the ones recorded will be encoded on-the-fly, with no need for post-processing.

Motivation and context

Fixes #6203. It's done mainly to get rid of a dependency and licensing issues for customers.

Tests

Ideally, we should test this on phones or emulators in versions < 10 and >= 10, both recording and playing and on both ARM and x86 archs.

  • Open a room with someone else.
  • Record and send a voice message.
  • Play that voice message.
  • Play some other voice message received from the other user (ideally, from a version without this change).

Tested devices

  • Physical
  • Emulator
  • OS version(s): 12 (emulator), 9 (phone).

Checklist

@jmartinesp jmartinesp requested review from a team, Florian14 and Claire1817 and removed request for a team May 31, 2022 13:32
@jmartinesp jmartinesp self-assigned this May 31, 2022
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2022 New Vector Ltd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should keep the original copyright.

Also, maybe create a doc to explain where does this code come from?

Copy link
Member Author

@jmartinesp jmartinesp May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I wrote this file I guess that's the original copyright? I just changed if from 'written by Jorge Martín on dd/MM' to the vector copyright, since it wasn't applied automatically and I didn't notice before uploading it.
Docs are a good idea, thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, sorry. If you are the author, this is the correct copyright.

@jmartinesp jmartinesp force-pushed the feature/jorgem/6203-remove-usage-of-ffmpeg-kit branch from 837640b to 2c56b21 Compare May 31, 2022 13:53
@github-actions
Copy link

Unit Test Results

146 files  ±0  146 suites  ±0   2m 10s ⏱️ -30s
236 tests ±0  236 ✔️ ±0  0 💤 ±0  0 ±0 
788 runs  ±0  788 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 2c56b21. ± Comparison against base commit 9cf9e10.

@jmartinesp
Copy link
Member Author

Please note that there's no need to review the files in the opus/include directory as they're just included headers from the opus library. This should make the review go from 4400 LoC to ~500.

@jmartinesp jmartinesp requested review from onurays and removed request for Florian14 June 7, 2022 10:06
recordingJob = recorderScope.launch {
while (audioRecorder?.state != AudioRecord.STATE_INITIALIZED) {
// If the recorder is not ready let's give it some extra time
delay(10L)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a reported problem about this or can you reproduce an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I ran into this before, but I can't seem to trigger this situation again. It should always be STATE_INITIALIZED at this point, so I'll just remove it.

* Sampling rate of the input signal in Hz.
*/
sealed class SampleRate private constructor(val value: Int) {
object _8khz : SampleRate(8000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting with _ prefix is not allowed by lint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly can't find a better way to name these and keep the numbers. Any suggestions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end I went with a Rate prefix. It's a bit weird, but it should fix the issue.

@Claire1817
Copy link
Contributor

Code Quality Checks failed, did you check it ? :)

@jmartinesp
Copy link
Member Author

Code Quality Checks failed, did you check it ? :)

Yes, it's related to this: #6208 (comment)

@jmartinesp jmartinesp force-pushed the feature/jorgem/6203-remove-usage-of-ffmpeg-kit branch from 2c56b21 to 1162700 Compare June 7, 2022 15:15
@bmarty
Copy link
Member

bmarty commented Jun 7, 2022

What is the impact on the APK size? I think it will be good, can you check please? Thanks!

@jmartinesp
Copy link
Member Author

What is the impact on the APK size? I think it will be good, can you check please? Thanks!

With FFMPEG-kit:

 53M  8 jun 07:45 vector-gplay-arm64-v8a-release-unsigned.apk
 60M  8 jun 07:45 vector-gplay-armeabi-v7a-release-unsigned.apk
136M  8 jun 07:45 vector-gplay-universal-release-unsigned.apk
 54M  8 jun 07:45 vector-gplay-x86-release-unsigned.apk
 56M  8 jun 07:45 vector-gplay-x86_64-release-unsigned.apk

Without FFMPEG-kit, using libopus:

 45M  8 jun 08:30 vector-gplay-arm64-v8a-release-unsigned.apk
 43M  8 jun 08:30 vector-gplay-armeabi-v7a-release-unsigned.apk
 94M  8 jun 08:30 vector-gplay-universal-release-unsigned.apk
 46M  8 jun 08:30 vector-gplay-x86-release-unsigned.apk
 47M  8 jun 08:30 vector-gplay-x86_64-release-unsigned.apk

Copy link
Contributor

@Claire1817 Claire1817 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with:
Emulator API 31 and Element Web : OK 👍
Emulator API 30 and Emulator API 30: Ok 👍

@jmartinesp jmartinesp requested a review from onurays June 8, 2022 07:28
Copy link
Contributor

@onurays onurays left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement. LGTM, there are merge conflicts to resolve.

@jmartinesp jmartinesp force-pushed the feature/jorgem/6203-remove-usage-of-ffmpeg-kit branch from 1162700 to fd4276f Compare June 9, 2022 11:32
@jmartinesp jmartinesp enabled auto-merge June 9, 2022 11:32
@jmartinesp jmartinesp force-pushed the feature/jorgem/6203-remove-usage-of-ffmpeg-kit branch 2 times, most recently from 3aa7d7d to d1f9c0f Compare June 14, 2022 10:44
@@ -29,7 +29,7 @@ def jjwt = "0.11.5"
def vanniktechEmoji = "0.15.0"

// Testing
def mockk = "1.12.4"
def mockk = "1.12.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to downgrade here? If yes, please add a comment above this line, else Dependabot will change this line again and we will have some trouble.

@@ -337,6 +337,9 @@ android {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.aar", "*.jar"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to add this line? I prefer to add explicit dependencies one by one if any

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry, this was added to test some pre-built libs and I completely forgot to delete it.

@jmartinesp jmartinesp force-pushed the feature/jorgem/6203-remove-usage-of-ffmpeg-kit branch from d1f9c0f to c204f41 Compare June 15, 2022 09:39
@sonarcloud
Copy link

sonarcloud bot commented Jun 15, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

68.0% 68.0% Coverage
0.0% 0.0% Duplication

@bmarty bmarty disabled auto-merge June 15, 2022 13:43
@bmarty bmarty merged commit cbfe0d6 into develop Jun 15, 2022
@bmarty bmarty deleted the feature/jorgem/6203-remove-usage-of-ffmpeg-kit branch June 15, 2022 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove usage of ffmpeg-kit
4 participants