Fix ERROR_IO due to timeout on video stream and corrupt samples

This change applies to the wv extractor when used in conjunction
with new MediaCodec model.

Change-Id: I999990ff41d35641110a58472f1cdb8c4c7db02e
related-to-bug: 5986621
This commit is contained in:
Jeff Tinker
2012-04-27 18:52:09 -07:00
parent d4241dddd3
commit ec2d703970
6 changed files with 33 additions and 11 deletions

View File

@@ -200,8 +200,11 @@ void WVMExtractorImpl::SocketInfoCallback(int fd, int closing, void *context)
WVMExtractorImpl *obj = (WVMExtractorImpl *)context; WVMExtractorImpl *obj = (WVMExtractorImpl *)context;
if (!obj || !obj->mUIDIsSet) { if (!obj) {
ALOGW("SocketInfoCallback - UID not set!"); ALOGW("SocketInfoCallback: missing context!");
return;
} else if (!obj->mUIDIsSet) {
ALOGW("SocketInfoCallback: UID not set!");
return; return;
} }
@@ -331,8 +334,10 @@ status_t WVMExtractorImpl::readMetaData()
} }
} }
mAudioSource = new WVMMediaSource(mSession, WV_EsSelector_Audio, audioMetaData, mIsLiveStream); mAudioSource = new WVMMediaSource(mSession, WV_EsSelector_Audio, audioMetaData,
mVideoSource = new WVMMediaSource(mSession, WV_EsSelector_Video, videoMetaData, mIsLiveStream); mIsLiveStream, mCryptoPluginMode);
mVideoSource = new WVMMediaSource(mSession, WV_EsSelector_Video, videoMetaData,
mIsLiveStream, mCryptoPluginMode);
// Since the WVExtractor goes away soon after this, we delegate ownership of some resources // Since the WVExtractor goes away soon after this, we delegate ownership of some resources
// to the constructed media source // to the constructed media source

View File

@@ -25,13 +25,15 @@ static void _cb(int code)
status_t WVMMediaSource::sLastError = NO_ERROR; status_t WVMMediaSource::sLastError = NO_ERROR;
WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector, WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
const sp<MetaData> &metaData, bool isLive) const sp<MetaData> &metaData, bool isLive,
bool cryptoPluginMode)
: mSession(session), : mSession(session),
mESSelector(esSelector), mESSelector(esSelector),
mTrackMetaData(metaData), mTrackMetaData(metaData),
mStarted(false), mStarted(false),
mIsLiveStream(isLive), mIsLiveStream(isLive),
mNewSegment(false), mNewSegment(false),
mCryptoInitialized(false),
mGroup(NULL), mGroup(NULL),
mDts(0), mDts(0),
mPts(0) mPts(0)
@@ -39,7 +41,14 @@ WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
_ah010(_cb); _ah010(_cb);
#ifdef REQUIRE_SECURE_BUFFERS #ifdef REQUIRE_SECURE_BUFFERS
if (esSelector == WV_EsSelector_Video) { if (esSelector == WV_EsSelector_Video) {
OEMCrypto_Initialize(); if (!cryptoPluginMode) {
OEMCryptoResult result = OEMCrypto_Initialize();
if (result == OEMCrypto_SUCCESS) {
mCryptoInitialized = true;
} else {
ALOGE("Crypto initialize failed (%d)", result);
}
}
} }
#endif #endif
} }
@@ -157,6 +166,12 @@ sp<MetaData> WVMMediaSource::getFormat()
if (!mIsLiveStream && (mESSelector == WV_EsSelector_Video)) { if (!mIsLiveStream && (mESSelector == WV_EsSelector_Video)) {
mTrackMetaData->setInt32(kKeyRequiresSecureBuffers, true); mTrackMetaData->setInt32(kKeyRequiresSecureBuffers, true);
} }
// Only support AAC on android for now, so assume the audio
// track is AAC and notify the audio codec it has ADTS framing
if (mESSelector == WV_EsSelector_Audio) {
mTrackMetaData->setInt32(kKeyIsADTS, 1);
}
#endif #endif
return mTrackMetaData; return mTrackMetaData;
@@ -425,6 +440,7 @@ WVStatus WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void*
if (key) { if (key) {
source->addEncryptedSize(length); source->addEncryptedSize(length);
} }
memcpy((uint8_t *)context.mMediaBuf->data() + context.mOffset, input, length);
} else { } else {
// do decrypt // do decrypt
if (key) if (key)
@@ -446,9 +462,8 @@ WVStatus WVMMediaSource::DecryptCallback(WVEsSelector esType, void* input, void*
status = WV_Status_Unknown; status = WV_Status_Unknown;
ALOGD("OEMCrypto decrypt failure: %d", result); ALOGD("OEMCrypto decrypt failure: %d", result);
} }
context.mOffset += copied;
} }
context.mOffset += copied;
return status; return status;
} }
@@ -467,7 +482,9 @@ WVMMediaSource::~WVMMediaSource()
if (mSession != NULL) { if (mSession != NULL) {
WV_Teardown(mSession); WV_Teardown(mSession);
#ifdef REQUIRE_SECURE_BUFFERS #ifdef REQUIRE_SECURE_BUFFERS
OEMCrypto_Terminate(); if (mCryptoInitialized) {
OEMCrypto_Terminate();
}
#endif #endif
} }
WVMExtractorImpl::cleanup(); WVMExtractorImpl::cleanup();

View File

@@ -25,7 +25,7 @@ class WVMFileSource;
class WVMMediaSource : public MediaSource { class WVMMediaSource : public MediaSource {
public: public:
WVMMediaSource(WVSession *session, WVEsSelector esSelector, WVMMediaSource(WVSession *session, WVEsSelector esSelector,
const sp<MetaData> &metaData, bool isLive); const sp<MetaData> &metaData, bool isLive, bool cryptoPluginMode);
void delegateFileSource(sp<WVMFileSource> fileSource); void delegateFileSource(sp<WVMFileSource> fileSource);
void delegateDataSource(sp<DataSource> dataSource); void delegateDataSource(sp<DataSource> dataSource);
@@ -79,7 +79,7 @@ private:
bool mLogOnce; bool mLogOnce;
bool mIsLiveStream; bool mIsLiveStream;
bool mNewSegment; bool mNewSegment;
bool mCryptoPluginMode; bool mCryptoInitialized;
MediaBufferGroup *mGroup; MediaBufferGroup *mGroup;