blob: 9c915ce89e1a5072c7c3b570612d75045b6226f8 [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
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
Andreas Huber10b9b3f2010-10-08 10:16:24 -070094 static const Type kSeekAvailable = 32; // Boolean
nikobc726922009-07-20 15:07:26 -070095
96 // @param p[inout] The parcel to append the metadata records
97 // to. The global metadata header should have been set already.
98 explicit Metadata(Parcel *p);
99 ~Metadata();
100
101 // Rewind the underlying parcel, undoing all the changes.
102 void resetParcel();
103
104 // Append the size and 'META' marker.
105 bool appendHeader();
106
107 // Once all the records have been added, call this to update the
108 // lenght field in the header.
109 void updateLength();
110
111 // append* are methods to append metadata.
112 // @param key Is the metadata Id.
113 // @param val Is the value of the metadata.
114 // @return true if successful, false otherwise.
115 // TODO: add more as needed to handle other types.
116 bool appendBool(Type key, bool val);
117 bool appendInt32(Type key, int32_t val);
118
119 private:
120 Metadata(const Metadata&);
121 Metadata& operator=(const Metadata&);
122
123
124 // Checks the key is valid and not already present.
125 bool checkKey(Type key);
126
127 Parcel *mData;
128 size_t mBegin;
129};
130
131} // namespace android::media
132} // namespace android
133
134#endif // ANDROID_MEDIA_METADATA_H__