blob: 5248004cb2889331da9b0ca15ac20acac3926f0e [file] [log] [blame]
Andreas Hubere71d10e2010-06-07 14:35:29 -07001/*
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;
Andreas Huberbff07d02010-10-12 11:34:37 -070035 bool isComplete() const;
Andreas Huberb7c8e912012-11-27 15:02:53 -080036 bool isEvent() const;
Andreas Hubere71d10e2010-06-07 14:35:29 -070037
38 sp<AMessage> meta();
39
40 size_t size();
41 bool itemAt(size_t index, AString *uri, sp<AMessage> *meta = NULL);
42
Andreas Huber14f76722013-01-15 09:04:18 -080043 void pickRandomMediaItems();
Chong Zhangdcb89b32013-08-06 09:44:47 -070044 status_t selectTrack(size_t index, bool select);
45 status_t getTrackInfo(Parcel* reply) const;
46 ssize_t getSelectedIndex() const;
Andreas Huber14f76722013-01-15 09:04:18 -080047
48 bool getAudioURI(size_t index, AString *uri) const;
49 bool getVideoURI(size_t index, AString *uri) const;
50 bool getSubtitleURI(size_t index, AString *uri) const;
51
Andreas Hubere71d10e2010-06-07 14:35:29 -070052protected:
53 virtual ~M3UParser();
54
55private:
Andreas Huber14f76722013-01-15 09:04:18 -080056 struct MediaGroup;
57
Andreas Hubere71d10e2010-06-07 14:35:29 -070058 struct Item {
59 AString mURI;
60 sp<AMessage> mMeta;
61 };
62
63 status_t mInitCheck;
64
65 AString mBaseURI;
66 bool mIsExtM3U;
67 bool mIsVariantPlaylist;
Andreas Huberbff07d02010-10-12 11:34:37 -070068 bool mIsComplete;
Andreas Huberb7c8e912012-11-27 15:02:53 -080069 bool mIsEvent;
Andreas Hubere71d10e2010-06-07 14:35:29 -070070
71 sp<AMessage> mMeta;
72 Vector<Item> mItems;
Chong Zhangdcb89b32013-08-06 09:44:47 -070073 ssize_t mSelectedIndex;
Andreas Hubere71d10e2010-06-07 14:35:29 -070074
Andreas Huber14f76722013-01-15 09:04:18 -080075 // Media groups keyed by group ID.
76 KeyedVector<AString, sp<MediaGroup> > mMediaGroups;
77
Andreas Hubere71d10e2010-06-07 14:35:29 -070078 status_t parse(const void *data, size_t size);
79
80 static status_t parseMetaData(
81 const AString &line, sp<AMessage> *meta, const char *key);
82
Andreas Huber9067e302011-06-21 11:55:34 -070083 static status_t parseMetaDataDuration(
84 const AString &line, sp<AMessage> *meta, const char *key);
85
Andreas Huber14f76722013-01-15 09:04:18 -080086 status_t parseStreamInf(
87 const AString &line, sp<AMessage> *meta) const;
Andreas Huber2a4d22d2010-09-08 14:32:20 -070088
Andreas Hubere332a912010-11-15 09:03:03 -080089 static status_t parseCipherInfo(
Andreas Huberdecd9692010-12-02 13:27:47 -080090 const AString &line, sp<AMessage> *meta, const AString &baseURI);
Andreas Hubere332a912010-11-15 09:03:03 -080091
Andreas Huber2aa4cc02011-08-08 11:20:53 -070092 static status_t parseByteRange(
93 const AString &line, uint64_t curOffset,
94 uint64_t *length, uint64_t *offset);
95
Andreas Huber14f76722013-01-15 09:04:18 -080096 status_t parseMedia(const AString &line);
97
98 bool getTypeURI(size_t index, const char *key, AString *uri) const;
99
Andreas Hubere71d10e2010-06-07 14:35:29 -0700100 static status_t ParseInt32(const char *s, int32_t *x);
Andreas Huber9067e302011-06-21 11:55:34 -0700101 static status_t ParseDouble(const char *s, double *x);
Andreas Hubere71d10e2010-06-07 14:35:29 -0700102
103 DISALLOW_EVIL_CONSTRUCTORS(M3UParser);
104};
105
106} // namespace android
107
108#endif // M3U_PARSER_H_