-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCameraServer.cpp
80 lines (66 loc) · 3.01 KB
/
CameraServer.cpp
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
/*
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
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 Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "H264LiveServerMediaSubsession.hpp"
#include "ADTSLiveServerMediaSubsession.hpp"
#include <BasicUsageEnvironment.hh>
#include <liveMedia.hh>
#include <string.h>
#define CAMERA_SERVER_VERSION_STRING "0.1"
#define VIDEO_WIDTH 640
#define VIDEO_HEIGTH 480
#define FRAME_PER_SEC 25.0
#define AUDIO_SAMPLE_RATE 44100
#define AUDIO_NUM_CHANNEL 2
int main(int argc, char** argv)
{
// Begin by setting up our usage environment:
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
UserAuthenticationDatabase* authDB = NULL;
#ifdef ACCESS_CONTROL
// To implement client access control to the RTSP server, do the following:
authDB = new UserAuthenticationDatabase;
authDB->addUserRecord("username1", "password1"); // replace these with real strings
// Repeat the above with each <username>, <password> that you wish to allow
// access to the server.
#endif
// Create the RTSP server. Try first with the default port number (554),
// and then with the alternative port number (8554):
RTSPServer* rtspServer;
portNumBits rtspServerPortNum = 554;
rtspServer = RTSPServer::createNew(*env, rtspServerPortNum, authDB);
if (rtspServer == NULL)
{
rtspServerPortNum = 8554;
rtspServer = RTSPServer::createNew(*env, rtspServerPortNum, authDB);
}
if (rtspServer == NULL)
{
*env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
exit(1);
}
*env << "Camera server version " << CAMERA_SERVER_VERSION_STRING << "\n";
ServerMediaSession *sms = ServerMediaSession::createNew(*env,
"webcam", 0, "Camera server, streamed by the LIVE555 Media Server");
sms->addSubsession(H264LiveServerMediaSubsession::createNew(*env,
"/dev/video0", VIDEO_WIDTH, VIDEO_HEIGTH, FRAME_PER_SEC));
sms->addSubsession(ADTSLiveServerMediaSubsession::createNew(*env,
"hw:0,0", AUDIO_SAMPLE_RATE, AUDIO_NUM_CHANNEL));
rtspServer->addServerMediaSession(sms);
char* url = rtspServer->rtspURL(sms);
*env << "Using url \"" << url << "\"\n";
delete[] url;
env->taskScheduler().doEventLoop(); // does not return
return 0; // only to prevent compiler warning
}