Home | History | Annotate | Download | only in include
      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 protected:
     44     virtual ~M3UParser();
     45 
     46 private:
     47     struct Item {
     48         AString mURI;
     49         sp<AMessage> mMeta;
     50     };
     51 
     52     status_t mInitCheck;
     53 
     54     AString mBaseURI;
     55     bool mIsExtM3U;
     56     bool mIsVariantPlaylist;
     57     bool mIsComplete;
     58     bool mIsEvent;
     59 
     60     sp<AMessage> mMeta;
     61     Vector<Item> mItems;
     62 
     63     status_t parse(const void *data, size_t size);
     64 
     65     static status_t parseMetaData(
     66             const AString &line, sp<AMessage> *meta, const char *key);
     67 
     68     static status_t parseMetaDataDuration(
     69             const AString &line, sp<AMessage> *meta, const char *key);
     70 
     71     static status_t parseStreamInf(
     72             const AString &line, sp<AMessage> *meta);
     73 
     74     static status_t parseCipherInfo(
     75             const AString &line, sp<AMessage> *meta, const AString &baseURI);
     76 
     77     static status_t parseByteRange(
     78             const AString &line, uint64_t curOffset,
     79             uint64_t *length, uint64_t *offset);
     80 
     81     static status_t ParseInt32(const char *s, int32_t *x);
     82     static status_t ParseDouble(const char *s, double *x);
     83 
     84     DISALLOW_EVIL_CONSTRUCTORS(M3UParser);
     85 };
     86 
     87 }  // namespace android
     88 
     89 #endif  // M3U_PARSER_H_
     90