ID3.h revision fc9ba09e3bb368f823d473f5e2bb9aa32dba6289
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_V2_2,
32        ID3_V2_3
33    };
34
35    ID3(const sp<DataSource> &source);
36    ~ID3();
37
38    bool isValid() const;
39
40    Version version() const;
41
42    const void *getAlbumArt(size_t *length, String8 *mime) const;
43
44    struct Iterator {
45        Iterator(const ID3 &parent, const char *id);
46        ~Iterator();
47
48        bool done() const;
49        void getID(String8 *id) const;
50        void getString(String8 *s) const;
51        const uint8_t *getData(size_t *length) const;
52        void next();
53
54    private:
55        const ID3 &mParent;
56        char *mID;
57        size_t mOffset;
58
59        const uint8_t *mFrameData;
60        size_t mFrameSize;
61
62        void findFrame();
63
64        size_t getHeaderLength() const;
65
66        Iterator(const Iterator &);
67        Iterator &operator=(const Iterator &);
68    };
69
70private:
71    bool mIsValid;
72    uint8_t *mData;
73    size_t mSize;
74    size_t mFirstFrameOffset;
75    Version mVersion;
76
77    bool parse(const sp<DataSource> &source);
78    void removeUnsynchronization();
79
80    ID3(const ID3 &);
81    ID3 &operator=(const ID3 &);
82};
83
84}  // namespace android
85
86#endif  // ID3_H_
87
88