Status Update
Comments
ub...@gmail.com <ub...@gmail.com> #2
If that's not the case and I change the microphone source, it would affect the sound quality as well.
Edit: Probably on the Mac program `Audio MIDI Setup` the sound source format is changed to a lower bitrate
sa...@google.com <sa...@google.com> #3
I've tried the Audio MIDI Setup program, but it doesn't show any changes for my headphones that are bluetooth connected with a USB dongle.
aq...@google.com <aq...@google.com> #5
I don't think that is what is happening. For me, when the emulator launches, it changes the macOS input device from the internal speaker to my headphones which switches the bt profile to a2dp.
As a temporary workaround, I set hw.audioInput=no
in my avd config.ini and it seemed to help.
aq...@google.com <aq...@google.com> #6
aq...@google.com <aq...@google.com> #7
ub...@gmail.com <ub...@gmail.com> #8
ub...@gmail.com <ub...@gmail.com> #9
ub...@gmail.com <ub...@gmail.com> #10
ub...@gmail.com <ub...@gmail.com> #11
Which is almost a year old, guys!
ub...@gmail.com <ub...@gmail.com> #12
As a temporary workaround,
ub...@gmail.com <ub...@gmail.com> #13
config.ini do the fix, thanks!
source: #5 comment
- Device manager -> virtual device dropdown menu -> Show on Disk
- open config.ini and add this line: hw.audioInput=no
ub...@gmail.com <ub...@gmail.com> #14
config.ini changes don't seem to work for me - tried on various emulators with API level 31+. Both freshly installed emulators and existing ones.
ub...@gmail.com <ub...@gmail.com> #15
Hi. I am sorry for the issues around sound quality. I am working on a new sound card, this bug will be the next issue I will be working on.
aq...@google.com <aq...@google.com> #16
I was able to repro this with bluetooth headphones, it does not repro with laptop speakers somehow. It happens very early, even before the kernel is loaded.
aq...@google.com <aq...@google.com> #17
Bluetooth audio devices switch operating modes when used as: a) Speaker only (simplex, only supports audio out and up to stereo 48KHz sampling rate) b) Speakers + Microphone (duplex, supports both mono audio in and out at 8 or 16 Khz sampling rate)
Devices are usually by default in mode a, as soon as a sw opens the the microphone they switch to mode b and therefore any audio being reproduced suddenly jumps from 48 to 16khz and the quality gap can be clearly heard. Some drivers even have different volume settings between the 2 modes and when switching mode the volume can suddenly jump up or down.
This is why you can't repro with built in laptop speakers: their sound card is not a bluetooth device and hence doesn't have this peculiar behavior.
ub...@gmail.com <ub...@gmail.com> #18
Thank you for the details. To me this sounds like, bluetooth headphones have to switch to 16Khz if we want to use their microphone in the emulator. One way of fixing this is to avoid touching the microphone in the emulator unless we want to record from it. As a quick fix, it is possible to switch the audio input in MacOS to the "Internal microphone" then the running emulator does not affect audio quality.
ub...@gmail.com <ub...@gmail.com> #19
To me this sounds like, bluetooth headphones have to switch to 16Khz if we want to use their microphone in the emulator.
Correct. There’s no way out from here.
One way of fixing this is to avoid touching the microphone in the emulator unless we want to record from it.
Indeed. And closing the mike as soon as finishing recording.
As a quick fix, it is possible to switch the audio input in MacOS to the "Internal microphone" then the running emulator does not affect audio quality.
Yes. This is how most of us are coping with this since years :) but every time you disconnect and reconnect the bt headphones the system automatically reselects them as microphone. So it’s easy to retrigger this unpleasant behavior.
ub...@gmail.com <ub...@gmail.com> #20
AUD_open_in
(as well as _out
) is called twice: in
#0 AUD_open_out (card=card@entry=0x7b1f178, sw=sw@entry=0x0, name=0x2759e5 "goldfish_audio", callback_opaque=callback_opaque@entry=0x7b1ed00,
callback_fn=0x1155300 <goldfish_audio_callback>, as=as@entry=0x7fffe03b3fc0) at ../audio/audio_template.h:399
#1 0x0000000001155208 in goldfish_audio_realize (dev=<optimized out>, errp=<optimized out>) at ../hw/audio/goldfish_audio.c:450
#2 0x0000000001176890 in device_set_realized (obj=<optimized out>, value=true, errp=0x7fffe03b4118) at ../hw/core/qdev.c:852
#3 0x0000000001247fdc in property_set_bool (obj=0x7b1ed00, v=<optimized out>, name=<optimized out>, opaque=0x7a4b210, errp=0x7fffe03b4118)
at ../qom/object.c:1923
#4 0x00000000012498ed in object_property_set_qobject (obj=0x7b1f178, value=<optimized out>, name=0x2759e5 "goldfish_audio", errp=0x7b1ed00)
at ../qom/qom-qobject.c:27
#5 0x00000000012467cc in object_property_set_bool (obj=0x7b1f178, value=<optimized out>, name=0x2759e5 "goldfish_audio", errp=0x7b1ed00)
at ../qom/object.c:1188
#6 0x000000000117541f in qdev_init_nofail (dev=dev@entry=0x7b1ed00) at ../hw/core/qdev.c:339
#7 0x0000000001177ef3 in sysbus_create_varargs (name=<optimized out>, addr=addr@entry=4278267904) at ../hw/core/sysbus.c:226
#8 0x0000000001083cf0 in sysbus_create_simple (name=0x7b1f178 " \263\244\a", addr=4278267904, irq=0x2759e5) at ../include/hw/sysbus.h:111
#9 pc_init1 (machine=0x3b25880, host_type=<optimized out>, pci_type=<optimized out>) at ../hw/i386/pc_piix.c:288
#10 0x000000000116fa72 in machine_run_board_init (machine=0x3b25880) at ../hw/core/machine.c:829
#11 0x000000000109b4c5 in main_impl (argc=<optimized out>, argv=<optimized out>,
on_main_loop_done=0x10959a0 <enter_qemu_main_loop(int, char**)::$_4::__invoke()>) at ../vl.c:5533
#12 0x0000000001097746 in run_qemu_main (argc=129102200, argv=0x0, on_main_loop_done=0x2759e5) at ../vl.c:3360
#13 0x0000000001092c3a in enter_qemu_main_loop (argc=112, argv=0x3b24e00) at ../android-qemu2-glue/main.cpp:731
#14 0x00007ffff7320233 in QThreadPrivate::start (arg=0x3a9a420)
at /usr/local/google/home/wdu/build-qt/src/qt-everywhere-src-5.12.1/qtbase/src/corelib/thread/qthread_unix.cpp:361
#15 0x00007ffff79d4d80 in start_thread (arg=0x7fffe03b5640) at pthread_create.c:481
#16 0x00007ffff6396bdf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
#0 AUD_open_in (card=card@entry=0x7b1f178, sw=sw@entry=0x0, name=0x392aaf "goldfish_audio_in", callback_opaque=callback_opaque@entry=0x7b1ed00,
callback_fn=0x11554a0 <goldfish_audio_in_callback>, as=as@entry=0x7fffe03b3fc0) at ../audio/audio_template.h:399
#1 0x0000000001155280 in goldfish_audio_realize (dev=<optimized out>, errp=<optimized out>) at ../hw/audio/goldfish_audio.c:471
#2 0x0000000001176890 in device_set_realized (obj=<optimized out>, value=true, errp=0x7fffe03b4118) at ../hw/core/qdev.c:852
#3 0x0000000001247fdc in property_set_bool (obj=0x7b1ed00, v=<optimized out>, name=<optimized out>, opaque=0x7a4b210, errp=0x7fffe03b4118)
at ../qom/object.c:1923
#4 0x00000000012498ed in object_property_set_qobject (obj=0x7b1f178, value=<optimized out>, name=0x392aaf "goldfish_audio_in", errp=0x7b1ed00)
at ../qom/qom-qobject.c:27
#5 0x00000000012467cc in object_property_set_bool (obj=0x7b1f178, value=<optimized out>, name=0x392aaf "goldfish_audio_in", errp=0x7b1ed00)
at ../qom/object.c:1188
#6 0x000000000117541f in qdev_init_nofail (dev=dev@entry=0x7b1ed00) at ../hw/core/qdev.c:339
#7 0x0000000001177ef3 in sysbus_create_varargs (name=<optimized out>, addr=addr@entry=4278267904) at ../hw/core/sysbus.c:226
#8 0x0000000001083cf0 in sysbus_create_simple (name=0x7b1f178 " \263\244\a", addr=4278267904, irq=0x392aaf) at ../include/hw/sysbus.h:111
#9 pc_init1 (machine=0x3b25880, host_type=<optimized out>, pci_type=<optimized out>) at ../hw/i386/pc_piix.c:288
#10 0x000000000116fa72 in machine_run_board_init (machine=0x3b25880) at ../hw/core/machine.c:829
#11 0x000000000109b4c5 in main_impl (argc=<optimized out>, argv=<optimized out>,
on_main_loop_done=0x10959a0 <enter_qemu_main_loop(int, char**)::$_4::__invoke()>) at ../vl.c:5533
#12 0x0000000001097746 in run_qemu_main (argc=129102200, argv=0x0, on_main_loop_done=0x392aaf) at ../vl.c:3360
#13 0x0000000001092c3a in enter_qemu_main_loop (argc=112, argv=0x3b24e00) at ../android-qemu2-glue/main.cpp:731
#14 0x00007ffff7320233 in QThreadPrivate::start (arg=0x3a9a420)
at /usr/local/google/home/wdu/build-qt/src/qt-everywhere-src-5.12.1/qtbase/src/corelib/thread/qthread_unix.cpp:361
#15 0x00007ffff79d4d80 in start_thread (arg=0x7fffe03b5640) at pthread_create.c:481
#16 0x00007ffff6396bdf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
#0 AUD_open_out (card=0x5086388, sw=0x0, name=0x2d9383 "dac", callback_opaque=callback_opaque@entry=0x50863a8,
callback_fn=0x1156820 <hda_audio_output_cb>, as=as@entry=0x50863d4) at ../audio/audio_template.h:399
#1 0x000000000115677f in hda_audio_setup (st=0x50863a8) at ../hw/audio/hda-codec.c:288
#2 0x0000000001156c8d in hda_audio_init (hda=hda@entry=0x5086300, desc=<optimized out>) at ../hw/audio/hda-codec.c:520
#3 0x0000000001156e34 in hda_audio_init_duplex (hda=0x5086300) at ../hw/audio/hda-codec.c:640
#4 0x00000000011590c3 in hda_codec_dev_realize (qdev=<optimized out>, errp=0x7fffe03b4288) at ../hw/audio/intel-hda.c:69
#5 0x0000000001176890 in device_set_realized (obj=<optimized out>, value=true, errp=0x7fffe03b4378) at ../hw/core/qdev.c:852
#6 0x0000000001247fdc in property_set_bool (obj=0x5086300, v=<optimized out>, name=<optimized out>, opaque=0x9604650, errp=0x7fffe03b4378)
at ../qom/object.c:1923
#7 0x00000000012498ed in object_property_set_qobject (obj=0x5086388, value=<optimized out>, name=0x2d9383 "dac", errp=0x50863a8)
at ../qom/qom-qobject.c:27
#8 0x00000000012467cc in object_property_set_bool (obj=0x5086388, value=<optimized out>, name=0x2d9383 "dac", errp=0x50863a8)
at ../qom/object.c:1188
#9 0x000000000117541f in qdev_init_nofail (dev=0x5086300) at ../hw/core/qdev.c:339
#10 0x000000000115713c in intel_hda_and_codec_init (bus=<optimized out>) at ../hw/audio/intel-hda.c:1355
#11 0x00000000011594d6 in soundhw_init () at ../hw/audio/soundhw.c:151
#12 0x000000000109b514 in main_impl (argc=<optimized out>, argv=<optimized out>,
on_main_loop_done=0x10959a0 <enter_qemu_main_loop(int, char**)::$_4::__invoke()>) at ../vl.c:5554
#13 0x0000000001097746 in run_qemu_main (argc=84435848, argv=0x0, on_main_loop_done=0x2d9383) at ../vl.c:3360
#14 0x0000000001092c3a in enter_qemu_main_loop (argc=112, argv=0x3b24e00) at ../android-qemu2-glue/main.cpp:731
#15 0x00007ffff7320233 in QThreadPrivate::start (arg=0x3a9a420)
at /usr/local/google/home/wdu/build-qt/src/qt-everywhere-src-5.12.1/qtbase/src/corelib/thread/qthread_unix.cpp:361
#16 0x00007ffff79d4d80 in start_thread (arg=0x7fffe03b5640) at pthread_create.c:481
#17 0x00007ffff6396bdf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
#0 AUD_open_in (card=0x5086388, sw=0x0, name=0x392af6 "adc", callback_opaque=callback_opaque@entry=0x50864f8,
callback_fn=0x1155910 <hda_audio_input_cb>, as=as@entry=0x5086524) at ../audio/audio_template.h:399
#1 0x000000000115680c in hda_audio_setup (st=0x50864f8) at ../hw/audio/hda-codec.c:293
#2 0x0000000001156c8d in hda_audio_init (hda=hda@entry=0x5086300, desc=<optimized out>) at ../hw/audio/hda-codec.c:520
#3 0x0000000001156e34 in hda_audio_init_duplex (hda=0x5086300) at ../hw/audio/hda-codec.c:640
#4 0x00000000011590c3 in hda_codec_dev_realize (qdev=<optimized out>, errp=0x7fffe03b4288) at ../hw/audio/intel-hda.c:69
#5 0x0000000001176890 in device_set_realized (obj=<optimized out>, value=true, errp=0x7fffe03b4378) at ../hw/core/qdev.c:852
#6 0x0000000001247fdc in property_set_bool (obj=0x5086300, v=<optimized out>, name=<optimized out>, opaque=0x9604650, errp=0x7fffe03b4378)
at ../qom/object.c:1923
#7 0x00000000012498ed in object_property_set_qobject (obj=0x5086388, value=<optimized out>, name=0x392af6 "adc", errp=0x50864f8)
at ../qom/qom-qobject.c:27
#8 0x00000000012467cc in object_property_set_bool (obj=0x5086388, value=<optimized out>, name=0x392af6 "adc", errp=0x50864f8)
at ../qom/object.c:1188
#9 0x000000000117541f in qdev_init_nofail (dev=0x5086300) at ../hw/core/qdev.c:339
#10 0x000000000115713c in intel_hda_and_codec_init (bus=<optimized out>) at ../hw/audio/intel-hda.c:1355
#11 0x00000000011594d6 in soundhw_init () at ../hw/audio/soundhw.c:151
#12 0x000000000109b514 in main_impl (argc=<optimized out>, argv=<optimized out>,
on_main_loop_done=0x10959a0 <enter_qemu_main_loop(int, char**)::$_4::__invoke()>) at ../vl.c:5554
#13 0x0000000001097746 in run_qemu_main (argc=84435848, argv=0x0, on_main_loop_done=0x392af6) at ../vl.c:3360
#14 0x0000000001092c3a in enter_qemu_main_loop (argc=112, argv=0x3b24e00) at ../android-qemu2-glue/main.cpp:731
#15 0x00007ffff7320233 in QThreadPrivate::start (arg=0x3a9a420)
at /usr/local/google/home/wdu/build-qt/src/qt-everywhere-src-5.12.1/qtbase/src/corelib/thread/qthread_unix.cpp:361
#16 0x00007ffff79d4d80 in start_thread (arg=0x7fffe03b5640) at pthread_create.c:481
#17 0x00007ffff6396bdf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
aq...@google.com <aq...@google.com> #21
BTW, I am migrating us to
aq...@google.com <aq...@google.com> #22
Not opening the microphone at all is definitely a strategy. I don't think many people actually do record sound with the emulator (but happy to be proven wrong). Or perhaps adding a default-off checkbox in the emulator settings to explicitly enable the microphone only when actually needed could be another way to go.
ub...@gmail.com <ub...@gmail.com> #23
I suspect there could be a reason (probably not a very good one) why sound cards are implemented this way. I XRUN
because some global variables compare in a certain way) similar to what I am having in virtio-snd currently. So, I
aq...@google.com <aq...@google.com> #24
I'm sorry but I only have high level knowledge of this stuff so I can't help much when it comes to linux drivers. But I'll be happy to try out any pre-release should this be of help!
py...@squareup.com <py...@squareup.com> #25
I believe this is not a kernel, but some weird assumptions in qemu which break if we open a device moments before using it or in a wrong thread. If you happen to have a linux machine and willing to build and play with our emulator, we will be happy to take a patch from you :) From here I will be working on virtio-snd first and then I will try to figure out if we can -no-microphone
.
aq...@google.com <aq...@google.com> #26
This looks like not an easy issue to fix! I also personally dislike fixing race-condition bugs by adding delays as these bugs could resurface back after some time.
Do you think we could disable mic by default and add an option to manually enable it for those who need it? The audio recording isn't a main stream feature for many developers
ko...@gmail.com <ko...@gmail.com> #27
This looks like not an easy issue to fix! ... as these bugs could resurface back after some time.
I agree :(
we could disable mic by default
If we go this way, we probably want to add an option to disable it.
aq...@google.com <aq...@google.com> #28
If we go this way, we probably want to add an option to disable it.
This also works, at least we could disable mic manually and have the sound quality back. Do you think you could use it as a short term fix while you are looking for a better solution?
aq...@google.com <aq...@google.com> #29
a short term fix while you are looking for a better solution?
I'll talk about it on our weekly meeting on Tuesday.
aq...@google.com <aq...@google.com> #30
na...@google.com <na...@google.com> #31
ke...@gmail.com <ke...@gmail.com> #32
ke...@gmail.com <ke...@gmail.com> #33
I figured out how to pass runtime values into virtio-snd
and hda-duplex
, we should be able to avoid opening the microphone in those devices. When I tried the same with goldfish_audio
, the QEMU says -device goldfish_audio,debug=42: Parameter 'driver' expects pluggable device type
. We probably want to retire (not sure if we can just disable it) this device instead of hacking it further.
aq...@google.com <aq...@google.com> #34
I merged a
ke...@gmail.com <ke...@gmail.com> #35
"Sounds like" (pun intended) a very good improvement!
BTW: What decides which audio driver to use (I mean with which logic virtio-snd
or hda-duplex
or goldfish_audio
is used) ?
Description
The essential output from LeakCanary for API level 19:
* GC ROOT android.os.Handler$MessengerImpl.this$0
* references android.support.v4.media.MediaBrowserServiceCompat$ServiceHandler.this$0
* leaks com.bubenheimer.mbscl.BrowserService instance
For API level 25 (21-24 are equivalent):
* GC ROOT android.service.media.MediaBrowserService$ServiceBinder.this$0
* references android.support.v4.media.MediaBrowserServiceCompatApi24$MediaBrowserServiceAdaptor.mBase
* leaks com.bubenheimer.mbscl.BrowserService instance
com.bubenheimer.mbscl.BrowserService extends MediaBrowserServiceCompat.
My minimal app is at:
My fork of UniversalMediaPlayer with LeakCanary added:
To reproduce the issue, simply start the app, then hit the back button to close the Activity. The MediaSession gets closed at that point, and the Service is leaked.
The leak occurs also when using plain MediaBrowserService, not just the Compat variant.
I have seen MediaBrowserService get leaked in different ways when it is used more seriously (actually playing music then stopping it, showing and discarding notifications, handling user input, etc.), so when addressing this issue, please also review potential leaks in more complex use cases.
I am using the latest support library version (25.2.0) in my sample app, UniversalMediaPlayer uses 23.4.0. The leak is the same.