Skip to content

Commit

Permalink
Fix #192 - Cannot open recording stream on Moto G
Browse files Browse the repository at this point in the history
  • Loading branch information
dturner committed Sep 5, 2018
1 parent a76ed67 commit 462d5a6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/opensles/AudioInputStreamOpenSLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Result AudioInputStreamOpenSLES::open() {
channelCountToChannelMask(mChannelCount), // channelMask
getDefaultByteOrder(),
};
bool usingExtendedDataFormat = false;

SLDataSink audioSink = {&loc_bufq, &format_pcm};

Expand All @@ -112,6 +113,7 @@ Result AudioInputStreamOpenSLES::open() {
format_pcm_ex = OpenSLES_createExtendedFormat(format_pcm, representation);
// Use in place of the previous format.
audioSink.pFormat = &format_pcm_ex;
usingExtendedDataFormat = true;
}


Expand All @@ -125,11 +127,29 @@ Result AudioInputStreamOpenSLES::open() {
SLresult result = EngineOpenSLES::getInstance().createAudioRecorder(&mObjectInterface,
&audioSrc,
&audioSink);

// If the result is "invalid parameter" and we're using the extended data format it could be
// that the underlying hardware doesn't support it
// (e.g. Moto G: https://github.com/google/oboe/issues/192)
// Try again using the old format
if (result == SL_RESULT_PARAMETER_INVALID && usingExtendedDataFormat){

LOGW("Unable to open recording stream using PCM_EX format, trying again using PCM...");
audioSink.pFormat = &format_pcm;
result = EngineOpenSLES::getInstance().createAudioRecorder(&mObjectInterface,
&audioSrc,
&audioSink);
}

if (SL_RESULT_SUCCESS != result) {
LOGE("createAudioRecorder() result:%s", getSLErrStr(result));
goto error;
}

// If the stream is not using the extended data format it must have a format of I16 since no
// other format is supported, regardless of what format was requested.
if (!usingExtendedDataFormat) mFormat = AudioFormat::I16;

// Configure the stream.
result = (*mObjectInterface)->GetInterface(mObjectInterface,
SL_IID_ANDROIDCONFIGURATION,
Expand Down

0 comments on commit 462d5a6

Please sign in to comment.