You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004 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. #include "talk/media/base/codec.h"
  28. #include <sstream>
  29. #include "talk/base/stringutils.h"
  30. namespace cricket {
  31. static const int kMaxStaticPayloadId = 95;
  32. bool Codec::Matches(int payload, const std::string& nm) const {
  33. return (payload <= kMaxStaticPayloadId) ?
  34. (id == payload) : (_stricmp(name.c_str(), nm.c_str()) == 0);
  35. }
  36. bool Codec::Matches(const Codec& codec) const {
  37. return Matches(codec.id, codec.name);
  38. }
  39. bool AudioCodec::Matches(int payload, const std::string& nm) const {
  40. // Match the codec id/name based on the typical static/dynamic name rules.
  41. // Matching is case-insensitive.
  42. return (payload <= kMaxStaticPayloadId) ?
  43. (id == payload) : (_stricmp(name.c_str(), nm.c_str()) == 0);
  44. }
  45. bool AudioCodec::Matches(const AudioCodec& codec) const {
  46. // If a nonzero clockrate is specified, it must match the actual clockrate.
  47. // If a nonzero bitrate is specified, it must match the actual bitrate,
  48. // unless the codec is VBR (0), where we just force the supplied value.
  49. // The number of channels must match exactly, with the exception
  50. // that channels=0 is treated synonymously as channels=1, per RFC
  51. // 4566 section 6: " [The channels] parameter is OPTIONAL and may be
  52. // omitted if the number of channels is one."
  53. // Preference is ignored.
  54. // TODO(juberti): Treat a zero clockrate as 8000Hz, the RTP default clockrate.
  55. return Matches(codec.id, codec.name) &&
  56. ((codec.clockrate == 0 /*&& clockrate == 8000*/) ||
  57. clockrate == codec.clockrate) &&
  58. (codec.bitrate == 0 || bitrate <= 0 || bitrate == codec.bitrate) &&
  59. ((codec.channels < 2 && channels < 2) || channels == codec.channels);
  60. }
  61. std::string AudioCodec::ToString() const {
  62. std::ostringstream os;
  63. os << "AudioCodec[" << id << ":" << name << ":" << clockrate << ":" << bitrate
  64. << ":" << channels << ":" << preference << "]";
  65. return os.str();
  66. }
  67. std::string VideoCodec::ToString() const {
  68. std::ostringstream os;
  69. os << "VideoCodec[" << id << ":" << name << ":" << width << ":" << height
  70. << ":" << framerate << ":" << preference << "]";
  71. return os.str();
  72. }
  73. std::string DataCodec::ToString() const {
  74. std::ostringstream os;
  75. os << "DataCodec[" << id << ":" << name << "]";
  76. return os.str();
  77. }
  78. } // namespace cricket