summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/SampleTable.cpp
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2009-10-22 13:49:30 -0700
committerAndreas Huber <andih@google.com>2009-10-22 14:22:57 -0700
commit7e04dcf8d6784dd56f53aa90bf34431ab4f0710c (patch)
tree62d858199d99be0c19887e2eca64495218067c01 /media/libstagefright/SampleTable.cpp
parent521bad496a8b80008abe573a6712a8051c9eb322 (diff)
downloadframeworks_av-7e04dcf8d6784dd56f53aa90bf34431ab4f0710c.zip
frameworks_av-7e04dcf8d6784dd56f53aa90bf34431ab4f0710c.tar.gz
frameworks_av-7e04dcf8d6784dd56f53aa90bf34431ab4f0710c.tar.bz2
Extract video thumbnails from the largest sync sample among the first 20.
Also fixes OMXCodec seek behaviour on the very first call to OMXCodec::read()
Diffstat (limited to 'media/libstagefright/SampleTable.cpp')
-rw-r--r--media/libstagefright/SampleTable.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/media/libstagefright/SampleTable.cpp b/media/libstagefright/SampleTable.cpp
index 5c5bb4d..3eed52a 100644
--- a/media/libstagefright/SampleTable.cpp
+++ b/media/libstagefright/SampleTable.cpp
@@ -575,5 +575,52 @@ status_t SampleTable::findClosestSyncSample(
return OK;
}
+status_t SampleTable::findThumbnailSample(uint32_t *sample_index) {
+ if (mSyncSampleOffset < 0) {
+ // All samples are sync-samples.
+ *sample_index = 0;
+ return OK;
+ }
+
+ uint32_t bestSampleIndex = 0;
+ size_t maxSampleSize = 0;
+
+ static const size_t kMaxNumSyncSamplesToScan = 20;
+
+ // Consider the first kMaxNumSyncSamplesToScan sync samples and
+ // pick the one with the largest (compressed) size as the thumbnail.
+
+ size_t numSamplesToScan = mNumSyncSamples;
+ if (numSamplesToScan > kMaxNumSyncSamplesToScan) {
+ numSamplesToScan = kMaxNumSyncSamplesToScan;
+ }
+
+ for (size_t i = 0; i < numSamplesToScan; ++i) {
+ uint32_t x;
+ if (mDataSource->read_at(
+ mSyncSampleOffset + 8 + i * 4, &x, 4) != 4) {
+ return ERROR_IO;
+ }
+ x = ntohl(x);
+ --x;
+
+ // Now x is a sample index.
+ size_t sampleSize;
+ status_t err = getSampleSize(x, &sampleSize);
+ if (err != OK) {
+ return err;
+ }
+
+ if (i == 0 || sampleSize > maxSampleSize) {
+ bestSampleIndex = x;
+ maxSampleSize = sampleSize;
+ }
+ }
+
+ *sample_index = bestSampleIndex;
+
+ return OK;
+}
+
} // namespace android