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.

250 lines
6.9 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. #ifndef TALK_MEDIA_BASE_CODEC_H_
  28. #define TALK_MEDIA_BASE_CODEC_H_
  29. #include <map>
  30. #include <string>
  31. #include "talk/media/base/constants.h"
  32. namespace cricket {
  33. typedef std::map<std::string, std::string> CodecParameterMap;
  34. struct Codec {
  35. int id;
  36. std::string name;
  37. int clockrate;
  38. int preference;
  39. CodecParameterMap params;
  40. // Creates a codec with the given parameters.
  41. Codec(int id, const std::string& name, int clockrate, int preference)
  42. : id(id),
  43. name(name),
  44. clockrate(clockrate),
  45. preference(preference) {
  46. }
  47. // Creates an empty codec.
  48. Codec() : id(0), clockrate(0), preference(0) {}
  49. // Indicates if this codec is compatible with the specified codec.
  50. bool Matches(int id, const std::string& name) const;
  51. bool Matches(const Codec& codec) const;
  52. static bool Preferable(const Codec& first, const Codec& other) {
  53. return first.preference > other.preference;
  54. }
  55. Codec& operator=(const Codec& c) {
  56. this->id = c.id; // id is reserved in objective-c
  57. name = c.name;
  58. clockrate = c.clockrate;
  59. preference = c.preference;
  60. return *this;
  61. }
  62. bool operator==(const Codec& c) const {
  63. return this->id == c.id && // id is reserved in objective-c
  64. name == c.name &&
  65. clockrate == c.clockrate &&
  66. preference == c.preference;
  67. }
  68. bool operator!=(const Codec& c) const {
  69. return !(*this == c);
  70. }
  71. };
  72. struct AudioCodec : public Codec {
  73. int bitrate;
  74. int channels;
  75. // Creates a codec with the given parameters.
  76. AudioCodec(int pt, const std::string& nm, int cr, int br, int cs, int pr)
  77. : Codec(pt, nm, cr, pr),
  78. bitrate(br),
  79. channels(cs) {
  80. }
  81. // Creates an empty codec.
  82. AudioCodec() : Codec(), bitrate(0), channels(0) {}
  83. // Indicates if this codec is compatible with the specified codec.
  84. bool Matches(int payload, const std::string& nm) const;
  85. bool Matches(const AudioCodec& codec) const;
  86. static bool Preferable(const AudioCodec& first, const AudioCodec& other) {
  87. return first.preference > other.preference;
  88. }
  89. std::string ToString() const;
  90. AudioCodec& operator=(const AudioCodec& c) {
  91. this->id = c.id; // id is reserved in objective-c
  92. name = c.name;
  93. clockrate = c.clockrate;
  94. bitrate = c.bitrate;
  95. channels = c.channels;
  96. preference = c.preference;
  97. params = c.params;
  98. return *this;
  99. }
  100. bool operator==(const AudioCodec& c) const {
  101. return this->id == c.id && // id is reserved in objective-c
  102. name == c.name &&
  103. clockrate == c.clockrate &&
  104. bitrate == c.bitrate &&
  105. channels == c.channels &&
  106. preference == c.preference &&
  107. params == c.params;
  108. }
  109. bool operator!=(const AudioCodec& c) const {
  110. return !(*this == c);
  111. }
  112. };
  113. struct VideoCodec : public Codec {
  114. int width;
  115. int height;
  116. int framerate;
  117. // Creates a codec with the given parameters.
  118. VideoCodec(int pt, const std::string& nm, int w, int h, int fr, int pr)
  119. : Codec(pt, nm, kVideoCodecClockrate, pr),
  120. width(w),
  121. height(h),
  122. framerate(fr) {
  123. }
  124. // Creates an empty codec.
  125. VideoCodec()
  126. : Codec(),
  127. width(0),
  128. height(0),
  129. framerate(0) {
  130. clockrate = kVideoCodecClockrate;
  131. }
  132. static bool Preferable(const VideoCodec& first, const VideoCodec& other) {
  133. return first.preference > other.preference;
  134. }
  135. std::string ToString() const;
  136. VideoCodec& operator=(const VideoCodec& c) {
  137. this->id = c.id; // id is reserved in objective-c
  138. name = c.name;
  139. clockrate = c.clockrate;
  140. width = c.width;
  141. height = c.height;
  142. framerate = c.framerate;
  143. preference = c.preference;
  144. params = c.params;
  145. return *this;
  146. }
  147. bool operator==(const VideoCodec& c) const {
  148. return this->id == c.id && // id is reserved in objective-c
  149. name == c.name &&
  150. clockrate == c.clockrate &&
  151. width == c.width &&
  152. height == c.height &&
  153. framerate == c.framerate &&
  154. preference == c.preference &&
  155. params == c.params;
  156. }
  157. bool operator!=(const VideoCodec& c) const {
  158. return !(*this == c);
  159. }
  160. };
  161. struct DataCodec : public Codec {
  162. DataCodec(int id, const std::string& name, int preference)
  163. : Codec(id, name, kDataCodecClockrate, preference) {
  164. }
  165. DataCodec() : Codec() {
  166. clockrate = kDataCodecClockrate;
  167. }
  168. std::string ToString() const;
  169. };
  170. struct VideoEncoderConfig {
  171. static const int kDefaultMaxThreads = -1;
  172. static const int kDefaultCpuProfile = -1;
  173. VideoEncoderConfig()
  174. : max_codec(),
  175. num_threads(kDefaultMaxThreads),
  176. cpu_profile(kDefaultCpuProfile) {
  177. }
  178. VideoEncoderConfig(const VideoCodec& c)
  179. : max_codec(c),
  180. num_threads(kDefaultMaxThreads),
  181. cpu_profile(kDefaultCpuProfile) {
  182. }
  183. VideoEncoderConfig(const VideoCodec& c, int t, int p)
  184. : max_codec(c),
  185. num_threads(t),
  186. cpu_profile(p) {
  187. }
  188. VideoEncoderConfig& operator=(const VideoEncoderConfig& config) {
  189. max_codec = config.max_codec;
  190. num_threads = config.num_threads;
  191. cpu_profile = config.cpu_profile;
  192. return *this;
  193. }
  194. bool operator==(const VideoEncoderConfig& config) const {
  195. return max_codec == config.max_codec &&
  196. num_threads == config.num_threads &&
  197. cpu_profile == config.cpu_profile;
  198. }
  199. bool operator!=(const VideoEncoderConfig& config) const {
  200. return !(*this == config);
  201. }
  202. VideoCodec max_codec;
  203. int num_threads;
  204. int cpu_profile;
  205. };
  206. } // namespace cricket
  207. #endif // TALK_MEDIA_BASE_CODEC_H_