2004-12-22 18:57:29 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 1999-2001 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2004-12-22 18:57:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2009-10-07 12:26:12 +00:00
|
|
|
#include <stdio.h>
|
2004-12-22 18:57:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include "gstmms.h"
|
|
|
|
|
2007-08-08 15:15:56 +00:00
|
|
|
#define DEFAULT_CONNECTION_SPEED 0
|
|
|
|
|
2004-12-22 18:57:29 +00:00
|
|
|
enum
|
|
|
|
{
|
2010-05-06 06:08:06 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_LOCATION,
|
|
|
|
PROP_CONNECTION_SPEED
|
2004-12-22 18:57:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-06-23 09:09:44 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (mmssrc_debug);
|
2006-03-10 13:49:23 +00:00
|
|
|
#define GST_CAT_DEFAULT mmssrc_debug
|
2004-12-22 18:57:29 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-ms-asf")
|
|
|
|
);
|
|
|
|
|
2006-01-25 14:20:04 +00:00
|
|
|
static void gst_mms_finalize (GObject * gobject);
|
2004-12-22 18:57:29 +00:00
|
|
|
static void gst_mms_uri_handler_init (gpointer g_iface, gpointer iface_data);
|
|
|
|
|
|
|
|
static void gst_mms_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_mms_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2009-05-03 12:28:51 +00:00
|
|
|
static gboolean gst_mms_query (GstBaseSrc * src, GstQuery * query);
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2005-11-29 02:55:18 +00:00
|
|
|
static gboolean gst_mms_start (GstBaseSrc * bsrc);
|
2005-12-11 23:09:21 +00:00
|
|
|
static gboolean gst_mms_stop (GstBaseSrc * bsrc);
|
2009-01-23 10:50:29 +00:00
|
|
|
static gboolean gst_mms_is_seekable (GstBaseSrc * src);
|
|
|
|
static gboolean gst_mms_get_size (GstBaseSrc * src, guint64 * size);
|
|
|
|
static gboolean gst_mms_prepare_seek_segment (GstBaseSrc * src,
|
|
|
|
GstEvent * event, GstSegment * segment);
|
|
|
|
static gboolean gst_mms_do_seek (GstBaseSrc * src, GstSegment * segment);
|
|
|
|
|
2005-11-29 02:55:18 +00:00
|
|
|
static GstFlowReturn gst_mms_create (GstPushSrc * psrc, GstBuffer ** buf);
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2010-05-06 07:48:00 +00:00
|
|
|
static gboolean gst_mms_uri_set_uri (GstURIHandler * handler,
|
2011-11-13 23:55:56 +00:00
|
|
|
const gchar * uri, GError ** error);
|
2010-05-06 07:48:00 +00:00
|
|
|
|
2011-10-04 16:54:13 +00:00
|
|
|
#define gst_mms_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstMMS, gst_mms, GST_TYPE_PUSH_SRC,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_mms_uri_handler_init));
|
2004-12-22 18:57:29 +00:00
|
|
|
|
|
|
|
/* initialize the plugin's class */
|
|
|
|
static void
|
|
|
|
gst_mms_class_init (GstMMSClass * klass)
|
|
|
|
{
|
2010-05-06 06:08:06 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
2011-10-04 16:54:13 +00:00
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2010-05-06 06:08:06 +00:00
|
|
|
GstBaseSrcClass *gstbasesrc_class = (GstBaseSrcClass *) klass;
|
|
|
|
GstPushSrcClass *gstpushsrc_class = (GstPushSrcClass *) klass;
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2005-11-29 02:55:18 +00:00
|
|
|
gobject_class->set_property = gst_mms_set_property;
|
|
|
|
gobject_class->get_property = gst_mms_get_property;
|
2006-01-25 14:20:04 +00:00
|
|
|
gobject_class->finalize = gst_mms_finalize;
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2010-05-06 06:08:06 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LOCATION,
|
2004-12-22 18:57:29 +00:00
|
|
|
g_param_spec_string ("location", "location",
|
|
|
|
"Host URL to connect to. Accepted are mms://, mmsu://, mmst:// URL types",
|
2010-05-06 06:08:06 +00:00
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2011-11-24 01:22:13 +00:00
|
|
|
/* Note: connection-speed is intentionaly limited to G_MAXINT as libmms
|
|
|
|
* uses int for it */
|
2010-05-06 06:08:06 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
|
2011-11-24 01:22:13 +00:00
|
|
|
g_param_spec_uint64 ("connection-speed", "Connection Speed",
|
2007-08-08 15:15:56 +00:00
|
|
|
"Network connection speed in kbps (0 = unknown)",
|
2010-05-06 06:08:06 +00:00
|
|
|
0, G_MAXINT / 1000, DEFAULT_CONNECTION_SPEED,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-08-08 15:15:56 +00:00
|
|
|
|
2011-10-04 16:54:13 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&src_factory));
|
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2011-10-04 16:54:13 +00:00
|
|
|
"MMS streaming source", "Source/Network",
|
|
|
|
"Receive data streamed via MSFT Multi Media Server protocol",
|
|
|
|
"Maciej Katafiasz <mathrick@users.sourceforge.net>");
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (mmssrc_debug, "mmssrc", 0, "MMS Source Element");
|
|
|
|
|
2006-02-14 12:26:20 +00:00
|
|
|
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_mms_start);
|
|
|
|
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_mms_stop);
|
2005-11-29 02:55:18 +00:00
|
|
|
|
2006-02-14 12:26:20 +00:00
|
|
|
gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_mms_create);
|
2005-11-29 02:55:18 +00:00
|
|
|
|
2009-01-23 10:50:29 +00:00
|
|
|
gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_mms_is_seekable);
|
|
|
|
gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_mms_get_size);
|
|
|
|
gstbasesrc_class->prepare_seek_segment =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mms_prepare_seek_segment);
|
|
|
|
gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_mms_do_seek);
|
2009-05-03 12:28:51 +00:00
|
|
|
gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_mms_query);
|
2004-12-22 18:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the new element
|
|
|
|
* instantiate pads and add them to element
|
|
|
|
* set functions
|
|
|
|
* initialize structure
|
|
|
|
*/
|
|
|
|
static void
|
2011-10-04 16:54:13 +00:00
|
|
|
gst_mms_init (GstMMS * mmssrc)
|
2004-12-22 18:57:29 +00:00
|
|
|
{
|
|
|
|
mmssrc->uri_name = NULL;
|
2009-01-23 10:50:29 +00:00
|
|
|
mmssrc->current_connection_uri_name = NULL;
|
2004-12-22 18:57:29 +00:00
|
|
|
mmssrc->connection = NULL;
|
2007-08-08 15:15:56 +00:00
|
|
|
mmssrc->connection_speed = DEFAULT_CONNECTION_SPEED;
|
2004-12-22 18:57:29 +00:00
|
|
|
}
|
|
|
|
|
2006-01-25 14:20:04 +00:00
|
|
|
static void
|
|
|
|
gst_mms_finalize (GObject * gobject)
|
|
|
|
{
|
|
|
|
GstMMS *mmssrc = GST_MMS (gobject);
|
|
|
|
|
2009-01-23 10:50:29 +00:00
|
|
|
/* We may still have a connection open, as we preserve unused / pristine
|
|
|
|
open connections in stop to reuse them in start. */
|
|
|
|
if (mmssrc->connection) {
|
|
|
|
mmsx_close (mmssrc->connection);
|
|
|
|
mmssrc->connection = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mmssrc->current_connection_uri_name) {
|
|
|
|
g_free (mmssrc->current_connection_uri_name);
|
|
|
|
mmssrc->current_connection_uri_name = NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-25 14:20:04 +00:00
|
|
|
if (mmssrc->uri_name) {
|
|
|
|
g_free (mmssrc->uri_name);
|
|
|
|
mmssrc->uri_name = NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-06 06:08:06 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (gobject);
|
2006-01-25 14:20:04 +00:00
|
|
|
}
|
|
|
|
|
2009-05-03 12:28:51 +00:00
|
|
|
/* FIXME operating in TIME rather than BYTES could remove this altogether
|
|
|
|
* and be more convenient elsewhere */
|
2004-12-22 18:57:29 +00:00
|
|
|
static gboolean
|
2009-05-03 12:28:51 +00:00
|
|
|
gst_mms_query (GstBaseSrc * src, GstQuery * query)
|
2004-12-22 18:57:29 +00:00
|
|
|
{
|
2009-05-03 12:28:51 +00:00
|
|
|
GstMMS *mmssrc = GST_MMS (src);
|
2004-12-22 18:57:29 +00:00
|
|
|
gboolean res = TRUE;
|
2005-11-29 02:55:18 +00:00
|
|
|
GstFormat format;
|
|
|
|
gint64 value;
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2005-11-29 02:55:18 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2004-12-22 18:57:29 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2005-11-29 02:55:18 +00:00
|
|
|
gst_query_parse_position (query, &format, &value);
|
|
|
|
if (format != GST_FORMAT_BYTES) {
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2009-01-23 10:50:29 +00:00
|
|
|
value = (gint64) mmsx_get_current_pos (mmssrc->connection);
|
2005-11-29 02:55:18 +00:00
|
|
|
gst_query_set_position (query, format, value);
|
|
|
|
break;
|
|
|
|
case GST_QUERY_DURATION:
|
2009-01-23 10:50:29 +00:00
|
|
|
if (!mmsx_get_seekable (mmssrc->connection)) {
|
2005-11-29 02:55:18 +00:00
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2009-01-23 10:50:29 +00:00
|
|
|
gst_query_parse_duration (query, &format, &value);
|
|
|
|
switch (format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
value = (gint64) mmsx_get_length (mmssrc->connection);
|
|
|
|
gst_query_set_duration (query, format, value);
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
value = mmsx_get_time_length (mmssrc->connection) * GST_SECOND;
|
|
|
|
gst_query_set_duration (query, format, value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2005-12-11 23:09:21 +00:00
|
|
|
}
|
2004-12-22 18:57:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-05-03 12:28:51 +00:00
|
|
|
/* chain to parent */
|
|
|
|
res =
|
|
|
|
GST_BASE_SRC_CLASS (parent_class)->query (GST_BASE_SRC (src), query);
|
2004-12-22 18:57:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-01-23 10:50:29 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mms_prepare_seek_segment (GstBaseSrc * src, GstEvent * event,
|
|
|
|
GstSegment * segment)
|
|
|
|
{
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gint64 cur, stop;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstFormat seek_format;
|
|
|
|
gdouble rate;
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &seek_format, &flags,
|
|
|
|
&cur_type, &cur, &stop_type, &stop);
|
|
|
|
|
|
|
|
if (seek_format != GST_FORMAT_BYTES && seek_format != GST_FORMAT_TIME) {
|
2009-06-19 15:21:28 +00:00
|
|
|
GST_LOG_OBJECT (src, "Only byte or time seeking is supported");
|
2009-01-23 10:50:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stop_type != GST_SEEK_TYPE_NONE) {
|
2009-06-19 15:21:28 +00:00
|
|
|
GST_LOG_OBJECT (src, "Stop seeking not supported");
|
2009-01-23 10:50:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_type != GST_SEEK_TYPE_NONE && cur_type != GST_SEEK_TYPE_SET) {
|
2009-06-19 15:21:28 +00:00
|
|
|
GST_LOG_OBJECT (src, "Only absolute seeking is supported");
|
2009-01-23 10:50:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We would like to convert from GST_FORMAT_TIME to GST_FORMAT_BYTES here
|
|
|
|
when needed, but we cannot as to do that we need to actually do the seek,
|
|
|
|
so we handle this in do_seek instead. */
|
|
|
|
|
|
|
|
/* FIXME implement relative seeking, we could do any needed relevant
|
|
|
|
seeking calculations here (in seek_format metrics), before the re-init
|
|
|
|
of the segment. */
|
|
|
|
|
|
|
|
gst_segment_init (segment, seek_format);
|
2011-10-04 16:54:13 +00:00
|
|
|
gst_segment_do_seek (segment, rate, seek_format, flags, cur_type, cur,
|
2009-01-23 10:50:29 +00:00
|
|
|
stop_type, stop, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mms_do_seek (GstBaseSrc * src, GstSegment * segment)
|
|
|
|
{
|
2011-08-31 21:06:53 +00:00
|
|
|
gint64 start;
|
2009-01-23 10:50:29 +00:00
|
|
|
GstMMS *mmssrc = GST_MMS (src);
|
|
|
|
|
|
|
|
if (segment->format == GST_FORMAT_TIME) {
|
|
|
|
if (!mmsx_time_seek (NULL, mmssrc->connection,
|
|
|
|
(double) segment->start / GST_SECOND)) {
|
|
|
|
GST_LOG_OBJECT (mmssrc, "mmsx_time_seek() failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
start = mmsx_get_current_pos (mmssrc->connection);
|
2009-11-05 21:58:38 +00:00
|
|
|
GST_INFO_OBJECT (mmssrc, "sought to %" GST_TIME_FORMAT ", offset after "
|
|
|
|
"seek: %" G_GINT64_FORMAT, GST_TIME_ARGS (segment->start), start);
|
2009-01-23 10:50:29 +00:00
|
|
|
} else if (segment->format == GST_FORMAT_BYTES) {
|
|
|
|
start = mmsx_seek (NULL, mmssrc->connection, segment->start, SEEK_SET);
|
|
|
|
/* mmsx_seek will close and reopen the connection when seeking with the
|
|
|
|
mmsh protocol, if the reopening fails this is indicated with -1 */
|
|
|
|
if (start == -1) {
|
|
|
|
GST_DEBUG_OBJECT (mmssrc, "connection broken during seek");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-11-05 21:58:38 +00:00
|
|
|
GST_INFO_OBJECT (mmssrc, "sought to: %" G_GINT64_FORMAT " bytes, "
|
|
|
|
"result: %" G_GINT64_FORMAT, segment->start, start);
|
2009-01-23 10:50:29 +00:00
|
|
|
} else {
|
2009-11-05 21:58:38 +00:00
|
|
|
GST_DEBUG_OBJECT (mmssrc, "unsupported seek segment format: %s",
|
|
|
|
GST_STR_NULL (gst_format_get_name (segment->format)));
|
2009-01-23 10:50:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_segment_init (segment, GST_FORMAT_BYTES);
|
2011-10-04 16:54:13 +00:00
|
|
|
gst_segment_do_seek (segment, segment->rate, GST_FORMAT_BYTES,
|
2012-04-24 12:57:11 +00:00
|
|
|
GST_SEEK_FLAG_NONE, GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_NONE,
|
2009-01-23 10:50:29 +00:00
|
|
|
segment->stop, NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-22 18:57:29 +00:00
|
|
|
/* get function
|
|
|
|
* this function generates new data when needed
|
|
|
|
*/
|
|
|
|
|
2005-11-29 02:55:18 +00:00
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mms_create (GstPushSrc * psrc, GstBuffer ** buf)
|
2004-12-22 18:57:29 +00:00
|
|
|
{
|
2010-05-06 06:08:06 +00:00
|
|
|
GstMMS *mmssrc = GST_MMS (psrc);
|
2004-12-22 18:57:29 +00:00
|
|
|
guint8 *data;
|
2006-03-10 13:49:23 +00:00
|
|
|
guint blocksize;
|
2004-12-22 18:57:29 +00:00
|
|
|
gint result;
|
2012-12-11 10:58:54 +00:00
|
|
|
goffset offset;
|
2009-01-23 10:50:29 +00:00
|
|
|
|
|
|
|
*buf = NULL;
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2009-01-23 10:50:29 +00:00
|
|
|
offset = mmsx_get_current_pos (mmssrc->connection);
|
|
|
|
|
|
|
|
/* Check if a seek perhaps has wrecked our connection */
|
|
|
|
if (offset == -1) {
|
2010-05-06 06:08:06 +00:00
|
|
|
GST_ERROR_OBJECT (mmssrc,
|
2009-01-23 10:50:29 +00:00
|
|
|
"connection broken (probably an error during mmsx_seek_time during a convert query) returning FLOW_ERROR");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Choose blocksize best for optimum performance */
|
|
|
|
if (offset == 0)
|
|
|
|
blocksize = mmsx_get_asf_header_len (mmssrc->connection);
|
|
|
|
else
|
|
|
|
blocksize = mmsx_get_asf_packet_len (mmssrc->connection);
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2011-10-04 16:54:13 +00:00
|
|
|
data = g_try_malloc (blocksize);
|
|
|
|
if (!data) {
|
2010-05-06 06:08:06 +00:00
|
|
|
GST_ERROR_OBJECT (mmssrc, "Failed to allocate %u bytes", blocksize);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2005-11-29 02:55:18 +00:00
|
|
|
|
2006-12-15 09:34:31 +00:00
|
|
|
GST_LOG_OBJECT (mmssrc, "reading %d bytes", blocksize);
|
2009-01-23 10:50:29 +00:00
|
|
|
result = mmsx_read (NULL, mmssrc->connection, (char *) data, blocksize);
|
2004-12-22 18:57:29 +00:00
|
|
|
/* EOS? */
|
2006-03-10 13:49:23 +00:00
|
|
|
if (result == 0)
|
|
|
|
goto eos;
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2011-10-04 16:54:13 +00:00
|
|
|
*buf = gst_buffer_new_wrapped (data, result);
|
2009-01-23 10:50:29 +00:00
|
|
|
GST_BUFFER_OFFSET (*buf) = offset;
|
2005-12-11 23:09:21 +00:00
|
|
|
|
2012-12-11 10:58:54 +00:00
|
|
|
GST_LOG_OBJECT (mmssrc, "Returning buffer with offset %" G_GOFFSET_FORMAT
|
2011-10-04 16:54:13 +00:00
|
|
|
" and size %u", offset, result);
|
2005-12-11 23:09:21 +00:00
|
|
|
|
2006-03-10 13:49:23 +00:00
|
|
|
return GST_FLOW_OK;
|
2005-11-29 02:55:18 +00:00
|
|
|
|
2006-03-10 13:49:23 +00:00
|
|
|
eos:
|
|
|
|
{
|
2006-12-15 09:34:31 +00:00
|
|
|
GST_DEBUG_OBJECT (mmssrc, "EOS");
|
2011-10-04 16:54:13 +00:00
|
|
|
g_free (data);
|
2006-03-10 13:49:23 +00:00
|
|
|
*buf = NULL;
|
2012-01-03 14:26:54 +00:00
|
|
|
return GST_FLOW_EOS;
|
2006-03-10 13:49:23 +00:00
|
|
|
}
|
2004-12-22 18:57:29 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 10:50:29 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mms_is_seekable (GstBaseSrc * src)
|
|
|
|
{
|
|
|
|
GstMMS *mmssrc = GST_MMS (src);
|
|
|
|
|
|
|
|
return mmsx_get_seekable (mmssrc->connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mms_get_size (GstBaseSrc * src, guint64 * size)
|
|
|
|
{
|
|
|
|
GstMMS *mmssrc = GST_MMS (src);
|
|
|
|
|
|
|
|
/* non seekable usually means live streams, and get_length() returns,
|
|
|
|
erm, interesting values for live streams */
|
|
|
|
if (!mmsx_get_seekable (mmssrc->connection))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*size = mmsx_get_length (mmssrc->connection);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-11-29 02:55:18 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mms_start (GstBaseSrc * bsrc)
|
2004-12-22 18:57:29 +00:00
|
|
|
{
|
2010-05-06 06:08:06 +00:00
|
|
|
GstMMS *mms = GST_MMS (bsrc);
|
2007-08-08 15:15:56 +00:00
|
|
|
guint bandwidth_avail;
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2006-03-10 13:49:23 +00:00
|
|
|
if (!mms->uri_name || *mms->uri_name == '\0')
|
|
|
|
goto no_uri;
|
2006-02-14 12:26:20 +00:00
|
|
|
|
2007-08-08 15:15:56 +00:00
|
|
|
if (mms->connection_speed)
|
|
|
|
bandwidth_avail = mms->connection_speed;
|
|
|
|
else
|
|
|
|
bandwidth_avail = G_MAXINT;
|
|
|
|
|
2009-01-23 10:50:29 +00:00
|
|
|
/* If we already have a connection, and the uri isn't changed, reuse it,
|
|
|
|
as connecting is expensive. */
|
|
|
|
if (mms->connection) {
|
|
|
|
if (!strcmp (mms->uri_name, mms->current_connection_uri_name)) {
|
|
|
|
GST_DEBUG_OBJECT (mms, "Reusing existing connection for %s",
|
|
|
|
mms->uri_name);
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
mmsx_close (mms->connection);
|
|
|
|
g_free (mms->current_connection_uri_name);
|
|
|
|
mms->current_connection_uri_name = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-29 02:55:18 +00:00
|
|
|
/* FIXME: pass some sane arguments here */
|
2007-08-08 15:15:56 +00:00
|
|
|
GST_DEBUG_OBJECT (mms,
|
|
|
|
"Trying mms_connect (%s) with bandwidth constraint of %d bps",
|
|
|
|
mms->uri_name, bandwidth_avail);
|
2009-01-23 10:50:29 +00:00
|
|
|
mms->connection = mmsx_connect (NULL, NULL, mms->uri_name, bandwidth_avail);
|
|
|
|
if (mms->connection) {
|
|
|
|
/* Save the uri name so that it can be checked for connection reusing,
|
|
|
|
see above. */
|
|
|
|
mms->current_connection_uri_name = g_strdup (mms->uri_name);
|
2006-03-10 13:49:23 +00:00
|
|
|
GST_DEBUG_OBJECT (mms, "Connect successful");
|
|
|
|
return TRUE;
|
2009-01-23 10:50:29 +00:00
|
|
|
} else {
|
2009-04-21 14:48:39 +00:00
|
|
|
gchar *url, *location;
|
|
|
|
|
|
|
|
GST_ERROR_OBJECT (mms,
|
|
|
|
"Could not connect to this stream, redirecting to rtsp");
|
2010-05-06 07:51:15 +00:00
|
|
|
location = strstr (mms->uri_name, "://");
|
|
|
|
if (location == NULL || *location == '\0' || *(location + 3) == '\0')
|
|
|
|
goto no_uri;
|
|
|
|
url = g_strdup_printf ("rtsp://%s", location + 3);
|
2009-04-21 14:48:39 +00:00
|
|
|
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (mms),
|
|
|
|
gst_message_new_element (GST_OBJECT_CAST (mms),
|
|
|
|
gst_structure_new ("redirect", "new-location", G_TYPE_STRING, url,
|
|
|
|
NULL)));
|
2010-01-12 23:53:18 +00:00
|
|
|
|
|
|
|
/* post an error message as well, so that applications that don't handle
|
|
|
|
* redirect messages get to see a proper error message */
|
|
|
|
GST_ELEMENT_ERROR (mms, RESOURCE, OPEN_READ,
|
|
|
|
("Could not connect to streaming server."),
|
|
|
|
("A redirect message was posted on the bus and should have been "
|
|
|
|
"handled by the application."));
|
|
|
|
|
2006-03-10 13:49:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2009-01-23 10:50:29 +00:00
|
|
|
no_uri:
|
2006-03-10 13:49:23 +00:00
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (mms, RESOURCE, OPEN_READ,
|
2009-01-23 10:50:29 +00:00
|
|
|
("No URI to open specified"), (NULL));
|
2006-03-10 13:49:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-22 18:57:29 +00:00
|
|
|
}
|
|
|
|
|
2005-12-11 23:09:21 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mms_stop (GstBaseSrc * bsrc)
|
|
|
|
{
|
2010-05-06 06:08:06 +00:00
|
|
|
GstMMS *mms = GST_MMS (bsrc);
|
2005-12-11 23:09:21 +00:00
|
|
|
|
|
|
|
if (mms->connection != NULL) {
|
2009-01-23 10:50:29 +00:00
|
|
|
/* Check if the connection is still pristine, that is if no more then
|
|
|
|
just the mmslib cached asf header has been read. If it is still pristine
|
|
|
|
preserve it as we often are re-started with the same URL and connecting
|
|
|
|
is expensive */
|
|
|
|
if (mmsx_get_current_pos (mms->connection) >
|
|
|
|
mmsx_get_asf_header_len (mms->connection)) {
|
|
|
|
mmsx_close (mms->connection);
|
|
|
|
mms->connection = NULL;
|
|
|
|
g_free (mms->current_connection_uri_name);
|
|
|
|
mms->current_connection_uri_name = NULL;
|
|
|
|
}
|
2005-12-11 23:09:21 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-12-22 18:57:29 +00:00
|
|
|
static void
|
|
|
|
gst_mms_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2010-05-06 06:08:06 +00:00
|
|
|
GstMMS *mmssrc = GST_MMS (object);
|
2004-12-22 18:57:29 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2010-05-06 06:08:06 +00:00
|
|
|
case PROP_LOCATION:
|
2010-05-06 07:48:00 +00:00
|
|
|
gst_mms_uri_set_uri (GST_URI_HANDLER (mmssrc),
|
2011-11-13 23:55:56 +00:00
|
|
|
g_value_get_string (value), NULL);
|
2004-12-22 18:57:29 +00:00
|
|
|
break;
|
2010-05-06 06:08:06 +00:00
|
|
|
case PROP_CONNECTION_SPEED:
|
2010-05-06 07:48:00 +00:00
|
|
|
GST_OBJECT_LOCK (mmssrc);
|
2011-11-24 01:22:13 +00:00
|
|
|
mmssrc->connection_speed = g_value_get_uint64 (value) * 1000;
|
2010-05-06 07:48:00 +00:00
|
|
|
GST_OBJECT_UNLOCK (mmssrc);
|
2007-08-08 15:15:56 +00:00
|
|
|
break;
|
2004-12-22 18:57:29 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mms_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2010-05-06 06:08:06 +00:00
|
|
|
GstMMS *mmssrc = GST_MMS (object);
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2006-03-10 13:49:23 +00:00
|
|
|
GST_OBJECT_LOCK (mmssrc);
|
2004-12-22 18:57:29 +00:00
|
|
|
switch (prop_id) {
|
2010-05-06 06:08:06 +00:00
|
|
|
case PROP_LOCATION:
|
2006-01-25 14:20:04 +00:00
|
|
|
if (mmssrc->uri_name)
|
|
|
|
g_value_set_string (value, mmssrc->uri_name);
|
2004-12-22 18:57:29 +00:00
|
|
|
break;
|
2010-05-06 06:08:06 +00:00
|
|
|
case PROP_CONNECTION_SPEED:
|
2011-11-24 01:22:13 +00:00
|
|
|
g_value_set_uint64 (value, mmssrc->connection_speed / 1000);
|
2007-08-08 15:15:56 +00:00
|
|
|
break;
|
2004-12-22 18:57:29 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2006-03-10 13:49:23 +00:00
|
|
|
GST_OBJECT_UNLOCK (mmssrc);
|
2004-12-22 18:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* entry point to initialize the plug-in
|
|
|
|
* initialize the plug-in itself
|
|
|
|
* register the element factories and pad templates
|
|
|
|
* register the features
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "mmssrc", GST_RANK_NONE, GST_TYPE_MMS);
|
|
|
|
}
|
|
|
|
|
2008-09-30 10:17:41 +00:00
|
|
|
static GstURIType
|
2011-10-04 16:54:13 +00:00
|
|
|
gst_mms_uri_get_type (GType type)
|
2004-12-22 18:57:29 +00:00
|
|
|
{
|
|
|
|
return GST_URI_SRC;
|
|
|
|
}
|
|
|
|
|
2011-11-13 23:55:56 +00:00
|
|
|
static const gchar *const *
|
2011-10-04 16:54:13 +00:00
|
|
|
gst_mms_uri_get_protocols (GType type)
|
2004-12-22 18:57:29 +00:00
|
|
|
{
|
2010-03-22 12:16:33 +00:00
|
|
|
static const gchar *protocols[] = { "mms", "mmsh", "mmst", "mmsu", NULL };
|
2004-12-22 18:57:29 +00:00
|
|
|
|
2011-11-13 23:55:56 +00:00
|
|
|
return protocols;
|
2004-12-22 18:57:29 +00:00
|
|
|
}
|
|
|
|
|
2011-11-13 23:55:56 +00:00
|
|
|
static gchar *
|
2004-12-22 18:57:29 +00:00
|
|
|
gst_mms_uri_get_uri (GstURIHandler * handler)
|
|
|
|
{
|
|
|
|
GstMMS *src = GST_MMS (handler);
|
|
|
|
|
2011-11-13 23:55:56 +00:00
|
|
|
/* FIXME: make thread-safe */
|
|
|
|
return g_strdup (src->uri_name);
|
2004-12-22 18:57:29 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 07:48:00 +00:00
|
|
|
static gchar *
|
|
|
|
gst_mms_src_make_valid_uri (const gchar * uri)
|
2004-12-22 18:57:29 +00:00
|
|
|
{
|
|
|
|
gchar *protocol;
|
2010-05-06 07:48:00 +00:00
|
|
|
const gchar *colon, *tmp;
|
|
|
|
gsize len;
|
|
|
|
|
|
|
|
if (!uri || !gst_uri_is_valid (uri))
|
|
|
|
return NULL;
|
2004-12-22 18:57:29 +00:00
|
|
|
|
|
|
|
protocol = gst_uri_get_protocol (uri);
|
2010-05-06 07:48:00 +00:00
|
|
|
|
2010-05-06 06:08:06 +00:00
|
|
|
if ((strcmp (protocol, "mms") != 0) && (strcmp (protocol, "mmsh") != 0) &&
|
|
|
|
(strcmp (protocol, "mmst") != 0) && (strcmp (protocol, "mmsu") != 0)) {
|
2004-12-22 18:57:29 +00:00
|
|
|
g_free (protocol);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
g_free (protocol);
|
2010-05-06 07:48:00 +00:00
|
|
|
|
|
|
|
colon = strstr (uri, "://");
|
|
|
|
if (!colon)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tmp = colon + 3;
|
|
|
|
len = strlen (tmp);
|
|
|
|
if (len == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* libmms segfaults if there's no hostname or
|
|
|
|
* no / after the hostname
|
|
|
|
*/
|
|
|
|
colon = strstr (tmp, "/");
|
|
|
|
if (colon == tmp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (strstr (tmp, "/") == NULL) {
|
|
|
|
gchar *ret;
|
|
|
|
|
|
|
|
len = strlen (uri);
|
|
|
|
ret = g_malloc0 (len + 2);
|
|
|
|
memcpy (ret, uri, len);
|
|
|
|
ret[len] = '/';
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
return g_strdup (uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-13 23:55:56 +00:00
|
|
|
gst_mms_uri_set_uri (GstURIHandler * handler, const gchar * uri,
|
|
|
|
GError ** error)
|
2010-05-06 07:48:00 +00:00
|
|
|
{
|
|
|
|
GstMMS *src = GST_MMS (handler);
|
|
|
|
gchar *fixed_uri;
|
|
|
|
|
|
|
|
fixed_uri = gst_mms_src_make_valid_uri (uri);
|
2011-11-13 23:55:56 +00:00
|
|
|
if (!fixed_uri && uri) {
|
|
|
|
g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
|
|
|
|
"Invalid MMS URI");
|
2010-05-06 07:48:00 +00:00
|
|
|
return FALSE;
|
2011-11-13 23:55:56 +00:00
|
|
|
}
|
2010-05-06 07:48:00 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (src);
|
2015-11-17 23:23:17 +00:00
|
|
|
g_free (src->uri_name);
|
2010-05-06 07:48:00 +00:00
|
|
|
src->uri_name = fixed_uri;
|
|
|
|
GST_OBJECT_UNLOCK (src);
|
2004-12-22 18:57:29 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mms_uri_handler_init (gpointer g_iface, gpointer iface_data)
|
|
|
|
{
|
|
|
|
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
|
|
|
|
|
|
|
|
iface->get_type = gst_mms_uri_get_type;
|
|
|
|
iface->get_protocols = gst_mms_uri_get_protocols;
|
|
|
|
iface->get_uri = gst_mms_uri_get_uri;
|
|
|
|
iface->set_uri = gst_mms_uri_set_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* this is the structure that gst-register looks for
|
|
|
|
* so keep the name plugin_desc, or you cannot get your plug-in registered */
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 16:02:56 +00:00
|
|
|
mms,
|
2004-12-22 18:57:29 +00:00
|
|
|
"Microsoft Multi Media Server streaming protocol support",
|
2008-03-13 14:25:20 +00:00
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|