mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 17:20:36 +00:00
signalprocessor: change _setup to pass whole caps and not just sampling_rate
This allows to get rid of the sampling_rate variable in the base-class. Also now subclasses can modify the caps to actualy negotiate. This is needed to e.g. set audio-channel positions.
This commit is contained in:
parent
469446c7a4
commit
8a5e9a3363
4 changed files with 36 additions and 37 deletions
|
@ -60,8 +60,7 @@ static void gst_ladspa_set_property (GObject * object, guint prop_id,
|
|||
static void gst_ladspa_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
static gboolean gst_ladspa_setup (GstSignalProcessor * sigproc,
|
||||
guint sample_rate);
|
||||
static gboolean gst_ladspa_setup (GstSignalProcessor * sigproc, GstCaps * caps);
|
||||
static gboolean gst_ladspa_start (GstSignalProcessor * sigproc);
|
||||
static void gst_ladspa_stop (GstSignalProcessor * sigproc);
|
||||
static void gst_ladspa_cleanup (GstSignalProcessor * sigproc);
|
||||
|
@ -557,13 +556,15 @@ gst_ladspa_get_property (GObject * object, guint prop_id, GValue * value,
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_ladspa_setup (GstSignalProcessor * gsp, guint sample_rate)
|
||||
gst_ladspa_setup (GstSignalProcessor * gsp, GstCaps * caps)
|
||||
{
|
||||
GstLADSPA *ladspa;
|
||||
GstLADSPAClass *oclass;
|
||||
GstSignalProcessorClass *gsp_class;
|
||||
LADSPA_Descriptor *desc;
|
||||
int i;
|
||||
GstStructure *s;
|
||||
gint sample_rate;
|
||||
gint i;
|
||||
|
||||
gsp_class = GST_SIGNAL_PROCESSOR_GET_CLASS (gsp);
|
||||
ladspa = (GstLADSPA *) gsp;
|
||||
|
@ -573,6 +574,10 @@ gst_ladspa_setup (GstSignalProcessor * gsp, guint sample_rate)
|
|||
g_return_val_if_fail (ladspa->handle == NULL, FALSE);
|
||||
g_return_val_if_fail (ladspa->activated == FALSE, FALSE);
|
||||
|
||||
s = gst_caps_get_structure (caps, 0);
|
||||
if (!gst_structure_get_int (s, "rate", &sample_rate))
|
||||
goto no_sample_rate;
|
||||
|
||||
GST_DEBUG_OBJECT (ladspa, "instantiating the plugin at %d Hz", sample_rate);
|
||||
|
||||
ladspa->handle = desc->instantiate (desc, sample_rate);
|
||||
|
@ -588,6 +593,12 @@ gst_ladspa_setup (GstSignalProcessor * gsp, guint sample_rate)
|
|||
oclass->control_out_portnums[i], &(gsp->control_out[i]));
|
||||
|
||||
return TRUE;
|
||||
|
||||
no_sample_rate:
|
||||
{
|
||||
GST_WARNING_OBJECT (gsp, "got no sample-rate");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -53,7 +53,7 @@ static void gst_lv2_set_property (GObject * object,
|
|||
static void gst_lv2_get_property (GObject * object,
|
||||
guint prop_id, GValue * value, GParamSpec * pspec);
|
||||
|
||||
static gboolean gst_lv2_setup (GstSignalProcessor * sigproc, guint sample_rate);
|
||||
static gboolean gst_lv2_setup (GstSignalProcessor * sigproc, GstCaps * caps);
|
||||
static gboolean gst_lv2_start (GstSignalProcessor * sigproc);
|
||||
static void gst_lv2_stop (GstSignalProcessor * sigproc);
|
||||
static void gst_lv2_cleanup (GstSignalProcessor * sigproc);
|
||||
|
@ -591,11 +591,13 @@ gst_lv2_get_property (GObject * object, guint prop_id, GValue * value,
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_lv2_setup (GstSignalProcessor * gsp, guint sample_rate)
|
||||
gst_lv2_setup (GstSignalProcessor * gsp, GstCaps * caps)
|
||||
{
|
||||
GstLV2 *lv2;
|
||||
GstLV2Class *oclass;
|
||||
GstSignalProcessorClass *gsp_class;
|
||||
GstStructure *s;
|
||||
gint sample_rate;
|
||||
gint i;
|
||||
|
||||
gsp_class = GST_SIGNAL_PROCESSOR_GET_CLASS (gsp);
|
||||
|
@ -604,6 +606,10 @@ gst_lv2_setup (GstSignalProcessor * gsp, guint sample_rate)
|
|||
|
||||
g_return_val_if_fail (lv2->activated == FALSE, FALSE);
|
||||
|
||||
s = gst_caps_get_structure (caps, 0);
|
||||
if (!gst_structure_get_int (s, "rate", &sample_rate))
|
||||
goto no_sample_rate;
|
||||
|
||||
GST_DEBUG_OBJECT (lv2, "instantiating the plugin at %d Hz", sample_rate);
|
||||
|
||||
lv2->instance = slv2_plugin_instantiate (oclass->plugin, sample_rate, NULL);
|
||||
|
@ -621,6 +627,12 @@ gst_lv2_setup (GstSignalProcessor * gsp, guint sample_rate)
|
|||
&(gsp->control_out[i]));
|
||||
|
||||
return TRUE;
|
||||
|
||||
no_sample_rate:
|
||||
{
|
||||
GST_WARNING_OBJECT (gsp, "got no sample-rate");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -278,8 +278,6 @@ gst_signal_processor_init (GstSignalProcessor * self,
|
|||
/* init */
|
||||
self->pending_in = klass->num_group_in + klass->num_audio_in;
|
||||
self->pending_out = 0;
|
||||
|
||||
self->sample_rate = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -304,7 +302,7 @@ gst_signal_processor_finalize (GObject * object)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_signal_processor_setup (GstSignalProcessor * self, guint sample_rate)
|
||||
gst_signal_processor_setup (GstSignalProcessor * self, GstCaps * caps)
|
||||
{
|
||||
GstSignalProcessorClass *klass;
|
||||
gboolean ret = TRUE;
|
||||
|
@ -316,7 +314,7 @@ gst_signal_processor_setup (GstSignalProcessor * self, guint sample_rate)
|
|||
g_return_val_if_fail (self->state == GST_SIGNAL_PROCESSOR_STATE_NULL, FALSE);
|
||||
|
||||
if (klass->setup)
|
||||
ret = klass->setup (self, sample_rate);
|
||||
ret = klass->setup (self, caps);
|
||||
|
||||
if (!ret)
|
||||
goto setup_failed;
|
||||
|
@ -327,7 +325,7 @@ gst_signal_processor_setup (GstSignalProcessor * self, guint sample_rate)
|
|||
|
||||
setup_failed:
|
||||
{
|
||||
GST_INFO_OBJECT (self, "setup() failed at %u Hz", sample_rate);
|
||||
GST_INFO_OBJECT (self, "setup() failed for caps: %" GST_PTR_FORMAT, caps);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -476,28 +474,16 @@ gst_signal_processor_setcaps (GstPad * pad, GstCaps * caps)
|
|||
/* the whole processor has one caps; if the sample rate changes, let subclass
|
||||
implementations know */
|
||||
if (!gst_caps_is_equal (caps, self->caps)) {
|
||||
GstStructure *s;
|
||||
gint sample_rate;
|
||||
|
||||
GST_DEBUG_OBJECT (pad, "got caps %" GST_PTR_FORMAT, caps);
|
||||
|
||||
s = gst_caps_get_structure (caps, 0);
|
||||
if (!gst_structure_get_int (s, "rate", &sample_rate)) {
|
||||
GST_WARNING ("got no sample-rate");
|
||||
goto impossible;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (self, "Got rate=%d", sample_rate);
|
||||
|
||||
if (GST_SIGNAL_PROCESSOR_IS_RUNNING (self))
|
||||
gst_signal_processor_stop (self);
|
||||
if (GST_SIGNAL_PROCESSOR_IS_INITIALIZED (self))
|
||||
gst_signal_processor_cleanup (self);
|
||||
|
||||
if (!gst_signal_processor_setup (self, sample_rate))
|
||||
if (!gst_signal_processor_setup (self, caps))
|
||||
goto start_or_setup_failed;
|
||||
|
||||
self->sample_rate = sample_rate;
|
||||
gst_caps_replace (&self->caps, caps);
|
||||
} else {
|
||||
GST_DEBUG_OBJECT (self, "skipping, have caps already");
|
||||
|
@ -509,7 +495,7 @@ gst_signal_processor_setcaps (GstPad * pad, GstCaps * caps)
|
|||
sample rate (e.g., when having gone PLAYING->READY->PLAYING). make sure
|
||||
when we leave that the processor is RUNNING. */
|
||||
if (!GST_SIGNAL_PROCESSOR_IS_INITIALIZED (self)
|
||||
&& !gst_signal_processor_setup (self, self->sample_rate))
|
||||
&& !gst_signal_processor_setup (self, self->caps))
|
||||
goto start_or_setup_failed;
|
||||
if (!GST_SIGNAL_PROCESSOR_IS_RUNNING (self)
|
||||
&& !gst_signal_processor_start (self))
|
||||
|
@ -529,12 +515,6 @@ setcaps_pull_failed:
|
|||
gst_object_unref (self);
|
||||
return FALSE;
|
||||
}
|
||||
impossible:
|
||||
{
|
||||
g_critical ("something impossible happened");
|
||||
gst_object_unref (self);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/** De-interleave a pad (gstreamer => plugin) */
|
||||
|
|
|
@ -78,14 +78,10 @@ struct _GstSignalProcessorGroup {
|
|||
struct _GstSignalProcessor {
|
||||
GstElement element;
|
||||
|
||||
/* state */
|
||||
GstCaps *caps;
|
||||
|
||||
guint sample_rate;
|
||||
|
||||
GstSignalProcessorState state;
|
||||
|
||||
GstFlowReturn flow_state;
|
||||
|
||||
GstActivateMode mode;
|
||||
|
||||
/* pending inputs before processing can take place */
|
||||
|
@ -121,7 +117,7 @@ struct _GstSignalProcessorClass {
|
|||
|
||||
/* virtual methods for subclasses */
|
||||
|
||||
gboolean (*setup) (GstSignalProcessor *self, guint sample_rate);
|
||||
gboolean (*setup) (GstSignalProcessor *self, GstCaps *caps);
|
||||
gboolean (*start) (GstSignalProcessor *self);
|
||||
void (*stop) (GstSignalProcessor *self);
|
||||
void (*cleanup) (GstSignalProcessor *self);
|
||||
|
|
Loading…
Reference in a new issue