summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/AwesomePlayer.cpp
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-10-15 08:32:06 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-10-15 08:32:06 -0700
commit6fed68ded4ab2c042b7ca14409a24aee916313d5 (patch)
tree95818c6ea5f9e4988449d166bbec31251030b46e /media/libstagefright/AwesomePlayer.cpp
parenta44501ea0896c2508bd6b807185d9049be6752f3 (diff)
parent0b5181ddfdde400f9cac6db239cf97ced3b67e22 (diff)
downloadframeworks_av-6fed68ded4ab2c042b7ca14409a24aee916313d5.zip
frameworks_av-6fed68ded4ab2c042b7ca14409a24aee916313d5.tar.gz
frameworks_av-6fed68ded4ab2c042b7ca14409a24aee916313d5.tar.bz2
am bb5d7c21: am 5f423917: Merge "Attempt to derive the avg. bitrate of the entire stream from metadata." into gingerbread
Merge commit 'bb5d7c21615128630fc9d08274bb14ca01e2124b' * commit 'bb5d7c21615128630fc9d08274bb14ca01e2124b': Attempt to derive the avg. bitrate of the entire stream from metadata.
Diffstat (limited to 'media/libstagefright/AwesomePlayer.cpp')
-rw-r--r--media/libstagefright/AwesomePlayer.cpp55
1 files changed, 46 insertions, 9 deletions
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 7b4dd1c..a0b7f70 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -306,6 +306,28 @@ status_t AwesomePlayer::setDataSource_l(
}
status_t AwesomePlayer::setDataSource_l(const sp<MediaExtractor> &extractor) {
+ // Attempt to approximate overall stream bitrate by summing all
+ // tracks' individual bitrates, if not all of them advertise bitrate,
+ // we have to fail.
+
+ int64_t totalBitRate = 0;
+
+ for (size_t i = 0; i < extractor->countTracks(); ++i) {
+ sp<MetaData> meta = extractor->getTrackMetaData(i);
+
+ int32_t bitrate;
+ if (!meta->findInt32(kKeyBitRate, &bitrate)) {
+ totalBitRate = -1;
+ break;
+ }
+
+ totalBitRate += bitrate;
+ }
+
+ mBitrate = totalBitRate;
+
+ LOGV("mBitrate = %lld bits/sec", mBitrate);
+
bool haveAudio = false;
bool haveVideo = false;
for (size_t i = 0; i < extractor->countTracks(); ++i) {
@@ -444,6 +466,8 @@ void AwesomePlayer::reset_l() {
delete mSuspensionState;
mSuspensionState = NULL;
+
+ mBitrate = -1;
}
void AwesomePlayer::notifyListener_l(int msg, int ext1, int ext2) {
@@ -456,17 +480,32 @@ void AwesomePlayer::notifyListener_l(int msg, int ext1, int ext2) {
}
}
+bool AwesomePlayer::getBitrate(int64_t *bitrate) {
+ off_t size;
+ if (mDurationUs >= 0 && mCachedSource != NULL
+ && mCachedSource->getSize(&size) == OK) {
+ *bitrate = size * 8000000ll / mDurationUs; // in bits/sec
+ return true;
+ }
+
+ if (mBitrate >= 0) {
+ *bitrate = mBitrate;
+ return true;
+ }
+
+ *bitrate = 0;
+
+ return false;
+}
+
// Returns true iff cached duration is available/applicable.
bool AwesomePlayer::getCachedDuration_l(int64_t *durationUs, bool *eos) {
- off_t totalSize;
+ int64_t bitrate;
if (mRTSPController != NULL) {
*durationUs = mRTSPController->getQueueDurationUs(eos);
return true;
- } else if (mCachedSource != NULL && mDurationUs >= 0
- && mCachedSource->getSize(&totalSize) == OK) {
- int64_t bitrate = totalSize * 8000000ll / mDurationUs; // in bits/sec
-
+ } else if (mCachedSource != NULL && getBitrate(&bitrate)) {
size_t cachedDataRemaining = mCachedSource->approxDataRemaining(eos);
*durationUs = cachedDataRemaining * 8000000ll / bitrate;
return true;
@@ -493,10 +532,8 @@ void AwesomePlayer::onBufferingUpdate() {
finishAsyncPrepare_l();
}
} else {
- off_t size;
- if (mDurationUs >= 0 && mCachedSource->getSize(&size) == OK) {
- int64_t bitrate = size * 8000000ll / mDurationUs; // in bits/sec
-
+ int64_t bitrate;
+ if (getBitrate(&bitrate)) {
size_t cachedSize = mCachedSource->cachedSize();
int64_t cachedDurationUs = cachedSize * 8000000ll / bitrate;