1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*
* vim: set sts=2 sw=2 et :
*
* License: LGPL-2.1+
* Copyright (c) 2014 Nirbheek Chauhan <nirbheek@centricular.com>
*
* 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
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _SST_LIB
#define _SST_LIB
#include <glib.h>
#include <gst/gst.h>
#include <libsoup/soup.h>
typedef struct _STPServerCtx STPServerCtx;
typedef struct _STPClientCtx STPClientCtx;
typedef struct _STPStreamToken STPStreamToken;
#define STP_STREAM_TYPE_INVALID (1 << 0)
#define STP_STREAM_TYPE_HTTP (1 << 1)
#define STP_STREAM_TYPE_RTP_UDP (1 << 2)
#define STP_STREAM_TYPE_RTP_TCP (1 << 3) /* Not supported yet */
#define STP_STREAM_TYPE_ALL STP_STREAM_TYPE_HTTP | STP_STREAM_TYPE_RTP_UDP
#define STP_STATUS_NONE g_intern_static_string ("none")
#define STP_STATUS_STREAMING g_intern_static_string ("streaming")
#define STP_STATUS_FLUSHING g_intern_static_string ("flushing")
#define STP_STATUS_FINISHED g_intern_static_string ("finished")
struct _STPServerCtx {
SoupMessage *msg;
GstElement *pipeline;
GstElement *appsrc;
/* Also used as the key in the parent hash table */
char *sessionid;
/* Comman-separated list of host:port pairs */
char *udp_clients;
/* RTP or HTTP or both */
guint stream_type;
/* Keeps track of the stream running status, let's us know if
* we need to set the PUT response on EOS/ERROR on the pipeline,
* and whether to reject further data when using a persistent
* Content-Length + Content-Range PUT stream. */
const char *status;
/* If the encoding is not chunked, we'll get multiple requests
* with separate Content-Length headers on the same path */
SoupEncoding encoding;
guint timeout_handler_id;
guint seconds_since_read;
/* List of client contexts */
GList *clients;
/* Reference to the parent context hash table */
GHashTable *parent_ctx_table;
};
struct _STPClientCtx {
/* We don't hold refs to any of these */
SoupMessage *msg;
GstElement *appsink;
GstPad *ghostsinkpad;
gboolean keyframe_found;
guint timeout_handler_id;
gulong finished_handler_id;
guint seconds_since_write;
/* The transcode server context; we don't hold a ref to this */
STPServerCtx *server_ctx;
};
struct _STPStreamToken {
guint stream_type;
/* Comma-separated host:port list */
char *udp_clients;
};
#ifdef ENCODE_DEBUG
#define stp_print_status(...) g_print(__VA_ARGS__)
#else
#define stp_print_status(...) do {} while (0)
#endif
gboolean invoke_g_hash_table_remove (STPServerCtx *ctx);
gboolean invoke_g_free_client_context (STPClientCtx *ctx);
const char* stp_get_stream_type_string (guint stream_type);
guint stp_get_stream_type_from_string (const char *type);
gboolean stp_validate_token_server (GInetAddressMask *mask,
SoupClientContext *client);
void stp_server_ctx_cleanup (STPServerCtx *ctx);
void stp_client_ctx_cleanup (STPClientCtx *ctx);
void stp_stream_token_free (STPStreamToken *token);
gboolean stp_on_gst_bus_message (GstBus *bus,
GstMessage *msg,
STPServerCtx *ctx);
GstBuffer* stp_get_streamheader_from_caps (GstCaps *caps);
GstBuffer* stp_get_gst_buffer (SoupBuffer *chunk);
#endif /* _SST_LIB */
|