Metadata.h revision a64c8c79af1a15911c55306d83a797fa50969f77
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_MEDIA_METADATA_H__
18#define ANDROID_MEDIA_METADATA_H__
19
20#include <sys/types.h>
21#include <utils/Errors.h>
22#include <utils/RefBase.h>
23#include <utils/SortedVector.h>
24
25namespace android {
26class Parcel;
27
28namespace media {
29
30// Metadata is a class to build/serialize a set of metadata in a Parcel.
31//
32// This class should be kept in sync with android/media/Metadata.java.
33// It provides all the metadata ids available and methods to build the
34// header, add records and adjust the set size header field.
35//
36// Typical Usage:
37// ==============
38//  Parcel p;
39//  media::Metadata data(&p);
40//
41//  data.appendHeader();
42//  data.appendBool(Metadata::kPauseAvailable, true);
43//   ... more append ...
44//  data.updateLength();
45//
46
47class Metadata {
48  public:
49    typedef int32_t Type;
50    typedef SortedVector<Type> Filter;
51
52    static const Type kAny = 0;
53
54    // Keep in sync with android/media/Metadata.java
55    static const Type kTitle = 1;           // String
56    static const Type kComment = 2;         // String
57    static const Type kCopyright = 3;       // String
58    static const Type kAlbum = 4;           // String
59    static const Type kArtist = 5;          // String
60    static const Type kAuthor = 6;          // String
61    static const Type kComposer = 7;        // String
62    static const Type kGenre = 8;           // String
63    static const Type kDate = 9;            // Date
64    static const Type kDuration = 10;       // Integer(millisec)
65    static const Type kCdTrackNum = 11;     // Integer 1-based
66    static const Type kCdTrackMax = 12;     // Integer
67    static const Type kRating = 13;         // String
68    static const Type kAlbumArt = 14;       // byte[]
69    static const Type kVideoFrame = 15;     // Bitmap
70    static const Type kCaption = 16;        // TimedText
71
72    static const Type kBitRate = 17;       // Integer, Aggregate rate of
73    // all the streams in bps.
74
75    static const Type kAudioBitRate = 18; // Integer, bps
76    static const Type kVideoBitRate = 19; // Integer, bps
77    static const Type kAudioSampleRate = 20; // Integer, Hz
78    static const Type kVideoframeRate = 21;  // Integer, Hz
79
80    // See RFC2046 and RFC4281.
81    static const Type kMimeType = 22;      // String
82    static const Type kAudioCodec = 23;    // String
83    static const Type kVideoCodec = 24;    // String
84
85    static const Type kVideoHeight = 25;   // Integer
86    static const Type kVideoWidth = 26;    // Integer
87    static const Type kNumTracks = 27;     // Integer
88    static const Type kDrmCrippled = 28;   // Boolean
89
90    // Playback capabilities.
91    static const Type kPauseAvailable = 29;        // Boolean
92    static const Type kSeekBackwardAvailable = 30; // Boolean
93    static const Type kSeekForwardAvailable = 31;  // Boolean
94
95    // @param p[inout] The parcel to append the metadata records
96    // to. The global metadata header should have been set already.
97    explicit Metadata(Parcel *p);
98    ~Metadata();
99
100    // Rewind the underlying parcel, undoing all the changes.
101    void resetParcel();
102
103    // Append the size and 'META' marker.
104    bool appendHeader();
105
106    // Once all the records have been added, call this to update the
107    // lenght field in the header.
108    void updateLength();
109
110    // append* are methods to append metadata.
111    // @param key Is the metadata Id.
112    // @param val Is the value of the metadata.
113    // @return true if successful, false otherwise.
114    // TODO: add more as needed to handle other types.
115    bool appendBool(Type key, bool val);
116    bool appendInt32(Type key, int32_t val);
117
118  private:
119    Metadata(const Metadata&);
120    Metadata& operator=(const Metadata&);
121
122
123    // Checks the key is valid and not already present.
124    bool checkKey(Type key);
125
126    Parcel *mData;
127    size_t mBegin;
128};
129
130}  // namespace android::media
131}  // namespace android
132
133#endif  // ANDROID_MEDIA_METADATA_H__
134