• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2001 Thomas <thomas@apestaart.org>
4  *               2005,2006 Wim Taymans <wim@fluendo.com>
5  *                    2013 Sebastian Dröge <sebastian@centricular.com>
6  * Copyright (C) 2020 Huawei Technologies Co., Ltd.
7  *   @Author: Stéphane Cerveau <scerveau@collabora.com>
8  *
9  * audiomixer.c: AudioMixer element, N in, one out, samples are added
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  */
26 /**
27  * SECTION:element-liveadder
28  * @title: liveadder
29  *
30  *
31  *
32  */
33 
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37 
38 #include "gstaudiomixerelements.h"
39 #include "gstaudiomixerorc.h"
40 
41 #include "gstaudiointerleave.h"
42 
43 /* Empty liveadder alias with non-zero latency */
44 
45 typedef GstAudioMixer GstLiveAdder;
46 typedef GstAudioMixerClass GstLiveAdderClass;
47 
48 static GType gst_live_adder_get_type (void);
49 #define GST_TYPE_LIVE_ADDER gst_live_adder_get_type ()
50 
51 G_DEFINE_TYPE (GstLiveAdder, gst_live_adder, GST_TYPE_AUDIO_MIXER);
52 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (liveadder, "liveadder",
53     GST_RANK_NONE, GST_TYPE_LIVE_ADDER, audiomixer_element_init (plugin));
54 
55 enum
56 {
57   LIVEADDER_PROP_LATENCY = 1
58 };
59 
60 static void
gst_live_adder_init(GstLiveAdder * self)61 gst_live_adder_init (GstLiveAdder * self)
62 {
63 }
64 
65 static void
gst_live_adder_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)66 gst_live_adder_set_property (GObject * object, guint prop_id,
67     const GValue * value, GParamSpec * pspec)
68 {
69   switch (prop_id) {
70     case LIVEADDER_PROP_LATENCY:
71     {
72       GParamSpec *parent_spec =
73           g_object_class_find_property (G_OBJECT_CLASS
74           (gst_live_adder_parent_class), "latency");
75       GObjectClass *pspec_class = g_type_class_peek (parent_spec->owner_type);
76       GValue v = { 0 };
77 
78       g_value_init (&v, G_TYPE_UINT64);
79 
80       g_value_set_uint64 (&v, g_value_get_uint (value) * GST_MSECOND);
81 
82       G_OBJECT_CLASS (pspec_class)->set_property (object,
83           parent_spec->param_id, &v, parent_spec);
84       break;
85     }
86     default:
87       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
88       break;
89   }
90 }
91 
92 static void
gst_live_adder_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)93 gst_live_adder_get_property (GObject * object, guint prop_id, GValue * value,
94     GParamSpec * pspec)
95 {
96   switch (prop_id) {
97     case LIVEADDER_PROP_LATENCY:
98     {
99       GParamSpec *parent_spec =
100           g_object_class_find_property (G_OBJECT_CLASS
101           (gst_live_adder_parent_class), "latency");
102       GObjectClass *pspec_class = g_type_class_peek (parent_spec->owner_type);
103       GValue v = { 0 };
104 
105       g_value_init (&v, G_TYPE_UINT64);
106 
107       G_OBJECT_CLASS (pspec_class)->get_property (object,
108           parent_spec->param_id, &v, parent_spec);
109 
110       g_value_set_uint (value, g_value_get_uint64 (&v) / GST_MSECOND);
111       break;
112     }
113     default:
114       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
115       break;
116   }
117 }
118 
119 static void
gst_live_adder_class_init(GstLiveAdderClass * klass)120 gst_live_adder_class_init (GstLiveAdderClass * klass)
121 {
122   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
123 
124   gobject_class->set_property = gst_live_adder_set_property;
125   gobject_class->get_property = gst_live_adder_get_property;
126 
127   g_object_class_install_property (gobject_class, LIVEADDER_PROP_LATENCY,
128       g_param_spec_uint ("latency", "Buffer latency",
129           "Additional latency in live mode to allow upstream "
130           "to take longer to produce buffers for the current "
131           "position (in milliseconds)", 0, G_MAXUINT,
132           30, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT));
133 }
134