summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/StagefrightMetadataRetriever.cpp112
1 files changed, 71 insertions, 41 deletions
diff --git a/media/libstagefright/StagefrightMetadataRetriever.cpp b/media/libstagefright/StagefrightMetadataRetriever.cpp
index c7877a9..020887c 100644
--- a/media/libstagefright/StagefrightMetadataRetriever.cpp
+++ b/media/libstagefright/StagefrightMetadataRetriever.cpp
@@ -107,48 +107,14 @@ status_t StagefrightMetadataRetriever::setDataSource(
return OK;
}
-VideoFrame *StagefrightMetadataRetriever::captureFrame() {
- LOGV("captureFrame");
-
- if (mExtractor.get() == NULL) {
- LOGV("no extractor.");
- return NULL;
- }
-
- size_t n = mExtractor->countTracks();
- size_t i;
- for (i = 0; i < n; ++i) {
- sp<MetaData> meta = mExtractor->getTrackMetaData(i);
-
- const char *mime;
- CHECK(meta->findCString(kKeyMIMEType, &mime));
-
- if (!strncasecmp(mime, "video/", 6)) {
- break;
- }
- }
-
- if (i == n) {
- LOGV("no video track found.");
- return NULL;
- }
-
- sp<MetaData> trackMeta = mExtractor->getTrackMetaData(
- i, MediaExtractor::kIncludeExtensiveMetaData);
-
- sp<MediaSource> source = mExtractor->getTrack(i);
-
- if (source.get() == NULL) {
- LOGV("unable to instantiate video track.");
- return NULL;
- }
-
- sp<MetaData> meta = source->getFormat();
-
+static VideoFrame *extractVideoFrameWithCodecFlags(
+ OMXClient *client,
+ const sp<MetaData> &trackMeta,
+ const sp<MediaSource> &source, uint32_t flags) {
sp<MediaSource> decoder =
OMXCodec::Create(
- mClient.interface(), meta, false, source,
- NULL, OMXCodec::kPreferSoftwareCodecs);
+ client->interface(), source->getFormat(), false, source,
+ NULL, flags);
if (decoder.get() == NULL) {
LOGV("unable to instantiate video decoder.");
@@ -165,6 +131,8 @@ VideoFrame *StagefrightMetadataRetriever::captureFrame() {
int64_t thumbNailTime;
if (trackMeta->findInt64(kKeyThumbnailTime, &thumbNailTime)) {
options.setSeekTo(thumbNailTime);
+ } else {
+ thumbNailTime = -1;
}
MediaBuffer *buffer = NULL;
@@ -190,7 +158,19 @@ VideoFrame *StagefrightMetadataRetriever::captureFrame() {
LOGV("successfully decoded video frame.");
- meta = decoder->getFormat();
+ int64_t timeUs;
+ CHECK(buffer->meta_data()->findInt64(kKeyTime, &timeUs));
+ if (thumbNailTime >= 0) {
+ if (timeUs != thumbNailTime) {
+ const char *mime;
+ CHECK(trackMeta->findCString(kKeyMIMEType, &mime));
+
+ LOGV("thumbNailTime = %lld us, timeUs = %lld us, mime = %s",
+ thumbNailTime, timeUs, mime);
+ }
+ }
+
+ sp<MetaData> meta = decoder->getFormat();
int32_t width, height;
CHECK(meta->findInt32(kKeyWidth, &width));
@@ -225,6 +205,56 @@ VideoFrame *StagefrightMetadataRetriever::captureFrame() {
return frame;
}
+VideoFrame *StagefrightMetadataRetriever::captureFrame() {
+ LOGV("captureFrame");
+
+ if (mExtractor.get() == NULL) {
+ LOGV("no extractor.");
+ return NULL;
+ }
+
+ size_t n = mExtractor->countTracks();
+ size_t i;
+ for (i = 0; i < n; ++i) {
+ sp<MetaData> meta = mExtractor->getTrackMetaData(i);
+
+ const char *mime;
+ CHECK(meta->findCString(kKeyMIMEType, &mime));
+
+ if (!strncasecmp(mime, "video/", 6)) {
+ break;
+ }
+ }
+
+ if (i == n) {
+ LOGV("no video track found.");
+ return NULL;
+ }
+
+ sp<MetaData> trackMeta = mExtractor->getTrackMetaData(
+ i, MediaExtractor::kIncludeExtensiveMetaData);
+
+ sp<MediaSource> source = mExtractor->getTrack(i);
+
+ if (source.get() == NULL) {
+ LOGV("unable to instantiate video track.");
+ return NULL;
+ }
+
+ VideoFrame *frame =
+ extractVideoFrameWithCodecFlags(
+ &mClient, trackMeta, source, OMXCodec::kPreferSoftwareCodecs);
+
+ if (frame == NULL) {
+ LOGV("Software decoder failed to extract thumbnail, "
+ "trying hardware decoder.");
+
+ frame = extractVideoFrameWithCodecFlags(&mClient, trackMeta, source, 0);
+ }
+
+ return frame;
+}
+
MediaAlbumArt *StagefrightMetadataRetriever::extractAlbumArt() {
LOGV("extractAlbumArt (extractor: %s)", mExtractor.get() != NULL ? "YES" : "NO");