• 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 constexpr char kPayloadNameAv1[] = "AV1";
25 // TODO(bugs.webrtc.org/13166): Remove AV1X when backwards compatibility is not
26 // needed.
27 constexpr char kPayloadNameAv1x[] = "AV1X";
28 constexpr char kPayloadNameH264[] = "H264";
29 constexpr char kPayloadNameGeneric[] = "Generic";
30 constexpr char kPayloadNameMultiplex[] = "Multiplex";
31 }  // namespace
32 
operator ==(const VideoCodecVP8 & other) const33 bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
34   return (numberOfTemporalLayers == other.numberOfTemporalLayers &&
35           denoisingOn == other.denoisingOn &&
36           automaticResizeOn == other.automaticResizeOn &&
37           keyFrameInterval == other.keyFrameInterval);
38 }
39 
operator ==(const VideoCodecVP9 & other) const40 bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
41   return (numberOfTemporalLayers == other.numberOfTemporalLayers &&
42           denoisingOn == other.denoisingOn &&
43           keyFrameInterval == other.keyFrameInterval &&
44           adaptiveQpMode == other.adaptiveQpMode &&
45           automaticResizeOn == other.automaticResizeOn &&
46           numberOfSpatialLayers == other.numberOfSpatialLayers &&
47           flexibleMode == other.flexibleMode);
48 }
49 
operator ==(const VideoCodecH264 & other) const50 bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
51   return (keyFrameInterval == other.keyFrameInterval &&
52           numberOfTemporalLayers == other.numberOfTemporalLayers);
53 }
54 
VideoCodec()55 VideoCodec::VideoCodec()
56     : codecType(kVideoCodecGeneric),
57       width(0),
58       height(0),
59       startBitrate(0),
60       maxBitrate(0),
61       minBitrate(0),
62       maxFramerate(0),
63       active(true),
64       qpMax(0),
65       numberOfSimulcastStreams(0),
66       simulcastStream(),
67       spatialLayers(),
68       mode(VideoCodecMode::kRealtimeVideo),
69       expect_encode_from_texture(false),
70       timing_frame_thresholds({0, 0}),
71       legacy_conference_mode(false),
72       codec_specific_(),
73       complexity_(VideoCodecComplexity::kComplexityNormal) {}
74 
VP8()75 VideoCodecVP8* VideoCodec::VP8() {
76   RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
77   return &codec_specific_.VP8;
78 }
79 
VP8() const80 const VideoCodecVP8& VideoCodec::VP8() const {
81   RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
82   return codec_specific_.VP8;
83 }
84 
VP9()85 VideoCodecVP9* VideoCodec::VP9() {
86   RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
87   return &codec_specific_.VP9;
88 }
89 
VP9() const90 const VideoCodecVP9& VideoCodec::VP9() const {
91   RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
92   return codec_specific_.VP9;
93 }
94 
H264()95 VideoCodecH264* VideoCodec::H264() {
96   RTC_DCHECK_EQ(codecType, kVideoCodecH264);
97   return &codec_specific_.H264;
98 }
99 
H264() const100 const VideoCodecH264& VideoCodec::H264() const {
101   RTC_DCHECK_EQ(codecType, kVideoCodecH264);
102   return codec_specific_.H264;
103 }
104 
CodecTypeToPayloadString(VideoCodecType type)105 const char* CodecTypeToPayloadString(VideoCodecType type) {
106   switch (type) {
107     case kVideoCodecVP8:
108       return kPayloadNameVp8;
109     case kVideoCodecVP9:
110       return kPayloadNameVp9;
111     case kVideoCodecAV1:
112       return kPayloadNameAv1;
113     case kVideoCodecH264:
114       return kPayloadNameH264;
115     case kVideoCodecMultiplex:
116       return kPayloadNameMultiplex;
117     case kVideoCodecGeneric:
118       return kPayloadNameGeneric;
119   }
120   RTC_CHECK_NOTREACHED();
121 }
122 
PayloadStringToCodecType(const std::string & name)123 VideoCodecType PayloadStringToCodecType(const std::string& name) {
124   if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
125     return kVideoCodecVP8;
126   if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
127     return kVideoCodecVP9;
128   if (absl::EqualsIgnoreCase(name, kPayloadNameAv1) ||
129       absl::EqualsIgnoreCase(name, kPayloadNameAv1x))
130     return kVideoCodecAV1;
131   if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
132     return kVideoCodecH264;
133   if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
134     return kVideoCodecMultiplex;
135   return kVideoCodecGeneric;
136 }
137 
GetVideoEncoderComplexity() const138 VideoCodecComplexity VideoCodec::GetVideoEncoderComplexity() const {
139   return complexity_;
140 }
141 
SetVideoEncoderComplexity(VideoCodecComplexity complexity_setting)142 void VideoCodec::SetVideoEncoderComplexity(
143     VideoCodecComplexity complexity_setting) {
144   complexity_ = complexity_setting;
145 }
146 
GetFrameDropEnabled() const147 bool VideoCodec::GetFrameDropEnabled() const {
148   return frame_drop_enabled_;
149 }
150 
SetFrameDropEnabled(bool enabled)151 void VideoCodec::SetFrameDropEnabled(bool enabled) {
152   frame_drop_enabled_ = enabled;
153 }
154 
155 }  // namespace webrtc
156