Loading media/tests/benchmark/MediaBenchmarkTest/src/main/java/com/android/media/benchmark/library/Encoder.java +22 −12 Original line number Diff line number Diff line Loading @@ -29,7 +29,9 @@ import java.io.IOException; import java.nio.ByteBuffer; public class Encoder { private static final int ENCODE_DEFAULT_MAX_INPUT_SIZE = 3840; // Change in AUDIO_ENCODE_DEFAULT_MAX_INPUT_SIZE should also be taken to // kDefaultAudioEncodeFrameSize present in BenchmarkCommon.h private static final int AUDIO_ENCODE_DEFAULT_MAX_INPUT_SIZE = 4096; private static final String TAG = "Encoder"; private static final boolean DEBUG = false; private static final int kQueueDequeueTimeoutUs = 1000; Loading Loading @@ -134,7 +136,7 @@ public class Encoder { if (mMime.startsWith("video/")) { mFrameSize = frameSize; } else { int maxInputSize = ENCODE_DEFAULT_MAX_INPUT_SIZE; int maxInputSize = AUDIO_ENCODE_DEFAULT_MAX_INPUT_SIZE; MediaFormat format = mCodec.getInputFormat(); if (format.containsKey(MediaFormat.KEY_MAX_INPUT_SIZE)) { maxInputSize = format.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE); Loading Loading @@ -281,19 +283,27 @@ public class Encoder { return; } int bufSize = inputBuffer.capacity(); int bytesRead = mFrameSize; int bytesToRead = mFrameSize; if (mInputBufferSize - mOffset < mFrameSize) { bytesRead = (int) (mInputBufferSize - mOffset); bytesToRead = (int) (mInputBufferSize - mOffset); } if (bufSize < bytesRead) { //b/148655275 - Update Frame size, as Format value may not be valid if (bufSize < bytesToRead) { if(mNumInputFrame == 0) { mFrameSize = bufSize; bytesToRead = bufSize; mNumFrames = (int) ((mInputBufferSize + mFrameSize - 1) / mFrameSize); } else { mSignalledError = true; return; } byte[] inputArray = new byte[bytesRead]; mInputStream.read(inputArray, 0, bytesRead); } byte[] inputArray = new byte[bytesToRead]; mInputStream.read(inputArray, 0, bytesToRead); inputBuffer.put(inputArray); int flag = 0; if (mNumInputFrame >= mNumFrames - 1 || bytesRead == 0) { if (mNumInputFrame >= mNumFrames - 1 || bytesToRead == 0) { Log.i(TAG, "Sending EOS on input last frame"); mSawInputEOS = true; flag = MediaCodec.BUFFER_FLAG_END_OF_STREAM; Loading @@ -304,9 +314,9 @@ public class Encoder { } else { presentationTimeUs = mNumInputFrame * mFrameSize * 1000000 / mSampleRate; } mediaCodec.queueInputBuffer(inputBufferId, 0, bytesRead, presentationTimeUs, flag); mediaCodec.queueInputBuffer(inputBufferId, 0, bytesToRead, presentationTimeUs, flag); mNumInputFrame++; mOffset += bytesRead; mOffset += bytesToRead; } /** Loading media/tests/benchmark/src/native/common/BenchmarkCommon.h +3 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ using namespace std; constexpr uint32_t kQueueDequeueTimeoutUs = 1000; constexpr uint32_t kMaxCSDStrlen = 16; constexpr uint32_t kMaxBufferSize = 1024 * 1024 * 16; // Change in kDefaultAudioEncodeFrameSize should also be taken to // AUDIO_ENCODE_DEFAULT_MAX_INPUT_SIZE present in Encoder.java constexpr uint32_t kDefaultAudioEncodeFrameSize = 4096; template <typename T> class CallBackQueue { Loading media/tests/benchmark/src/native/encoder/Encoder.cpp +27 −21 Original line number Diff line number Diff line Loading @@ -47,29 +47,36 @@ void Encoder::onInputAvailable(AMediaCodec *mediaCodec, int32_t bufIdx) { mEncoderDoneCondition.notify_one(); return; } size_t bytesRead = mParams.frameSize; size_t bytesToRead = mParams.frameSize; if (mInputBufferSize - mOffset < mParams.frameSize) { bytesRead = mInputBufferSize - mOffset; bytesToRead = mInputBufferSize - mOffset; } if (bufSize < bytesRead) { ALOGE("bytes to read %zu bufSize %zu \n", bytesRead, bufSize); //b/148655275 - Update Frame size, as Format value may not be valid if (bufSize < bytesToRead) { if(mNumInputFrame == 0) { mParams.frameSize = bufSize; bytesToRead = bufSize; mParams.numFrames = (mInputBufferSize + mParams.frameSize - 1) / mParams.frameSize; } else { ALOGE("bytes to read %zu bufSize %zu \n", bytesToRead, bufSize); mErrorCode = AMEDIA_ERROR_MALFORMED; mSignalledError = true; mEncoderDoneCondition.notify_one(); return; } if (bytesRead < mParams.frameSize && mNumInputFrame < mParams.numFrames - 1) { ALOGE("Partial frame at frameID %d bytesRead %zu frameSize %d total numFrames %d\n", mNumInputFrame, bytesRead, mParams.frameSize, mParams.numFrames); } if (bytesToRead < mParams.frameSize && mNumInputFrame < mParams.numFrames - 1) { ALOGE("Partial frame at frameID %d bytesToRead %zu frameSize %d total numFrames %d\n", mNumInputFrame, bytesToRead, mParams.frameSize, mParams.numFrames); mErrorCode = AMEDIA_ERROR_MALFORMED; mSignalledError = true; mEncoderDoneCondition.notify_one(); return; } mEleStream->read(buf, bytesRead); mEleStream->read(buf, bytesToRead); size_t bytesgcount = mEleStream->gcount(); if (bytesgcount != bytesRead) { ALOGE("bytes to read %zu actual bytes read %zu \n", bytesRead, bytesgcount); if (bytesgcount != bytesToRead) { ALOGE("bytes to read %zu actual bytes read %zu \n", bytesToRead, bytesgcount); mErrorCode = AMEDIA_ERROR_MALFORMED; mSignalledError = true; mEncoderDoneCondition.notify_one(); Loading @@ -77,7 +84,7 @@ void Encoder::onInputAvailable(AMediaCodec *mediaCodec, int32_t bufIdx) { } uint32_t flag = 0; if (mNumInputFrame == mParams.numFrames - 1 || bytesRead == 0) { if (mNumInputFrame == mParams.numFrames - 1 || bytesToRead == 0) { ALOGD("Sending EOS on input Last frame\n"); flag |= AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM; } Loading @@ -92,10 +99,10 @@ void Encoder::onInputAvailable(AMediaCodec *mediaCodec, int32_t bufIdx) { if (flag == AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) mSawInputEOS = true; ALOGV("%s bytesRead : %zd presentationTimeUs : %" PRIu64 " mSawInputEOS : %s", __FUNCTION__, bytesRead, presentationTimeUs, mSawInputEOS ? "TRUE" : "FALSE"); bytesToRead, presentationTimeUs, mSawInputEOS ? "TRUE" : "FALSE"); media_status_t status = AMediaCodec_queueInputBuffer(mCodec, bufIdx, 0 /* offset */, bytesRead, presentationTimeUs, flag); bytesToRead, presentationTimeUs, flag); if (AMEDIA_OK != status) { mErrorCode = status; mSignalledError = true; Loading @@ -103,7 +110,7 @@ void Encoder::onInputAvailable(AMediaCodec *mediaCodec, int32_t bufIdx) { return; } mNumInputFrame++; mOffset += bytesRead; mOffset += bytesToRead; } } Loading Loading @@ -220,13 +227,12 @@ int32_t Encoder::encode(string &codecName, ifstream &eleStream, size_t eleSize, if (!strncmp(mMime, "video/", 6)) { mParams.frameSize = mParams.width * mParams.height * 3 / 2; } else { mParams.frameSize = 4096; mParams.frameSize = kDefaultAudioEncodeFrameSize; // Get mInputMaxBufSize AMediaFormat *inputFormat = AMediaCodec_getInputFormat(mCodec); AMediaFormat_getInt32(inputFormat, AMEDIAFORMAT_KEY_MAX_INPUT_SIZE, &mParams.maxFrameSize); if (mParams.maxFrameSize < 0) { ALOGE("Invalid mParams.maxFrameSize %d\n", mParams.maxFrameSize); return AMEDIA_ERROR_INVALID_PARAMETER; mParams.maxFrameSize = kDefaultAudioEncodeFrameSize; } if (mParams.frameSize > mParams.maxFrameSize) { mParams.frameSize = mParams.maxFrameSize; Loading Loading
media/tests/benchmark/MediaBenchmarkTest/src/main/java/com/android/media/benchmark/library/Encoder.java +22 −12 Original line number Diff line number Diff line Loading @@ -29,7 +29,9 @@ import java.io.IOException; import java.nio.ByteBuffer; public class Encoder { private static final int ENCODE_DEFAULT_MAX_INPUT_SIZE = 3840; // Change in AUDIO_ENCODE_DEFAULT_MAX_INPUT_SIZE should also be taken to // kDefaultAudioEncodeFrameSize present in BenchmarkCommon.h private static final int AUDIO_ENCODE_DEFAULT_MAX_INPUT_SIZE = 4096; private static final String TAG = "Encoder"; private static final boolean DEBUG = false; private static final int kQueueDequeueTimeoutUs = 1000; Loading Loading @@ -134,7 +136,7 @@ public class Encoder { if (mMime.startsWith("video/")) { mFrameSize = frameSize; } else { int maxInputSize = ENCODE_DEFAULT_MAX_INPUT_SIZE; int maxInputSize = AUDIO_ENCODE_DEFAULT_MAX_INPUT_SIZE; MediaFormat format = mCodec.getInputFormat(); if (format.containsKey(MediaFormat.KEY_MAX_INPUT_SIZE)) { maxInputSize = format.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE); Loading Loading @@ -281,19 +283,27 @@ public class Encoder { return; } int bufSize = inputBuffer.capacity(); int bytesRead = mFrameSize; int bytesToRead = mFrameSize; if (mInputBufferSize - mOffset < mFrameSize) { bytesRead = (int) (mInputBufferSize - mOffset); bytesToRead = (int) (mInputBufferSize - mOffset); } if (bufSize < bytesRead) { //b/148655275 - Update Frame size, as Format value may not be valid if (bufSize < bytesToRead) { if(mNumInputFrame == 0) { mFrameSize = bufSize; bytesToRead = bufSize; mNumFrames = (int) ((mInputBufferSize + mFrameSize - 1) / mFrameSize); } else { mSignalledError = true; return; } byte[] inputArray = new byte[bytesRead]; mInputStream.read(inputArray, 0, bytesRead); } byte[] inputArray = new byte[bytesToRead]; mInputStream.read(inputArray, 0, bytesToRead); inputBuffer.put(inputArray); int flag = 0; if (mNumInputFrame >= mNumFrames - 1 || bytesRead == 0) { if (mNumInputFrame >= mNumFrames - 1 || bytesToRead == 0) { Log.i(TAG, "Sending EOS on input last frame"); mSawInputEOS = true; flag = MediaCodec.BUFFER_FLAG_END_OF_STREAM; Loading @@ -304,9 +314,9 @@ public class Encoder { } else { presentationTimeUs = mNumInputFrame * mFrameSize * 1000000 / mSampleRate; } mediaCodec.queueInputBuffer(inputBufferId, 0, bytesRead, presentationTimeUs, flag); mediaCodec.queueInputBuffer(inputBufferId, 0, bytesToRead, presentationTimeUs, flag); mNumInputFrame++; mOffset += bytesRead; mOffset += bytesToRead; } /** Loading
media/tests/benchmark/src/native/common/BenchmarkCommon.h +3 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ using namespace std; constexpr uint32_t kQueueDequeueTimeoutUs = 1000; constexpr uint32_t kMaxCSDStrlen = 16; constexpr uint32_t kMaxBufferSize = 1024 * 1024 * 16; // Change in kDefaultAudioEncodeFrameSize should also be taken to // AUDIO_ENCODE_DEFAULT_MAX_INPUT_SIZE present in Encoder.java constexpr uint32_t kDefaultAudioEncodeFrameSize = 4096; template <typename T> class CallBackQueue { Loading
media/tests/benchmark/src/native/encoder/Encoder.cpp +27 −21 Original line number Diff line number Diff line Loading @@ -47,29 +47,36 @@ void Encoder::onInputAvailable(AMediaCodec *mediaCodec, int32_t bufIdx) { mEncoderDoneCondition.notify_one(); return; } size_t bytesRead = mParams.frameSize; size_t bytesToRead = mParams.frameSize; if (mInputBufferSize - mOffset < mParams.frameSize) { bytesRead = mInputBufferSize - mOffset; bytesToRead = mInputBufferSize - mOffset; } if (bufSize < bytesRead) { ALOGE("bytes to read %zu bufSize %zu \n", bytesRead, bufSize); //b/148655275 - Update Frame size, as Format value may not be valid if (bufSize < bytesToRead) { if(mNumInputFrame == 0) { mParams.frameSize = bufSize; bytesToRead = bufSize; mParams.numFrames = (mInputBufferSize + mParams.frameSize - 1) / mParams.frameSize; } else { ALOGE("bytes to read %zu bufSize %zu \n", bytesToRead, bufSize); mErrorCode = AMEDIA_ERROR_MALFORMED; mSignalledError = true; mEncoderDoneCondition.notify_one(); return; } if (bytesRead < mParams.frameSize && mNumInputFrame < mParams.numFrames - 1) { ALOGE("Partial frame at frameID %d bytesRead %zu frameSize %d total numFrames %d\n", mNumInputFrame, bytesRead, mParams.frameSize, mParams.numFrames); } if (bytesToRead < mParams.frameSize && mNumInputFrame < mParams.numFrames - 1) { ALOGE("Partial frame at frameID %d bytesToRead %zu frameSize %d total numFrames %d\n", mNumInputFrame, bytesToRead, mParams.frameSize, mParams.numFrames); mErrorCode = AMEDIA_ERROR_MALFORMED; mSignalledError = true; mEncoderDoneCondition.notify_one(); return; } mEleStream->read(buf, bytesRead); mEleStream->read(buf, bytesToRead); size_t bytesgcount = mEleStream->gcount(); if (bytesgcount != bytesRead) { ALOGE("bytes to read %zu actual bytes read %zu \n", bytesRead, bytesgcount); if (bytesgcount != bytesToRead) { ALOGE("bytes to read %zu actual bytes read %zu \n", bytesToRead, bytesgcount); mErrorCode = AMEDIA_ERROR_MALFORMED; mSignalledError = true; mEncoderDoneCondition.notify_one(); Loading @@ -77,7 +84,7 @@ void Encoder::onInputAvailable(AMediaCodec *mediaCodec, int32_t bufIdx) { } uint32_t flag = 0; if (mNumInputFrame == mParams.numFrames - 1 || bytesRead == 0) { if (mNumInputFrame == mParams.numFrames - 1 || bytesToRead == 0) { ALOGD("Sending EOS on input Last frame\n"); flag |= AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM; } Loading @@ -92,10 +99,10 @@ void Encoder::onInputAvailable(AMediaCodec *mediaCodec, int32_t bufIdx) { if (flag == AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) mSawInputEOS = true; ALOGV("%s bytesRead : %zd presentationTimeUs : %" PRIu64 " mSawInputEOS : %s", __FUNCTION__, bytesRead, presentationTimeUs, mSawInputEOS ? "TRUE" : "FALSE"); bytesToRead, presentationTimeUs, mSawInputEOS ? "TRUE" : "FALSE"); media_status_t status = AMediaCodec_queueInputBuffer(mCodec, bufIdx, 0 /* offset */, bytesRead, presentationTimeUs, flag); bytesToRead, presentationTimeUs, flag); if (AMEDIA_OK != status) { mErrorCode = status; mSignalledError = true; Loading @@ -103,7 +110,7 @@ void Encoder::onInputAvailable(AMediaCodec *mediaCodec, int32_t bufIdx) { return; } mNumInputFrame++; mOffset += bytesRead; mOffset += bytesToRead; } } Loading Loading @@ -220,13 +227,12 @@ int32_t Encoder::encode(string &codecName, ifstream &eleStream, size_t eleSize, if (!strncmp(mMime, "video/", 6)) { mParams.frameSize = mParams.width * mParams.height * 3 / 2; } else { mParams.frameSize = 4096; mParams.frameSize = kDefaultAudioEncodeFrameSize; // Get mInputMaxBufSize AMediaFormat *inputFormat = AMediaCodec_getInputFormat(mCodec); AMediaFormat_getInt32(inputFormat, AMEDIAFORMAT_KEY_MAX_INPUT_SIZE, &mParams.maxFrameSize); if (mParams.maxFrameSize < 0) { ALOGE("Invalid mParams.maxFrameSize %d\n", mParams.maxFrameSize); return AMEDIA_ERROR_INVALID_PARAMETER; mParams.maxFrameSize = kDefaultAudioEncodeFrameSize; } if (mParams.frameSize > mParams.maxFrameSize) { mParams.frameSize = mParams.maxFrameSize; Loading