1 /*
2 * Copyright (c) 2014 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_encoder_config.h"
11
12 #include <string>
13
14 #include "rtc_base/checks.h"
15 #include "rtc_base/strings/string_builder.h"
16
17 namespace webrtc {
VideoStream()18 VideoStream::VideoStream()
19 : width(0),
20 height(0),
21 max_framerate(-1),
22 min_bitrate_bps(-1),
23 target_bitrate_bps(-1),
24 max_bitrate_bps(-1),
25 scale_resolution_down_by(-1.),
26 max_qp(-1),
27 num_temporal_layers(absl::nullopt),
28 active(true) {}
29 VideoStream::VideoStream(const VideoStream& other) = default;
30
31 VideoStream::~VideoStream() = default;
32
ToString() const33 std::string VideoStream::ToString() const {
34 char buf[1024];
35 rtc::SimpleStringBuilder ss(buf);
36 ss << "{width: " << width;
37 ss << ", height: " << height;
38 ss << ", max_framerate: " << max_framerate;
39 ss << ", min_bitrate_bps:" << min_bitrate_bps;
40 ss << ", target_bitrate_bps:" << target_bitrate_bps;
41 ss << ", max_bitrate_bps:" << max_bitrate_bps;
42 ss << ", max_qp: " << max_qp;
43 ss << ", num_temporal_layers: " << num_temporal_layers.value_or(1);
44 ss << ", bitrate_priority: " << bitrate_priority.value_or(0);
45 ss << ", active: " << active;
46
47 return ss.str();
48 }
49
VideoEncoderConfig()50 VideoEncoderConfig::VideoEncoderConfig()
51 : codec_type(kVideoCodecGeneric),
52 video_format("Unset"),
53 content_type(ContentType::kRealtimeVideo),
54 encoder_specific_settings(nullptr),
55 min_transmit_bitrate_bps(0),
56 max_bitrate_bps(0),
57 bitrate_priority(1.0),
58 number_of_streams(0) {}
59
60 VideoEncoderConfig::VideoEncoderConfig(VideoEncoderConfig&&) = default;
61
62 VideoEncoderConfig::~VideoEncoderConfig() = default;
63
ToString() const64 std::string VideoEncoderConfig::ToString() const {
65 char buf[1024];
66 rtc::SimpleStringBuilder ss(buf);
67 ss << "{codec_type: ";
68 ss << CodecTypeToPayloadString(codec_type);
69 ss << ", content_type: ";
70 switch (content_type) {
71 case ContentType::kRealtimeVideo:
72 ss << "kRealtimeVideo";
73 break;
74 case ContentType::kScreen:
75 ss << "kScreenshare";
76 break;
77 }
78 ss << ", encoder_specific_settings: ";
79 ss << (encoder_specific_settings != NULL ? "(ptr)" : "NULL");
80
81 ss << ", min_transmit_bitrate_bps: " << min_transmit_bitrate_bps;
82 ss << '}';
83 return ss.str();
84 }
85
86 VideoEncoderConfig::VideoEncoderConfig(const VideoEncoderConfig&) = default;
87
FillEncoderSpecificSettings(VideoCodec * codec) const88 void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings(
89 VideoCodec* codec) const {
90 if (codec->codecType == kVideoCodecH264) {
91 FillVideoCodecH264(codec->H264());
92 } else if (codec->codecType == kVideoCodecVP8) {
93 FillVideoCodecVp8(codec->VP8());
94 } else if (codec->codecType == kVideoCodecVP9) {
95 FillVideoCodecVp9(codec->VP9());
96 } else {
97 RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type.";
98 }
99 }
100
FillVideoCodecH264(VideoCodecH264 * h264_settings) const101 void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264(
102 VideoCodecH264* h264_settings) const {
103 RTC_NOTREACHED();
104 }
105
FillVideoCodecVp8(VideoCodecVP8 * vp8_settings) const106 void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8(
107 VideoCodecVP8* vp8_settings) const {
108 RTC_NOTREACHED();
109 }
110
FillVideoCodecVp9(VideoCodecVP9 * vp9_settings) const111 void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp9(
112 VideoCodecVP9* vp9_settings) const {
113 RTC_NOTREACHED();
114 }
115
H264EncoderSpecificSettings(const VideoCodecH264 & specifics)116 VideoEncoderConfig::H264EncoderSpecificSettings::H264EncoderSpecificSettings(
117 const VideoCodecH264& specifics)
118 : specifics_(specifics) {}
119
FillVideoCodecH264(VideoCodecH264 * h264_settings) const120 void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264(
121 VideoCodecH264* h264_settings) const {
122 *h264_settings = specifics_;
123 }
124
Vp8EncoderSpecificSettings(const VideoCodecVP8 & specifics)125 VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings(
126 const VideoCodecVP8& specifics)
127 : specifics_(specifics) {}
128
FillVideoCodecVp8(VideoCodecVP8 * vp8_settings) const129 void VideoEncoderConfig::Vp8EncoderSpecificSettings::FillVideoCodecVp8(
130 VideoCodecVP8* vp8_settings) const {
131 *vp8_settings = specifics_;
132 }
133
Vp9EncoderSpecificSettings(const VideoCodecVP9 & specifics)134 VideoEncoderConfig::Vp9EncoderSpecificSettings::Vp9EncoderSpecificSettings(
135 const VideoCodecVP9& specifics)
136 : specifics_(specifics) {}
137
FillVideoCodecVp9(VideoCodecVP9 * vp9_settings) const138 void VideoEncoderConfig::Vp9EncoderSpecificSettings::FillVideoCodecVp9(
139 VideoCodecVP9* vp9_settings) const {
140 *vp9_settings = specifics_;
141 }
142
143 } // namespace webrtc
144