From 2c758796f5edd377fc7918ceccbab8f3bee433c5 Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Tue, 3 Dec 2002 00:36:54 +0000 Subject: [PATCH] Make the OSSSrc set the correct rate/number of channels as set in the GstCaps. Original commit message from CVS: Make the OSSSrc set the correct rate/number of channels as set in the GstCaps. Handle state changes correctly according to docs/random/wtay/states --- common | 2 +- sys/oss/gstosssrc.c | 67 +++++++++++++++++++++++++++++++++++++++++------------ sys/oss/gstosssrc.h | 4 +++- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/common b/common index f2d9b99..c73793f 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit f2d9b99515c73da09bfe307d273d320f79a226da +Subproject commit c73793f7022cbc8ffd39f9c0b0587078f47c0b06 diff --git a/sys/oss/gstosssrc.c b/sys/oss/gstosssrc.c index fef297f..fe91782 100644 --- a/sys/oss/gstosssrc.c +++ b/sys/oss/gstosssrc.c @@ -91,6 +91,7 @@ static void gst_osssrc_set_property (GObject *object, guint prop_id, const GV static void gst_osssrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static GstElementStateReturn gst_osssrc_change_state (GstElement *element); +static GstPadConnectReturn gst_osssrc_connect (GstPad *pad, GstCaps *caps); static void gst_osssrc_close_audio (GstOssSrc *src); static gboolean gst_osssrc_open_audio (GstOssSrc *src); static void gst_osssrc_sync_parms (GstOssSrc *osssrc); @@ -164,6 +165,7 @@ gst_osssrc_init (GstOssSrc *osssrc) osssrc->srcpad = gst_pad_new_from_template ( GST_PAD_TEMPLATE_GET (osssrc_src_factory), "src"); gst_pad_set_get_function(osssrc->srcpad,gst_osssrc_get); + gst_pad_set_connect_function (osssrc->srcpad, gst_osssrc_connect); gst_element_add_pad (GST_ELEMENT (osssrc), osssrc->srcpad); osssrc->device = g_strdup ("/dev/dsp"); @@ -322,28 +324,44 @@ gst_osssrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSp static GstElementStateReturn gst_osssrc_change_state (GstElement *element) { - /* GstOssSrc *src = GST_OSSSRC (element); */ + GstOssSrc *osssrc = GST_OSSSRC (element); g_return_val_if_fail (GST_IS_OSSSRC (element), FALSE); GST_DEBUG (GST_CAT_PLUGIN_INFO, "osssrc: state change"); - /* if going down into NULL state, close the file if it's open */ - if (GST_STATE_PENDING (element) == GST_STATE_NULL) { + + switch (GST_STATE_TRANSITION (element)) { + case GST_STATE_READY_TO_NULL: + break; + + case GST_STATE_NULL_TO_READY: + break; + + case GST_STATE_READY_TO_PAUSED: + /* Paused state: open device */ + if (!GST_FLAG_IS_SET (element, GST_OSSSRC_OPEN)) { + if (!gst_osssrc_open_audio (GST_OSSSRC (element))) + return GST_STATE_FAILURE; + } + + break; + + case GST_STATE_PAUSED_TO_READY: + /* Going down to ready: close device */ if (GST_FLAG_IS_SET (element, GST_OSSSRC_OPEN)) gst_osssrc_close_audio (GST_OSSSRC (element)); - /* otherwise (READY or higher) we need to open the sound card */ - } else { - GST_DEBUG (GST_CAT_PLUGIN_INFO, "DEBUG: osssrc: ready or higher"); + + break; - if (!GST_FLAG_IS_SET (element, GST_OSSSRC_OPEN)) { - if (!gst_osssrc_open_audio (GST_OSSSRC (element))) - return GST_STATE_FAILURE; - else - { - GST_DEBUG (GST_CAT_PLUGIN_INFO, "osssrc: device opened successfully"); - /* thomas: we can't set caps here because the element is - * not actually ready yet */ - } + case GST_STATE_PAUSED_TO_PLAYING: + if (osssrc->need_sync) { + gst_osssrc_sync_parms (GST_OSSSRC (element)); + osssrc->need_sync = FALSE; } + + break; + + case GST_STATE_PLAYING_TO_PAUSED: + break; } if (GST_ELEMENT_CLASS (parent_class)->change_state) @@ -352,6 +370,25 @@ gst_osssrc_change_state (GstElement *element) return GST_STATE_SUCCESS; } +static GstPadConnectReturn +gst_osssrc_connect (GstPad *pad, + GstCaps *caps) +{ + GstOssSrc *osssrc; + + osssrc = GST_OSSSRC (GST_PAD_PARENT (pad)); + + if (!GST_CAPS_IS_FIXED (caps)) { + return GST_PAD_CONNECT_DELAYED; + } + + gst_caps_get_int (caps, "rate", &osssrc->frequency); + gst_caps_get_int (caps, "channels", &osssrc->channels); + + osssrc->need_sync = TRUE; + return GST_PAD_CONNECT_OK; +} + static gboolean gst_osssrc_open_audio (GstOssSrc *src) { diff --git a/sys/oss/gstosssrc.h b/sys/oss/gstosssrc.h index 1ba2a04..343190e 100644 --- a/sys/oss/gstosssrc.h +++ b/sys/oss/gstosssrc.h @@ -70,12 +70,14 @@ struct _GstOssSrc { gint format; gint channels; gint frequency; - + gboolean need_sync; /* Do the parameters need resynced? */ + /* blocking */ guint64 basetime; guint64 samples_since_basetime; gulong curoffset; gulong bytes_per_read; + }; struct _GstOssSrcClass { -- 2.7.4