Andreas Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 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 | |
| 26 | namespace android { |
| 27 | |
| 28 | struct 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 Huber | bff07d0 | 2010-10-12 11:34:37 -0700 | [diff] [blame] | 35 | bool isComplete() const; |
Andreas Huber | b7c8e91 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 36 | bool isEvent() const; |
Andreas Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 37 | |
| 38 | sp<AMessage> meta(); |
| 39 | |
| 40 | size_t size(); |
| 41 | bool itemAt(size_t index, AString *uri, sp<AMessage> *meta = NULL); |
| 42 | |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 43 | void pickRandomMediaItems(); |
Chong Zhang | dcb89b3 | 2013-08-06 09:44:47 -0700 | [diff] [blame^] | 44 | status_t selectTrack(size_t index, bool select); |
| 45 | status_t getTrackInfo(Parcel* reply) const; |
| 46 | ssize_t getSelectedIndex() const; |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 47 | |
| 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 Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 52 | protected: |
| 53 | virtual ~M3UParser(); |
| 54 | |
| 55 | private: |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 56 | struct MediaGroup; |
| 57 | |
Andreas Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 58 | 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 Huber | bff07d0 | 2010-10-12 11:34:37 -0700 | [diff] [blame] | 68 | bool mIsComplete; |
Andreas Huber | b7c8e91 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 69 | bool mIsEvent; |
Andreas Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 70 | |
| 71 | sp<AMessage> mMeta; |
| 72 | Vector<Item> mItems; |
Chong Zhang | dcb89b3 | 2013-08-06 09:44:47 -0700 | [diff] [blame^] | 73 | ssize_t mSelectedIndex; |
Andreas Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 74 | |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 75 | // Media groups keyed by group ID. |
| 76 | KeyedVector<AString, sp<MediaGroup> > mMediaGroups; |
| 77 | |
Andreas Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 78 | 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 Huber | 9067e30 | 2011-06-21 11:55:34 -0700 | [diff] [blame] | 83 | static status_t parseMetaDataDuration( |
| 84 | const AString &line, sp<AMessage> *meta, const char *key); |
| 85 | |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 86 | status_t parseStreamInf( |
| 87 | const AString &line, sp<AMessage> *meta) const; |
Andreas Huber | 2a4d22d | 2010-09-08 14:32:20 -0700 | [diff] [blame] | 88 | |
Andreas Huber | e332a91 | 2010-11-15 09:03:03 -0800 | [diff] [blame] | 89 | static status_t parseCipherInfo( |
Andreas Huber | decd969 | 2010-12-02 13:27:47 -0800 | [diff] [blame] | 90 | const AString &line, sp<AMessage> *meta, const AString &baseURI); |
Andreas Huber | e332a91 | 2010-11-15 09:03:03 -0800 | [diff] [blame] | 91 | |
Andreas Huber | 2aa4cc0 | 2011-08-08 11:20:53 -0700 | [diff] [blame] | 92 | static status_t parseByteRange( |
| 93 | const AString &line, uint64_t curOffset, |
| 94 | uint64_t *length, uint64_t *offset); |
| 95 | |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 96 | status_t parseMedia(const AString &line); |
| 97 | |
| 98 | bool getTypeURI(size_t index, const char *key, AString *uri) const; |
| 99 | |
Andreas Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 100 | static status_t ParseInt32(const char *s, int32_t *x); |
Andreas Huber | 9067e30 | 2011-06-21 11:55:34 -0700 | [diff] [blame] | 101 | static status_t ParseDouble(const char *s, double *x); |
Andreas Huber | e71d10e | 2010-06-07 14:35:29 -0700 | [diff] [blame] | 102 | |
| 103 | DISALLOW_EVIL_CONSTRUCTORS(M3UParser); |
| 104 | }; |
| 105 | |
| 106 | } // namespace android |
| 107 | |
| 108 | #endif // M3U_PARSER_H_ |