32 for( StringArray::const_iterator p = lines.begin() ; p != lines.end() ; ++p )
34 G_DEBUG(
"Sdp::ctor: [" << *p <<
"]" ) ;
35 if( (*p).length() <= 2U )
throw Error() ;
36 if( (*p).at(1U) !=
'=' )
throw Error() ;
38 if( (*p).at(0U) ==
't' || (*p).at(0U) ==
'r' )
40 if( (*p).at(0U) ==
't' )
41 m_time.push_back( Map() ) ;
42 m_time.back().insert( pair(*p) ) ;
44 else if( (*p).at(0U) ==
'm' )
46 m_media.push_back( Map() ) ;
47 m_media.back().insert( pair(*p) ) ;
49 else if( m_media.empty() )
51 m_session.insert( pair(*p) ) ;
55 m_media.back().insert( pair(*p) ) ;
60 Gv::Sdp::Map::value_type Gv::Sdp::pair(
const std::string & line )
62 return Map::value_type( line.substr(0U,1U) , line.substr(2U) ) ;
77 return attributes( m_session ) ;
82 return str( attributes(m_session) , sep ) ;
87 return m_time.size() ;
92 return m_media.size() ;
97 return value( m_media.at(index) ,
"m" ) ;
102 return value( m_media.at(index) ,
"i" ,
"undefined" ) ;
107 return value( m_media.at(index) , m_session ,
"c" ) ;
112 return attributes( m_media.at(index) ) ;
117 return str( attributes(m_media.at(index)) , sep ) ;
122 return value( mediaAttributes(index) , key ) ;
127 return value( mediaAttributes(index) , key , default_ ) ;
135 const std::string a(
"a" ) ;
136 for( Map::const_iterator p = map.find(a) ; p != map.end() && (*p).first == a ; ++p )
138 std::string v = (*p).second ;
139 std::string::size_type pos = v.find(
":") ;
145 std::string Gv::Sdp::str(
const Map & map ,
const std::string & sep )
148 for( Map::const_iterator p = map.begin() ; p != map.end() ; ++p )
150 if( p != map.begin() ) result.append( sep ) ;
151 result.append( (*p).first ) ;
152 if( !(*p).second.empty() )
154 result.append(
":" ) ;
155 result.append( (*p).second ) ;
161 std::string Gv::Sdp::value(
const std::string & key )
const
163 return value( m_session , key ) ;
166 std::string Gv::Sdp::value(
const Map & map_1 ,
const Map & map_2 ,
const std::string & key )
168 Map::const_iterator p = map_1.find( key ) ;
169 if( p == map_1.end() )
171 p = map_2.find( key ) ;
172 if( p == map_2.end() )
173 throw Error(
"no such value" ) ;
178 std::string Gv::Sdp::value(
const Map & map ,
const std::string & key ,
const std::string & default_ )
180 Map::const_iterator p = map.find( key ) ;
181 return p == map.end() ? default_ : (*p).second ;
184 std::string Gv::Sdp::value(
const Map & map ,
const std::string & key )
186 Map::const_iterator p = map.find( key ) ;
188 throw Error(
"no such value" ) ;
195 for(
size_t i = 0 ; i < m_media.size() ; i++ )
197 if( mediaType(i).find(
"video") == 0U && mediaType(i).find(
"RTP/AVP") != std::string::npos )
199 std::string value = mediaAttribute( i ,
"fmtp" , std::string() ) ;
static std::string printable(const std::string &in, char escape= '\\')
Returns a printable represention of the given input string.
std::string mediaAttribute(size_t index, const std::string &key) const
Returns the specified attribute of the index-th media ("a=key").
std::string name() const
Returns the session name ("s=").
Map attributes() const
Returns the session attributes as a multimap ("a=key:value").
std::string originator() const
Returns the session originator ("o=").
std::vector< std::string > StringArray
A std::vector of std::strings.
Sdp(const std::vector< std::string > &sdp_lines)
Constructor taking a list of text lines.
static std::string tail(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the last part of the string after the given position.
std::string mediaTitle(size_t index=0U) const
Returns the title of the index-th media ("i=").
std::string mediaConnection(size_t index=0U) const
Returns the connection of the index-th media ("c=").
std::string fmtp() const
A convenience method that returns the value of the "fmtp" attribute of the first video "RTP/AVP" medi...
static std::string head(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the first part of the string up to just before the given position.
std::string mediaType(size_t index=0U) const
Returns the type of the index-th media ("m=").
Map mediaAttributes(size_t index=0U) const
Returns the attributes of the index-th media as a multimap ("a=").
size_t mediaCount() const
Returns the number of mediaType()s.
size_t timeCount() const
Returns the number of timeValue()s.