ID3.h revision 428d96d5f882d01acb0abb7e1ceb51d4ccc48efa
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) 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
69        Iterator(const Iterator &);
70        Iterator &operator=(const Iterator &);
71    };
72
73private:
74    bool mIsValid;
75    uint8_t *mData;
76    size_t mSize;
77    size_t mFirstFrameOffset;
78    Version mVersion;
79
80    bool parseV1(const sp<DataSource> &source);
81    bool parseV2(const sp<DataSource> &source);
82    void removeUnsynchronization();
83    bool removeUnsynchronizationV2_4(bool iTunesHack);
84
85    static bool ParseSyncsafeInteger(const uint8_t encoded[4], size_t *x);
86
87    ID3(const ID3 &);
88    ID3 &operator=(const ID3 &);
89};
90
91}  // namespace android
92
93#endif  // ID3_H_
94
95