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