Skip to content

Commit

Permalink
Add audio energy metric.
Browse files Browse the repository at this point in the history
More details on audio energy can be found here:
https://w3c.github.io/webrtc-stats/#dom-rtcaudiosourcestats-totalaudioenergy

Change-Id: Ie8b543c0c3d2136f453c6731945f93de4c38218c
Bug: b/272781101
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/310121
Reviewed-by: Mirko Bonadei <[email protected]>
Commit-Queue: Jeremy Leconte <[email protected]>
Cr-Commit-Position: refs/heads/main@{#40352}
  • Loading branch information
jleconte2 authored and WebRTC LUCI CQ committed Jun 27, 2023
1 parent 38aa4ef commit 3458992
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
10 changes: 10 additions & 0 deletions test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void DefaultAudioQualityAnalyzer::OnStatsReports(
TimeDelta::Seconds(stat->jitter_buffer_target_delay.ValueOrDefault(0.));
sample.jitter_buffer_emitted_count =
stat->jitter_buffer_emitted_count.ValueOrDefault(0ul);
sample.total_samples_duration =
stat->total_samples_duration.ValueOrDefault(0.);
sample.total_audio_energy = stat->total_audio_energy.ValueOrDefault(0.);

TrackIdStreamInfoMap::StreamInfo stream_info =
analyzer_helper_->GetStreamInfoFromTrackId(*stat->track_identifier);
Expand Down Expand Up @@ -115,6 +118,9 @@ void DefaultAudioQualityAnalyzer::OnStatsReports(
jitter_buffer_target_delay_diff.ms<double>() /
jitter_buffer_emitted_count_diff);
}
audio_stream_stats.energy.AddSample(sqrt(
(sample.total_audio_energy - prev_sample.total_audio_energy) /
(sample.total_samples_duration - prev_sample.total_samples_duration)));

last_stats_sample_[stream_info.stream_label] = sample;
}
Expand Down Expand Up @@ -161,6 +167,10 @@ void DefaultAudioQualityAnalyzer::Stop() {
"preferred_buffer_size_ms", GetTestCaseName(item.first),
item.second.preferred_buffer_size_ms, Unit::kMilliseconds,
ImprovementDirection::kNeitherIsBetter, metric_metadata);
metrics_logger_->LogMetric("energy", GetTestCaseName(item.first),
item.second.energy, Unit::kUnitless,
ImprovementDirection::kNeitherIsBetter,
metric_metadata);
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct AudioStreamStats {
SamplesStatsCounter speech_expand_rate;
SamplesStatsCounter average_jitter_buffer_delay_ms;
SamplesStatsCounter preferred_buffer_size_ms;
SamplesStatsCounter energy;
};

class DefaultAudioQualityAnalyzer : public AudioQualityAnalyzerInterface {
Expand Down Expand Up @@ -59,6 +60,8 @@ class DefaultAudioQualityAnalyzer : public AudioQualityAnalyzerInterface {
TimeDelta jitter_buffer_delay = TimeDelta::Zero();
TimeDelta jitter_buffer_target_delay = TimeDelta::Zero();
uint64_t jitter_buffer_emitted_count = 0;
double total_samples_duration = 0.0;
double total_audio_energy = 0.0;
};

std::string GetTestCaseName(const std::string& stream_label) const;
Expand Down
26 changes: 24 additions & 2 deletions test/pc/e2e/peer_connection_quality_test_metric_names_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1090,10 +1090,32 @@ TEST(PeerConnectionE2EQualityTestMetricNamesTest,
.name = "video_ahead_ms",
.unit = Unit::kMilliseconds,
.improvement_direction = ImprovementDirection::kSmallerIsBetter,
.metadata =
{{MetricMetadataKey::kAudioStreamMetadataKey, "bob_video"},
{MetricMetadataKey::kPeerMetadataKey, "alice"},
{MetricMetadataKey::kPeerSyncGroupMetadataKey, "bob"},
{MetricMetadataKey::kReceiverMetadataKey, "alice"},
{MetricMetadataKey::kExperimentalTestNameMetadataKey,
"test_case"}}},
MetricValidationInfo{
.test_case = "test_case/alice_audio",
.name = "energy",
.unit = Unit::kUnitless,
.improvement_direction = ImprovementDirection::kNeitherIsBetter,
.metadata = {{MetricMetadataKey::kAudioStreamMetadataKey,
"alice_audio"},
{MetricMetadataKey::kPeerMetadataKey, "bob"},
{MetricMetadataKey::kReceiverMetadataKey, "bob"},
{MetricMetadataKey::kExperimentalTestNameMetadataKey,
"test_case"}}},
MetricValidationInfo{
.test_case = "test_case/bob_audio",
.name = "energy",
.unit = Unit::kUnitless,
.improvement_direction = ImprovementDirection::kNeitherIsBetter,
.metadata = {
{MetricMetadataKey::kAudioStreamMetadataKey, "bob_video"},
{MetricMetadataKey::kAudioStreamMetadataKey, "bob_audio"},
{MetricMetadataKey::kPeerMetadataKey, "alice"},
{MetricMetadataKey::kPeerSyncGroupMetadataKey, "bob"},
{MetricMetadataKey::kReceiverMetadataKey, "alice"},
{MetricMetadataKey::kExperimentalTestNameMetadataKey,
"test_case"}}}));
Expand Down

0 comments on commit 3458992

Please sign in to comment.