diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2014-08-18 14:56:56 (GMT) |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2014-08-18 14:56:56 (GMT) |
commit | aeb78c6cb31cd638b0a7dd92de3b9817ced53eb5 (patch) | |
tree | dea50013d80fc8140ec0f3c75c5a20a3aa3f8e0e | |
parent | 281222987d800e76049d4667a7bdd6b4a8f20660 (diff) | |
download | soup-transcoding-proxy-aeb78c6cb31cd638b0a7dd92de3b9817ced53eb5.zip soup-transcoding-proxy-aeb78c6cb31cd638b0a7dd92de3b9817ced53eb5.tar.gz |
server: Add /stream/ prefix for streaming URLs
-rw-r--r-- | README | 16 | ||||
-rw-r--r-- | TESTING | 5 | ||||
-rw-r--r-- | src/main.c | 33 |
3 files changed, 31 insertions, 23 deletions
@@ -14,7 +14,7 @@ Usage with curl: ---------------- > Sending a stream (PUT) for only HTTP GET streaming: - $ curl -v "http://localhost:8000/[sessionid]?type=http" -T - < [video file] + $ curl -v "http://localhost:8000/stream/[sessionid]?type=http" -T - < [video file] This will use Chunked encoding and send the file in chunks. Optionally, you can rate limit to emulate a live stream (--limit-rate) @@ -22,18 +22,18 @@ Trying to create two streams on the same path will return a 409. > Reading the webm output stream (GET): - $ curl -v "http://localhost:8000/[sessionid]" > [output file] + $ curl -v "http://localhost:8000/stream/[sessionid]" > [output file] The server supports multiple PUT requests on different paths, and multiple GET requests from these paths. > Sending a stream (PUT) for only RTP-UDP streaming to 127.0.0.1:5004: - $ curl -v "http://localhost:8000/[sessionid]?type=rtp-udp&udp-clients=127.0.0.1:5004" -T - < [video file] + $ curl -v "http://localhost:8000/stream/[sessionid]?type=rtp-udp&udp-clients=127.0.0.1:5004" -T - < [video file] > Sending a stream (PUT) for both RTP-UDP and HTTP GET streaming: - $ curl -v "http://localhost:8000/[sessionid]?type=rtp-udp,http&udp-clients=127.0.0.1:5004" -T - < [video file] + $ curl -v "http://localhost:8000/stream/[sessionid]?type=rtp-udp,http&udp-clients=127.0.0.1:5004" -T - < [video file] > curl handles only HTTP, so there is no way to read the RTP-UDP stream using it @@ -43,7 +43,7 @@ Usage with souphttp: > Sending a stream from a file (PUT) for only HTTP GET streaming: $ gst-launch-1.0 filesrc location=[video file] ! \ - souphttpclientsink location="http://localhost:8000/[sessionid]?type=http" + souphttpclientsink location="http://localhost:8000/stream/[sessionid]?type=http" This will use a persistent HTTP connection and Content-Length + Content-Range headers to send the stream data. @@ -51,11 +51,11 @@ headers to send the stream data. > Sending a stream from a file (PUT) for only RTP-UDP streaming: $ gst-launch-1.0 filesrc location=[video file] ! \ - souphttpclientsink location="http://localhost:8000/[sessionid]?type=rtp-udp&udp-clients=localhost:5004" + souphttpclientsink location="http://localhost:8000/stream/[sessionid]?type=rtp-udp&udp-clients=localhost:5004" > Reading a webm output stream (GET): - $ gst-launch-1.0 souphttpsrc location="http://localhost:8000/[sessionid]" ! \ + $ gst-launch-1.0 souphttpsrc location="http://localhost:8000/stream/[sessionid]" ! \ filesink location=[some output file] > Reading an RTP-UDP output stream: @@ -66,7 +66,7 @@ headers to send the stream data. > Sending a stream from a file (PUT) for both RTP-UDP and HTTP GET streaming: $ gst-launch-1.0 filesrc location=[video file] ! \ - souphttpclientsink location="http://localhost:8000/[sessionid]?type=rtp-udp,http&udp-clients=localhost:5004" + souphttpclientsink location="http://localhost:8000/stream/[sessionid]?type=rtp-udp,http&udp-clients=localhost:5004" "udp-clients" is a comma-separated list of UDP host:ports to broadcast the RTP stream to. @@ -11,12 +11,13 @@ PUT stream: ----------- $ gst-launch-1.0 -e videotestsrc is-live=TRUE ! videoscale ! \ video/x-raw, height=120, width=160 ! timeoverlay font-desc="80px" ! tee name=t \ - t. ! queue ! videoconvert ! theoraenc ! oggmux ! souphttpclientsink location="http://localhost:8000/somepath?type=http" \ + t. ! queue ! videoconvert ! theoraenc ! oggmux ! \ + souphttpclientsink location="http://localhost:8000/stream/somepath?type=http" \ t. ! queue ! videoconvert ! xvimagesink GET stream: ----------- - $ gst-launch-1.0 souphttpsrc location="http://localhost:8000/somepath" ! \ + $ gst-launch-1.0 souphttpsrc location="http://localhost:8000/stream/somepath" ! \ decodebin ! videoconvert ! videoscale ! autovideosink Launch as many GET streams as necessary. For multiple PUT streams, just change "somepath" to something else. @@ -31,11 +31,16 @@ #include "debug/local-play.h" #endif -#define STP_REST_LIST_STREAMS "/api/list-streams" -#define STP_REST_ABORT_STREAM "/api/abort-stream" -#define STP_REST_ADD_TOKEN "/api/add-token" -#define STP_REST_REVOKE_TOKEN "/api/revoke-token" -#define STP_REST_LIST_TOKENS "/api/list-tokens" +#define STP_STREAM_PREFIX "/stream/" +#define STP_REST_API_PREFIX "/api/" + +#define STP_REST_LIST_STREAMS STP_REST_API_PREFIX "list-streams" +#define STP_REST_ABORT_STREAM STP_REST_API_PREFIX "abort-stream" +#define STP_REST_ADD_TOKEN STP_REST_API_PREFIX "add-token" +#define STP_REST_REVOKE_TOKEN STP_REST_API_PREFIX "revoke-token" +#define STP_REST_LIST_TOKENS STP_REST_API_PREFIX "list-tokens" + +#define STP_SESSIONID(X) &X[sizeof(STP_STREAM_PREFIX)-1] typedef struct _STPHashTables STPHashTables; @@ -74,7 +79,8 @@ get_server_ctx_from_msg (SoupMessage *msg, STPServerCtx *ctx; g_object_get (msg, "uri", &uri, NULL); - ctx = g_hash_table_lookup (ctx_table, &soup_uri_get_path (uri)[1]); + ctx = g_hash_table_lookup (ctx_table, + STP_SESSIONID (soup_uri_get_path (uri))); soup_uri_free (uri); if (!ctx) @@ -633,15 +639,16 @@ got_request_headers (SoupMessage *msg, /* Token API methods are handled in the server callbacks, * so we ignore those paths here. */ - if (g_str_has_prefix (path, STP_REST_LIST_STREAMS) || - g_str_has_prefix (path, STP_REST_ABORT_STREAM) || - g_str_has_prefix (path, STP_REST_ADD_TOKEN) || - g_str_has_prefix (path, STP_REST_REVOKE_TOKEN) || - g_str_has_prefix (path, STP_REST_LIST_TOKENS)) + if (g_str_has_prefix (path, STP_REST_API_PREFIX)) goto out; - /* Remove the leading '/' to get the session id */ - sessionid = &path[1]; + /* Reject non-stream-prefix requests */ + if (!g_str_has_prefix (path, STP_STREAM_PREFIX)) { + soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND); + goto out; + } + /* Remove the leading '/stream/' to get the session id */ + sessionid = STP_SESSIONID(path); if (msg->method == SOUP_METHOD_PUT || msg->method == SOUP_METHOD_POST) |