• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     ID3(const uint8_t *data, size_t size, bool ignoreV1 = false);
41     ~ID3();
42 
43     bool isValid() const;
44 
45     Version version() const;
46 
47     const void *getAlbumArt(size_t *length, String8 *mime) const;
48 
49     struct Iterator {
50         Iterator(const ID3 &parent, const char *id);
51         ~Iterator();
52 
53         bool done() const;
54         void getID(String8 *id) const;
55         void getString(String8 *s, String8 *ss = NULL) const;
56         const uint8_t *getData(size_t *length) const;
57         void next();
58 
59     private:
60         const ID3 &mParent;
61         char *mID;
62         size_t mOffset;
63 
64         const uint8_t *mFrameData;
65         size_t mFrameSize;
66 
67         void findFrame();
68 
69         size_t getHeaderLength() const;
70         void getstring(String8 *s, bool secondhalf) const;
71 
72         Iterator(const Iterator &);
73         Iterator &operator=(const Iterator &);
74     };
75 
rawSizeID376     size_t rawSize() const { return mRawSize; }
77 
78 private:
79     class DataSourceUnwrapper;
80     struct MemorySource;
81     bool mIsValid;
82     uint8_t *mData;
83     size_t mSize;
84     size_t mFirstFrameOffset;
85     Version mVersion;
86 
87     // size of the ID3 tag including header before any unsynchronization.
88     // only valid for IDV2+
89     size_t mRawSize;
90 
91     bool parseV1(DataSourceBase *source);
92     bool parseV2(DataSourceBase *source, off64_t offset);
93     void removeUnsynchronization();
94     bool removeUnsynchronizationV2_4(bool iTunesHack, bool hasGlobalUnsync);
95 
96     static bool ParseSyncsafeInteger(const uint8_t encoded[4], size_t *x);
97 
98     ID3(const ID3 &);
99     ID3 &operator=(const ID3 &);
100 };
101 
102 }  // namespace android
103 
104 #endif  // ID3_H_
105 
106