Fix pause at end of movie.
The function WVMExtractorImpl::getCachedDurationUs returns the cached buffer size in microseconds, and sets a status to ERROR_END_OF_STREAM at the end of the movie. The AwesomePlayer will pause if the cache is too small and the status is not EOS. In bug 6277231, the player would pause just before the EOS marker would have been seen by the Widevine library. This change checks the current play time against the total movie duration. If there is less than 10 seconds left in the movie, the EOS flag is set. related-to-bug: 6277231 Change-Id: I8dbf60c82c41df485185f85e72452aab0a6a9686
This commit is contained in:
@@ -98,6 +98,7 @@ WVMExtractorImpl::WVMExtractorImpl(sp<DataSource> dataSource)
|
|||||||
mUseAdaptiveStreaming(false),
|
mUseAdaptiveStreaming(false),
|
||||||
mIsLiveStream(false),
|
mIsLiveStream(false),
|
||||||
mSession(NULL),
|
mSession(NULL),
|
||||||
|
mDuration(0),
|
||||||
mSetupStatus(OK)
|
mSetupStatus(OK)
|
||||||
{
|
{
|
||||||
dataSource->getDrmInfo(sDecryptHandle, &sDrmManagerClient);
|
dataSource->getDrmInfo(sDecryptHandle, &sDrmManagerClient);
|
||||||
@@ -272,13 +273,13 @@ status_t WVMExtractorImpl::readMetaData()
|
|||||||
return ERROR_MALFORMED;
|
return ERROR_MALFORMED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t duration = (int64_t)(strtod(durationString.c_str(), NULL) * 1000000);
|
mDuration = (int64_t)(strtod(durationString.c_str(), NULL) * 1000000);
|
||||||
|
|
||||||
sp<MetaData> audioMetaData = new MetaData();
|
sp<MetaData> audioMetaData = new MetaData();
|
||||||
sp<MetaData> videoMetaData = new MetaData();
|
sp<MetaData> videoMetaData = new MetaData();
|
||||||
|
|
||||||
audioMetaData->setInt64(kKeyDuration, duration);
|
audioMetaData->setInt64(kKeyDuration, mDuration);
|
||||||
videoMetaData->setInt64(kKeyDuration, duration);
|
videoMetaData->setInt64(kKeyDuration, mDuration);
|
||||||
|
|
||||||
audioMetaData->setInt32(kKeyBitRate, audioBitRate);
|
audioMetaData->setInt32(kKeyBitRate, audioBitRate);
|
||||||
videoMetaData->setInt32(kKeyBitRate, videoBitRate);
|
videoMetaData->setInt32(kKeyBitRate, videoBitRate);
|
||||||
@@ -505,11 +506,28 @@ int64_t WVMExtractorImpl::getCachedDurationUs(status_t *finalStatus) {
|
|||||||
} else if (status != WV_Status_OK) {
|
} else if (status != WV_Status_OK) {
|
||||||
*finalStatus = ERROR_IO;
|
*finalStatus = ERROR_IO;
|
||||||
} else {
|
} else {
|
||||||
if (mIsLiveStream)
|
|
||||||
*finalStatus = ERROR_END_OF_STREAM;
|
|
||||||
else
|
|
||||||
*finalStatus = OK;
|
|
||||||
durationUs = (uint64_t)(secondsBuffered * 1000000LL);
|
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();
|
||||||
|
} else {
|
||||||
|
ALOGV("getCachedDurationUs: current_time not yet valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ALOGD("current_time=%.2f, duration %.2f, delta = %.2f, buffered=%.2f",
|
||||||
|
// current_time/1e6, mDuration/1e6,
|
||||||
|
// (mDuration - current_time )/1e6, time_buffered);
|
||||||
|
|
||||||
|
// If we are less than 10 seconds from end, report we are at the end.
|
||||||
|
if (mDuration > 0 && mDuration - current_time < 10000000) {
|
||||||
|
*finalStatus = ERROR_END_OF_STREAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale the duration to account for Stagefright's conservative buffering.
|
// Scale the duration to account for Stagefright's conservative buffering.
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
|
|||||||
mNewSegment(false),
|
mNewSegment(false),
|
||||||
mCryptoInitialized(false),
|
mCryptoInitialized(false),
|
||||||
mGroup(NULL),
|
mGroup(NULL),
|
||||||
|
mKeyTime(0),
|
||||||
mDts(0),
|
mDts(0),
|
||||||
mPts(0)
|
mPts(0)
|
||||||
{
|
{
|
||||||
@@ -263,7 +264,6 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
|||||||
size_t bytesRead;
|
size_t bytesRead;
|
||||||
bool auStart;
|
bool auStart;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
int64_t keyTime;
|
|
||||||
|
|
||||||
bool syncFrame;
|
bool syncFrame;
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
@@ -338,9 +338,9 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define PCR_HZ 90000
|
#define PCR_HZ 90000
|
||||||
keyTime = (int64_t)mPts * 1000000 / PCR_HZ;
|
mKeyTime = (int64_t)mPts * 1000000 / PCR_HZ;
|
||||||
|
|
||||||
if (seekNextSync && ((keyTime < seekTimeUs) || !syncFrame)) {
|
if (seekNextSync && ((mKeyTime < seekTimeUs) || !syncFrame)) {
|
||||||
// drop frames up to next sync if requested
|
// drop frames up to next sync if requested
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
#ifdef REQUIRE_SECURE_BUFFERS
|
#ifdef REQUIRE_SECURE_BUFFERS
|
||||||
@@ -380,7 +380,7 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mediaBuf->meta_data()->clear();
|
mediaBuf->meta_data()->clear();
|
||||||
mediaBuf->meta_data()->setInt64(kKeyTime, keyTime);
|
mediaBuf->meta_data()->setInt64(kKeyTime, mKeyTime);
|
||||||
|
|
||||||
mediaBuf->set_range(0, bytesRead + offset);
|
mediaBuf->set_range(0, bytesRead + offset);
|
||||||
|
|
||||||
@@ -414,7 +414,7 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
|
|||||||
#if 0
|
#if 0
|
||||||
ALOGD("[%p] %s packet length=%d kKeyTime=%lld %s\n", mediaBuf,
|
ALOGD("[%p] %s packet length=%d kKeyTime=%lld %s\n", mediaBuf,
|
||||||
(mESSelector == WV_EsSelector_Video ? "video" : "audio"),
|
(mESSelector == WV_EsSelector_Video ? "video" : "audio"),
|
||||||
bytesRead + offset, keyTime, syncFrame ? "sync" : "");
|
bytesRead + offset, mKeyTime, syncFrame ? "sync" : "");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*buffer = mediaBuf;
|
*buffer = mediaBuf;
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ private:
|
|||||||
|
|
||||||
WVSession *mSession;
|
WVSession *mSession;
|
||||||
|
|
||||||
|
int64_t mDuration; // usec.
|
||||||
|
|
||||||
status_t mSetupStatus;
|
status_t mSetupStatus;
|
||||||
|
|
||||||
status_t readMetaData();
|
status_t readMetaData();
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ public:
|
|||||||
|
|
||||||
static int sLastError;
|
static int sLastError;
|
||||||
|
|
||||||
|
int64_t getTime() { return mKeyTime; }; // usec.
|
||||||
|
|
||||||
#ifdef REQUIRE_SECURE_BUFFERS
|
#ifdef REQUIRE_SECURE_BUFFERS
|
||||||
class DecryptContext {
|
class DecryptContext {
|
||||||
public:
|
public:
|
||||||
@@ -84,6 +86,7 @@ private:
|
|||||||
|
|
||||||
MediaBufferGroup *mGroup;
|
MediaBufferGroup *mGroup;
|
||||||
|
|
||||||
|
int64_t mKeyTime;
|
||||||
unsigned long long mDts;
|
unsigned long long mDts;
|
||||||
unsigned long long mPts;
|
unsigned long long mPts;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user