• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "api/video_codecs/video_codec.h"
12 
13 #include <string.h>
14 
15 #include <string>
16 
17 #include "absl/strings/match.h"
18 #include "rtc_base/checks.h"
19 
20 namespace webrtc {
21 namespace {
22 constexpr char kPayloadNameVp8[] = "VP8";
23 constexpr char kPayloadNameVp9[] = "VP9";
24 // TODO(bugs.webrtc.org/11042): Rename to AV1 when rtp payload format for av1 is
25 // frozen.
26 constexpr char kPayloadNameAv1[] = "AV1X";
27 constexpr char kPayloadNameH264[] = "H264";
28 constexpr char kPayloadNameGeneric[] = "Generic";
29 constexpr char kPayloadNameMultiplex[] = "Multiplex";
30 }  // namespace
31 
operator ==(const VideoCodecVP8 & other) const32 bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
33   return (complexity == other.complexity &&
34           numberOfTemporalLayers == other.numberOfTemporalLayers &&
35           denoisingOn == other.denoisingOn &&
36           automaticResizeOn == other.automaticResizeOn &&
37           frameDroppingOn == other.frameDroppingOn &&
38           keyFrameInterval == other.keyFrameInterval);
39 }
40 
operator ==(const VideoCodecVP9 & other) const41 bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
42   return (complexity == other.complexity &&
43           numberOfTemporalLayers == other.numberOfTemporalLayers &&
44           denoisingOn == other.denoisingOn &&
45           frameDroppingOn == other.frameDroppingOn &&
46           keyFrameInterval == other.keyFrameInterval &&
47           adaptiveQpMode == other.adaptiveQpMode &&
48           automaticResizeOn == other.automaticResizeOn &&
49           numberOfSpatialLayers == other.numberOfSpatialLayers &&
50           flexibleMode == other.flexibleMode);
51 }
52 
operator ==(const VideoCodecH264 & other) const53 bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
54   return (frameDroppingOn == other.frameDroppingOn &&
55           keyFrameInterval == other.keyFrameInterval &&
56           numberOfTemporalLayers == other.numberOfTemporalLayers);
57 }
58 
operator ==(const SpatialLayer & other) const59 bool SpatialLayer::operator==(const SpatialLayer& other) const {
60   return (width == other.width && height == other.height &&
61           maxFramerate == other.maxFramerate &&
62           numberOfTemporalLayers == other.numberOfTemporalLayers &&
63           maxBitrate == other.maxBitrate &&
64           targetBitrate == other.targetBitrate &&
65           minBitrate == other.minBitrate && qpMax == other.qpMax &&
66           active == other.active);
67 }
68 
VideoCodec()69 VideoCodec::VideoCodec()
70     : codecType(kVideoCodecGeneric),
71       plType(0),
72       width(0),
73       height(0),
74       startBitrate(0),
75       maxBitrate(0),
76       minBitrate(0),
77       maxFramerate(0),
78       active(true),
79       qpMax(0),
80       numberOfSimulcastStreams(0),
81       simulcastStream(),
82       spatialLayers(),
83       mode(VideoCodecMode::kRealtimeVideo),
84       expect_encode_from_texture(false),
85       timing_frame_thresholds({0, 0}),
86       codec_specific_() {}
87 
VP8()88 VideoCodecVP8* VideoCodec::VP8() {
89   RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
90   return &codec_specific_.VP8;
91 }
92 
VP8() const93 const VideoCodecVP8& VideoCodec::VP8() const {
94   RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
95   return codec_specific_.VP8;
96 }
97 
VP9()98 VideoCodecVP9* VideoCodec::VP9() {
99   RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
100   return &codec_specific_.VP9;
101 }
102 
VP9() const103 const VideoCodecVP9& VideoCodec::VP9() const {
104   RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
105   return codec_specific_.VP9;
106 }
107 
H264()108 VideoCodecH264* VideoCodec::H264() {
109   RTC_DCHECK_EQ(codecType, kVideoCodecH264);
110   return &codec_specific_.H264;
111 }
112 
H264() const113 const VideoCodecH264& VideoCodec::H264() const {
114   RTC_DCHECK_EQ(codecType, kVideoCodecH264);
115   return codec_specific_.H264;
116 }
117 
CodecTypeToPayloadString(VideoCodecType type)118 const char* CodecTypeToPayloadString(VideoCodecType type) {
119   switch (type) {
120     case kVideoCodecVP8:
121       return kPayloadNameVp8;
122     case kVideoCodecVP9:
123       return kPayloadNameVp9;
124     case kVideoCodecAV1:
125       return kPayloadNameAv1;
126     case kVideoCodecH264:
127       return kPayloadNameH264;
128     case kVideoCodecMultiplex:
129       return kPayloadNameMultiplex;
130     case kVideoCodecGeneric:
131       return kPayloadNameGeneric;
132   }
133 }
134 
PayloadStringToCodecType(const std::string & name)135 VideoCodecType PayloadStringToCodecType(const std::string& name) {
136   if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
137     return kVideoCodecVP8;
138   if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
139     return kVideoCodecVP9;
140   if (absl::EqualsIgnoreCase(name, kPayloadNameAv1))
141     return kVideoCodecAV1;
142   if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
143     return kVideoCodecH264;
144   if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
145     return kVideoCodecMultiplex;
146   return kVideoCodecGeneric;
147 }
148 
149 }  // namespace webrtc
150