mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-04 23:46:43 +00:00
level: Fix integer overflow when filling LevelMeta
The level in GstAudioLevelMeta is represented as a signed 8bit value from 0 to 127 (with 127 meaning silence). When converting from double, make sure to clip the value, this also prevent integer overflow in the conversion. This fixes an issue where a lower then -127db is reported and random level with near silent streams (due to integer overflow). Fixes #4068 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8012>
This commit is contained in:
parent
4507f92b0d
commit
85969fdaa7
1 changed files with 11 additions and 1 deletions
|
@ -731,8 +731,18 @@ gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
if (filter->audio_level_meta) {
|
if (filter->audio_level_meta) {
|
||||||
gdouble RMS = sqrt (CS_tot / num_int_samples);
|
gdouble RMS = sqrt (CS_tot / num_int_samples);
|
||||||
gdouble RMSdB = 20 * log10 (RMS + EPSILON);
|
gdouble RMSdB = 20 * log10 (RMS + EPSILON);
|
||||||
|
guint8 level;
|
||||||
|
|
||||||
gst_level_rtp_audio_level_meta (filter, in, -RMSdB);
|
/* -127db is considered silent in audio level meta, clip anything below and
|
||||||
|
* avoid possible integer overflow */
|
||||||
|
if (RMSdB < -127.0)
|
||||||
|
level = 127;
|
||||||
|
else if (RMSdB > 0.0)
|
||||||
|
level = 0;
|
||||||
|
else
|
||||||
|
level = -RMSdB;
|
||||||
|
|
||||||
|
gst_level_rtp_audio_level_meta (filter, in, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_OBJECT_UNLOCK (filter);
|
GST_OBJECT_UNLOCK (filter);
|
||||||
|
|
Loading…
Reference in a new issue