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;
|
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) {
|
if (status == WV_Status_End_Of_Media) {
|
||||||
*finalStatus = ERROR_END_OF_STREAM;
|
*finalStatus = ERROR_END_OF_STREAM;
|
||||||
} else if (status != WV_Status_OK) {
|
} else if (status != WV_Status_OK) {
|
||||||
*finalStatus = ERROR_IO;
|
*finalStatus = ERROR_IO;
|
||||||
} else {
|
} else {
|
||||||
durationUs = (uint64_t)(secondsBuffered * 1000000LL);
|
|
||||||
|
|
||||||
if (mIsLiveStream) {
|
if (mIsLiveStream) {
|
||||||
*finalStatus = ERROR_END_OF_STREAM;
|
*finalStatus = ERROR_END_OF_STREAM;
|
||||||
} else {
|
} else {
|
||||||
*finalStatus = OK;
|
*finalStatus = OK;
|
||||||
|
|
||||||
int64_t current_time = 0; // usec.
|
int64_t current_time = 0; // usec.
|
||||||
if (mVideoSource != NULL) {
|
if (mVideoSource != NULL) {
|
||||||
current_time = mVideoSource->getTime();
|
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.
|
return durationUs;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WVMExtractorImpl::setAdaptiveStreamingMode(bool adaptive)
|
void WVMExtractorImpl::setAdaptiveStreamingMode(bool adaptive)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
|
|||||||
mIsLiveStream(isLive),
|
mIsLiveStream(isLive),
|
||||||
mNewSegment(false),
|
mNewSegment(false),
|
||||||
mCryptoInitialized(false),
|
mCryptoInitialized(false),
|
||||||
|
mIsStalled(false),
|
||||||
mGroup(NULL),
|
mGroup(NULL),
|
||||||
mKeyTime(0),
|
mKeyTime(0),
|
||||||
mDts(0),
|
mDts(0),
|
||||||
@@ -203,6 +204,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
|||||||
{
|
{
|
||||||
Mutex::Autolock autoLock(mLock);
|
Mutex::Autolock autoLock(mLock);
|
||||||
|
|
||||||
|
mIsStalled = false;
|
||||||
|
|
||||||
CHECK(mStarted);
|
CHECK(mStarted);
|
||||||
|
|
||||||
*buffer = NULL;
|
*buffer = NULL;
|
||||||
@@ -333,16 +336,20 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
|||||||
return ERROR_IO;
|
return ERROR_IO;
|
||||||
} else {
|
} else {
|
||||||
// Didn't get anything, sleep a bit so we don't hog the CPU then try again
|
// Didn't get anything, sleep a bit so we don't hog the CPU then try again
|
||||||
|
if (retryCount > 10)
|
||||||
|
mIsStalled = true;
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define PCR_HZ 90000
|
#define PCR_HZ 90000
|
||||||
mKeyTime = (int64_t)mPts * 1000000 / PCR_HZ;
|
mKeyTime = (int64_t)mPts * 1000000 / PCR_HZ;
|
||||||
|
|
||||||
if (seekNextSync && ((mKeyTime < seekTimeUs) || !syncFrame)) {
|
if (seekNextSync && ((mKeyTime < seekTimeUs) || !syncFrame)) {
|
||||||
// drop frames up to next sync if requested
|
// drop frames up to next sync if requested
|
||||||
|
mIsStalled = true;
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
#ifdef REQUIRE_SECURE_BUFFERS
|
#ifdef REQUIRE_SECURE_BUFFERS
|
||||||
mDecryptContext.Initialize(mediaBuf);
|
mDecryptContext.Initialize(mediaBuf);
|
||||||
@@ -351,6 +358,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mIsStalled = false;
|
||||||
|
|
||||||
if (offset + bytesRead < mediaBuf->size())
|
if (offset + bytesRead < mediaBuf->size())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public:
|
|||||||
virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL);
|
virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL);
|
||||||
|
|
||||||
void addEncryptedSize(size_t size) { mEncryptedSizes.push_back(size); }
|
void addEncryptedSize(size_t size) { mEncryptedSizes.push_back(size); }
|
||||||
|
bool isStalled() const { return mIsStalled; }
|
||||||
|
|
||||||
static int sLastError;
|
static int sLastError;
|
||||||
|
|
||||||
@@ -84,6 +85,7 @@ private:
|
|||||||
bool mIsLiveStream;
|
bool mIsLiveStream;
|
||||||
bool mNewSegment;
|
bool mNewSegment;
|
||||||
bool mCryptoInitialized;
|
bool mCryptoInitialized;
|
||||||
|
bool mIsStalled;
|
||||||
|
|
||||||
MediaBufferGroup *mGroup;
|
MediaBufferGroup *mGroup;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user