Home | History | Annotate | Download | only in rtsp
      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 A_SESSION_DESCRIPTION_H_
     18 
     19 #define A_SESSION_DESCRIPTION_H_
     20 
     21 #include <sys/types.h>
     22 
     23 #include <media/stagefright/foundation/ABase.h>
     24 #include <utils/KeyedVector.h>
     25 #include <utils/RefBase.h>
     26 #include <utils/Vector.h>
     27 
     28 namespace android {
     29 
     30 struct AString;
     31 
     32 struct ASessionDescription : public RefBase {
     33     ASessionDescription();
     34 
     35     bool setTo(const void *data, size_t size);
     36     bool isValid() const;
     37 
     38     // Actually, 1 + number of tracks, as index 0 is reserved for the
     39     // session description root-level attributes.
     40     size_t countTracks() const;
     41     void getFormat(size_t index, AString *value) const;
     42 
     43     void getFormatType(
     44             size_t index, unsigned long *PT,
     45             AString *desc, AString *params) const;
     46 
     47     bool getDimensions(
     48             size_t index, unsigned long PT,
     49             int32_t *width, int32_t *height) const;
     50 
     51     bool getDurationUs(int64_t *durationUs) const;
     52 
     53     static void ParseFormatDesc(
     54             const char *desc, int32_t *timescale, int32_t *numChannels);
     55 
     56     bool findAttribute(size_t index, const char *key, AString *value) const;
     57 
     58     // parses strings of the form
     59     //   npt      := npt-time "-" npt-time? | "-" npt-time
     60     //   npt-time := "now" | [0-9]+("." [0-9]*)?
     61     //
     62     // Returns true iff both "npt1" and "npt2" times were available,
     63     // i.e. we have a fixed duration, otherwise this is live streaming.
     64     static bool parseNTPRange(const char *s, float *npt1, float *npt2);
     65 
     66 protected:
     67     virtual ~ASessionDescription();
     68 
     69 private:
     70     typedef KeyedVector<AString,AString> Attribs;
     71 
     72     bool mIsValid;
     73     Vector<Attribs> mTracks;
     74     Vector<AString> mFormats;
     75 
     76     bool parse(const void *data, size_t size);
     77 
     78     DISALLOW_EVIL_CONSTRUCTORS(ASessionDescription);
     79 };
     80 
     81 }  // namespace android
     82 
     83 #endif  // A_SESSION_DESCRIPTION_H_
     84