summaryrefslogtreecommitdiff
path: root/src/gstscsrc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gstscsrc.c')
-rw-r--r--src/gstscsrc.c136
1 files changed, 67 insertions, 69 deletions
diff --git a/src/gstscsrc.c b/src/gstscsrc.c
index f7ed0e9..23d89f7 100644
--- a/src/gstscsrc.c
+++ b/src/gstscsrc.c
@@ -39,8 +39,9 @@
#include <arpa/inet.h>
#include <gst/gstelement.h>
-//#include <gst/gst-i18n-plugin.h>
#include <gst/base/gsttypefindhelper.h>
+
+#include "gst-i18n-plugin.h"
#include "gstscsrc.h"
GST_DEBUG_CATEGORY_STATIC (sopcastsrc_debug);
@@ -76,7 +77,8 @@ static void gst_sopcast_src_set_property (GObject * object, guint prop_id,
static void gst_sopcast_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
-static GstFlowReturn gst_sopcast_src_create (GstPushSrc * src, GstBuffer ** buffer);
+static GstFlowReturn gst_sopcast_src_create (GstPushSrc * src,
+ GstBuffer ** buffer);
static gboolean gst_sopcast_src_start (GstBaseSrc * bsrc);
@@ -147,7 +149,7 @@ gst_sopcast_src_class_init (GstSopcastSrcClass * klass)
g_object_class_install_property (gobject_class,
PROP_LOCATION,
g_param_spec_string ("location", "Location",
- "Location to read from", "", G_PARAM_READWRITE));
+ "Location to read from", "", G_PARAM_READWRITE));
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_sopcast_src_start);
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_sopcast_src_stop);
@@ -160,7 +162,8 @@ gst_sopcast_src_class_init (GstSopcastSrcClass * klass)
gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_sopcast_src_do_seek);
gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_sopcast_src_create);
- gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_sopcast_src_change_state);
+ gstelement_class->change_state =
+ GST_DEBUG_FUNCPTR (gst_sopcast_src_change_state);
GST_DEBUG_CATEGORY_INIT (sopcastsrc_debug, "sopcastsrc", 0,
"Sopcast stream Source");
@@ -241,7 +244,7 @@ gst_sopcast_src_get_property (GObject * object, guint prop_id,
}
static gboolean
-gst_sopcast_src_connect_server (GstSopcastSrc *src)
+gst_sopcast_src_connect_server (GstSopcastSrc * src)
{
struct sockaddr_in sockaddr;
int sock;
@@ -258,14 +261,14 @@ gst_sopcast_src_connect_server (GstSopcastSrc *src)
return FALSE;
}
- memset (&sockaddr, 0, sizeof(sockaddr));
+ memset (&sockaddr, 0, sizeof (sockaddr));
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons (src->ports[1]);
inet_aton ("127.0.0.1", &sockaddr.sin_addr);
GST_DEBUG_OBJECT (src, "Connecting to http://127.0.0.1:%d", src->ports[1]);
- if (connect (sock, (const struct sockaddr*)&sockaddr,
- sizeof(sockaddr)) < 0) {
+ if (connect (sock, (const struct sockaddr *) &sockaddr,
+ sizeof (sockaddr)) < 0) {
close (sock);
return FALSE;
}
@@ -276,7 +279,7 @@ gst_sopcast_src_connect_server (GstSopcastSrc *src)
}
static gboolean
-gst_sopcast_src_send_get_request (GstSopcastSrc *src)
+gst_sopcast_src_send_get_request (GstSopcastSrc * src)
{
gchar request[1024];
gchar reply[1024];
@@ -284,11 +287,10 @@ gst_sopcast_src_send_get_request (GstSopcastSrc *src)
int n;
snprintf (request, sizeof (request),
- "GET / HTTP/1.1\r\n"
- "Host: 127.0.0.1:%d\r\n"
- "Connection: close\r\n"
- "User-Agent: Gstreamer sopcastsrc\r\n"
- "\r\n", src->ports[1]);
+ "GET / HTTP/1.1\r\n"
+ "Host: 127.0.0.1:%d\r\n"
+ "Connection: close\r\n"
+ "User-Agent: Gstreamer sopcastsrc\r\n" "\r\n", src->ports[1]);
ret = send (src->sock, request, strlen (request), 0);
if (ret < 0) {
@@ -315,8 +317,8 @@ gst_sopcast_src_send_get_request (GstSopcastSrc *src)
return FALSE;
}
-static gchar*
-gst_sopcast_src_get_stats (GstSopcastSrc *src)
+static gchar *
+gst_sopcast_src_get_stats (GstSopcastSrc * src)
{
struct sockaddr_in sockaddr;
gchar request[] = "state\ns\n";
@@ -333,16 +335,17 @@ gst_sopcast_src_get_stats (GstSopcastSrc *src)
return NULL;
}
- memset (&sockaddr, 0, sizeof(sockaddr));
+ memset (&sockaddr, 0, sizeof (sockaddr));
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons (src->ports[1]);
inet_aton ("127.0.0.1", &sockaddr.sin_addr);
- if (connect (sock, (const struct sockaddr*)&sockaddr,
- sizeof(sockaddr)) < 0)
+ if (connect (sock, (const struct sockaddr *) &sockaddr,
+ sizeof (sockaddr)) < 0)
goto failed;
- GST_LOG_OBJECT (src, "Connected to server tcp://127.0.0.1:%d.", src->ports[0]);
+ GST_LOG_OBJECT (src, "Connected to server tcp://127.0.0.1:%d.",
+ src->ports[0]);
for (n = 0; n < 2; n++) {
ret = send (sock, request, strlen (request), 0);
@@ -369,7 +372,7 @@ gst_sopcast_src_get_stats (GstSopcastSrc *src)
do {
errno = 0;
- ret = recv (sock, &reply[n], sizeof(reply) - n, 0);
+ ret = recv (sock, &reply[n], sizeof (reply) - n, 0);
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
perror ("Failed to receive a reply from server");
@@ -382,10 +385,10 @@ gst_sopcast_src_get_stats (GstSopcastSrc *src)
for (i = 0; i < ret; i++) {
if (reply[n + i] == '\n') {
- close (sock);
- reply[n + i + 1] = '\0';
- GST_LOG_OBJECT (src, "stats: %s", reply);
- return g_strdup (reply);
+ close (sock);
+ reply[n + i + 1] = '\0';
+ GST_LOG_OBJECT (src, "stats: %s", reply);
+ return g_strdup (reply);
}
}
}
@@ -396,7 +399,7 @@ failed:
}
static gboolean
-gst_sopcast_src_helper_is_running (GstSopcastSrc *src)
+gst_sopcast_src_helper_is_running (GstSopcastSrc * src)
{
int ret;
@@ -411,7 +414,7 @@ gst_sopcast_src_helper_is_running (GstSopcastSrc *src)
}
static int
-gst_src_src_get_buffering_level (GstSopcastSrc *src)
+gst_src_src_get_buffering_level (GstSopcastSrc * src)
{
gchar *stats;
gint percent = 0;
@@ -433,7 +436,7 @@ gst_src_src_get_buffering_level (GstSopcastSrc *src)
}
static void
-gst_sopcast_src_update_buffering_progress (GstSopcastSrc *src, gint percent)
+gst_sopcast_src_update_buffering_progress (GstSopcastSrc * src, gint percent)
{
GstMessage *message;
@@ -443,8 +446,7 @@ gst_sopcast_src_update_buffering_progress (GstSopcastSrc *src, gint percent)
src->percent = percent;
message = gst_message_new_element (GST_OBJECT_CAST (src),
- gst_structure_new ("progress", "percent",
- G_TYPE_INT, percent, NULL));
+ gst_structure_new ("progress", "percent", G_TYPE_INT, percent, NULL));
gst_element_post_message (GST_ELEMENT_CAST (src), message);
}
@@ -468,15 +470,15 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
percent = gst_src_src_get_buffering_level (src);
if (src->interrupted || !gst_sopcast_src_helper_is_running (src))
- return GST_FLOW_ERROR;
+ return GST_FLOW_ERROR;
if (percent > 50)
- break;
+ break;
if (percent == src->percent) {
- if (++times > 5)
- src->percent = -1;
+ if (++times > 5)
+ src->percent = -1;
} else {
- times = 0;
+ times = 0;
}
gst_sopcast_src_update_buffering_progress (src, percent);
@@ -486,9 +488,9 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
/* connect to server */
do {
if (gst_sopcast_src_connect_server (src))
- break;
+ break;
if (src->interrupted || !gst_sopcast_src_helper_is_running (src))
- return GST_FLOW_ERROR;
+ return GST_FLOW_ERROR;
g_usleep (500000);
} while (1);
@@ -525,7 +527,7 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
struct timeval tv;
int sock = src->sock;
- if (src->interrupted /* || !gst_sopcast_src_helper_is_running (src) */)
+ if (src->interrupted /* || !gst_sopcast_src_helper_is_running (src) */ )
goto could_not_read;
FD_ZERO (&rfs);
@@ -545,8 +547,7 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
if (!ret || !FD_ISSET (sock, &rfs))
continue;
- ret = recv (sock, GST_BUFFER_DATA (buf),
- GST_BUFFER_SIZE (buf), 0);
+ ret = recv (sock, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf), 0);
if (ret < 0 && errno != EINTR)
goto could_not_read;
@@ -597,12 +598,12 @@ gst_sopcast_src_allocate_port (void)
port = g_random_int_range (3000, 65535);
sock = socket (AF_INET, SOCK_STREAM, 0);
- memset (&sockaddr, 0, sizeof(sockaddr));
+ memset (&sockaddr, 0, sizeof (sockaddr));
sockaddr.sin_family = AF_INET;
- sockaddr.sin_port = htons(port);
+ sockaddr.sin_port = htons (port);
inet_aton ("127.0.0.1", &sockaddr.sin_addr);
- if (connect (sock, (const struct sockaddr*)&sockaddr,
- sizeof(sockaddr)) != 0) {
+ if (connect (sock, (const struct sockaddr *) &sockaddr,
+ sizeof (sockaddr)) != 0) {
close (sock);
break;
}
@@ -626,13 +627,13 @@ gst_sopcast_src_allocate_ports (GstSopcastSrc * src)
static gboolean
gst_sopcast_src_spawn_helper (GstSopcastSrc * src)
{
- gchar* argv[12];
- gchar ports[2][20];
+ gchar *argv[12];
+ gchar ports[2][20];
int argc;
gboolean ret;
- snprintf (ports[0], sizeof(ports[0]), "%d", src->ports[0]);
- snprintf (ports[1], sizeof(ports[1]), "%d", src->ports[1]);
+ snprintf (ports[0], sizeof (ports[0]), "%d", src->ports[0]);
+ snprintf (ports[1], sizeof (ports[1]), "%d", src->ports[1]);
argc = 0;
argv[argc++] = "sp-sc";
@@ -642,17 +643,15 @@ gst_sopcast_src_spawn_helper (GstSopcastSrc * src)
argv[argc++] = NULL;
ret = g_spawn_async ("/tmp", argv, NULL,
- G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL,
- NULL, NULL, &src->helper_pid,
- NULL);
+ G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL,
+ NULL, NULL, &src->helper_pid, NULL);
if (ret)
return TRUE;
argv[0] = "sp-sc-auth";
return g_spawn_async ("/tmp", argv, NULL,
- G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL,
- NULL, NULL, &src->helper_pid,
- NULL);
+ G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL,
+ NULL, NULL, &src->helper_pid, NULL);
}
static void
@@ -665,7 +664,7 @@ gst_sopcast_src_monitor_main (GstSopcastSrc * src, pid_t ppid, int sock)
char buf[1024];
/* cleanup fds */
- max = sysconf(_SC_OPEN_MAX);
+ max = sysconf (_SC_OPEN_MAX);
for (i = 3; i < max; i++)
if (i != sock)
close (i);
@@ -681,8 +680,8 @@ gst_sopcast_src_monitor_main (GstSopcastSrc * src, pid_t ppid, int sock)
int error;
if (getppid () != ppid) {
- GST_DEBUG_OBJECT (src, "ppid changed %d -> %d", ppid, getppid ());
- break;
+ GST_DEBUG_OBJECT (src, "ppid changed %d -> %d", ppid, getppid ());
+ break;
}
if (!gst_sopcast_src_helper_is_running (src)) {
@@ -708,17 +707,17 @@ gst_sopcast_src_monitor_main (GstSopcastSrc * src, pid_t ppid, int sock)
continue;
if (FD_ISSET (sock, &efs)) {
- GST_DEBUG_OBJECT (src, "player closed the sock.");
- break;
+ GST_DEBUG_OBJECT (src, "player closed the sock.");
+ break;
}
if (FD_ISSET (sock, &rfs)) {
do {
- ret = recv (sock, buf, sizeof (buf), 0);
+ ret = recv (sock, buf, sizeof (buf), 0);
} while (ret < 0 && errno == EINTR);
if (ret < 0 || buf[0] == 'b') {
- GST_DEBUG_OBJECT (src, "player said goodbye to me.");
- break;
+ GST_DEBUG_OBJECT (src, "player said goodbye to me.");
+ break;
}
}
}
@@ -782,14 +781,15 @@ gst_sopcast_src_start (GstBaseSrc * bsrc)
src = GST_SOPCAST_SRC (bsrc);
if (!gst_sopcast_src_allocate_ports (src)) {
- GST_ERROR_OBJECT (src, "Coudn't allocate two ports.");
+ GST_ERROR_OBJECT (src, _("Failed to allocate two tcp ports."));
return FALSE;
}
- GST_DEBUG_OBJECT (src, "localport: %d playerport: %d.", src->ports[0], src->ports[1]);
+ GST_DEBUG_OBJECT (src, "localport: %d playerport: %d.", src->ports[0],
+ src->ports[1]);
src->heatebeat_fd = -1;
if (!gst_sopcast_src_start_monitor (src)) {
- GST_ERROR_OBJECT (src, "Coudn't fork the monitor subprocess.");
+ GST_ERROR_OBJECT (src, _("Failed to fork the monitor subprocess."));
return FALSE;
}
@@ -923,7 +923,7 @@ gst_sopcast_src_change_state (GstElement * element, GstStateChange transition)
GST_DEBUG_OBJECT (scsrc, "NULL->READY");
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
- GST_DEBUG_OBJECT (scsrc, "READY->PAUSED");
+ GST_DEBUG_OBJECT (scsrc, "READY->PAUSED");
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
GST_DEBUG_OBJECT (scsrc, "PAUSED->PLAYING");
@@ -1019,6 +1019,4 @@ plugin_init (GstPlugin * plugin)
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
- "sopcast",
- "sopcast stream src",
- plugin_init, VERSION, "LGPL", PACKAGE, "")
+ "sopcast", "sopcast stream src", plugin_init, VERSION, "LGPL", PACKAGE, "")