summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/private/surfaceflinger/SharedBufferStack.h10
-rw-r--r--media/libstagefright/AwesomePlayer.cpp11
-rw-r--r--media/libstagefright/NuCachedSource2.cpp14
-rw-r--r--media/libstagefright/include/AwesomePlayer.h1
-rw-r--r--media/libstagefright/include/NuCachedSource2.h6
5 files changed, 37 insertions, 5 deletions
diff --git a/include/private/surfaceflinger/SharedBufferStack.h b/include/private/surfaceflinger/SharedBufferStack.h
index d6ae5e9..9d589cf 100644
--- a/include/private/surfaceflinger/SharedBufferStack.h
+++ b/include/private/surfaceflinger/SharedBufferStack.h
@@ -285,6 +285,8 @@ public:
uint32_t getTransform(int buffer) const;
status_t resize(int newNumBuffers);
+ status_t grow(int newNumBuffers);
+ status_t shrink(int newNumBuffers);
SharedBufferStack::Statistics getStats() const;
@@ -346,6 +348,14 @@ private:
int mNumBuffers;
BufferList mBufferList;
+ struct BuffersAvailableCondition : public ConditionBase {
+ int mNumBuffers;
+ inline BuffersAvailableCondition(SharedBufferServer* sbs,
+ int numBuffers);
+ inline bool operator()() const;
+ inline const char* name() const { return "BuffersAvailableCondition"; }
+ };
+
struct UnlockUpdate : public UpdateBase {
const int lockedBuffer;
inline UnlockUpdate(SharedBufferBase* sbb, int lockedBuffer);
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 4e1969b..f084e28 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -564,6 +564,12 @@ bool AwesomePlayer::getCachedDuration_l(int64_t *durationUs, bool *eos) {
return false;
}
+void AwesomePlayer::ensureCacheIsFetching_l() {
+ if (mCachedSource != NULL) {
+ mCachedSource->resumeFetchingIfNecessary();
+ }
+}
+
void AwesomePlayer::onBufferingUpdate() {
Mutex::Autolock autoLock(mLock);
if (!mBufferingEventPending) {
@@ -606,6 +612,7 @@ void AwesomePlayer::onBufferingUpdate() {
kLowWaterMarkBytes);
mFlags |= CACHE_UNDERRUN;
pause_l();
+ ensureCacheIsFetching_l();
notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
} else if (eos || cachedDataRemaining > kHighWaterMarkBytes) {
if (mFlags & CACHE_UNDERRUN) {
@@ -627,12 +634,16 @@ void AwesomePlayer::onBufferingUpdate() {
int64_t cachedDurationUs;
bool eos;
if (getCachedDuration_l(&cachedDurationUs, &eos)) {
+ LOGV("cachedDurationUs = %.2f secs, eos=%d",
+ cachedDurationUs / 1E6, eos);
+
if ((mFlags & PLAYING) && !eos
&& (cachedDurationUs < kLowWaterMarkUs)) {
LOGI("cache is running low (%.2f secs) , pausing.",
cachedDurationUs / 1E6);
mFlags |= CACHE_UNDERRUN;
pause_l();
+ ensureCacheIsFetching_l();
notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
} else if (eos || cachedDurationUs > kHighWaterMarkUs) {
if (mFlags & CACHE_UNDERRUN) {
diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp
index a69c396..4a2402b 100644
--- a/media/libstagefright/NuCachedSource2.cpp
+++ b/media/libstagefright/NuCachedSource2.cpp
@@ -325,15 +325,17 @@ void NuCachedSource2::onRead(const sp<AMessage> &msg) {
mCondition.signal();
}
-void NuCachedSource2::restartPrefetcherIfNecessary_l() {
+void NuCachedSource2::restartPrefetcherIfNecessary_l(
+ bool ignoreLowWaterThreshold) {
static const size_t kGrayArea = 256 * 1024;
if (mFetching || mFinalStatus != OK) {
return;
}
- if (mCacheOffset + mCache->totalSize() - mLastAccessPos
- >= kLowWaterThreshold) {
+ if (!ignoreLowWaterThreshold
+ && mCacheOffset + mCache->totalSize() - mLastAccessPos
+ >= kLowWaterThreshold) {
return;
}
@@ -510,6 +512,12 @@ void NuCachedSource2::onSuspend() {
mSuspended = true;
}
+void NuCachedSource2::resumeFetchingIfNecessary() {
+ Mutex::Autolock autoLock(mLock);
+
+ restartPrefetcherIfNecessary_l(true /* ignore low water threshold */);
+}
+
DecryptHandle* NuCachedSource2::DrmInitialization(DrmManagerClient* client) {
return mSource->DrmInitialization(client);
}
diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h
index a0a7436..302a1ba 100644
--- a/media/libstagefright/include/AwesomePlayer.h
+++ b/media/libstagefright/include/AwesomePlayer.h
@@ -274,6 +274,7 @@ private:
bool getBitrate(int64_t *bitrate);
void finishSeekIfNecessary(int64_t videoTimeUs);
+ void ensureCacheIsFetching_l();
AwesomePlayer(const AwesomePlayer &);
AwesomePlayer &operator=(const AwesomePlayer &);
diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h
index 4067585..8cec1b1 100644
--- a/media/libstagefright/include/NuCachedSource2.h
+++ b/media/libstagefright/include/NuCachedSource2.h
@@ -47,6 +47,8 @@ struct NuCachedSource2 : public DataSource {
void suspend();
void clearCacheAndResume();
+ void resumeFetchingIfNecessary();
+
protected:
virtual ~NuCachedSource2();
@@ -56,7 +58,7 @@ private:
enum {
kPageSize = 65536,
kHighWaterThreshold = 5 * 1024 * 1024,
- kLowWaterThreshold = 512 * 1024,
+ kLowWaterThreshold = 1024 * 1024,
// Read data after a 15 sec timeout whether we're actively
// fetching or not.
@@ -96,7 +98,7 @@ private:
status_t seekInternal_l(off_t offset);
size_t approxDataRemaining_l(bool *eos);
- void restartPrefetcherIfNecessary_l();
+ void restartPrefetcherIfNecessary_l(bool ignoreLowWaterThreshold = false);
DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2);
};