1 /*
2  * WebRTC Audio Processing Elements
3  *
4  *  Copyright 2016 Collabora Ltd
5  *    @author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20  *
21  */
22 
23 #ifndef __GST_WEBRTC_ECHO_PROBE_H__
24 #define __GST_WEBRTC_ECHO_PROBE_H__
25 
26 #include <gst/gst.h>
27 #include <gst/base/gstadapter.h>
28 #include <gst/base/gstbasetransform.h>
29 #include <gst/audio/audio.h>
30 
31 #ifndef GST_USE_UNSTABLE_API
32 #define GST_USE_UNSTABLE_API
33 #endif
34 #include <gst/audio/gstplanaraudioadapter.h>
35 
36 G_BEGIN_DECLS
37 
38 #define GST_TYPE_WEBRTC_ECHO_PROBE            (gst_webrtc_echo_probe_get_type())
39 #define GST_WEBRTC_ECHO_PROBE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WEBRTC_ECHO_PROBE,GstWebrtcEchoProbe))
40 #define GST_IS_WEBRTC_ECHO_PROBE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WEBRTC_ECHO_PROBE))
41 #define GST_WEBRTC_ECHO_PROBE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_WEBRTC_ECHO_PROBE,GstWebrtcEchoProbeClass))
42 #define GST_IS_WEBRTC_ECHO_PROBE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_WEBRTC_ECHO_PROBE))
43 #define GST_WEBRTC_ECHO_PROBE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_WEBRTC_ECHO_PROBE,GstWebrtcEchoProbeClass))
44 
45 #define GST_WEBRTC_ECHO_PROBE_LOCK(obj) g_mutex_lock (&GST_WEBRTC_ECHO_PROBE (obj)->lock)
46 #define GST_WEBRTC_ECHO_PROBE_UNLOCK(obj) g_mutex_unlock (&GST_WEBRTC_ECHO_PROBE (obj)->lock)
47 
48 typedef struct _GstWebrtcEchoProbe GstWebrtcEchoProbe;
49 typedef struct _GstWebrtcEchoProbeClass GstWebrtcEchoProbeClass;
50 
51 /**
52  * GstWebrtcEchoProbe:
53  *
54  * The adder object structure.
55  */
56 struct _GstWebrtcEchoProbe
57 {
58   GstAudioFilter parent;
59 
60   /* This lock is required as the DSP may need to lock itself using it's
61    * object lock and also lock the probe. The natural order for the DSP is
62    * to lock the DSP and then the echo probe. If we where using the probe
63    * object lock, we'd be racing with GstBin which will lock sink to src,
64    * and may accidently reverse the order. */
65   GMutex lock;
66 
67   /* Protected by the lock */
68   GstAudioInfo info;
69   guint period_size;
70   guint period_samples;
71   GstClockTime latency;
72   gint delay;
73   gboolean interleaved;
74 
75   GstSegment segment;
76   GstAdapter *adapter;
77   GstPlanarAudioAdapter *padapter;
78 
79   /* Private */
80   gboolean acquired;
81 };
82 
83 struct _GstWebrtcEchoProbeClass
84 {
85   GstAudioFilterClass parent_class;
86 };
87 
88 GType gst_webrtc_echo_probe_get_type (void);
89 
90 GstWebrtcEchoProbe *gst_webrtc_acquire_echo_probe (const gchar * name);
91 void gst_webrtc_release_echo_probe (GstWebrtcEchoProbe * probe);
92 gint gst_webrtc_echo_probe_read (GstWebrtcEchoProbe * self,
93     GstClockTime rec_time, gpointer frame, GstBuffer ** buf);
94 
95 G_END_DECLS
96 #endif /* __GST_WEBRTC_ECHO_PROBE_H__ */
97