summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andy Hung <hunga@google.com> 2016-03-30 17:06:17 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-03-30 17:06:18 +0000
commit9a99629eaa79a7e6c3bcc0ecf674bd7981fef5a0 (patch)
tree5e76a984186a575c57325af0444f1afc48622ca6
parent725dd4ac85bcc1e9ee8d5322807c19d17d581aa0 (diff)
parent0474773aab24594f4f4d395bf058d6f5b16db958 (diff)
Merge "Stop SoundPool decode if NdkMediaCodec returns null buffers" into nyc-dev
-rw-r--r--media/jni/soundpool/SoundPool.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp
index b63df6fe7ff1..d2dc44045c38 100644
--- a/media/jni/soundpool/SoundPool.cpp
+++ b/media/jni/soundpool/SoundPool.cpp
@@ -554,6 +554,10 @@ static status_t decode(int fd, int64_t offset, int64_t length,
if (bufidx >= 0) {
size_t bufsize;
uint8_t *buf = AMediaCodec_getInputBuffer(codec, bufidx, &bufsize);
+ if (buf == nullptr) {
+ ALOGE("AMediaCodec_getInputBuffer returned nullptr, short decode");
+ break;
+ }
int sampleSize = AMediaExtractor_readSampleData(ex, buf, bufsize);
ALOGV("read %d", sampleSize);
if (sampleSize < 0) {
@@ -563,10 +567,16 @@ static status_t decode(int fd, int64_t offset, int64_t length,
}
int64_t presentationTimeUs = AMediaExtractor_getSampleTime(ex);
- AMediaCodec_queueInputBuffer(codec, bufidx,
+ media_status_t mstatus = AMediaCodec_queueInputBuffer(codec, bufidx,
0 /* offset */, sampleSize, presentationTimeUs,
sawInputEOS ? AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM : 0);
- AMediaExtractor_advance(ex);
+ if (mstatus != AMEDIA_OK) {
+ // AMEDIA_ERROR_UNKNOWN == { -ERANGE -EINVAL -EACCES }
+ ALOGE("AMediaCodec_queueInputBuffer returned status %d, short decode",
+ (int)mstatus);
+ break;
+ }
+ (void)AMediaExtractor_advance(ex);
}
}
@@ -581,6 +591,10 @@ static status_t decode(int fd, int64_t offset, int64_t length,
ALOGV("got decoded buffer size %d", info.size);
uint8_t *buf = AMediaCodec_getOutputBuffer(codec, status, NULL /* out_size */);
+ if (buf == nullptr) {
+ ALOGE("AMediaCodec_getOutputBuffer returned nullptr, short decode");
+ break;
+ }
size_t dataSize = info.size;
if (dataSize > available) {
dataSize = available;
@@ -589,7 +603,14 @@ static status_t decode(int fd, int64_t offset, int64_t length,
writePos += dataSize;
written += dataSize;
available -= dataSize;
- AMediaCodec_releaseOutputBuffer(codec, status, false /* render */);
+ media_status_t mstatus = AMediaCodec_releaseOutputBuffer(
+ codec, status, false /* render */);
+ if (mstatus != AMEDIA_OK) {
+ // AMEDIA_ERROR_UNKNOWN == { -ERANGE -EINVAL -EACCES }
+ ALOGE("AMediaCodec_releaseOutputBuffer returned status %d, short decode",
+ (int)mstatus);
+ break;
+ }
if (available == 0) {
// there might be more data, but there's no space for it
sawOutputEOS = true;
@@ -610,21 +631,21 @@ static status_t decode(int fd, int64_t offset, int64_t length,
}
}
- AMediaCodec_stop(codec);
- AMediaCodec_delete(codec);
- AMediaExtractor_delete(ex);
+ (void)AMediaCodec_stop(codec);
+ (void)AMediaCodec_delete(codec);
+ (void)AMediaExtractor_delete(ex);
if (!AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_SAMPLE_RATE, (int32_t*) rate) ||
!AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_CHANNEL_COUNT, numChannels)) {
- AMediaFormat_delete(format);
+ (void)AMediaFormat_delete(format);
return UNKNOWN_ERROR;
}
- AMediaFormat_delete(format);
+ (void)AMediaFormat_delete(format);
*memsize = written;
return OK;
}
- AMediaFormat_delete(format);
+ (void)AMediaFormat_delete(format);
}
- AMediaExtractor_delete(ex);
+ (void)AMediaExtractor_delete(ex);
return UNKNOWN_ERROR;
}