webrtcdsp: Propagate VAD to audio level meta
authorPhilippe Normand <philn@igalia.com>
Sun, 18 Apr 2021 12:49:59 +0000 (13:49 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 19 Apr 2021 15:51:32 +0000 (15:51 +0000)
Whenever the voice activity changed on the stream, update or create an
AudioLevelMeta and associate it to the corresponding buffer.

Fixes #1073

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2170>

ext/webrtcdsp/gstwebrtcdsp.cpp

index 27b286f..7ee0948 100644 (file)
@@ -442,12 +442,24 @@ done:
 }
 
 static void
-gst_webrtc_vad_post_message (GstWebrtcDsp *self, GstClockTime timestamp,
+gst_webrtc_vad_post_activity (GstWebrtcDsp *self, GstBuffer *buffer,
     gboolean stream_has_voice)
 {
+  GstClockTime timestamp = GST_BUFFER_PTS (buffer);
   GstBaseTransform *trans = GST_BASE_TRANSFORM_CAST (self);
   GstStructure *s;
   GstClockTime stream_time;
+  GstAudioLevelMeta *meta;
+  guint8 level;
+
+  level = self->apm->level_estimator ()->RMS ();
+  meta = gst_buffer_get_audio_level_meta (buffer);
+  if (meta) {
+    meta->voice_activity = stream_has_voice;
+    meta->level = level;
+  } else {
+    gst_buffer_add_audio_level_meta (buffer, level, stream_has_voice);
+  }
 
   stream_time = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
       timestamp);
@@ -502,7 +514,7 @@ gst_webrtc_dsp_process_stream (GstWebrtcDsp * self,
       gboolean stream_has_voice = apm->voice_detection ()->stream_has_voice ();
 
       if (stream_has_voice != self->stream_has_voice)
-        gst_webrtc_vad_post_message (self, GST_BUFFER_PTS (buffer), stream_has_voice);
+        gst_webrtc_vad_post_activity (self, buffer, stream_has_voice);
 
       self->stream_has_voice = stream_has_voice;
     }
@@ -716,6 +728,7 @@ gst_webrtc_dsp_setup (GstAudioFilter * filter, const GstAudioInfo * info)
     apm->voice_detection ()->set_likelihood (self->voice_detection_likelihood);
     apm->voice_detection ()->set_frame_size_ms (
         self->voice_detection_frame_size_ms);
+    apm->level_estimator ()->Enable (true);
   }
 
   GST_OBJECT_UNLOCK (self);