am 1024b041: Part of fix for double spins & faster startup
* commit '1024b041e824bb6eb232971fc4a2984d63f7e079': Part of fix for double spins & faster startup
This commit is contained in:
@@ -499,19 +499,24 @@ int64_t WVMExtractorImpl::getCachedDurationUs(status_t *finalStatus) {
|
||||
}
|
||||
|
||||
uint64_t durationUs = 0;
|
||||
float secondsBuffered;
|
||||
status = WV_Info_TimeBuffered(mSession, &secondsBuffered);
|
||||
|
||||
if (!mVideoSource->isStalled() && !mAudioSource->isStalled()) {
|
||||
// Data is buffered as long as the pull isn't stalled.
|
||||
// The amount indicated doesn't matter as long as it
|
||||
// is more than the high water mark.
|
||||
durationUs = 10000000LL;
|
||||
}
|
||||
|
||||
if (status == WV_Status_End_Of_Media) {
|
||||
*finalStatus = ERROR_END_OF_STREAM;
|
||||
} else if (status != WV_Status_OK) {
|
||||
*finalStatus = ERROR_IO;
|
||||
} else {
|
||||
durationUs = (uint64_t)(secondsBuffered * 1000000LL);
|
||||
|
||||
if (mIsLiveStream) {
|
||||
*finalStatus = ERROR_END_OF_STREAM;
|
||||
} else {
|
||||
*finalStatus = OK;
|
||||
|
||||
int64_t current_time = 0; // usec.
|
||||
if (mVideoSource != NULL) {
|
||||
current_time = mVideoSource->getTime();
|
||||
@@ -530,13 +535,7 @@ int64_t WVMExtractorImpl::getCachedDurationUs(status_t *finalStatus) {
|
||||
}
|
||||
}
|
||||
|
||||
// Scale the duration to account for Stagefright's conservative buffering.
|
||||
// This provides much more responsive operation and due to the ability to
|
||||
// adapt, we don't need to prebuffer so much data. Based on testing, 2x
|
||||
// is a reasonable compromise between faster startup time and additional
|
||||
// pauses after playback starts.
|
||||
|
||||
return durationUs * 2;
|
||||
return durationUs;
|
||||
}
|
||||
|
||||
void WVMExtractorImpl::setAdaptiveStreamingMode(bool adaptive)
|
||||
|
||||
@@ -35,6 +35,7 @@ WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
|
||||
mIsLiveStream(isLive),
|
||||
mNewSegment(false),
|
||||
mCryptoInitialized(false),
|
||||
mIsStalled(false),
|
||||
mGroup(NULL),
|
||||
mKeyTime(0),
|
||||
mDts(0),
|
||||
@@ -203,6 +204,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
{
|
||||
Mutex::Autolock autoLock(mLock);
|
||||
|
||||
mIsStalled = false;
|
||||
|
||||
CHECK(mStarted);
|
||||
|
||||
*buffer = NULL;
|
||||
@@ -333,16 +336,20 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
return ERROR_IO;
|
||||
} else {
|
||||
// Didn't get anything, sleep a bit so we don't hog the CPU then try again
|
||||
if (retryCount > 10)
|
||||
mIsStalled = true;
|
||||
usleep(10000);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define PCR_HZ 90000
|
||||
mKeyTime = (int64_t)mPts * 1000000 / PCR_HZ;
|
||||
|
||||
if (seekNextSync && ((mKeyTime < seekTimeUs) || !syncFrame)) {
|
||||
// drop frames up to next sync if requested
|
||||
mIsStalled = true;
|
||||
usleep(10000);
|
||||
#ifdef REQUIRE_SECURE_BUFFERS
|
||||
mDecryptContext.Initialize(mediaBuf);
|
||||
@@ -351,6 +358,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
||||
continue;
|
||||
}
|
||||
|
||||
mIsStalled = false;
|
||||
|
||||
if (offset + bytesRead < mediaBuf->size())
|
||||
break;
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL);
|
||||
|
||||
void addEncryptedSize(size_t size) { mEncryptedSizes.push_back(size); }
|
||||
bool isStalled() const { return mIsStalled; }
|
||||
|
||||
static int sLastError;
|
||||
|
||||
@@ -84,6 +85,7 @@ private:
|
||||
bool mIsLiveStream;
|
||||
bool mNewSegment;
|
||||
bool mCryptoInitialized;
|
||||
bool mIsStalled;
|
||||
|
||||
MediaBufferGroup *mGroup;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user