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     bool getCvoExtMap(size_t index, int32_t *cvoExtMap) const;
44 
45     void getFormatType(
46             size_t index, unsigned long *PT,
47             AString *desc, AString *params) const;
48 
49     bool getDimensions(
50             size_t index, unsigned long PT,
51             int32_t *width, int32_t *height) const;
52 
53     bool getDurationUs(int64_t *durationUs) const;
54 
55     static void ParseFormatDesc(
56             const char *desc, int32_t *timescale, int32_t *numChannels);
57 
58     bool findAttribute(size_t index, const char *key, AString *value) const;
59 
60     // parses strings of the form
61     //   npt      := npt-time "-" npt-time? | "-" npt-time
62     //   npt-time := "now" | [0-9]+("." [0-9]*)?
63     //
64     // Returns true iff both "npt1" and "npt2" times were available,
65     // i.e. we have a fixed duration, otherwise this is live streaming.
66     static bool parseNTPRange(const char *s, float *npt1, float *npt2);
67 
68     static void SDPStringFactory(AString &sdp, const char *ip, bool isAudio, unsigned port,
69         unsigned payloadType, unsigned as, const char *codec, const char *fmtp = NULL,
70         int32_t width = 0, int32_t height = 0, int32_t cvoExtMap = 0);
71 protected:
72     virtual ~ASessionDescription();
73 
74 private:
75     typedef KeyedVector<AString,AString> Attribs;
76 
77     bool mIsValid;
78     Vector<Attribs> mTracks;
79     Vector<AString> mFormats;
80 
81     bool parse(const void *data, size_t size);
82 
83     DISALLOW_EVIL_CONSTRUCTORS(ASessionDescription);
84 };
85 
86 }  // namespace android
87 
88 #endif  // A_SESSION_DESCRIPTION_H_
89