VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gvsdp.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gvsdp.h
19 ///
20 
21 #ifndef GV_SDP__H
22 #define GV_SDP__H
23 
24 #include "gdef.h"
25 #include "gexception.h"
26 #include <string>
27 #include <vector>
28 #include <map>
29 
30 namespace Gv
31 {
32  class Sdp ;
33 }
34 
35 /// \class Gv::Sdp
36 /// A parser for a Session Description Protocol block, with a MIME type of
37 /// "application/sdp". This is used by RTSP, but is also relevant to other
38 /// session setup protocols such as SIP.
39 ///
40 /// The SDP block contains information in one "session" section, one or more
41 /// "timing" sections, and zero or more "media" sections. Each section is a
42 /// list of key-value pairs, with non-unique keys, and where the key is a
43 /// single letter. The "a" values are "attributes", having an attribute name
44 /// and an optional attribute value with a colon separator.
45 ///
46 /// \see RFC 4566
47 ///
48 class Gv::Sdp
49 {
50 public:
51  G_EXCEPTION( Error , "session description error" ) ;
52  typedef std::multimap<std::string,std::string> Map ;
53 
54  explicit Sdp( const std::vector<std::string> & sdp_lines ) ;
55  ///< Constructor taking a list of text lines.
56 
57  std::string originator() const ;
58  ///< Returns the session originator ("o=").
59 
60  std::string name() const ;
61  ///< Returns the session name ("s=").
62 
63  Map attributes() const ;
64  ///< Returns the session attributes as a multimap ("a=key:value").
65 
66  std::string attributes( const std::string & sep ) const ;
67  ///< Returns the session attributes as a sep-separated string.
68 
69  size_t timeCount() const ;
70  ///< Returns the number of timeValue()s.
71 
72  time_t timeValue( size_t index = 0U ) ;
73  ///< Returns the index-th time value.
74 
75  size_t mediaCount() const ;
76  ///< Returns the number of mediaType()s.
77 
78  std::string mediaType( size_t index = 0U ) const ;
79  ///< Returns the type of the index-th media ("m=").
80 
81  std::string mediaTitle( size_t index = 0U ) const ;
82  ///< Returns the title of the index-th media ("i=").
83 
84  std::string mediaConnection( size_t index = 0U ) const ;
85  ///< Returns the connection of the index-th media ("c=").
86 
87  Map mediaAttributes( size_t index = 0U ) const ;
88  ///< Returns the attributes of the index-th media as a multimap ("a=").
89 
90  std::string mediaAttributes( size_t index , const std::string & sep ) const ;
91  ///< Returns the attributes of the index-th media as a string.
92 
93  std::string mediaAttribute( size_t index , const std::string & key ) const ;
94  ///< Returns the specified attribute of the index-th media ("a=key").
95  ///< Throws if no such key.
96 
97  std::string mediaAttribute( size_t index , const std::string & key , const std::string & default_ ) const ;
98  ///< Returns the specified attribute of the index-th media ("a=key").
99  ///< Returns the default if no such key.
100 
101  std::string fmtp() const ;
102  ///< A convenience method that returns the value of the "fmtp" attribute
103  ///< of the first video "RTP/AVP" medium. Returns the empty string on error.
104 
105 private:
106  std::string value( const std::string & ) const ;
107  static std::string value( const Map & , const std::string & , const std::string & ) ;
108  static std::string value( const Map & , const std::string & ) ;
109  static std::string value( const Map & , const Map & , const std::string & ) ;
110  static Map::value_type pair( const std::string & line ) ;
111  static Map attributes( const Map & ) ;
112  static std::string str( const Map & , const std::string & sep ) ;
113 
114 private:
115  Map m_session ;
116  std::vector<Map> m_time ;
117  std::vector<Map> m_media ;
118 } ;
119 
120 #endif
std::string mediaAttribute(size_t index, const std::string &key) const
Returns the specified attribute of the index-th media ("a=key").
Definition: gvsdp.cpp:120
std::string name() const
Returns the session name ("s=").
Definition: gvsdp.cpp:70
Map attributes() const
Returns the session attributes as a multimap ("a=key:value").
Definition: gvsdp.cpp:75
std::string originator() const
Returns the session originator ("o=").
Definition: gvsdp.cpp:65
time_t timeValue(size_t index=0U)
Returns the index-th time value.
A parser for a Session Description Protocol block, with a MIME type of "application/sdp".
Definition: gvsdp.h:48
Sdp(const std::vector< std::string > &sdp_lines)
Constructor taking a list of text lines.
Definition: gvsdp.cpp:26
std::string mediaTitle(size_t index=0U) const
Returns the title of the index-th media ("i=").
Definition: gvsdp.cpp:100
std::string mediaConnection(size_t index=0U) const
Returns the connection of the index-th media ("c=").
Definition: gvsdp.cpp:105
std::string fmtp() const
A convenience method that returns the value of the "fmtp" attribute of the first video "RTP/AVP" medi...
Definition: gvsdp.cpp:192
std::string mediaType(size_t index=0U) const
Returns the type of the index-th media ("m=").
Definition: gvsdp.cpp:95
Map mediaAttributes(size_t index=0U) const
Returns the attributes of the index-th media as a multimap ("a=").
Definition: gvsdp.cpp:110
size_t mediaCount() const
Returns the number of mediaType()s.
Definition: gvsdp.cpp:90
size_t timeCount() const
Returns the number of timeValue()s.
Definition: gvsdp.cpp:85