-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.c
68 lines (57 loc) · 2.13 KB
/
server.c
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
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#define DEFAULT_RTSP_PORT "8554"
static char* password = "wjJcr4DO0V5OzIrz20";
static char* port = (char *) DEFAULT_RTSP_PORT;
static char* command = (char *) "( \
rpicamsrc annotation-mode=frame-number \
roi-x=0.0 roi-w=1.0 \
roi-y=0.0 roi-h=1.0 \
sharpness=100 \
contrast=100 \
brightness=60 \
drc=0 \
preview=false \
bitrate=2000000 \
keyframe-interval=60 ! \
video/x-h264, framerate=30/1, profile=high, width=1640, height=1232 ! \
h264parse ! \
rtph264pay name=pay0 pt=96 \
alsasrc device=hw:1 ! \
audioconvert ! \
audioresample ! \
alawenc ! \
rtppcmapay name=pay1 pt=8 )";
int main (int argc, char *argv[]) {
GMainLoop *loop;
GstRTSPServer *server;
GstRTSPMountPoints *mounts;
GstRTSPMediaFactory *factory;
GstRTSPAuth *auth;
GstRTSPToken *token;
gchar *basic;
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
server = gst_rtsp_server_new ();
g_object_set (server, "service", port, NULL);
mounts = gst_rtsp_server_get_mount_points (server);
factory = gst_rtsp_media_factory_new ();
gst_rtsp_media_factory_set_launch (factory, command);
gst_rtsp_mount_points_add_factory (mounts, "/stream", factory);
g_object_unref (mounts);
gst_rtsp_media_factory_add_role (factory, "user",
GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
auth = gst_rtsp_auth_new ();
token = gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, "user", NULL);
basic = gst_rtsp_auth_make_basic ("user", password);
gst_rtsp_auth_add_basic (auth, basic, token);
g_free (basic);
gst_rtsp_token_unref (token);
gst_rtsp_server_set_auth (server, auth);
g_object_unref (auth);
gst_rtsp_server_attach (server, NULL);
g_print ("stream ready at rtsp://127.0.0.1:%s/stream\n", port);
g_main_loop_run (loop);
return 0;
}