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 23namespace android { 24 25struct DataSource; 26struct String8; 27 28struct ID3 { 29 enum Version { 30 ID3_UNKNOWN, 31 ID3_V1, 32 ID3_V1_1, 33 ID3_V2_2, 34 ID3_V2_3, 35 ID3_V2_4, 36 }; 37 38 ID3(const sp<DataSource> &source); 39 ~ID3(); 40 41 bool isValid() const; 42 43 Version version() const; 44 45 const void *getAlbumArt(size_t *length, String8 *mime) const; 46 47 struct Iterator { 48 Iterator(const ID3 &parent, const char *id); 49 ~Iterator(); 50 51 bool done() const; 52 void getID(String8 *id) const; 53 void getString(String8 *s, String8 *ss = NULL) const; 54 const uint8_t *getData(size_t *length) const; 55 void next(); 56 57 private: 58 const ID3 &mParent; 59 char *mID; 60 size_t mOffset; 61 62 const uint8_t *mFrameData; 63 size_t mFrameSize; 64 65 void findFrame(); 66 67 size_t getHeaderLength() const; 68 void getstring(String8 *s, bool secondhalf) const; 69 70 Iterator(const Iterator &); 71 Iterator &operator=(const Iterator &); 72 }; 73 74private: 75 bool mIsValid; 76 uint8_t *mData; 77 size_t mSize; 78 size_t mFirstFrameOffset; 79 Version mVersion; 80 81 bool parseV1(const sp<DataSource> &source); 82 bool parseV2(const sp<DataSource> &source); 83 void removeUnsynchronization(); 84 bool removeUnsynchronizationV2_4(bool iTunesHack); 85 86 static bool ParseSyncsafeInteger(const uint8_t encoded[4], size_t *x); 87 88 ID3(const ID3 &); 89 ID3 &operator=(const ID3 &); 90}; 91 92} // namespace android 93 94#endif // ID3_H_ 95 96