From 19712f28f6409666ed290a57776f953ba81a43da Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 7 Oct 2005 13:17:53 +0000 Subject: ext/raw1394/gstdv1394src.c: Clean up for style before doing some hacking. The only change should be that the state ch... Original commit message from CVS: 2005-10-07 Andy Wingo * ext/raw1394/gstdv1394src.c: Clean up for style before doing some hacking. The only change should be that the state change stuff was put into basesrc's start() and stop() routines, which coalesces some steps. --- ext/raw1394/gstdv1394src.c | 358 +++++++++++++++------------------------------ 1 file changed, 121 insertions(+), 237 deletions(-) (limited to 'ext/raw1394') diff --git a/ext/raw1394/gstdv1394src.c b/ext/raw1394/gstdv1394src.c index c7571f67..012d09a7 100644 --- a/ext/raw1394/gstdv1394src.c +++ b/ext/raw1394/gstdv1394src.c @@ -40,7 +40,6 @@ GST_DEBUG_CATEGORY_STATIC (dv1394src_debug); #define NTSC_FRAMESIZE 120000 #define NTSC_FRAMERATE 30 -/* Filter signals and args */ enum { SIGNAL_FRAME_DROPPED, @@ -58,14 +57,14 @@ enum enum { - ARG_0, - ARG_PORT, - ARG_CHANNEL, - ARG_CONSECUTIVE, - ARG_SKIP, - ARG_DROP_INCOMPLETE, - ARG_USE_AVC, - ARG_GUID + PROP_0, + PROP_PORT, + PROP_CHANNEL, + PROP_CONSECUTIVE, + PROP_SKIP, + PROP_DROP_INCOMPLETE, + PROP_USE_AVC, + PROP_GUID }; static GstElementDetails gst_dv1394src_details = @@ -82,29 +81,19 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", "format = (string) { NTSC, PAL }, " "systemstream = (boolean) true") ); -static void gst_dv1394src_base_init (gpointer g_class); -static void gst_dv1394src_class_init (GstDV1394SrcClass * klass); -static void gst_dv1394src_init (GstDV1394Src * filter); -static void gst_dv1394src_dispose (GObject * obj); +static void gst_dv1394src_uri_handler_init (gpointer g_iface, + gpointer iface_data); static void gst_dv1394src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_dv1394src_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -static GstStateChangeReturn gst_dv1394src_change_state (GstElement * element, - GstStateChange transition); +static gboolean gst_dv1394src_start (GstBaseSrc * bsrc); +static gboolean gst_dv1394src_stop (GstBaseSrc * bsrc); static GstFlowReturn gst_dv1394src_create (GstPushSrc * psrc, GstBuffer ** buf); -#if 0 -static const GstEventMask *gst_dv1394src_get_event_mask (GstPad * pad); -#endif -static gboolean gst_dv1394src_event (GstPad * pad, GstEvent * event); - -#if 0 -static const GstFormat *gst_dv1394src_get_formats (GstPad * pad); -#endif static gboolean gst_dv1394src_convert (GstPad * pad, GstFormat src_format, gint64 src_value, GstFormat * dest_format, gint64 * dest_value); @@ -112,48 +101,26 @@ static gboolean gst_dv1394src_convert (GstPad * pad, static const GstQueryType *gst_dv1394src_get_query_types (GstPad * pad); static gboolean gst_dv1394src_query (GstPad * pad, GstQuery * query); -static GstElementClass *parent_class = NULL; +static void +_do_init (GType type) +{ + static const GInterfaceInfo urihandler_info = { + gst_dv1394src_uri_handler_init, + NULL, + NULL, + }; + g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info); + + GST_DEBUG_CATEGORY_INIT (dv1394src_debug, "dv1394src", 0, + "DV firewire source"); +} + +GST_BOILERPLATE_FULL (GstDV1394Src, gst_dv1394src, GstPushSrc, + GST_TYPE_PUSH_SRC, _do_init); -static void gst_dv1394src_uri_handler_init (gpointer g_iface, - gpointer iface_data); static guint gst_dv1394src_signals[LAST_SIGNAL] = { 0 }; -GType -gst_dv1394src_get_type (void) -{ - static GType gst_dv1394src_type = 0; - - if (!gst_dv1394src_type) { - static const GTypeInfo gst_dv1394src_info = { - sizeof (GstDV1394Src), - gst_dv1394src_base_init, - NULL, - (GClassInitFunc) gst_dv1394src_class_init, - NULL, - NULL, - sizeof (GstDV1394Src), - 0, - (GInstanceInitFunc) gst_dv1394src_init, - }; - static const GInterfaceInfo urihandler_info = { - gst_dv1394src_uri_handler_init, - NULL, - NULL, - }; - - gst_dv1394src_type = - g_type_register_static (GST_TYPE_PUSH_SRC, "DV1394Src", - &gst_dv1394src_info, 0); - - g_type_add_interface_static (gst_dv1394src_type, GST_TYPE_URI_HANDLER, - &urihandler_info); - - GST_DEBUG_CATEGORY_INIT (dv1394src_debug, "dv1394src", 0, - "DV firewire source"); - } - return gst_dv1394src_type; -} static void gst_dv1394src_base_init (gpointer g_class) @@ -170,77 +137,64 @@ static void gst_dv1394src_class_init (GstDV1394SrcClass * klass) { GObjectClass *gobject_class; - GstElementClass *gstelement_class; GstBaseSrcClass *gstbasesrc_class; GstPushSrcClass *gstpushsrc_class; gobject_class = (GObjectClass *) klass; - gstelement_class = (GstElementClass *) klass; gstbasesrc_class = (GstBaseSrcClass *) klass; gstpushsrc_class = (GstPushSrcClass *) klass; - parent_class = g_type_class_ref (GST_TYPE_PUSH_SRC); - gobject_class->set_property = gst_dv1394src_set_property; gobject_class->get_property = gst_dv1394src_get_property; - gobject_class->dispose = gst_dv1394src_dispose; gst_dv1394src_signals[SIGNAL_FRAME_DROPPED] = g_signal_new ("frame-dropped", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDV1394SrcClass, frame_dropped), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PORT, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT, g_param_spec_int ("port", "Port", "Port number (-1 automatic)", -1, 16, DEFAULT_PORT, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CHANNEL, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CHANNEL, g_param_spec_int ("channel", "Channel", "Channel number for listening", 0, 64, DEFAULT_CHANNEL, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CONSECUTIVE, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CONSECUTIVE, g_param_spec_int ("consecutive", "consecutive frames", "send n consecutive frames after skipping", 1, G_MAXINT, DEFAULT_CONSECUTIVE, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SKIP, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SKIP, g_param_spec_int ("skip", "skip frames", "skip n frames", 0, G_MAXINT, DEFAULT_SKIP, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DROP_INCOMPLETE, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DROP_INCOMPLETE, g_param_spec_boolean ("drop_incomplete", "drop_incomplete", "drop incomplete frames", DEFAULT_DROP_INCOMPLETE, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_USE_AVC, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_USE_AVC, g_param_spec_boolean ("use-avc", "Use AV/C", "Use AV/C VTR control", DEFAULT_USE_AVC, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_GUID, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_GUID, g_param_spec_uint64 ("guid", "GUID", "select one of multiple DV devices by its GUID. use a hexadecimal " "like 0xhhhhhhhhhhhhhhhh. (0 = no guid)", 0, G_MAXUINT64, DEFAULT_GUID, G_PARAM_READWRITE)); - gstelement_class->change_state = gst_dv1394src_change_state; - gstbasesrc_class->negotiate = NULL; + gstbasesrc_class->start = gst_dv1394src_start; + gstbasesrc_class->stop = gst_dv1394src_stop; gstpushsrc_class->create = gst_dv1394src_create; } static void -gst_dv1394src_init (GstDV1394Src * dv1394src) +gst_dv1394src_init (GstDV1394Src * dv1394src, GstDV1394SrcClass * klass) { GstPad *srcpad = GST_BASE_SRC_PAD (dv1394src); gst_base_src_set_live (GST_BASE_SRC (dv1394src), TRUE); gst_pad_use_fixed_caps (srcpad); - gst_pad_set_event_function (srcpad, gst_dv1394src_event); gst_pad_set_query_function (srcpad, gst_dv1394src_query); gst_pad_set_query_type_function (srcpad, gst_dv1394src_get_query_types); -#if 0 - gst_pad_set_event_mask_function (dv1394src->srcpad, - gst_dv1394src_get_event_mask); - gst_pad_set_convert_function (dv1394src->srcpad, gst_dv1394src_convert); - gst_pad_set_formats_function (dv1394src->srcpad, gst_dv1394src_get_formats); -#endif - dv1394src->dv_lock = g_mutex_new (); dv1394src->port = DEFAULT_PORT; dv1394src->channel = DEFAULT_CHANNEL; @@ -259,16 +213,6 @@ gst_dv1394src_init (GstDV1394Src * dv1394src) dv1394src->frame_sequence = 0; } -static void -gst_dv1394src_dispose (GObject * obj) -{ - GstDV1394Src *dv1394src; - - dv1394src = GST_DV1394SRC (obj); - - G_OBJECT_CLASS (parent_class)->dispose (obj); -} - static void gst_dv1394src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) @@ -276,25 +220,25 @@ gst_dv1394src_set_property (GObject * object, guint prop_id, GstDV1394Src *filter = GST_DV1394SRC (object); switch (prop_id) { - case ARG_PORT: + case PROP_PORT: filter->port = g_value_get_int (value); break; - case ARG_CHANNEL: + case PROP_CHANNEL: filter->channel = g_value_get_int (value); break; - case ARG_SKIP: + case PROP_SKIP: filter->skip = g_value_get_int (value); break; - case ARG_CONSECUTIVE: + case PROP_CONSECUTIVE: filter->consecutive = g_value_get_int (value); break; - case ARG_DROP_INCOMPLETE: + case PROP_DROP_INCOMPLETE: filter->drop_incomplete = g_value_get_boolean (value); break; - case ARG_USE_AVC: + case PROP_USE_AVC: filter->use_avc = g_value_get_boolean (value); break; - case ARG_GUID: + case PROP_GUID: filter->guid = g_value_get_uint64 (value); break; default: @@ -309,25 +253,25 @@ gst_dv1394src_get_property (GObject * object, guint prop_id, GValue * value, GstDV1394Src *filter = GST_DV1394SRC (object); switch (prop_id) { - case ARG_PORT: + case PROP_PORT: g_value_set_int (value, filter->port); break; - case ARG_CHANNEL: + case PROP_CHANNEL: g_value_set_int (value, filter->channel); break; - case ARG_SKIP: + case PROP_SKIP: g_value_set_int (value, filter->skip); break; - case ARG_CONSECUTIVE: + case PROP_CONSECUTIVE: g_value_set_int (value, filter->consecutive); break; - case ARG_DROP_INCOMPLETE: + case PROP_DROP_INCOMPLETE: g_value_set_boolean (value, filter->drop_incomplete); break; - case ARG_USE_AVC: + case PROP_USE_AVC: g_value_set_boolean (value, filter->use_avc); break; - case ARG_GUID: + case PROP_GUID: g_value_set_uint64 (value, filter->guid); break; default: @@ -399,23 +343,21 @@ gst_dv1394src_iso_receive (raw1394handle_t handle, int channel, size_t len, dv1394src->frame = NULL; if ((dv1394src->frame_sequence + 1) % (dv1394src->skip + dv1394src->consecutive) < dv1394src->consecutive) { - //GstFormat format; + GstFormat format; GstBuffer *buf; + gint64 i64; buf = gst_buffer_new_and_alloc (dv1394src->frame_size); -#if 0 - /* fill in default offset */ - format = GST_FORMAT_DEFAULT; - gst_dv1394src_query (dv1394src->srcpad, GST_QUERY_POSITION, &format, - &GST_BUFFER_OFFSET (buf)); - /* fill in timestamp */ + + /* fill in offset, duration, timestamp */ + GST_BUFFER_OFFSET (buf) = dv1394src->frame_sequence; format = GST_FORMAT_TIME; - gst_dv1394src_query (dv1394src->srcpad, GST_QUERY_POSITION, &format, - &GST_BUFFER_TIMESTAMP (buf)); - /* fill in duration by converting one frame to time */ - gst_dv1394src_convert (dv1394src->srcpad, GST_FORMAT_DEFAULT, 1, - &format, &GST_BUFFER_DURATION (buf)); -#endif + gst_dv1394src_convert (GST_BASE_SRC_PAD (dv1394src), GST_FORMAT_DEFAULT, + GST_BUFFER_OFFSET (buf), &format, &i64); + GST_BUFFER_TIMESTAMP (buf) = i64; + gst_dv1394src_convert (GST_BASE_SRC_PAD (dv1394src), GST_FORMAT_DEFAULT, + 1, &format, &i64); + GST_BUFFER_DURATION (buf) = i64; dv1394src->frame = buf; } @@ -558,157 +500,99 @@ gst_dv1394src_discover_avc_node (GstDV1394Src * src) return node; } -static GstStateChangeReturn -gst_dv1394src_change_state (GstElement * element, GstStateChange transition) +static gboolean +gst_dv1394src_start (GstBaseSrc * bsrc) { - GstDV1394Src *dv1394src; - GstStateChangeReturn ret; + GstDV1394Src *src = GST_DV1394SRC (bsrc); - dv1394src = GST_DV1394SRC (element); + src->handle = raw1394_new_handle (); - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - /* create a handle */ - if ((dv1394src->handle = raw1394_new_handle ()) == NULL) - goto no_handle; + if (!src->handle) + goto no_handle; - /* set this plugin as the user data */ - raw1394_set_userdata (dv1394src->handle, dv1394src); + raw1394_set_userdata (src->handle, src); - /* get number of ports */ - if ((dv1394src->num_ports = - raw1394_get_port_info (dv1394src->handle, dv1394src->pinfo, - 16)) == 0) - goto no_ports; + src->num_ports = raw1394_get_port_info (src->handle, src->pinfo, 16); - if (dv1394src->use_avc || dv1394src->port == -1) { - /* discover AVC and optionally the port */ - dv1394src->avc_node = gst_dv1394src_discover_avc_node (dv1394src); - } + if (src->num_ports == 0) + goto no_ports; - /* configure our port now */ - if (raw1394_set_port (dv1394src->handle, dv1394src->port) < 0) - goto cannot_set_port; + if (src->use_avc || src->port == -1) + src->avc_node = gst_dv1394src_discover_avc_node (src); - /* set the callbacks */ - raw1394_set_iso_handler (dv1394src->handle, dv1394src->channel, - gst_dv1394src_iso_receive); - raw1394_set_bus_reset_handler (dv1394src->handle, - gst_dv1394src_bus_reset); + if (raw1394_set_port (src->handle, src->port) < 0) + goto cannot_set_port; - GST_DEBUG_OBJECT (dv1394src, "successfully opened up 1394 connection"); - break; - case GST_STATE_CHANGE_PAUSED_TO_PLAYING: - if (raw1394_start_iso_rcv (dv1394src->handle, dv1394src->channel) < 0) - goto cannot_start; - - if (dv1394src->use_avc) { - /* start the VCR */ - if (!avc1394_vcr_is_recording (dv1394src->handle, dv1394src->avc_node) - && avc1394_vcr_is_playing (dv1394src->handle, dv1394src->avc_node) - != AVC1394_VCR_OPERAND_PLAY_FORWARD) { - avc1394_vcr_play (dv1394src->handle, dv1394src->avc_node); - } - } - break; - default: - break; - } + raw1394_set_iso_handler (src->handle, src->channel, + gst_dv1394src_iso_receive); + raw1394_set_bus_reset_handler (src->handle, gst_dv1394src_bus_reset); - /* if we haven't failed already, give the parent class a chance to ;-) */ - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - - switch (transition) { - case GST_STATE_CHANGE_PLAYING_TO_PAUSED: - /* we need to lock here as the _create function has to be completed. - * The base source will not call the _create() function again. */ - GST_DV_LOCK (dv1394src); - raw1394_stop_iso_rcv (dv1394src->handle, dv1394src->channel); - if (dv1394src->use_avc) { - /* pause the VCR */ - if (!avc1394_vcr_is_recording (dv1394src->handle, dv1394src->avc_node) - && (avc1394_vcr_is_playing (dv1394src->handle, dv1394src->avc_node) - != AVC1394_VCR_OPERAND_PLAY_FORWARD_PAUSE)) { - avc1394_vcr_pause (dv1394src->handle, dv1394src->avc_node); - } - } - GST_DV_UNLOCK (dv1394src); - break; - case GST_STATE_CHANGE_PAUSED_TO_READY: - dv1394src->negotiated = FALSE; - break; - case GST_STATE_CHANGE_READY_TO_NULL: - if (dv1394src->use_avc) { - /* stop the VCR */ - avc1394_vcr_stop (dv1394src->handle, dv1394src->avc_node); - } - raw1394_destroy_handle (dv1394src->handle); - break; - default: - break; + GST_DEBUG_OBJECT (src, "successfully opened up 1394 connection"); + + if (raw1394_start_iso_rcv (src->handle, src->channel) < 0) + goto cannot_start; + + if (src->use_avc) { + /* start the VCR */ + if (!avc1394_vcr_is_recording (src->handle, src->avc_node) + && avc1394_vcr_is_playing (src->handle, src->avc_node) + != AVC1394_VCR_OPERAND_PLAY_FORWARD) + avc1394_vcr_play (src->handle, src->avc_node); } - return ret; + return TRUE; no_handle: { - GST_ELEMENT_ERROR (dv1394src, RESOURCE, NOT_FOUND, (NULL), + GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), ("can't get raw1394 handle")); - return GST_STATE_CHANGE_FAILURE; + return FALSE; } no_ports: { - GST_ELEMENT_ERROR (dv1394src, RESOURCE, NOT_FOUND, (NULL), + GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), ("no ports available for raw1394")); - return GST_STATE_CHANGE_FAILURE; + return FALSE; } cannot_set_port: { - GST_ELEMENT_ERROR (dv1394src, RESOURCE, SETTINGS, (NULL), - ("can't set 1394 port %d", dv1394src->port)); - return GST_STATE_CHANGE_FAILURE; + GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL), + ("can't set 1394 port %d", src->port)); + return FALSE; } cannot_start: { - GST_ELEMENT_ERROR (dv1394src, RESOURCE, READ, (NULL), + GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("can't start 1394 iso receive")); - return GST_STATE_CHANGE_FAILURE; + return FALSE; } } - -#if 0 -static const GstEventMask * -gst_dv1394src_get_event_mask (GstPad * pad) -{ - static const GstEventMask masks[] = { - {0,} - }; - - return masks; -} -#endif - static gboolean -gst_dv1394src_event (GstPad * pad, GstEvent * event) +gst_dv1394src_stop (GstBaseSrc * bsrc) { - return FALSE; -} + GstDV1394Src *src = GST_DV1394SRC (bsrc); + + GST_DV_LOCK (src); + raw1394_stop_iso_rcv (src->handle, src->channel); + if (src->use_avc) { + /* pause the VCR */ + if (!avc1394_vcr_is_recording (src->handle, src->avc_node) + && (avc1394_vcr_is_playing (src->handle, src->avc_node) + != AVC1394_VCR_OPERAND_PLAY_FORWARD_PAUSE)) + avc1394_vcr_pause (src->handle, src->avc_node); + } + GST_DV_UNLOCK (src); + src->negotiated = FALSE; -#if 0 -static const GstFormat * -gst_dv1394src_get_formats (GstPad * pad) -{ - static GstFormat formats[] = { - GST_FORMAT_TIME, - GST_FORMAT_BYTES, - GST_FORMAT_DEFAULT, - 0 - }; + if (src->use_avc) + /* stop the VCR */ + avc1394_vcr_stop (src->handle, src->avc_node); + + raw1394_destroy_handle (src->handle); - return formats; + return TRUE; } -#endif static gboolean gst_dv1394src_convert (GstPad * pad, -- cgit