Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc726927 authored by niko's avatar niko
Browse files

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.
parent c7bebd15
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -26,11 +26,10 @@

#include <media/mediaplayer.h>
#include <media/AudioSystem.h>
#include <media/Metadata.h>

namespace android {

typedef int32_t MetadataType;

class Parcel;
template<typename T> class SortedVector;

@@ -129,8 +128,10 @@ public:
    //            the known metadata should be returned.
    // @param[inout] records Parcel where the player appends its metadata.
    // @return OK if the call was successful.
    virtual status_t    getMetadata(const SortedVector<MetadataType>& ids,
                                    Parcel *records) = 0;
    virtual status_t    getMetadata(const media::Metadata::Filter& ids,
                                    Parcel *records) {
        return INVALID_OPERATION;
    };

protected:
    virtual void        sendEvent(int msg, int ext1=0, int ext2=0) { if (mNotify) mNotify(mCookie, msg, ext1, ext2); }
+133 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_MEDIA_METADATA_H__
#define ANDROID_MEDIA_METADATA_H__

#include <sys/types.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
#include <utils/SortedVector.h>

namespace android {
class Parcel;

namespace media {

// Metadata is a class to build/serialize a set of metadata in a Parcel.
//
// This class should be kept in sync with android/media/Metadata.java.
// It provides all the metadata ids available and methods to build the
// header, add records and adjust the set size header field.
//
// Typical Usage:
// ==============
//  Parcel p;
//  media::Metadata data(&p);
//
//  data.appendHeader();
//  data.appendBool(Metadata::kPauseAvailable, true);
//   ... more append ...
//  data.updateLength();
//

class Metadata {
  public:
    typedef int32_t Type;
    typedef SortedVector<Type> Filter;

    static const Type kAny = 0;

    // Keep in sync with android/media/Metadata.java
    static const Type kTitle = 1;           // String
    static const Type kComment = 2;         // String
    static const Type kCopyright = 3;       // String
    static const Type kAlbum = 4;           // String
    static const Type kArtist = 5;          // String
    static const Type kAuthor = 6;          // String
    static const Type kComposer = 7;        // String
    static const Type kGenre = 8;           // String
    static const Type kDate = 9;            // Date
    static const Type kDuration = 10;       // Integer(millisec)
    static const Type kCdTrackNum = 11;     // Integer 1-based
    static const Type kCdTrackMax = 12;     // Integer
    static const Type kRating = 13;         // String
    static const Type kAlbumArt = 14;       // byte[]
    static const Type kVideoFrame = 15;     // Bitmap
    static const Type kCaption = 16;        // TimedText

    static const Type kBitRate = 17;       // Integer, Aggregate rate of
    // all the streams in bps.

    static const Type kAudioBitRate = 18; // Integer, bps
    static const Type kVideoBitRate = 19; // Integer, bps
    static const Type kAudioSampleRate = 20; // Integer, Hz
    static const Type kVideoframeRate = 21;  // Integer, Hz

    // See RFC2046 and RFC4281.
    static const Type kMimeType = 22;      // String
    static const Type kAudioCodec = 23;    // String
    static const Type kVideoCodec = 24;    // String

    static const Type kVideoHeight = 25;   // Integer
    static const Type kVideoWidth = 26;    // Integer
    static const Type kNumTracks = 27;     // Integer
    static const Type kDrmCrippled = 28;   // Boolean

    // Playback capabilities.
    static const Type kPauseAvailable = 29;        // Boolean
    static const Type kSeekBackwardAvailable = 30; // Boolean
    static const Type kSeekForwardAvailable = 31;  // Boolean

    // @param p[inout] The parcel to append the metadata records
    // to. The global metadata header should have been set already.
    explicit Metadata(Parcel *p);
    ~Metadata();

    // Rewind the underlying parcel, undoing all the changes.
    void resetParcel();

    // Append the size and 'META' marker.
    bool appendHeader();

    // Once all the records have been added, call this to update the
    // lenght field in the header.
    void updateLength();

    // append* are methods to append metadata.
    // @param key Is the metadata Id.
    // @param val Is the value of the metadata.
    // @return true if successful, false otherwise.
    // TODO: add more as needed to handle other types.
    bool appendBool(Type key, bool val);
    bool appendInt32(Type key, int32_t val);

  private:
    Metadata(const Metadata&);
    Metadata& operator=(const Metadata&);


    // Checks the key is valid and not already present.
    bool checkKey(Type key);

    Parcel *mData;
    size_t mBegin;
};

}  // namespace android::media
}  // namespace android

#endif  // ANDROID_MEDIA_METADATA_H__
+4 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <utils/Errors.h>
#include <media/MediaPlayerInterface.h>
#include <media/Metadata.h>

#define MAX_OPENCORE_INSTANCES 25

@@ -53,7 +54,8 @@ public:
    virtual status_t    setLooping(int loop);
    virtual player_type playerType() { return PV_PLAYER; }
    virtual status_t    invoke(const Parcel& request, Parcel *reply);
    virtual status_t    getMetadata(const SortedVector<MetadataType>& ids,
    virtual status_t    getMetadata(
        const SortedVector<media::Metadata::Type>& ids,
        Parcel *records);

    // make available to PlayerDriver
+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ public class Metadata
    public static final int SEEK_FORWARD_AVAILABLE = 31;  // Boolean

    private static final int LAST_SYSTEM = 31;
    private static final int FIRST_CUSTOM = 8092;
    private static final int FIRST_CUSTOM = 8192;

    // Shorthands to set the MediaPlayer's metadata filter.
    public static final Set<Integer> MATCH_NONE = Collections.EMPTY_SET;
+19 −18
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ LOCAL_SRC_FILES:= \
    IMediaPlayerClient.cpp \
    IMediaPlayer.cpp \
    IMediaRecorder.cpp \
    Metadata.cpp \
    mediarecorder.cpp \
    IMediaMetadataRetriever.cpp \
    mediametadataretriever.cpp \
Loading