Skip to content

Commit f8f1dfd

Browse files
DrekabiArchaeopteryx
authored andcommitted
Bug 1995393 - Vendor libwebrtc from 8e8480de52
Upstream commit: https://webrtc.googlesource.com/src/+/8e8480de52505e4a086010b4732ce1197bc17139 Calculate video encode PSNR (in supported codecs) the Y, U and V components, applications can do a weighted average. https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-psnrsum Depends on cisco/openh264#3824 (for OpenH264) https://chromium-review.googlesource.com/c/webm/libvpx/+/6167966 (libvpx) https://aomedia-review.googlesource.com/c/aom/+/196501 (libaom) This CL implements the codec changes, https://webrtc-review.googlesource.com/c/src/+/375021 is a follow-up to wire up getStats. BUG=webrtc:388070060 Change-Id: I7046158a7b6e4183a9ec939fcac94eee9d65530d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/368960 Reviewed-by: Erik Språng <[email protected]> Commit-Queue: Philipp Hancke <[email protected]> Reviewed-by: Harald Alvestrand <[email protected]> Cr-Commit-Position: refs/heads/main@{#45312}
1 parent ad80a63 commit f8f1dfd

29 files changed

+334
-59
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
2-
libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-22T20:59:28.116125+00:00.
2+
libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-22T21:02:26.587370+00:00.
33
# base of lastest vendoring
4-
b7bde5ab8a
4+
8e8480de52

third_party/libwebrtc/api/video/encoded_image.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ class RTC_EXPORT EncodedImageBuffer : public EncodedImageBufferInterface {
7878
// cleaned up. Direct use of its members is strongly discouraged.
7979
class RTC_EXPORT EncodedImage {
8080
public:
81+
// Peak signal to noise ratio, Y/U/V components.
82+
struct Psnr {
83+
double y = 0.0;
84+
double u = 0.0;
85+
double v = 0.0;
86+
};
87+
8188
EncodedImage();
8289
EncodedImage(EncodedImage&&);
8390
EncodedImage(const EncodedImage&);
@@ -260,6 +267,9 @@ class RTC_EXPORT EncodedImage {
260267
EncodedImage::Timing video_timing() const { return timing_; }
261268
EncodedImage::Timing* video_timing_mutable() { return &timing_; }
262269

270+
std::optional<Psnr> psnr() const { return psnr_; }
271+
void set_psnr(std::optional<Psnr> psnr) { psnr_ = psnr; }
272+
263273
private:
264274
size_t capacity() const { return encoded_data_ ? encoded_data_->size() : 0; }
265275

@@ -296,6 +306,9 @@ class RTC_EXPORT EncodedImage {
296306
// used.
297307
std::optional<CorruptionDetectionFilterSettings>
298308
corruption_detection_filter_settings_;
309+
310+
// Encoders may compute PSNR for a frame.
311+
std::optional<Psnr> psnr_;
299312
};
300313

301314
} // namespace webrtc

third_party/libwebrtc/call/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ rtc_library("video_send_stream_api") {
409409
"../api/adaptation:resource_adaptation_api",
410410
"../api/crypto:options",
411411
"../api/units:data_rate",
412+
"../api/video:encoded_image",
412413
"../api/video:video_frame",
413414
"../api/video:video_rtp_headers",
414415
"../api/video:video_stream_encoder",

third_party/libwebrtc/call/video_send_stream.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "api/rtp_sender_setparameters_callback.h"
2828
#include "api/scoped_refptr.h"
2929
#include "api/units/data_rate.h"
30+
#include "api/video/encoded_image.h"
3031
#include "api/video/video_content_type.h"
3132
#include "api/video/video_frame.h"
3233
#include "api/video/video_source_interface.h"
@@ -94,6 +95,8 @@ class VideoSendStream {
9495
double encode_frame_rate = 0.0;
9596
int frames_encoded = 0;
9697
std::optional<uint64_t> qp_sum;
98+
EncodedImage::Psnr psnr_sum;
99+
uint64_t psnr_measurements = 0;
97100
uint64_t total_encode_time_ms = 0;
98101
uint64_t total_encoded_bytes_target = 0;
99102
uint32_t huge_frames_sent = 0;

third_party/libwebrtc/experiments/field_trials.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ def bug_url(self) -> str:
197197
FieldTrial('WebRTC-VP9-SvcForSimulcast',
198198
347737882,
199199
date(2024, 10, 1)),
200+
FieldTrial('WebRTC-Video-CalculatePsnr',
201+
388070060,
202+
date(2026, 1, 1)),
200203
FieldTrial('WebRTC-Video-EnableRetransmitAllLayers',
201204
42225262,
202205
date(2024, 4, 1)),

third_party/libwebrtc/media/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ rtc_source_set("media_channel") {
352352
"../api/units:data_rate",
353353
"../api/units:time_delta",
354354
"../api/units:timestamp",
355+
"../api/video:encoded_image",
355356
"../api/video:recordable_encoded_frame",
356357
"../api/video:video_frame",
357358
"../api/video:video_rtp_headers",

third_party/libwebrtc/media/base/media_channel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "api/units/data_rate.h"
4444
#include "api/units/time_delta.h"
4545
#include "api/units/timestamp.h"
46+
#include "api/video/encoded_image.h"
4647
#include "api/video/recordable_encoded_frame.h"
4748
#include "api/video/video_content_type.h"
4849
#include "api/video/video_sink_interface.h"
@@ -593,8 +594,12 @@ struct VideoSenderInfo : public MediaSenderInfo {
593594
// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
594595
uint64_t total_encoded_bytes_target = 0;
595596
bool has_entered_low_resolution = false;
597+
// https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-qpsum
596598
std::optional<uint64_t> qp_sum;
597599
VideoContentType content_type = VideoContentType::UNSPECIFIED;
600+
// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-psnrsum
601+
webrtc::EncodedImage::Psnr psnr_sum;
602+
uint32_t psnr_measurements = 0;
598603
uint32_t frames_sent = 0;
599604
// https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
600605
uint32_t huge_frames_sent = 0;

third_party/libwebrtc/media/engine/webrtc_video_engine.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,8 @@ WebRtcVideoSendChannel::WebRtcVideoSendStream::GetPerLayerVideoSenderInfos(
25372537
info.report_block_datas.push_back(*stream_stats.report_block_data);
25382538
}
25392539
info.qp_sum = stream_stats.qp_sum;
2540+
info.psnr_sum = stream_stats.psnr_sum;
2541+
info.psnr_measurements = stream_stats.psnr_measurements;
25402542
info.total_encode_time_ms = stream_stats.total_encode_time_ms;
25412543
info.total_encoded_bytes_target = stream_stats.total_encoded_bytes_target;
25422544
info.huge_frames_sent = stream_stats.huge_frames_sent;
@@ -2589,6 +2591,12 @@ WebRtcVideoSendChannel::WebRtcVideoSendStream::GetAggregatedVideoSenderInfo(
25892591
}
25902592
info.qp_sum = *info.qp_sum + *infos[i].qp_sum;
25912593
}
2594+
if (infos[i].psnr_measurements > 0) {
2595+
info.psnr_measurements += infos[i].psnr_measurements;
2596+
info.psnr_sum.y += infos[i].psnr_sum.y;
2597+
info.psnr_sum.u += infos[i].psnr_sum.u;
2598+
info.psnr_sum.v += infos[i].psnr_sum.v;
2599+
}
25922600
info.frames_encoded += infos[i].frames_encoded;
25932601
info.frames_sent += infos[i].frames_sent;
25942602
info.total_encode_time_ms += infos[i].total_encode_time_ms;

third_party/libwebrtc/modules/video_coding/BUILD.gn

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,18 @@ if (rtc_use_h264 && rtc_system_openh264) {
388388
}
389389
}
390390

391+
rtc_library("frame_sampler") {
392+
visibility = [ "*" ]
393+
sources = [
394+
"utility/frame_sampler.cc",
395+
"utility/frame_sampler.h",
396+
]
397+
deps = [
398+
"..:module_api_public",
399+
"../../api/video:video_frame",
400+
]
401+
}
402+
391403
rtc_library("video_coding_utility") {
392404
visibility = [ "*" ]
393405
sources = [
@@ -488,6 +500,7 @@ rtc_library("webrtc_h264") {
488500
defines = []
489501
deps = [
490502
":codec_globals_headers",
503+
":frame_sampler",
491504
":video_codec_interface",
492505
":video_coding_utility",
493506
"../../api:scoped_refptr",
@@ -514,6 +527,7 @@ rtc_library("webrtc_h264") {
514527
"../../rtc_base:timeutils",
515528
"../../rtc_base/system:rtc_export",
516529
"../../system_wrappers:metrics",
530+
"../rtp_rtcp:rtp_rtcp_format",
517531
"svc:scalability_structures",
518532
"svc:scalable_video_controller",
519533
"//third_party/abseil-cpp/absl/base:nullability",
@@ -575,6 +589,7 @@ rtc_library("webrtc_vp8") {
575589

576590
deps = [
577591
":codec_globals_headers",
592+
":frame_sampler",
578593
":video_codec_interface",
579594
":video_coding_utility",
580595
":webrtc_libvpx_interface",
@@ -608,6 +623,7 @@ rtc_library("webrtc_vp8") {
608623
"../../rtc_base/experiments:field_trial_parser",
609624
"../../rtc_base/experiments:rate_control_settings",
610625
"../../system_wrappers:metrics",
626+
"../rtp_rtcp:rtp_rtcp_format",
611627
"svc:scalability_mode_util",
612628
"//third_party/abseil-cpp/absl/algorithm:container",
613629
"//third_party/abseil-cpp/absl/base:nullability",
@@ -701,6 +717,7 @@ rtc_library("webrtc_vp9") {
701717

702718
deps = [
703719
":codec_globals_headers",
720+
":frame_sampler",
704721
":video_codec_interface",
705722
":video_coding_utility",
706723
":webrtc_libvpx_interface",
@@ -1209,6 +1226,7 @@ if (rtc_include_tests) {
12091226
"utility/corruption_detection_settings_generator_unittest.cc",
12101227
"utility/decoded_frames_history_unittest.cc",
12111228
"utility/frame_dropper_unittest.cc",
1229+
"utility/frame_sampler_unittest.cc",
12121230
"utility/framerate_controller_deprecated_unittest.cc",
12131231
"utility/ivf_file_reader_unittest.cc",
12141232
"utility/ivf_file_writer_unittest.cc",
@@ -1233,6 +1251,7 @@ if (rtc_include_tests) {
12331251
":encoded_frame",
12341252
":frame_dependencies_calculator",
12351253
":frame_helpers",
1254+
":frame_sampler",
12361255
":h264_sprop_parameter_sets",
12371256
":h26x_packet_buffer",
12381257
":nack_requester",

third_party/libwebrtc/modules/video_coding/codecs/av1/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ rtc_library("libaom_av1_encoder") {
6060
]
6161
deps = [
6262
"../..:video_codec_interface",
63+
"../..:video_coding_utility",
64+
"../../:frame_sampler",
6365
"../../../../api:field_trials_view",
6466
"../../../../api:scoped_refptr",
6567
"../../../../api/environment",

0 commit comments

Comments
 (0)