Merge "Added more metadata published by the MediaMetaDataRetriever"
This commit is contained in:
committed by
Android (Google) Code Review
commit
bfa40efc9b
@@ -105768,6 +105768,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="METADATA_KEY_BITRATE"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="20"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="METADATA_KEY_CD_TRACK_NUMBER"
|
||||
type="int"
|
||||
transient="false"
|
||||
@@ -105845,6 +105856,28 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="METADATA_KEY_HAS_AUDIO"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="16"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="METADATA_KEY_HAS_VIDEO"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="17"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="METADATA_KEY_MIMETYPE"
|
||||
type="int"
|
||||
transient="false"
|
||||
@@ -105878,6 +105911,28 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="METADATA_KEY_VIDEO_HEIGHT"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="19"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="METADATA_KEY_VIDEO_WIDTH"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="18"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="METADATA_KEY_WRITER"
|
||||
type="int"
|
||||
transient="false"
|
||||
|
||||
@@ -47,6 +47,12 @@ enum {
|
||||
METADATA_KEY_ALBUMARTIST = 13,
|
||||
METADATA_KEY_DISC_NUMBER = 14,
|
||||
METADATA_KEY_COMPILATION = 15,
|
||||
METADATA_KEY_HAS_AUDIO = 16,
|
||||
METADATA_KEY_HAS_VIDEO = 17,
|
||||
METADATA_KEY_VIDEO_WIDTH = 18,
|
||||
METADATA_KEY_VIDEO_HEIGHT = 19,
|
||||
METADATA_KEY_BITRATE = 20,
|
||||
|
||||
// Add more here...
|
||||
};
|
||||
|
||||
|
||||
@@ -398,5 +398,25 @@ public class MediaMetadataRetriever
|
||||
* The metadata key to retrieve the music album compilation status.
|
||||
*/
|
||||
public static final int METADATA_KEY_COMPILATION = 15;
|
||||
/**
|
||||
* If this key exists the media contains audio content.
|
||||
*/
|
||||
public static final int METADATA_KEY_HAS_AUDIO = 16;
|
||||
/**
|
||||
* If this key exists the media contains video content.
|
||||
*/
|
||||
public static final int METADATA_KEY_HAS_VIDEO = 17;
|
||||
/**
|
||||
* If the media contains video, this key retrieves its width.
|
||||
*/
|
||||
public static final int METADATA_KEY_VIDEO_WIDTH = 18;
|
||||
/**
|
||||
* If the media contains video, this key retrieves its height.
|
||||
*/
|
||||
public static final int METADATA_KEY_VIDEO_HEIGHT = 19;
|
||||
/**
|
||||
* This key retrieves the average bitrate (in bits/sec), if available.
|
||||
*/
|
||||
public static final int METADATA_KEY_BITRATE = 20;
|
||||
// Add more here...
|
||||
}
|
||||
|
||||
@@ -411,6 +411,12 @@ void StagefrightMetadataRetriever::parseMetaData() {
|
||||
|
||||
mMetaData.add(METADATA_KEY_NUM_TRACKS, String8(tmp));
|
||||
|
||||
bool hasAudio = false;
|
||||
bool hasVideo = false;
|
||||
int32_t videoWidth = -1;
|
||||
int32_t videoHeight = -1;
|
||||
int32_t audioBitrate = -1;
|
||||
|
||||
// The overall duration is the duration of the longest track.
|
||||
int64_t maxDurationUs = 0;
|
||||
for (size_t i = 0; i < numTracks; ++i) {
|
||||
@@ -422,12 +428,55 @@ void StagefrightMetadataRetriever::parseMetaData() {
|
||||
maxDurationUs = durationUs;
|
||||
}
|
||||
}
|
||||
|
||||
const char *mime;
|
||||
if (trackMeta->findCString(kKeyMIMEType, &mime)) {
|
||||
if (!hasAudio && !strncasecmp("audio/", mime, 6)) {
|
||||
hasAudio = true;
|
||||
|
||||
if (!trackMeta->findInt32(kKeyBitRate, &audioBitrate)) {
|
||||
audioBitrate = -1;
|
||||
}
|
||||
} else if (!hasVideo && !strncasecmp("video/", mime, 6)) {
|
||||
hasVideo = true;
|
||||
|
||||
CHECK(trackMeta->findInt32(kKeyWidth, &videoWidth));
|
||||
CHECK(trackMeta->findInt32(kKeyHeight, &videoHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The duration value is a string representing the duration in ms.
|
||||
sprintf(tmp, "%lld", (maxDurationUs + 500) / 1000);
|
||||
mMetaData.add(METADATA_KEY_DURATION, String8(tmp));
|
||||
|
||||
if (hasAudio) {
|
||||
mMetaData.add(METADATA_KEY_HAS_AUDIO, String8("yes"));
|
||||
}
|
||||
|
||||
if (hasVideo) {
|
||||
mMetaData.add(METADATA_KEY_HAS_VIDEO, String8("yes"));
|
||||
|
||||
sprintf(tmp, "%d", videoWidth);
|
||||
mMetaData.add(METADATA_KEY_VIDEO_WIDTH, String8(tmp));
|
||||
|
||||
sprintf(tmp, "%d", videoHeight);
|
||||
mMetaData.add(METADATA_KEY_VIDEO_HEIGHT, String8(tmp));
|
||||
}
|
||||
|
||||
if (numTracks == 1 && hasAudio && audioBitrate >= 0) {
|
||||
sprintf(tmp, "%ld", audioBitrate);
|
||||
mMetaData.add(METADATA_KEY_BITRATE, String8(tmp));
|
||||
} else {
|
||||
off64_t sourceSize;
|
||||
if (mSource->getSize(&sourceSize) == OK) {
|
||||
int64_t avgBitRate = (int64_t)(sourceSize * 8E6 / maxDurationUs);
|
||||
|
||||
sprintf(tmp, "%lld", avgBitRate);
|
||||
mMetaData.add(METADATA_KEY_BITRATE, String8(tmp));
|
||||
}
|
||||
}
|
||||
|
||||
if (numTracks == 1) {
|
||||
const char *fileMIME;
|
||||
CHECK(meta->findCString(kKeyMIMEType, &fileMIME));
|
||||
|
||||
Reference in New Issue
Block a user