Ensure that an RTP audio level of 127 represents digital silence.
To quote rfc6464: The audio level for digital silence -- for a muted audio source, for example -- MUST be represented as 127 (-127 dBov), regardless of the dynamic range of the encoded audio format. The behavior in webrtc is correct that digital silence is represented with 127, but it is also possible to get a value of 127 for not quite digitally silent audio buffer (as in, not strictly 0s). Bug: webrtc:14029 Change-Id: I7ff8698a7e4d5c0960c667fd1cc961838e269456 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261244 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36793}
This commit is contained in:
@ -101,8 +101,18 @@ void RmsLevel::AnalyzeMuted(size_t length) {
|
||||
}
|
||||
|
||||
int RmsLevel::Average() {
|
||||
int rms = (sample_count_ == 0) ? RmsLevel::kMinLevelDb
|
||||
: ComputeRms(sum_square_ / sample_count_);
|
||||
const bool have_samples = (sample_count_ != 0);
|
||||
int rms = have_samples ? ComputeRms(sum_square_ / sample_count_)
|
||||
: RmsLevel::kMinLevelDb;
|
||||
|
||||
// To ensure that kMinLevelDb represents digital silence (muted audio
|
||||
// sources) we'll check here if the sum_square is actually 0. If it's not
|
||||
// we'll bump up the return value to `kInaudibleButNotMuted`.
|
||||
// https://datatracker.ietf.org/doc/html/rfc6464
|
||||
if (have_samples && rms == RmsLevel::kMinLevelDb && sum_square_ != 0.0f) {
|
||||
rms = kInaudibleButNotMuted;
|
||||
}
|
||||
|
||||
Reset();
|
||||
return rms;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user