Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********
- 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
- **********/
- // Copyright (c) 1996-2013, Live Networks, Inc. All rights reserved
- // LIVE555 Media Server
- // main program
- #define ANDROID 1
- #include <signal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <BasicUsageEnvironment.hh>
- #include "DynamicRTSPServer.hh"
- #include "version.hh"
- int p2p_mode=0;
- RTSPServer* rtspServer = NULL;
- void ptime(const char *message) {
- int sec, msec;
- struct timeval tp;
- gettimeofday(&tp, NULL);
- sec = tp.tv_sec%1000;
- msec = tp.tv_usec/1000;
- printf("[%03d.%03d]: %s",sec,msec,message);
- fflush(stdout);
- }
- static void catch_function(int signal) {
- fprintf(stderr, "Livemedia got [%d] signal, exit after 1 sec!\n", signal);
- delete rtspServer;
- sleep(1);
- exit(13);
- }
- int set_signal_handler(void) {
- if (signal(SIGTERM, catch_function) == SIG_ERR) {
- fprintf(stderr, "We cannot set SIGTERM handler!\n");
- return -1;
- }
- if (signal(SIGINT, catch_function) == SIG_ERR) {
- fprintf(stderr, "We cannot set SIGINT handler!\n");
- return -1;
- }
- ptime("All signal handlers successfully set!\n");
- return 0;
- }
- int main(int argc, char** argv) {
- // Begin by setting up our usage environment:
- if (argc>1) {
- if (strcmp(argv[1], "-p")==0) {
- p2p_mode=1;
- }
- else if (strcmp(argv[1], "-q")==0) {
- printf("Quit requested. Ok\n");
- exit(0);
- }
- else {
- printf("Unknown arg\n");
- }
- }
- // Set signal processor
- set_signal_handler();
- 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):
- portNumBits rtspServerPortNum = 554;
- #ifndef ANDROID
- rtspServer = DynamicRTSPServer::createNew(*env, rtspServerPortNum, authDB);
- #endif
- if (rtspServer == NULL) {
- if (p2p_mode==1) {
- rtspServerPortNum = 7236;
- }
- else {
- rtspServerPortNum = 8554;
- }
- rtspServer = DynamicRTSPServer::createNew(*env, rtspServerPortNum, authDB);
- }
- if (rtspServer == NULL) {
- *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
- exit(1);
- }
- *env << "LIVE555 Media Server, pid:" << getpid() << "\n";
- *env << "\tversion " << MEDIA_SERVER_VERSION_STRING
- << " (LIVE555 Streaming Media library version "
- << LIVEMEDIA_LIBRARY_VERSION_STRING << ").\n";
- char* urlPrefix = rtspServer->rtspURLPrefix();
- *env << "Play streams from this server using the URL\n\t"
- << urlPrefix << "<filename>\nwhere <filename> is a file present in the current directory.\n";
- /*
- *env << "Each file's type is inferred from its name suffix:\n";
- *env << "\t\".264\" => a H.264 Video Elementary Stream file\n";
- *env << "\t\".aac\" => an AAC Audio (ADTS format) file\n";
- *env << "\t\".ac3\" => an AC-3 Audio file\n";
- *env << "\t\".amr\" => an AMR Audio file\n";
- *env << "\t\".dv\" => a DV Video file\n";
- *env << "\t\".m4e\" => a MPEG-4 Video Elementary Stream file\n";
- *env << "\t\".mkv\" => a Matroska audio+video+(optional)subtitles file\n";
- *env << "\t\".mp3\" => a MPEG-1 or 2 Audio file\n";
- *env << "\t\".mpg\" => a MPEG-1 or 2 Program Stream (audio+video) file\n";
- *env << "\t\".ts\" => a MPEG Transport Stream file\n";
- *env << "\t\t(a \".tsx\" index file - if present - provides server 'trick play' support)\n";
- *env << "\t\".vob\" => a VOB (MPEG-2 video with AC-3 audio) file\n";
- *env << "\t\".wav\" => a WAV Audio file\n";
- *env << "\t\".webm\" => a WebM audio(Vorbis)+video(VP8) file\n";
- *env << "See http://www.live555.com/mediaServer/ for additional documentation.\n";
- */
- // Also, attempt to create a HTTP server for RTSP-over-HTTP tunneling.
- // Try first with the default HTTP port (80), and then with the alternative HTTP
- // port numbers (8000 and 8080).
- /*
- if (rtspServer->setUpTunnelingOverHTTP(80) || rtspServer->setUpTunnelingOverHTTP(8000) || rtspServer->setUpTunnelingOverHTTP(8080)) {
- *env << "(We use port " << rtspServer->httpServerPortNum() << " for optional RTSP-over-HTTP tunneling, or for HTTP live streaming (for indexed Transport Stream files only).)\n";
- }
- else {
- *env << "(RTSP-over-HTTP tunneling is not available.)\n";
- }
- */
- env->taskScheduler().doEventLoop(); // does not return
- return 0; // only to prevent compiler warning
- }
Add Comment
Please, Sign In to add comment