Added native metadata support.
Metadata.java:
Fixed typo 8k != 8092. The comment was correct though.
In Metadata.h, the new Metadata class is declared in the ns android::media
to limit the chances of conflict with other packages.
The MetadataType in MediaPlayerInterface is gone and moved to Metadata as
an inner typedef.
Similarly the SortedVector<MetadataType> instance have been replace by a
new type Metadata::Filter.
All the keys declared in the java counterpart are also in Metadata.h.
Metadata.cpp:
Contains the implementation of the native metadata packing.
There an associated change in the opencore package that should go in
at the same time as this one.
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 5e62f9d..77f7434 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -47,10 +47,9 @@
#include <media/MediaPlayerInterface.h>
#include <media/mediarecorder.h>
#include <media/MediaMetadataRetrieverInterface.h>
+#include <media/Metadata.h>
#include <media/AudioTrack.h>
-#include <utils/SortedVector.h>
-
#include "MediaRecorderClient.h"
#include "MediaPlayerService.h"
#include "MetadataRetrieverClient.h"
@@ -85,21 +84,17 @@
#endif
namespace {
+using android::media::Metadata;
using android::status_t;
using android::OK;
using android::BAD_VALUE;
using android::NOT_ENOUGH_DATA;
-using android::MetadataType;
using android::Parcel;
-using android::SortedVector;
// Max number of entries in the filter.
const int kMaxFilterSize = 64; // I pulled that out of thin air.
-// Keep in sync with ANY in Metadata.java
-const int32_t kAny = 0;
-
-const int32_t kMetaMarker = 0x4d455441; // 'M' 'E' 'T' 'A'
+// FIXME: Move all the metadata related function in the Metadata.cpp
// Unmarshall a filter from a Parcel.
@@ -124,7 +119,7 @@
// @param[out] status On exit contains the status code to be returned.
// @return true if the parcel starts with a valid filter.
bool unmarshallFilter(const Parcel& p,
- SortedVector<MetadataType> *filter,
+ Metadata::Filter *filter,
status_t *status)
{
int32_t val;
@@ -147,7 +142,7 @@
filter->clear();
filter->setCapacity(num);
- size_t size = num * sizeof(MetadataType);
+ size_t size = num * sizeof(Metadata::Type);
if (p.dataAvail() < size)
@@ -157,7 +152,8 @@
return false;
}
- const MetadataType *data = static_cast<const MetadataType*>(p.readInplace(size));
+ const Metadata::Type *data =
+ static_cast<const Metadata::Type*>(p.readInplace(size));
if (NULL == data)
{
@@ -181,11 +177,11 @@
// @param filter Of metadata type.
// @param val To be searched.
// @return true if a match was found.
-bool findMetadata(const SortedVector<MetadataType>& filter, const int32_t val)
+bool findMetadata(const Metadata::Filter& filter, const int32_t val)
{
// Deal with empty and ANY right away
if (filter.isEmpty()) return false;
- if (filter[0] == kAny) return true;
+ if (filter[0] == Metadata::kAny) return true;
return filter.indexOf(val) >= 0;
}
@@ -857,7 +853,7 @@
status_t MediaPlayerService::Client::setMetadataFilter(const Parcel& filter)
{
status_t status;
- SortedVector<MetadataType> allow, drop;
+ media::Metadata::Filter allow, drop;
if (unmarshallFilter(filter, &allow, &status) &&
unmarshallFilter(filter, &drop, &status)) {
@@ -872,14 +868,14 @@
status_t MediaPlayerService::Client::getMetadata(
bool update_only, bool apply_filter, Parcel *reply)
{
- sp<MediaPlayerBase> p = getPlayer();
- if (p == 0) return UNKNOWN_ERROR;
+ sp<MediaPlayerBase> player = getPlayer();
+ if (player == 0) return UNKNOWN_ERROR;
status_t status;
// Placeholder for the return code, updated by the caller.
reply->writeInt32(-1);
- SortedVector<MetadataType> ids;
+ media::Metadata::Filter ids;
// We don't block notifications while we fetch the data. We clear
// mMetadataUpdated first so we don't lose notifications happening
@@ -892,14 +888,13 @@
mMetadataUpdated.clear();
}
- const size_t begin = reply->dataPosition();
- reply->writeInt32(-1); // Placeholder for the length of the metadata
- reply->writeInt32(kMetaMarker);
+ media::Metadata metadata(reply);
- status = p->getMetadata(ids, reply);
+ metadata.appendHeader();
+ status = player->getMetadata(ids, reply);
if (status != OK) {
- reply->setDataPosition(begin);
+ metadata.resetParcel();
LOGE("getMetadata failed %d", status);
return status;
}
@@ -908,12 +903,8 @@
// filtering takes place on the update notifications already. This
// would be when all the metadata are fetch and a filter is set.
- const size_t end = reply->dataPosition();
-
// Everything is fine, update the metadata length.
- reply->setDataPosition(begin);
- reply->writeInt32(end - begin);
- reply->setDataPosition(end);
+ metadata.updateLength();
return OK;
}
@@ -1043,7 +1034,7 @@
if (MEDIA_INFO == msg &&
MEDIA_INFO_METADATA_UPDATE == ext1) {
- const MetadataType metadata_type = ext2;
+ const media::Metadata::Type metadata_type = ext2;
if(client->shouldDropMetadata(metadata_type)) {
return;
@@ -1058,7 +1049,7 @@
}
-bool MediaPlayerService::Client::shouldDropMetadata(MetadataType code) const
+bool MediaPlayerService::Client::shouldDropMetadata(media::Metadata::Type code) const
{
Mutex::Autolock lock(mLock);
@@ -1074,7 +1065,7 @@
}
-void MediaPlayerService::Client::addNewMetadataUpdate(MetadataType metadata_type) {
+void MediaPlayerService::Client::addNewMetadataUpdate(media::Metadata::Type metadata_type) {
Mutex::Autolock lock(mLock);
if (mMetadataUpdated.indexOf(metadata_type) < 0) {
mMetadataUpdated.add(metadata_type);
@@ -1499,4 +1490,4 @@
p->mSignal.signal();
}
-}; // namespace android
+} // namespace android
diff --git a/media/libmediaplayerservice/MediaPlayerService.h b/media/libmediaplayerservice/MediaPlayerService.h
index 94cb917..a4be414 100644
--- a/media/libmediaplayerservice/MediaPlayerService.h
+++ b/media/libmediaplayerservice/MediaPlayerService.h
@@ -23,15 +23,14 @@
#include <utils/List.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
-#include <utils/SortedVector.h>
#include <utils/Vector.h>
#include <ui/SurfaceComposerClient.h>
#include <media/IMediaPlayerService.h>
#include <media/MediaPlayerInterface.h>
+#include <media/Metadata.h>
namespace android {
-typedef int32_t MetadataType;
class IMediaRecorder;
class IMediaMetadataRetriever;
@@ -239,12 +238,12 @@
// @param type Of the metadata to be tested.
// @return true if the metadata should be dropped according to
// the filters.
- bool shouldDropMetadata(MetadataType type) const;
+ bool shouldDropMetadata(media::Metadata::Type type) const;
// Add a new element to the set of metadata updated. Noop if
// the element exists already.
// @param type Of the metadata to be recorded.
- void addNewMetadataUpdate(MetadataType type);
+ void addNewMetadataUpdate(media::Metadata::Type type);
mutable Mutex mLock;
sp<MediaPlayerBase> mPlayer;
@@ -257,14 +256,14 @@
int32_t mConnId;
// Metadata filters.
- SortedVector<int32_t> mMetadataAllow; // protected by mLock
- SortedVector<int32_t> mMetadataDrop; // protected by mLock
+ media::Metadata::Filter mMetadataAllow; // protected by mLock
+ media::Metadata::Filter mMetadataDrop; // protected by mLock
// Metadata updated. For each MEDIA_INFO_METADATA_UPDATE
// notification we try to update mMetadataUpdated which is a
// set: no duplicate.
// getMetadata clears this set.
- SortedVector<int32_t> mMetadataUpdated; // protected by mLock
+ media::Metadata::Filter mMetadataUpdated; // protected by mLock
#if CALLBACK_ANTAGONIZER
Antagonizer* mAntagonizer;
diff --git a/media/libmediaplayerservice/MidiFile.h b/media/libmediaplayerservice/MidiFile.h
index 30b6a2e..25d4a1b 100644
--- a/media/libmediaplayerservice/MidiFile.h
+++ b/media/libmediaplayerservice/MidiFile.h
@@ -49,10 +49,6 @@
virtual status_t invoke(const Parcel& request, Parcel *reply) {
return INVALID_OPERATION;
}
- virtual status_t getMetadata(const SortedVector<MetadataType>& ids,
- Parcel *records) {
- return INVALID_OPERATION;
- }
private:
status_t createOutputTrack();
diff --git a/media/libmediaplayerservice/StagefrightPlayer.cpp b/media/libmediaplayerservice/StagefrightPlayer.cpp
index 8597275..9a06d13 100644
--- a/media/libmediaplayerservice/StagefrightPlayer.cpp
+++ b/media/libmediaplayerservice/StagefrightPlayer.cpp
@@ -144,7 +144,7 @@
if (mPlayer == NULL) {
return NO_INIT;
}
-
+
status_t err = mPlayer->seekTo((int64_t)msec * 1000);
sendEvent(MEDIA_SEEK_COMPLETE);
@@ -205,9 +205,4 @@
}
}
-status_t StagefrightPlayer::getMetadata(
- const SortedVector<MetadataType> &ids, Parcel *records) {
- return INVALID_OPERATION;
-}
-
} // namespace android
diff --git a/media/libmediaplayerservice/StagefrightPlayer.h b/media/libmediaplayerservice/StagefrightPlayer.h
index f93c1f8..f214872 100644
--- a/media/libmediaplayerservice/StagefrightPlayer.h
+++ b/media/libmediaplayerservice/StagefrightPlayer.h
@@ -48,9 +48,6 @@
virtual status_t invoke(const Parcel &request, Parcel *reply);
virtual void setAudioSink(const sp<AudioSink> &audioSink);
- virtual status_t getMetadata(
- const SortedVector<MetadataType> &ids, Parcel *records);
-
private:
MediaPlayerImpl *mPlayer;
diff --git a/media/libmediaplayerservice/TestPlayerStub.h b/media/libmediaplayerservice/TestPlayerStub.h
index 339b108..80d53a8 100644
--- a/media/libmediaplayerservice/TestPlayerStub.h
+++ b/media/libmediaplayerservice/TestPlayerStub.h
@@ -94,10 +94,6 @@
virtual status_t invoke(const android::Parcel& in, android::Parcel *out) {
return mPlayer->invoke(in, out);
}
- virtual status_t getMetadata(const SortedVector<MetadataType>& ids,
- Parcel *records) {
- return INVALID_OPERATION;
- }
// @return true if the current build is 'eng' or 'test' and the
diff --git a/media/libmediaplayerservice/VorbisPlayer.h b/media/libmediaplayerservice/VorbisPlayer.h
index 040eb36..4024654 100644
--- a/media/libmediaplayerservice/VorbisPlayer.h
+++ b/media/libmediaplayerservice/VorbisPlayer.h
@@ -54,10 +54,6 @@
virtual status_t setLooping(int loop);
virtual player_type playerType() { return VORBIS_PLAYER; }
virtual status_t invoke(const Parcel& request, Parcel *reply) {return INVALID_OPERATION;}
- virtual status_t getMetadata(const SortedVector<MetadataType>& ids,
- Parcel *records) {
- return INVALID_OPERATION;
- }
private:
status_t setdatasource(const char *path, int fd, int64_t offset, int64_t length);