ext/libmms/gstmms.*: Some clean-ups; more debug output; use blocksize property of GstBaseSrc instead of re-registerin...

Original commit message from CVS:
* ext/libmms/gstmms.c: (gst_mms_urihandler_init),
(gst_mms_base_init), (gst_mms_class_init), (gst_mms_init),
(gst_mms_finalize), (gst_mms_create), (gst_mms_start),
(gst_mms_set_property), (gst_mms_get_property),
(gst_mms_uri_get_uri):
* ext/libmms/gstmms.h:
Some clean-ups; more debug output; use blocksize property
of GstBaseSrc instead of re-registering our own; make debug
category actually be used.
This commit is contained in:
Tim-Philipp Müller 2006-03-10 13:49:23 +00:00
parent 212c802ce2
commit e276fe38ba
3 changed files with 78 additions and 98 deletions

View file

@ -1,3 +1,15 @@
2006-03-10 Tim-Philipp Müller <tim at centricular dot net>
* ext/libmms/gstmms.c: (gst_mms_urihandler_init),
(gst_mms_base_init), (gst_mms_class_init), (gst_mms_init),
(gst_mms_finalize), (gst_mms_create), (gst_mms_start),
(gst_mms_set_property), (gst_mms_get_property),
(gst_mms_uri_get_uri):
* ext/libmms/gstmms.h:
Some clean-ups; more debug output; use blocksize property
of GstBaseSrc instead of re-registering our own; make debug
category actually be used.
2006-03-09 Tim-Philipp Müller <tim at centricular dot net> 2006-03-09 Tim-Philipp Müller <tim at centricular dot net>
* gst/qtdemux/qtdemux.c: (gst_qtdemux_send_event): * gst/qtdemux/qtdemux.c: (gst_qtdemux_send_event):

View file

@ -27,23 +27,15 @@
#include <string.h> #include <string.h>
#include "gstmms.h" #include "gstmms.h"
/* Filter signals and args */
enum
{
/* FILL ME */
LAST_SIGNAL
};
enum enum
{ {
ARG_0, ARG_0,
ARG_LOCATION, ARG_LOCATION
ARG_BLOCKSIZE
}; };
GST_DEBUG_CATEGORY (mmssrc_debug); GST_DEBUG_CATEGORY (mmssrc_debug);
#define GST_CATEGORY_DEFAULT mmssrc_debug #define GST_CAT_DEFAULT mmssrc_debug
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
@ -51,14 +43,9 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_STATIC_CAPS ("video/x-ms-asf") GST_STATIC_CAPS ("video/x-ms-asf")
); );
static void gst_mms_class_init (GstMMSClass * klass);
static void gst_mms_base_init (gpointer g_class);
static void gst_mms_init (GstMMS * mmssrc, GstMMSClass * g_class);
static void gst_mms_finalize (GObject * gobject); static void gst_mms_finalize (GObject * gobject);
static void gst_mms_uri_handler_init (gpointer g_iface, gpointer iface_data); static void gst_mms_uri_handler_init (gpointer g_iface, gpointer iface_data);
static void gst_mms_set_property (GObject * object, guint prop_id, static void gst_mms_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_mms_get_property (GObject * object, guint prop_id, static void gst_mms_get_property (GObject * object, guint prop_id,
@ -67,13 +54,12 @@ static void gst_mms_get_property (GObject * object, guint prop_id,
static const GstQueryType *gst_mms_get_query_types (GstPad * pad); static const GstQueryType *gst_mms_get_query_types (GstPad * pad);
static gboolean gst_mms_src_query (GstPad * pad, GstQuery * query); static gboolean gst_mms_src_query (GstPad * pad, GstQuery * query);
static gboolean gst_mms_start (GstBaseSrc * bsrc); static gboolean gst_mms_start (GstBaseSrc * bsrc);
static gboolean gst_mms_stop (GstBaseSrc * bsrc); static gboolean gst_mms_stop (GstBaseSrc * bsrc);
static GstFlowReturn gst_mms_create (GstPushSrc * psrc, GstBuffer ** buf); static GstFlowReturn gst_mms_create (GstPushSrc * psrc, GstBuffer ** buf);
static void static void
_urihandler_init (GType mms_type) gst_mms_urihandler_init (GType mms_type)
{ {
static const GInterfaceInfo urihandler_info = { static const GInterfaceInfo urihandler_info = {
gst_mms_uri_handler_init, gst_mms_uri_handler_init,
@ -83,12 +69,10 @@ _urihandler_init (GType mms_type)
g_type_add_interface_static (mms_type, GST_TYPE_URI_HANDLER, g_type_add_interface_static (mms_type, GST_TYPE_URI_HANDLER,
&urihandler_info); &urihandler_info);
GST_DEBUG_CATEGORY_INIT (mmssrc_debug, "mmssrc", 0, "MMS Source Element");
} }
GST_BOILERPLATE_FULL (GstMMS, gst_mms, GstPushSrc, GST_TYPE_PUSH_SRC, GST_BOILERPLATE_FULL (GstMMS, gst_mms, GstPushSrc, GST_TYPE_PUSH_SRC,
_urihandler_init); gst_mms_urihandler_init);
static void static void
gst_mms_base_init (gpointer g_class) gst_mms_base_init (gpointer g_class)
@ -104,6 +88,8 @@ gst_mms_base_init (gpointer g_class)
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_factory)); gst_static_pad_template_get (&src_factory));
gst_element_class_set_details (element_class, &plugin_details); gst_element_class_set_details (element_class, &plugin_details);
GST_DEBUG_CATEGORY_INIT (mmssrc_debug, "mmssrc", 0, "MMS Source Element");
} }
/* initialize the plugin's class */ /* initialize the plugin's class */
@ -127,12 +113,6 @@ gst_mms_class_init (GstMMSClass * klass)
"Host URL to connect to. Accepted are mms://, mmsu://, mmst:// URL types", "Host URL to connect to. Accepted are mms://, mmsu://, mmst:// URL types",
NULL, G_PARAM_READWRITE)); NULL, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, ARG_BLOCKSIZE,
g_param_spec_int ("blocksize", "blocksize",
"How many bytes should be read at once", 0, 65536, 2048,
G_PARAM_READWRITE));
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_mms_start); gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_mms_start);
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_mms_stop); gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_mms_stop);
@ -148,14 +128,15 @@ gst_mms_class_init (GstMMSClass * klass)
static void static void
gst_mms_init (GstMMS * mmssrc, GstMMSClass * g_class) gst_mms_init (GstMMS * mmssrc, GstMMSClass * g_class)
{ {
gst_pad_set_query_function (GST_BASE_SRC (mmssrc)->srcpad, gst_mms_src_query); gst_pad_set_query_function (GST_BASE_SRC (mmssrc)->srcpad,
GST_DEBUG_FUNCPTR (gst_mms_src_query));
gst_pad_set_query_type_function (GST_BASE_SRC (mmssrc)->srcpad, gst_pad_set_query_type_function (GST_BASE_SRC (mmssrc)->srcpad,
gst_mms_get_query_types); GST_DEBUG_FUNCPTR (gst_mms_get_query_types));
mmssrc->uri_name = NULL; mmssrc->uri_name = NULL;
mmssrc->connection = NULL; mmssrc->connection = NULL;
mmssrc->connection_h = NULL; mmssrc->connection_h = NULL;
mmssrc->blocksize = 2048; GST_BASE_SRC (mmssrc)->blocksize = 2048;
} }
static void static void
@ -163,8 +144,6 @@ gst_mms_finalize (GObject * gobject)
{ {
GstMMS *mmssrc = GST_MMS (gobject); GstMMS *mmssrc = GST_MMS (gobject);
gst_mms_stop (GST_BASE_SRC (mmssrc));
if (mmssrc->uri_name) { if (mmssrc->uri_name) {
g_free (mmssrc->uri_name); g_free (mmssrc->uri_name);
mmssrc->uri_name = NULL; mmssrc->uri_name = NULL;
@ -247,50 +226,29 @@ gst_mms_create (GstPushSrc * psrc, GstBuffer ** buf)
{ {
GstMMS *mmssrc; GstMMS *mmssrc;
guint8 *data; guint8 *data;
guint blocksize;
gint result; gint result;
GstFlowReturn ret = GST_FLOW_OK;
/* DEBUG */
GstFormat fmt = GST_FORMAT_BYTES;
gint64 query_res;
mmssrc = GST_MMS (psrc); mmssrc = GST_MMS (psrc);
*buf = gst_buffer_new_and_alloc (mmssrc->blocksize);
if (NULL == *buf) { GST_OBJECT_LOCK (mmssrc);
ret = GST_FLOW_ERROR; blocksize = GST_BASE_SRC (mmssrc)->blocksize;
goto done; GST_OBJECT_UNLOCK (mmssrc);
}
*buf = gst_buffer_new_and_alloc (blocksize);
data = GST_BUFFER_DATA (*buf); data = GST_BUFFER_DATA (*buf);
GST_DEBUG ("mms: data: %p\n", data);
if (NULL == GST_BUFFER_DATA (*buf)) {
ret = GST_FLOW_ERROR;
gst_buffer_unref (*buf);
*buf = NULL;
goto done;
}
GST_BUFFER_SIZE (*buf) = 0; GST_BUFFER_SIZE (*buf) = 0;
GST_DEBUG ("reading %d bytes", mmssrc->blocksize); GST_DEBUG ("reading %d bytes", blocksize);
if (mmssrc->connection) { if (mmssrc->connection) {
result = result = mms_read (NULL, mmssrc->connection, (char *) data, blocksize);
mms_read (NULL, mmssrc->connection, (char *) data, mmssrc->blocksize);
} else { } else {
result = result = mmsh_read (NULL, mmssrc->connection_h, (char *) data, blocksize);
mmsh_read (NULL, mmssrc->connection_h, (char *) data,
mmssrc->blocksize);
} }
/* EOS? */ /* EOS? */
if (result == 0) { if (result == 0)
gst_buffer_unref (*buf); goto eos;
*buf = NULL;
GST_DEBUG ("Returning EOS");
ret = GST_FLOW_UNEXPECTED;
goto done;
}
if (mmssrc->connection) { if (mmssrc->connection) {
GST_BUFFER_OFFSET (*buf) = GST_BUFFER_OFFSET (*buf) =
@ -301,48 +259,62 @@ gst_mms_create (GstPushSrc * psrc, GstBuffer ** buf)
} }
GST_BUFFER_SIZE (*buf) = result; GST_BUFFER_SIZE (*buf) = result;
/* DEBUG */ GST_DEBUG ("Returning buffer with offset %" G_GINT64_FORMAT " and size %u",
fmt = GST_FORMAT_BYTES; GST_BUFFER_OFFSET (*buf), GST_BUFFER_SIZE (*buf));
gst_pad_query_position (GST_BASE_SRC (mmssrc)->srcpad, &fmt, &query_res);
GST_DEBUG ("mms position: %" G_GINT64_FORMAT, query_res);
done: return GST_FLOW_OK;
return ret; eos:
{
GST_DEBUG ("EOS");
gst_buffer_unref (*buf);
*buf = NULL;
return GST_FLOW_UNEXPECTED;
}
} }
static gboolean static gboolean
gst_mms_start (GstBaseSrc * bsrc) gst_mms_start (GstBaseSrc * bsrc)
{ {
GstMMS *mms; GstMMS *mms;
gboolean ret = FALSE;
mms = GST_MMS (bsrc); mms = GST_MMS (bsrc);
if (!mms->uri_name || *mms->uri_name == '\0') { if (!mms->uri_name || *mms->uri_name == '\0')
goto no_uri;
/* FIXME: pass some sane arguments here */
GST_DEBUG_OBJECT (mms, "Trying mms_connect (%s)", mms->uri_name);
mms->connection = mms_connect (NULL, NULL, mms->uri_name, 128 * 1024);
if (mms->connection)
goto success;
GST_DEBUG_OBJECT (mms, "Trying mmsh_connect (%s)", mms->uri_name);
mms->connection_h = mmsh_connect (NULL, NULL, mms->uri_name, 128 * 1024);
if (!mms->connection_h)
goto no_connect;
/* fall through */
success:
{
GST_DEBUG_OBJECT (mms, "Connect successful");
return TRUE;
}
no_uri:
{
GST_ELEMENT_ERROR (mms, RESOURCE, OPEN_READ, GST_ELEMENT_ERROR (mms, RESOURCE, OPEN_READ,
("No URI to open specified"), (NULL)); ("No URI to open specified"), (NULL));
return FALSE; return FALSE;
} }
/* FIXME: pass some sane arguments here */ no_connect:
gst_mms_stop (bsrc); {
GST_ELEMENT_ERROR (mms, RESOURCE, OPEN_READ,
mms->connection = mms_connect (NULL, NULL, mms->uri_name, 128 * 1024); ("Could not connect to this stream"), (NULL));
if (mms->connection) { return FALSE;
ret = TRUE;
} else {
mms->connection_h = mmsh_connect (NULL, NULL, mms->uri_name, 128 * 1024);
if (mms->connection_h) {
ret = TRUE;
} else {
GST_ELEMENT_ERROR (mms, RESOURCE, OPEN_READ,
("Could not connect to this stream"), (NULL));
}
} }
return ret;
} }
static gboolean static gboolean
@ -370,6 +342,7 @@ gst_mms_set_property (GObject * object, guint prop_id,
mmssrc = GST_MMS (object); mmssrc = GST_MMS (object);
GST_OBJECT_LOCK (mmssrc);
switch (prop_id) { switch (prop_id) {
case ARG_LOCATION: case ARG_LOCATION:
if (mmssrc->uri_name) { if (mmssrc->uri_name) {
@ -378,13 +351,11 @@ gst_mms_set_property (GObject * object, guint prop_id,
} }
mmssrc->uri_name = g_value_dup_string (value); mmssrc->uri_name = g_value_dup_string (value);
break; break;
case ARG_BLOCKSIZE:
mmssrc->blocksize = g_value_get_int (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
} }
GST_OBJECT_UNLOCK (mmssrc);
} }
static void static void
@ -395,18 +366,17 @@ gst_mms_get_property (GObject * object, guint prop_id,
mmssrc = GST_MMS (object); mmssrc = GST_MMS (object);
GST_OBJECT_LOCK (mmssrc);
switch (prop_id) { switch (prop_id) {
case ARG_LOCATION: case ARG_LOCATION:
if (mmssrc->uri_name) if (mmssrc->uri_name)
g_value_set_string (value, mmssrc->uri_name); g_value_set_string (value, mmssrc->uri_name);
break; break;
case ARG_BLOCKSIZE:
g_value_set_int (value, mmssrc->blocksize);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
} }
GST_OBJECT_UNLOCK (mmssrc);
} }
/* entry point to initialize the plug-in /* entry point to initialize the plug-in
@ -437,7 +407,6 @@ gst_mms_uri_get_protocols (void)
static const gchar * static const gchar *
gst_mms_uri_get_uri (GstURIHandler * handler) gst_mms_uri_get_uri (GstURIHandler * handler)
{ {
GstMMS *src = GST_MMS (handler); GstMMS *src = GST_MMS (handler);
return src->uri_name; return src->uri_name;

View file

@ -18,10 +18,10 @@ G_BEGIN_DECLS
#define GST_MMS(obj) \ #define GST_MMS(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MMS,GstMMS)) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MMS,GstMMS))
#define GST_MMS_CLASS(klass) \ #define GST_MMS_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MMS,GstMMS)) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MMS,GstMMSClass))
#define GST_IS_MMS(obj) \ #define GST_IS_MMS(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MMS)) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MMS))
#define GST_IS_MMS_CLASS(obj) \ #define GST_IS_MMS_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MMS)) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MMS))
typedef struct _GstMMS GstMMS; typedef struct _GstMMS GstMMS;
@ -34,7 +34,6 @@ struct _GstMMS
gchar *uri_name; gchar *uri_name;
gpointer connection; gpointer connection;
gpointer connection_h; gpointer connection_h;
gint blocksize;
}; };
struct _GstMMSClass struct _GstMMSClass