blob: 07567ebbc1581dd49c4ee6d299d1c536de957f90 [file] [log] [blame]
nikobc726922009-07-20 15:07:26 -07001/*
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
Gloria Wang1e1b13e2011-06-23 10:39:51 -070054 // Playback capabilities.
55 static const Type kPauseAvailable = 1; // Boolean
56 static const Type kSeekBackwardAvailable = 2; // Boolean
57 static const Type kSeekForwardAvailable = 3; // Boolean
58 static const Type kSeekAvailable = 4; // Boolean
nikobc726922009-07-20 15:07:26 -070059
Gloria Wang1e1b13e2011-06-23 10:39:51 -070060 // Keep in sync with android/media/Metadata.java
61 static const Type kTitle = 5; // String
62 static const Type kComment = 6; // String
63 static const Type kCopyright = 7; // String
64 static const Type kAlbum = 8; // String
65 static const Type kArtist = 9; // String
66 static const Type kAuthor = 10; // String
67 static const Type kComposer = 11; // String
68 static const Type kGenre = 12; // String
69 static const Type kDate = 13; // Date
70 static const Type kDuration = 14; // Integer(millisec)
71 static const Type kCdTrackNum = 15; // Integer 1-based
72 static const Type kCdTrackMax = 16; // Integer
73 static const Type kRating = 17; // String
74 static const Type kAlbumArt = 18; // byte[]
75 static const Type kVideoFrame = 19; // Bitmap
76
77 static const Type kBitRate = 20; // Integer, Aggregate rate of
nikobc726922009-07-20 15:07:26 -070078 // all the streams in bps.
79
Gloria Wang1e1b13e2011-06-23 10:39:51 -070080 static const Type kAudioBitRate = 21; // Integer, bps
81 static const Type kVideoBitRate = 22; // Integer, bps
82 static const Type kAudioSampleRate = 23; // Integer, Hz
83 static const Type kVideoframeRate = 24; // Integer, Hz
nikobc726922009-07-20 15:07:26 -070084
85 // See RFC2046 and RFC4281.
Gloria Wang1e1b13e2011-06-23 10:39:51 -070086 static const Type kMimeType = 25; // String
87 static const Type kAudioCodec = 26; // String
88 static const Type kVideoCodec = 27; // String
nikobc726922009-07-20 15:07:26 -070089
Gloria Wang1e1b13e2011-06-23 10:39:51 -070090 static const Type kVideoHeight = 28; // Integer
91 static const Type kVideoWidth = 29; // Integer
92 static const Type kNumTracks = 30; // Integer
93 static const Type kDrmCrippled = 31; // Boolean
nikobc726922009-07-20 15:07:26 -070094
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__