1 /* 2 * Copyright (C) 2010 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 ID3_H_ 18 19 #define ID3_H_ 20 21 #include <utils/RefBase.h> 22 23 namespace android { 24 25 class DataSourceBase; 26 class String8; 27 class DataSourceHelper; 28 29 struct ID3 { 30 enum Version { 31 ID3_UNKNOWN, 32 ID3_V1, 33 ID3_V1_1, 34 ID3_V2_2, 35 ID3_V2_3, 36 ID3_V2_4, 37 }; 38 39 explicit ID3(DataSourceHelper *source, bool ignoreV1 = false, off64_t offset = 0); 40 explicit ID3(DataSourceBase *source, bool ignoreV1 = false, off64_t offset = 0); 41 ID3(const uint8_t *data, size_t size, bool ignoreV1 = false); 42 ~ID3(); 43 44 bool isValid() const; 45 46 Version version() const; 47 48 const void *getAlbumArt(size_t *length, String8 *mime) const; 49 50 struct Iterator { 51 Iterator(const ID3 &parent, const char *id); 52 ~Iterator(); 53 54 bool done() const; 55 void getID(String8 *id) const; 56 void getString(String8 *s, String8 *ss = NULL) const; 57 const uint8_t *getData(size_t *length) const; 58 void next(); 59 60 private: 61 const ID3 &mParent; 62 char *mID; 63 size_t mOffset; 64 65 const uint8_t *mFrameData; 66 size_t mFrameSize; 67 68 void findFrame(); 69 70 size_t getHeaderLength() const; 71 void getstring(String8 *s, bool secondhalf) const; 72 73 Iterator(const Iterator &); 74 Iterator &operator=(const Iterator &); 75 }; 76 rawSizeID377 size_t rawSize() const { return mRawSize; } 78 79 private: 80 class DataSourceUnwrapper; 81 struct MemorySource; 82 bool mIsValid; 83 uint8_t *mData; 84 size_t mSize; 85 size_t mFirstFrameOffset; 86 Version mVersion; 87 88 // size of the ID3 tag including header before any unsynchronization. 89 // only valid for IDV2+ 90 size_t mRawSize; 91 92 bool parseV1(DataSourceBase *source); 93 bool parseV2(DataSourceBase *source, off64_t offset); 94 void removeUnsynchronization(); 95 bool removeUnsynchronizationV2_4(bool iTunesHack); 96 97 static bool ParseSyncsafeInteger(const uint8_t encoded[4], size_t *x); 98 99 ID3(const ID3 &); 100 ID3 &operator=(const ID3 &); 101 }; 102 103 } // namespace android 104 105 #endif // ID3_H_ 106 107