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

Quick voice check hack #4964

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions media/audio/android/aaudio_output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ AAudioOutputStream::AAudioOutputStream(AudioManagerAndroid* manager,
switch (params.latency_tag()) {
case AudioLatency::LATENCY_EXACT_MS:
case AudioLatency::LATENCY_INTERACTIVE:
#define DISABLE_PERFORMANCE_MODE_HACK 1

#if !DISABLE_PERFORMANCE_MODE_HACK
case AudioLatency::LATENCY_RTC:
performance_mode_ = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY;
break;
case AudioLatency::LATENCY_PLAYBACK:
performance_mode_ = AAUDIO_PERFORMANCE_MODE_POWER_SAVING;
break;
#endif
default:
performance_mode_ = AAUDIO_PERFORMANCE_MODE_NONE;
}
Expand Down
22 changes: 21 additions & 1 deletion media/audio/android/opensles_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,26 @@ OpenSLESInputStream::OpenSLESInputStream(AudioManagerAndroid* audio_manager,

const SampleFormat kSampleFormat = kSampleFormatS16;

format_.formatType = SL_DATAFORMAT_PCM;
#if !FORMAT_HACK
LOG(WARNING) << "====bugbug: Using normal Chrome conf===";
format_.formatType = SL_DATAFORMAT_PCM;
format_.numChannels = static_cast<SLuint32>(params.channels());
// Provides sampling rate in milliHertz to OpenSLES.
format_.samplesPerSec = static_cast<SLuint32>(params.sample_rate() * 1000);
format_.bitsPerSample = format_.containerSize =
SampleFormatToBitsPerChannel(kSampleFormat);
format_.endianness = SL_BYTEORDER_LITTLEENDIAN;
format_.channelMask = ChannelCountToSLESChannelMask(params.channels());
#else
LOG(WARNING) << "====bugbug: Using Cobalt hardcoded conf===";
format_.formatType = SL_ANDROID_DATAFORMAT_PCM_EX;
format_.numChannels = static_cast<SLuint32>(params.channels());
format_.sampleRate = static_cast<SLuint32>(params.sample_rate() * 1000);
format_.bitsPerSample = format_.containerSize = SampleFormatToBitsPerChannel(kSampleFormat);
format_.channelMask = SL_SPEAKER_FRONT_CENTER;
format_.endianness = SL_BYTEORDER_LITTLEENDIAN;
format_.representation = SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT;
#endif

buffer_size_bytes_ = params.GetBytesPerBuffer(kSampleFormat);
hardware_delay_ = base::Seconds(params.frames_per_buffer() /
Expand Down Expand Up @@ -249,9 +261,17 @@ bool OpenSLESInputStream::CreateRecorder() {

// Uses the main microphone tuned for audio communications if effects are
// enabled and disables all audio processing if effects are disabled.
#define INPUT_PRESET_HACK 1

#if !INPUT_PRESET_HACK
SLint32 stream_type = no_effects_
? SL_ANDROID_RECORDING_PRESET_CAMCORDER
: SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
#else
// This is how Cobalt/Starboard sets it
SLint32 stream_type = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
#endif

LOG_ON_FAILURE_AND_RETURN(
(*recorder_config)->SetConfiguration(recorder_config,
SL_ANDROID_KEY_RECORDING_PRESET,
Expand Down
6 changes: 6 additions & 0 deletions media/audio/android/opensles_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ class OpenSLESInputStream : public AudioInputStream {
// Buffer queue recorder interface.
SLAndroidSimpleBufferQueueItf simple_buffer_queue_;

#define FORMAT_HACK 0

#if !FORMAT_HACK
SLDataFormat_PCM format_;
#else
SLAndroidDataFormat_PCM_EX format_;
#endif

// Audio buffers that are allocated in the constructor based on
// info from audio parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void setCommunicationAudioModeOnInternal(boolean on) {

if (on) {
try {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
// mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
} catch (SecurityException e) {
logDeviceInfo();
throw e;
Expand Down
Loading