Home | History | Annotate | Download | only in httplive
      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 <media/mediaplayer.h>
     25 #include <utils/Vector.h>
     26 
     27 namespace android {
     28 
     29 struct M3UParser : public RefBase {
     30     M3UParser(const char *baseURI, const void *data, size_t size);
     31 
     32     status_t initCheck() const;
     33 
     34     bool isExtM3U() const;
     35     bool isVariantPlaylist() const;
     36     bool isComplete() const;
     37     bool isEvent() const;
     38     size_t getDiscontinuitySeq() const;
     39 
     40     sp<AMessage> meta();
     41 
     42     size_t size();
     43     bool itemAt(size_t index, AString *uri, sp<AMessage> *meta = NULL);
     44 
     45     void pickRandomMediaItems();
     46     status_t selectTrack(size_t index, bool select);
     47     size_t getTrackCount() const;
     48     sp<AMessage> getTrackInfo(size_t index) const;
     49     ssize_t getSelectedIndex() const;
     50     ssize_t getSelectedTrack(media_track_type /* type */) const;
     51 
     52     bool getTypeURI(size_t index, const char *key, AString *uri) const;
     53 
     54 protected:
     55     virtual ~M3UParser();
     56 
     57 private:
     58     struct MediaGroup;
     59 
     60     struct Item {
     61         AString mURI;
     62         sp<AMessage> mMeta;
     63     };
     64 
     65     status_t mInitCheck;
     66 
     67     AString mBaseURI;
     68     bool mIsExtM3U;
     69     bool mIsVariantPlaylist;
     70     bool mIsComplete;
     71     bool mIsEvent;
     72     size_t mDiscontinuitySeq;
     73 
     74     sp<AMessage> mMeta;
     75     Vector<Item> mItems;
     76     ssize_t mSelectedIndex;
     77 
     78     // Media groups keyed by group ID.
     79     KeyedVector<AString, sp<MediaGroup> > mMediaGroups;
     80 
     81     status_t parse(const void *data, size_t size);
     82 
     83     static status_t parseMetaData(
     84             const AString &line, sp<AMessage> *meta, const char *key);
     85 
     86     static status_t parseMetaDataDuration(
     87             const AString &line, sp<AMessage> *meta, const char *key);
     88 
     89     status_t parseStreamInf(
     90             const AString &line, sp<AMessage> *meta) const;
     91 
     92     static status_t parseCipherInfo(
     93             const AString &line, sp<AMessage> *meta, const AString &baseURI);
     94 
     95     static status_t parseByteRange(
     96             const AString &line, uint64_t curOffset,
     97             uint64_t *length, uint64_t *offset);
     98 
     99     status_t parseMedia(const AString &line);
    100 
    101     static status_t parseDiscontinuitySequence(const AString &line, size_t *seq);
    102 
    103     static status_t ParseInt32(const char *s, int32_t *x);
    104     static status_t ParseDouble(const char *s, double *x);
    105 
    106     static bool isQuotedString(const AString &str);
    107     static AString unquoteString(const AString &str);
    108     static bool codecIsType(const AString &codec, const char *type);
    109 
    110     DISALLOW_EVIL_CONSTRUCTORS(M3UParser);
    111 };
    112 
    113 }  // namespace android
    114 
    115 #endif  // M3U_PARSER_H_
    116