forked from borisRobson/onvif_rtsp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtsp_handler.cpp
More file actions
133 lines (100 loc) · 3.5 KB
/
rtsp_handler.cpp
File metadata and controls
133 lines (100 loc) · 3.5 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
#include "rtsp_handler.h"
GMainLoop *loop;
GstRTSPServer *server;
GstRTSPMediaMapping *mapping;
GstRTSPMediaFactory *factory;
rtsp_handler::rtsp_handler(QObject *parent)
{
rtspServer = new rtsp_server(1, this);
setupServer();
}
/*define to enable user/admin pw*/
#undef WITH_AUTH
/*this timeout is periodically run to clean up expired sessions*/
static gboolean timeout(GstRTSPServer * server, gboolean ignored)
{
// Q_UNUSED(ignored);
GstRTSPSessionPool *pool;
pool = gst_rtsp_server_get_session_pool(server);
gst_rtsp_session_pool_cleanup(pool);
g_object_unref(pool);
return true;
}
void rtsp_handler::setupServer()
{
#ifdef WITH_AUTH
GstRTSPAuth *auth;
gchar *basic;
#endif
loop = g_main_loop_new(NULL, false);
//create server instance
server = gst_rtsp_server_new();
/*get the mapping for this server, every server has a default mapper object
*that can be used to map uri mount points to media factories*/
mapping = gst_rtsp_server_get_media_mapping(server);
#ifdef WITH_AUTH
/* make a new authentication manager. it can be added to control access to all
* the factories on the server or on individual factroies*/
auth = gst_rtsp_auth_new();
basic = gst_rtsp_auth_make_basic("user", "admin");
gst_rtsp_auth_set_basic(auth, basic);
g_free(basic);
/*congifure server*/
gst_rtsp_server_set_auth(server, auth);
#endif
/*make a media factory for a test stream. The default media factory can use
* gst-launch syntax to create pipelines
* any launch line works as long as it contains elements named pay%d
* Each element w ith pay%d will be a stream*/
factory = gst_rtsp_media_factory_new();
}
void rtsp_handler::start()
{
rtspServer->start(QThread::TimeCriticalPriority);
}
rtsp_server::rtsp_server(int ID, QObject *parent) :
QThread(parent)
{
QObject::connect(this, SIGNAL(serve()), this, SLOT(beginServe()));
qDebug() << "RtspThread ID: " << ID << " this thread: "<< this<< " Parent: " << parent;
}
void rtsp_server::run()
{
emit beginServe();
exec();
}
void rtsp_server::beginServe()
{
/*set launch & run main loop && exec()*/
#ifdef IMX6
gst_rtsp_media_factory_set_launch(factory, "("
"mfw_v4lsrc capture-mode=0 ! video/x-raw-yuv,width=640,height=480,framerate=15/1 ! "
"ffmpegcolorspace ! vpuenc codec=6 ! rtph264pay name=pay0 pt=96 " ")");
#else
gst_rtsp_media_factory_set_launch(factory, "("
"v4l2src ! video/x-raw-yuv,width=640,height=480,framerate=15/1 ! "
"ffmpegcolorspace ! x264enc ! rtph264pay name=pay0 pt=96 " ")");
#endif
gst_rtsp_media_factory_set_shared(factory, true);
//attach the test factory to the /test url
gst_rtsp_media_mapping_add_factory(mapping, "/test", factory);
g_print("%s",gst_rtsp_server_get_address(server));
g_object_unref(mapping);
//attach the server to the default maincontext
if(gst_rtsp_server_attach(server, NULL) == 0){
g_print("failed to attach the server") ;
QApplication::exit(-1);
}
//add timeout for cleanup
g_timeout_add_seconds(2, (GSourceFunc)timeout, server);
//start serving
exec();
g_main_loop_run(loop);
}
void rtsp_handler::updateVidSrcCnfg()
{
QString framerate = QString("15");
QString width = QString("640");
QString height = QString("480");
emit sendVidSrcCnfg(width , height, framerate);
}