Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[camera] Set encoding bitrate to recording bitrate (fixes 38787) #2426

Closed
wants to merge 6 commits into from

Conversation

cfchris
Copy link

@cfchris cfchris commented Dec 16, 2019

Description

This fixes flutter/flutter#38787. The code I added is the code that was suggested by the issue author.

I had the same problem as the issue author (garbled, tinny sound in Android Video). I applied their fix and it fixed the issue. (Sound is now nice and clear.)

Related Issues

fixes flutter/flutter#38787

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@cfchris cfchris changed the title [camera] Set encoding bitrate to recording bitrate (fixes flutter/flutter#38787) [camera] Set encoding bitrate to recording bitrate (fixes 38787) Dec 16, 2019
@cfchris
Copy link
Author

cfchris commented Dec 16, 2019

Full disclosure.

I followed the CONTRIBUTING.md to the best of my ability. The flutter test and .gradlew test both passed. (And of course manual testing.) But, the "integration/drive" tests started and never finished (on both my phone and Android emulator).

So, I know the code "works". And I'm hoping the automated tests here (or a reviewer with a better setup) will confirm that all of the various tests pass.

@cfchris
Copy link
Author

cfchris commented Dec 17, 2019

Yes! All 17 checks have passed!

Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! The fix here LG, but all PRs need to have automated tests before we can merge them into the tree. See Tree Hygiene #4.

Unfortunately adding tests for this is going to be tricky. I think the best bet would be adding a JUnit test in Android Studio or another Java IDE for Camera.java, and then making sure that setAudioEncodingBitRate is called. There's an existing JUnit test for If there's any possible way you could check for this in an e2e test there's also Flutter driver tests inexample/test_driver`, but from the description on the bug it sounds like this is a difficult thing to test for.

What do you think?

@cfchris
Copy link
Author

cfchris commented Dec 18, 2019

Is there an existing test file where I can making sure that setAudioEncodingBitRate is called?

I looked for the setter above it in the project and only found the one call in the file I edited. If I had found a similar test, I would have tried to use that convention to add a new test/assert/etc.

If there is an existing file to add test code to, I'll attempt it. If there is not, and that requires me to create tests for this existing plugin from scratch, I will not have the bandwidth to do it. (We'll probably have to run the fork for now.)

@mklim
Copy link
Contributor

mklim commented Jan 6, 2020

I don't think we have an existing test case similar to this, thanks for letting us know that you don't have the bandwidth. We'll shepherd the fix forward from here, thanks again for the contribution!

@tvolkert
Copy link
Contributor

@collinjackson would this benefit from some of the testing work you've been overseeing?

@BesartLaci
Copy link

@bparrishMines do you have time to do the review for this fix?
it would be realy nice to get the audio recording working well :)

@kev2513
Copy link

kev2513 commented Feb 17, 2020

I also run in to this problem and I´m glad to find the fix. Because this is a minor fix I would be happy to see it approved.

@baptisteArno
Copy link

Please we need this

@BesartLaci
Copy link

as long as this fix isn`t merged you can specifiy the fixed branch as target for camera package to avoid audio problems on android

dependencies:
  camera:
    git:
      url: https://github.com/DealerPeak/plugins.git
      path: packages/camera
      ref: camera-fix-android-audio

for me it works, ....so 👍 for MR

@leszekkrol
Copy link

leszekkrol commented May 2, 2020

It it possible to merge also this into master. This will add support for flash light on Android

camera: git: url: https://github.com/flutter/plugins.git ref: fba228dd06872b86c270403e9e4ad83f05ab874b path: packages/camera

@jpetro416
Copy link

Is this fixed yet? It's ridiculous that it was even a problem to begin with! Did no one ever take a video?

@cfchris
Copy link
Author

cfchris commented Jul 24, 2020

I fixed the conflicts. You're welcome to merge any time you want...

In the meantime, I pinned my dependency to this branch on our fork.

@cfchris
Copy link
Author

cfchris commented Oct 2, 2020

Really you guys. This is very frustrating. (cc @mklim @bparrishMines)

If you don't want my PR, then, let me know.

But, please, do the following (on an Android phone):

  1. Clone your repo
  2. cd packages/camera/example/
  3. flutter run (usb debugging)
  4. pick a camera and record a video
  5. listen to the playback (IT'S GARBLED)

Audio on Android sounds bad. It takes one line of code to fix it. I get that you have rules. But, this is embarassing. Nobody that wants to do any video recording with audio on Android can do so with the official camera plugin.

@@ -125,6 +125,7 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
// There's a specific order that mediaRecorder expects. Do not change the order
// of these function calls.
if (enableAudio) mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
if (enableAudio) mediaRecorder.setAudioEncodingBitRate(recordingProfile.audioBitRate);
Copy link
Author

@cfchris cfchris Oct 2, 2020

Choose a reason for hiding this comment

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

This is it guys. @mklim @tvolkert @BesartLaci @kev2513 @bparrishMines

Do you not trust that this fixes it? Without this change, I couldn't have launched our app (which is in production with hundreds of users on both iOS and Android). Without this change the audio is garbled.

How do we get this merged?

Copy link
Contributor

Choose a reason for hiding this comment

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

@cfchris some of our plugin PRs are in a state where we're transitioning ownership of them from the "core Flutter team" to community owners, and unfortunately, your PR got caught in that transition. I apologize. We'll try to make sure this gets unblocked in the next few days.

If you don't have resolution by next Friday (Oct 9), please ping me, and I'll make sure this is resolved.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you so much @tvolkert !

I know there are a bunch of people that are going to be very happy to have this fixed and switch back to the main repo instead of our various forks.

@mvanbeusekom mvanbeusekom mentioned this pull request Oct 8, 2020
13 tasks
@mvanbeusekom
Copy link
Contributor

@cfchris I took the liberty to write the necessary unit-tests to make sure the code is covered. Unfortunately I couldn't add find your fork in the "compare across forks" list when creating a PR and decided to just create a new PR (#3124) on the flutter/plugins repo. Of course I based my changes on your fork so your commits will also be included in the new PR.

It would be great if you can have a look and if you agree with the changes leave a comment with the text @googlebot I consent., so the Google bot will assign the CLA:yes label to the PR and we can get this merged.

@cfchris
Copy link
Author

cfchris commented Oct 8, 2020

@mvanbeusekom thank you so much for moving this forward. I looked at your code and it looks good. The one last thing I'm going to do is clone your fork and test the example app with your code changes. If that works, I'll add that consent.

@cfchris
Copy link
Author

cfchris commented Oct 8, 2020

I'm withdrawing this PR. It is replaced by pull request #3124.

@cfchris cfchris closed this Oct 8, 2020
@cfchris cfchris deleted the camera-fix-android-audio branch September 21, 2021 16:47
@cfchris cfchris restored the camera-fix-android-audio branch September 21, 2021 16:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Camera] Audio quality very bad on android
10 participants