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.

139 lines
4.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "api/video_codecs/video_codec.h"
  11. #include <string.h>
  12. #include <string>
  13. #include "absl/strings/match.h"
  14. #include "rtc_base/checks.h"
  15. namespace webrtc {
  16. bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
  17. return (complexity == other.complexity &&
  18. numberOfTemporalLayers == other.numberOfTemporalLayers &&
  19. denoisingOn == other.denoisingOn &&
  20. automaticResizeOn == other.automaticResizeOn &&
  21. frameDroppingOn == other.frameDroppingOn &&
  22. keyFrameInterval == other.keyFrameInterval);
  23. }
  24. bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
  25. return (complexity == other.complexity &&
  26. numberOfTemporalLayers == other.numberOfTemporalLayers &&
  27. denoisingOn == other.denoisingOn &&
  28. frameDroppingOn == other.frameDroppingOn &&
  29. keyFrameInterval == other.keyFrameInterval &&
  30. adaptiveQpMode == other.adaptiveQpMode &&
  31. automaticResizeOn == other.automaticResizeOn &&
  32. numberOfSpatialLayers == other.numberOfSpatialLayers &&
  33. flexibleMode == other.flexibleMode);
  34. }
  35. bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
  36. return (frameDroppingOn == other.frameDroppingOn &&
  37. keyFrameInterval == other.keyFrameInterval &&
  38. numberOfTemporalLayers == other.numberOfTemporalLayers);
  39. }
  40. bool SpatialLayer::operator==(const SpatialLayer& other) const {
  41. return (width == other.width && height == other.height &&
  42. numberOfTemporalLayers == other.numberOfTemporalLayers &&
  43. maxBitrate == other.maxBitrate &&
  44. targetBitrate == other.targetBitrate &&
  45. minBitrate == other.minBitrate && qpMax == other.qpMax &&
  46. active == other.active);
  47. }
  48. VideoCodec::VideoCodec()
  49. : codecType(kVideoCodecGeneric),
  50. plType(0),
  51. width(0),
  52. height(0),
  53. startBitrate(0),
  54. maxBitrate(0),
  55. minBitrate(0),
  56. maxFramerate(0),
  57. active(true),
  58. qpMax(0),
  59. numberOfSimulcastStreams(0),
  60. simulcastStream(),
  61. spatialLayers(),
  62. mode(VideoCodecMode::kRealtimeVideo),
  63. expect_encode_from_texture(false),
  64. timing_frame_thresholds({0, 0}),
  65. codec_specific_() {}
  66. VideoCodecVP8* VideoCodec::VP8() {
  67. RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
  68. return &codec_specific_.VP8;
  69. }
  70. const VideoCodecVP8& VideoCodec::VP8() const {
  71. RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
  72. return codec_specific_.VP8;
  73. }
  74. VideoCodecVP9* VideoCodec::VP9() {
  75. RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
  76. return &codec_specific_.VP9;
  77. }
  78. const VideoCodecVP9& VideoCodec::VP9() const {
  79. RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
  80. return codec_specific_.VP9;
  81. }
  82. VideoCodecH264* VideoCodec::H264() {
  83. RTC_DCHECK_EQ(codecType, kVideoCodecH264);
  84. return &codec_specific_.H264;
  85. }
  86. const VideoCodecH264& VideoCodec::H264() const {
  87. RTC_DCHECK_EQ(codecType, kVideoCodecH264);
  88. return codec_specific_.H264;
  89. }
  90. static const char* kPayloadNameVp8 = "VP8";
  91. static const char* kPayloadNameVp9 = "VP9";
  92. static const char* kPayloadNameH264 = "H264";
  93. static const char* kPayloadNameGeneric = "Generic";
  94. static const char* kPayloadNameMultiplex = "Multiplex";
  95. const char* CodecTypeToPayloadString(VideoCodecType type) {
  96. switch (type) {
  97. case kVideoCodecVP8:
  98. return kPayloadNameVp8;
  99. case kVideoCodecVP9:
  100. return kPayloadNameVp9;
  101. case kVideoCodecH264:
  102. return kPayloadNameH264;
  103. // Other codecs default to generic.
  104. default:
  105. return kPayloadNameGeneric;
  106. }
  107. }
  108. VideoCodecType PayloadStringToCodecType(const std::string& name) {
  109. if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
  110. return kVideoCodecVP8;
  111. if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
  112. return kVideoCodecVP9;
  113. if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
  114. return kVideoCodecH264;
  115. if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
  116. return kVideoCodecMultiplex;
  117. return kVideoCodecGeneric;
  118. }
  119. } // namespace webrtc