M3UParser.h revision 404fced9bfa8fa423ee210a271ca051ffd1bec13
1e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala/*
2e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * Copyright (C) 2010 The Android Open Source Project
3e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala *
4e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * Licensed under the Apache License, Version 2.0 (the "License");
5e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * you may not use this file except in compliance with the License.
6e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * You may obtain a copy of the License at
7e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala *
8e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala *      http://www.apache.org/licenses/LICENSE-2.0
9e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala *
10e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * Unless required by applicable law or agreed to in writing, software
11e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * distributed under the License is distributed on an "AS IS" BASIS,
12e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * See the License for the specific language governing permissions and
14e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala * limitations under the License.
15e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala */
16e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
17e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala#ifndef M3U_PARSER_H_
18e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
19e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala#define M3U_PARSER_H_
20e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
21042ecee2abf8584585f1f22f661ac6be9689edf4Eino-Ville Talvala#include <media/stagefright/foundation/ABase.h>
22042ecee2abf8584585f1f22f661ac6be9689edf4Eino-Ville Talvala#include <media/stagefright/foundation/AMessage.h>
23e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala#include <media/stagefright/foundation/AString.h>
24e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala#include <utils/Vector.h>
25e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
26e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvalanamespace android {
27e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
28e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvalastruct M3UParser : public RefBase {
29e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    M3UParser(const char *baseURI, const void *data, size_t size);
30e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
31e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    status_t initCheck() const;
32e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
33db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian    bool isExtM3U() const;
34595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    bool isVariantPlaylist() const;
35595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    bool isComplete() const;
36e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    bool isEvent() const;
37e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
38e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    sp<AMessage> meta();
39042ecee2abf8584585f1f22f661ac6be9689edf4Eino-Ville Talvala
40042ecee2abf8584585f1f22f661ac6be9689edf4Eino-Ville Talvala    size_t size();
41e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    bool itemAt(size_t index, AString *uri, sp<AMessage> *meta = NULL);
42db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian
43db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian    void pickRandomMediaItems();
44e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    status_t selectTrack(size_t index, bool select);
45e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    size_t getTrackCount() const;
46e232fdca2a62dc5e81b550f5be8710e36174e7a6Eino-Ville Talvala    sp<AMessage> getTrackInfo(size_t index) const;
47042ecee2abf8584585f1f22f661ac6be9689edf4Eino-Ville Talvala    ssize_t getSelectedIndex() const;
48e232fdca2a62dc5e81b550f5be8710e36174e7a6Eino-Ville Talvala
49e232fdca2a62dc5e81b550f5be8710e36174e7a6Eino-Ville Talvala    bool getTypeURI(size_t index, const char *key, AString *uri) const;
50042ecee2abf8584585f1f22f661ac6be9689edf4Eino-Ville Talvala
51042ecee2abf8584585f1f22f661ac6be9689edf4Eino-Ville Talvalaprotected:
52e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    virtual ~M3UParser();
53e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
54e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvalaprivate:
55db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian    struct MediaGroup;
56e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
57e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    struct Item {
58b4b63704c02319765625de360a140ef8a59ab43bZhijun He        AString mURI;
59b4b63704c02319765625de360a140ef8a59ab43bZhijun He        sp<AMessage> mMeta;
60b4b63704c02319765625de360a140ef8a59ab43bZhijun He    };
61db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian
62b4b63704c02319765625de360a140ef8a59ab43bZhijun He    status_t mInitCheck;
63b4b63704c02319765625de360a140ef8a59ab43bZhijun He
64b4b63704c02319765625de360a140ef8a59ab43bZhijun He    AString mBaseURI;
65b4b63704c02319765625de360a140ef8a59ab43bZhijun He    bool mIsExtM3U;
66b4b63704c02319765625de360a140ef8a59ab43bZhijun He    bool mIsVariantPlaylist;
67db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian    bool mIsComplete;
68b4b63704c02319765625de360a140ef8a59ab43bZhijun He    bool mIsEvent;
69b4b63704c02319765625de360a140ef8a59ab43bZhijun He
706a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    sp<AMessage> mMeta;
716a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    Vector<Item> mItems;
726a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    ssize_t mSelectedIndex;
736a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
746a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    // Media groups keyed by group ID.
756a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    KeyedVector<AString, sp<MediaGroup> > mMediaGroups;
766a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
776a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    status_t parse(const void *data, size_t size);
786a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
796a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    static status_t parseMetaData(
806a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar            const AString &line, sp<AMessage> *meta, const char *key);
816a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
826a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    static status_t parseMetaDataDuration(
836a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar            const AString &line, sp<AMessage> *meta, const char *key);
846a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
856a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    status_t parseStreamInf(
866a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar            const AString &line, sp<AMessage> *meta) const;
876a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
886a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    static status_t parseCipherInfo(
896a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar            const AString &line, sp<AMessage> *meta, const AString &baseURI);
906a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
916a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    static status_t parseByteRange(
926a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar            const AString &line, uint64_t curOffset,
936a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar            uint64_t *length, uint64_t *offset);
946a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
956a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    status_t parseMedia(const AString &line);
966a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar
976a26be7c2b1e5a84b5d2105780148016889285e6Lajos Molnar    static status_t ParseInt32(const char *s, int32_t *x);
98e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    static status_t ParseDouble(const char *s, double *x);
99e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
100e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    static bool isQuotedString(const AString &str);
101e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    static AString unquoteString(const AString &str);
102e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala    static bool codecIsType(const AString &codec, const char *type);
103a5b7513711555c8681eb9391cfafe30fb7d6dd3dIgor Murashkin
104a5b7513711555c8681eb9391cfafe30fb7d6dd3dIgor Murashkin    DISALLOW_EVIL_CONSTRUCTORS(M3UParser);
105a5b7513711555c8681eb9391cfafe30fb7d6dd3dIgor Murashkin};
106e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
107e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala}  // namespace android
108e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala
109e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala#endif  // M3U_PARSER_H_
110e41b318bc4708e1dee9364e73215ff0d51fb76a1Eino-Ville Talvala