summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2015-06-09 22:27:14 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-09 22:27:15 +0000
commit4e384ca65e5fd3eabac0621bed98f937d8a263c5 (patch)
treebaef63e63e5c2538bed3d5581aecc28e020a963a
parent26f9a1c4c14b0f7da8b0d60ffcecbf5e221d15c5 (diff)
parent71065fbf12abafd4c2a0dc85c81f13b564ff69fb (diff)
downloadandroid_frameworks_wilhelm-4e384ca65e5fd3eabac0621bed98f937d8a263c5.tar.gz
android_frameworks_wilhelm-4e384ca65e5fd3eabac0621bed98f937d8a263c5.tar.bz2
android_frameworks_wilhelm-4e384ca65e5fd3eabac0621bed98f937d8a263c5.zip
Merge "Check sample size in addition to container size" into mnc-dev
-rw-r--r--src/android/AudioPlayer_to_android.cpp13
-rw-r--r--src/android/AudioRecorder_to_android.cpp13
-rw-r--r--src/android/android_sles_conversions.h3
-rw-r--r--src/data.c7
4 files changed, 30 insertions, 6 deletions
diff --git a/src/android/AudioPlayer_to_android.cpp b/src/android/AudioPlayer_to_android.cpp
index 1771b5f..e887d1a 100644
--- a/src/android/AudioPlayer_to_android.cpp
+++ b/src/android/AudioPlayer_to_android.cpp
@@ -954,6 +954,7 @@ SLresult android_audioPlayer_checkSourceSink(CAudioPlayer *pAudioPlayer)
df_representation = &df_pcm->representation;
} // SL_ANDROID_DATAFORMAT_PCM_EX - fall through to next test.
case SL_DATAFORMAT_PCM: {
+ // checkDataFormat() already did generic checks, now do the Android-specific checks
const SLDataFormat_PCM *df_pcm = (const SLDataFormat_PCM *) pAudioSrc->pFormat;
SLresult result = android_audioPlayer_validateChannelMask(df_pcm->channelMask,
df_pcm->numChannels);
@@ -972,9 +973,19 @@ SLresult android_audioPlayer_checkSourceSink(CAudioPlayer *pAudioPlayer)
// upcoming check by sles_to_android_channelMaskOut are sufficient
if (df_pcm->endianness != pAudioPlayer->mObject.mEngine->mEngine.mNativeEndianness) {
- SL_LOGE("Cannot create audio player: unsupported byte order %u", df_pcm->endianness);
+ SL_LOGE("Cannot create audio player: unsupported byte order %u",
+ df_pcm->endianness);
return SL_RESULT_CONTENT_UNSUPPORTED;
}
+
+ // we don't support container size != sample depth
+ if (df_pcm->containerSize != df_pcm->bitsPerSample) {
+ SL_LOGE("Cannot create audio player: unsupported container size %u bits for "
+ "sample depth %u bits",
+ df_pcm->containerSize, (SLuint32)df_pcm->bitsPerSample);
+ return SL_RESULT_CONTENT_UNSUPPORTED;
+ }
+
} //case SL_DATAFORMAT_PCM
break;
case SL_DATAFORMAT_MIME:
diff --git a/src/android/AudioRecorder_to_android.cpp b/src/android/AudioRecorder_to_android.cpp
index e5fbc26..77ef589 100644
--- a/src/android/AudioRecorder_to_android.cpp
+++ b/src/android/AudioRecorder_to_android.cpp
@@ -179,14 +179,23 @@ SLresult android_audioRecorder_checkSourceSink(CAudioRecorder* ar) {
ar->mNumChannels = df_pcm->numChannels;
if (df_pcm->endianness != ar->mObject.mEngine->mEngine.mNativeEndianness) {
- SL_LOGE("Cannot create audio recorder: unsupported byte order %u", df_pcm->endianness);
+ SL_LOGE("Cannot create audio recorder: unsupported byte order %u",
+ df_pcm->endianness);
return SL_RESULT_CONTENT_UNSUPPORTED;
}
ar->mSampleRateMilliHz = df_pcm->samplesPerSec; // Note: bad field name in SL ES
SL_LOGV("AudioRecorder requested sample rate = %u mHz, %u channel(s)",
ar->mSampleRateMilliHz, ar->mNumChannels);
- // FIXME validates bitsPerSample
+
+ // we don't support container size != sample depth
+ if (df_pcm->containerSize != df_pcm->bitsPerSample) {
+ SL_LOGE("Cannot create audio recorder: unsupported container size %u bits for "
+ "sample depth %u bits",
+ df_pcm->containerSize, (SLuint32)df_pcm->bitsPerSample);
+ return SL_RESULT_CONTENT_UNSUPPORTED;
+ }
+
} break;
default:
SL_LOGE(ERROR_RECORDER_SINK_FORMAT_MUST_BE_PCM);
diff --git a/src/android/android_sles_conversions.h b/src/android/android_sles_conversions.h
index 277c471..05b4699 100644
--- a/src/android/android_sles_conversions.h
+++ b/src/android/android_sles_conversions.h
@@ -27,6 +27,9 @@ static inline uint32_t sles_to_android_sampleRate(SLuint32 sampleRateMilliHertz)
}
static inline audio_format_t sles_to_android_sampleFormat(const SLDataFormat_PCM *df_pcm) {
+ if (df_pcm->containerSize != df_pcm->bitsPerSample) {
+ return AUDIO_FORMAT_INVALID;
+ }
switch (df_pcm->formatType) {
case SL_DATAFORMAT_PCM:
switch (df_pcm->containerSize) {
diff --git a/src/data.c b/src/data.c
index 26208b7..575bd53 100644
--- a/src/data.c
+++ b/src/data.c
@@ -401,7 +401,7 @@ static SLresult checkDataFormat(const char *name, void *pFormat, DataFormat *pDa
break;
}
- // check the container bit depth
+ // check the container bit depth and representation
switch (pDataFormat->mPCM.containerSize) {
case 8:
if (df_representation != NULL &&
@@ -432,8 +432,9 @@ static SLresult checkDataFormat(const char *name, void *pFormat, DataFormat *pDa
break;
}
- // container size cannot be less than sample size
- if (pDataFormat->mPCM.containerSize < pDataFormat->mPCM.bitsPerSample) {
+ // sample size cannot be zero, and container size cannot be less than sample size
+ if (pDataFormat->mPCM.bitsPerSample == 0 ||
+ pDataFormat->mPCM.containerSize < pDataFormat->mPCM.bitsPerSample) {
result = SL_RESULT_PARAMETER_INVALID;
}
if (SL_RESULT_SUCCESS != result) {