M3UParser.h revision 9067e30b3ccb3a07e41b61af22c036378053a9a3
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 M3U_PARSER_H_
18
19#define M3U_PARSER_H_
20
21#include <media/stagefright/foundation/ABase.h>
22#include <media/stagefright/foundation/AMessage.h>
23#include <media/stagefright/foundation/AString.h>
24#include <utils/Vector.h>
25
26namespace android {
27
28struct M3UParser : public RefBase {
29    M3UParser(const char *baseURI, const void *data, size_t size);
30
31    status_t initCheck() const;
32
33    bool isExtM3U() const;
34    bool isVariantPlaylist() const;
35    bool isComplete() const;
36
37    sp<AMessage> meta();
38
39    size_t size();
40    bool itemAt(size_t index, AString *uri, sp<AMessage> *meta = NULL);
41
42protected:
43    virtual ~M3UParser();
44
45private:
46    struct Item {
47        AString mURI;
48        sp<AMessage> mMeta;
49    };
50
51    status_t mInitCheck;
52
53    AString mBaseURI;
54    bool mIsExtM3U;
55    bool mIsVariantPlaylist;
56    bool mIsComplete;
57
58    sp<AMessage> mMeta;
59    Vector<Item> mItems;
60
61    status_t parse(const void *data, size_t size);
62
63    static status_t parseMetaData(
64            const AString &line, sp<AMessage> *meta, const char *key);
65
66    static status_t parseMetaDataDuration(
67            const AString &line, sp<AMessage> *meta, const char *key);
68
69    static status_t parseStreamInf(
70            const AString &line, sp<AMessage> *meta);
71
72    static status_t parseCipherInfo(
73            const AString &line, sp<AMessage> *meta, const AString &baseURI);
74
75    static status_t ParseInt32(const char *s, int32_t *x);
76    static status_t ParseDouble(const char *s, double *x);
77
78    DISALLOW_EVIL_CONSTRUCTORS(M3UParser);
79};
80
81}  // namespace android
82
83#endif  // M3U_PARSER_H_
84