File: test_config.cc

package info (click to toggle)
firefox-esr 91.13.0esr-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,375,652 kB
  • sloc: cpp: 5,762,054; javascript: 5,481,714; ansic: 3,121,191; python: 851,492; asm: 331,172; xml: 178,949; java: 155,554; sh: 63,704; makefile: 20,127; perl: 12,825; yacc: 4,583; cs: 3,846; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; php: 436; lisp: 260; awk: 231; ruby: 103; sed: 53; sql: 46; csh: 45
file content (203 lines) | stat: -rw-r--r-- 7,672 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "modules/video_coding/codecs/test/test_config.h"

#include <sstream>

#include "modules/video_coding/include/video_codec_interface.h"
#include "rtc_base/checks.h"
#include "system_wrappers/include/cpu_info.h"
#include "test/video_codec_settings.h"

namespace webrtc {
namespace test {

namespace {
const int kBaseKeyFrameInterval = 3000;

std::string CodecSpecificToString(const webrtc::VideoCodec& codec) {
  std::stringstream ss;
  switch (codec.codecType) {
    case kVideoCodecVP8:
      ss << "\n  Complexity        : " << codec.VP8().complexity;
      ss << "\n  Resilience        : " << codec.VP8().resilience;
      ss << "\n  # temporal layers : "
         << static_cast<int>(codec.VP8().numberOfTemporalLayers);
      ss << "\n  Denoising         : " << codec.VP8().denoisingOn;
      ss << "\n  Error concealment : " << codec.VP8().errorConcealmentOn;
      ss << "\n  Automatic resize  : " << codec.VP8().automaticResizeOn;
      ss << "\n  Frame dropping    : " << codec.VP8().frameDroppingOn;
      ss << "\n  Key frame interval: " << codec.VP8().keyFrameInterval;
      break;
    case kVideoCodecVP9:
      ss << "\n  Complexity        : " << codec.VP9().complexity;
      ss << "\n  Resilience        : " << codec.VP9().resilienceOn;
      ss << "\n  # temporal layers : "
         << static_cast<int>(codec.VP9().numberOfTemporalLayers);
      ss << "\n  Denoising         : " << codec.VP9().denoisingOn;
      ss << "\n  Frame dropping    : " << codec.VP9().frameDroppingOn;
      ss << "\n  Key frame interval: " << codec.VP9().keyFrameInterval;
      ss << "\n  Adaptive QP mode  : " << codec.VP9().adaptiveQpMode;
      ss << "\n  Automatic resize  : " << codec.VP9().automaticResizeOn;
      ss << "\n  # spatial layers  : "
         << static_cast<int>(codec.VP9().numberOfSpatialLayers);
      ss << "\n  Flexible mode     : " << codec.VP9().flexibleMode;
      break;
    case kVideoCodecH264:
      ss << "\n  Frame dropping    : " << codec.H264().frameDroppingOn;
      ss << "\n  Key frame interval: " << codec.H264().keyFrameInterval;
      ss << "\n  Profile           : " << codec.H264().profile;
      break;
    default:
      break;
  }
  ss << "\n";
  return ss.str();
}
}  // namespace

void TestConfig::SetCodecSettings(VideoCodecType codec_type,
                                  int num_temporal_layers,
                                  bool error_concealment_on,
                                  bool denoising_on,
                                  bool frame_dropper_on,
                                  bool spatial_resize_on,
                                  bool resilience_on,
                                  int width,
                                  int height) {
  webrtc::test::CodecSettings(codec_type, &codec_settings);

  // TODO(brandtr): Move the setting of |width| and |height| to the tests, and
  // DCHECK that they are set before initializing the codec instead.
  codec_settings.width = width;
  codec_settings.height = height;

  switch (codec_settings.codecType) {
    case kVideoCodecVP8:
      codec_settings.VP8()->resilience =
          resilience_on ? kResilientStream : kResilienceOff;
      codec_settings.VP8()->numberOfTemporalLayers = num_temporal_layers;
      codec_settings.VP8()->denoisingOn = denoising_on;
      codec_settings.VP8()->errorConcealmentOn = error_concealment_on;
      codec_settings.VP8()->automaticResizeOn = spatial_resize_on;
      codec_settings.VP8()->frameDroppingOn = frame_dropper_on;
      codec_settings.VP8()->keyFrameInterval = kBaseKeyFrameInterval;
      break;
    case kVideoCodecVP9:
      codec_settings.VP9()->resilienceOn = resilience_on;
      codec_settings.VP9()->numberOfTemporalLayers = num_temporal_layers;
      codec_settings.VP9()->denoisingOn = denoising_on;
      codec_settings.VP9()->frameDroppingOn = frame_dropper_on;
      codec_settings.VP9()->keyFrameInterval = kBaseKeyFrameInterval;
      codec_settings.VP9()->automaticResizeOn = spatial_resize_on;
      break;
    case kVideoCodecH264:
      codec_settings.H264()->frameDroppingOn = frame_dropper_on;
      codec_settings.H264()->keyFrameInterval = kBaseKeyFrameInterval;
      break;
    default:
      RTC_NOTREACHED();
      break;
  }
}

int TestConfig::NumberOfCores() const {
  return use_single_core ? 1 : CpuInfo::DetectNumberOfCores();
}

int TestConfig::NumberOfTemporalLayers() const {
  if (codec_settings.codecType == kVideoCodecVP8) {
    return codec_settings.VP8().numberOfTemporalLayers;
  } else if (codec_settings.codecType == kVideoCodecVP9) {
    return codec_settings.VP9().numberOfTemporalLayers;
  } else {
    return 1;
  }
}

int TestConfig::TemporalLayerForFrame(int frame_idx) const {
  int tl = -1;
  switch (NumberOfTemporalLayers()) {
    case 1:
      tl = 0;
      break;
    case 2:
      // temporal layer 1:     1     3
      // temporal layer 0:  0     2     4 ...
      tl = (frame_idx % 2 == 0) ? 0 : 1;
      break;
    case 3:
      // temporal layer 2:     1     3     5     7
      // temporal layer 1:        2           6
      // temporal layer 0:  0           4           8 ...
      if (frame_idx % 4 == 0) {
        tl = 0;
      } else if ((frame_idx + 2) % 4 == 0) {
        tl = 1;
      } else if ((frame_idx + 1) % 2 == 0) {
        tl = 2;
      }
      break;
    default:
      RTC_NOTREACHED();
      break;
  }
  return tl;
}

std::vector<FrameType> TestConfig::FrameTypeForFrame(int frame_idx) const {
  if (keyframe_interval > 0 && (frame_idx % keyframe_interval == 0)) {
    return {kVideoFrameKey};
  }
  return {kVideoFrameDelta};
}

std::string TestConfig::ToString() const {
  std::string codec_type = CodecTypeToPayloadString(codec_settings.codecType);
  std::stringstream ss;
  ss << "\n Filename         : " << filename;
  ss << "\n # CPU cores used : " << NumberOfCores();
  ss << "\n General:";
  ss << "\n  Codec type        : " << codec_type;
  ss << "\n  Start bitrate     : " << codec_settings.startBitrate << " kbps";
  ss << "\n  Max bitrate       : " << codec_settings.maxBitrate << " kbps";
  ss << "\n  Min bitrate       : " << codec_settings.minBitrate << " kbps";
  ss << "\n  Width             : " << codec_settings.width;
  ss << "\n  Height            : " << codec_settings.height;
  ss << "\n  Max frame rate    : " << codec_settings.maxFramerate;
  ss << "\n  QPmax             : " << codec_settings.qpMax;
  ss << "\n " << codec_type << " specific: ";
  ss << CodecSpecificToString(codec_settings);
  return ss.str();
}

std::string TestConfig::CodecName() const {
  std::string codec_name = CodecTypeToPayloadString(codec_settings.codecType);
  if (codec_settings.codecType == kVideoCodecH264) {
    if (h264_codec_settings.profile == H264::kProfileConstrainedHigh) {
      codec_name += "-CHP";
    } else {
      RTC_DCHECK_EQ(h264_codec_settings.profile,
                    H264::kProfileConstrainedBaseline);
      codec_name += "-CBP";
    }
  }
  return codec_name;
}

std::string TestConfig::FilenameWithParams() const {
  std::string implementation_type = hw_encoder ? "hw" : "sw";
  return filename + "_" + CodecName() + "_" + implementation_type + "_" +
         std::to_string(codec_settings.startBitrate);
}

}  // namespace test
}  // namespace webrtc