• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libjingle
3  * Copyright 2004--2007, Google Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *  1. Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *  2. Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  *  3. The name of the author may not be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "talk/session/phone/codec.h"
29 #include <sstream>
30 
31 namespace cricket {
32 
33 static const int kMaxStaticPayloadId = 95;
34 
Matches(int payload,const std::string & nm) const35 bool AudioCodec::Matches(int payload, const std::string& nm) const {
36   // Match the codec id/name based on the typical static/dynamic name rules.
37   return (payload <= kMaxStaticPayloadId) ? (id == payload) : (name == nm);
38 }
39 
Matches(const AudioCodec & codec) const40 bool AudioCodec::Matches(const AudioCodec& codec) const {
41   // If a nonzero clockrate is specified, it must match the actual clockrate.
42   // If a nonzero bitrate is specified, it must match the actual bitrate,
43   // unless the codec is VBR (-1), where we just force the supplied value.
44   // The number of channels must match exactly.
45   // Preference is ignored.
46   // TODO: Treat a zero clockrate as 8000Hz, the RTP default clockrate.
47   return Matches(codec.id, codec.name) &&
48       ((codec.clockrate == 0 /*&& clockrate == 8000*/) ||
49           clockrate == codec.clockrate) &&
50       (codec.bitrate == 0 || bitrate == -1 || bitrate == codec.bitrate) &&
51       (codec.channels == 0 || channels == codec.channels);
52 }
53 
ToString() const54 std::string AudioCodec::ToString() const {
55   std::ostringstream os;
56   os << "AudioCodec[" << id << ":" << name << ":" << clockrate << ":" << bitrate
57      << ":" << channels << ":" << preference << "]";
58   return os.str();
59 }
60 
Matches(int payload,const std::string & nm) const61 bool VideoCodec::Matches(int payload, const std::string& nm) const {
62   // Match the codec id/name based on the typical static/dynamic name rules.
63   return (payload <= kMaxStaticPayloadId) ? (id == payload) : (name == nm);
64 }
65 
Matches(const VideoCodec & codec) const66 bool VideoCodec::Matches(const VideoCodec& codec) const {
67   // Only the id and name are matched.
68   return Matches(codec.id, codec.name);
69 }
70 
ToString() const71 std::string VideoCodec::ToString() const {
72   std::ostringstream os;
73   os << "VideoCodec[" << id << ":" << name << ":" << width << ":" << height
74      << ":" << framerate << ":" << preference << "]";
75   return os.str();
76 }
77 
78 }  // namespace cricket
79