summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2009-09-13 18:32:33 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2009-09-13 18:32:33 +0800
commit96c611840c876aec0d2827b50736f9935e7403cf (patch)
treedfc5808684736ce60026e1b211b8a39bd4df9e3a
parentabbde1eff9effcfc05f8b50ce3a5aacf4463df80 (diff)
sopcastsrc: cleanup
-rw-r--r--src/gstscsrc.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/gstscsrc.c b/src/gstscsrc.c
index 7346c2f..935c3b5 100644
--- a/src/gstscsrc.c
+++ b/src/gstscsrc.c
@@ -13,10 +13,10 @@
*/
/**
- * SECTION:element-ppssrc
+ * SECTION:element-sopcastsrc
*
* This plugin reads data from a remote location specified by a URI.
- * Supported protocols is 'pps'.
+ * Supported protocols is 'sop'.
*
*/
@@ -110,7 +110,7 @@ _do_init (GType type)
g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
GST_DEBUG_CATEGORY_INIT (sopcastsrc_debug, "sopcastsrc", 0,
- "SCtream src");
+ "Sopcast stream src");
}
GST_BOILERPLATE_FULL (GstSopcastSrc, gst_sopcast_src, GstPushSrc,
@@ -163,7 +163,7 @@ gst_sopcast_src_class_init (GstSopcastSrcClass * klass)
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_sopcast_src_change_state);
GST_DEBUG_CATEGORY_INIT (sopcastsrc_debug, "sopcastsrc", 0,
- "SCtream Source");
+ "Sopcast stream Source");
}
static void
@@ -246,6 +246,7 @@ gst_sopcast_src_connect_server (GstSopcastSrc *src)
struct sockaddr_in sockaddr;
int sock;
+ /* may try to connect to server several times */
if (src->sock >= 0) {
close (src->sock);
src->sock = -1;
@@ -275,7 +276,7 @@ gst_sopcast_src_connect_server (GstSopcastSrc *src)
}
static gboolean
-gst_sopcast_src_send_first_request (GstSopcastSrc *src)
+gst_sopcast_src_send_get_request (GstSopcastSrc *src)
{
gchar request[1024];
gchar reply[1024];
@@ -405,7 +406,6 @@ gst_sopcast_src_helper_is_running (GstSopcastSrc *src)
if (ret == 0)
return TRUE;
- perror ("helper is not running");
GST_ERROR_OBJECT (src, "helper is not running.");
return FALSE;
}
@@ -458,16 +458,18 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
GstBuffer *buf = NULL;
GstSopcastSrc *src = GST_SOPCAST_SRC (psrc);
+ /* send a get request */
if (src->first_request) {
int times = 0;
+ /* update buffering status */
src->percent = -1;
do {
percent = gst_src_src_get_buffering_level (src);
if (src->interrupted || !gst_sopcast_src_helper_is_running (src))
return GST_FLOW_ERROR;
- if (percent > 65)
+ if (percent > 50)
break;
if (percent == src->percent) {
@@ -481,7 +483,7 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
g_usleep (100000);
} while (1);
- GST_DEBUG_OBJECT (src, "Sending the GET request");
+ /* connect to server */
do {
if (gst_sopcast_src_connect_server (src))
break;
@@ -490,15 +492,18 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
g_usleep (500000);
} while (1);
- GST_DEBUG_OBJECT (src, "Sending the GET request");
- if (!gst_sopcast_src_send_first_request (src)) {
- GST_DEBUG_OBJECT (src, "Couldn't send the GET request");
+ GST_DEBUG_OBJECT (src, "Sending the GET request.");
+ if (!gst_sopcast_src_send_get_request (src)) {
+ GST_ERROR_OBJECT (src, "Couldn't send the GET request.");
goto open_error;
}
+ GST_DEBUG_OBJECT (src, "Connected to server.");
+
src->first_request = FALSE;
src->read_position = 0;
}
+ /* update buffering status every a second */
now = time (NULL);
if (now - src->last_update > 1 || now - src->last_update < 0) {
percent = gst_src_src_get_buffering_level (src);
@@ -506,9 +511,6 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
src->last_update = now;
}
- if (!gst_sopcast_src_helper_is_running (src))
- return GST_FLOW_ERROR;
-
blocksize = GST_BASE_SRC (src)->blocksize;
buf = gst_buffer_try_new_and_alloc (blocksize);
if (G_UNLIKELY (buf == NULL)) {
@@ -516,6 +518,7 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
return GST_FLOW_ERROR;
}
+ /* read data from server */
do {
fd_set rfs;
fd_set efs;
@@ -810,19 +813,19 @@ gst_sopcast_src_stop (GstBaseSrc * bsrc)
errno = 0;
ret = send (src->heatebeat_fd, "bye", 3, 0);
} while (ret < 0 && errno == EINTR);
- GST_DEBUG_OBJECT (src, "ret %d", ret);
+ GST_DEBUG_OBJECT (src, "sent %d bytes", ret);
do {
errno = 0;
ret = recv (src->heatebeat_fd, buf, 3, 0);
} while (ret < 0 && errno == EINTR);
- GST_DEBUG_OBJECT (src, "ret %d", ret);
+ GST_DEBUG_OBJECT (src, "sent %d bytes", ret);
close (src->heatebeat_fd);
src->heatebeat_fd = -1;
}
- GST_DEBUG_OBJECT (src, "fd = %d", src->sock);
+ GST_DEBUG_OBJECT (src, "closing socket = %d", src->sock);
if (src->sock >= 0) {
close (src->sock);
src->sock = -1;