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 <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;
     35     bool isComplete() const;
     36     bool isEvent() const;
     37 
     38     sp<AMessage> meta();
     39 
     40     size_t size();
     41     bool itemAt(size_t index, AString *uri, sp<AMessage> *meta = NULL);
     42 
     43     void pickRandomMediaItems();
     44     status_t selectTrack(size_t index, bool select);
     45     status_t getTrackInfo(Parcel* reply) const;
     46     ssize_t getSelectedIndex() const;
     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 
     52 protected:
     53     virtual ~M3UParser();
     54 
     55 private:
     56     struct MediaGroup;
     57 
     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;
     68     bool mIsComplete;
     69     bool mIsEvent;
     70 
     71     sp<AMessage> mMeta;
     72     Vector<Item> mItems;
     73     ssize_t mSelectedIndex;
     74 
     75     // Media groups keyed by group ID.
     76     KeyedVector<AString, sp<MediaGroup> > mMediaGroups;
     77 
     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 
     83     static status_t parseMetaDataDuration(
     84             const AString &line, sp<AMessage> *meta, const char *key);
     85 
     86     status_t parseStreamInf(
     87             const AString &line, sp<AMessage> *meta) const;
     88 
     89     static status_t parseCipherInfo(
     90             const AString &line, sp<AMessage> *meta, const AString &baseURI);
     91 
     92     static status_t parseByteRange(
     93             const AString &line, uint64_t curOffset,
     94             uint64_t *length, uint64_t *offset);
     95 
     96     status_t parseMedia(const AString &line);
     97 
     98     bool getTypeURI(size_t index, const char *key, AString *uri) const;
     99 
    100     static status_t ParseInt32(const char *s, int32_t *x);
    101     static status_t ParseDouble(const char *s, double *x);
    102 
    103     DISALLOW_EVIL_CONSTRUCTORS(M3UParser);
    104 };
    105 
    106 }  // namespace android
    107 
    108 #endif  // M3U_PARSER_H_
    109