Put myser. cpp and makefile in the live \ mediaserver folder.
Myser. cpp
# Include <basicusageenvironment. Hh>
# Include "livemedia. hh"
Static servermediasession * createnewsms (usageenvironment & ENV, char const * filename );
Int main ()
{
Taskscheduler * scheduler;
Usageenvironment * env;
Rtspserver * rtspserver;
Servermediasession * SMS;
// Create a task caller
Schedew = basictaskschedew: createnew ();
// Create an interactive environment
ENV = basicusageenvironment: createnew (* schedew );
// Create an RTSP Server
Rtspserver = rtspserver: createnew (* ENV, 554); // use port 554
If (rtspserver = NULL)
{
Rtspserver = rtspserver: createnew (* ENV, 8554); // port 554 is occupied and port 8554 is used.
}
// Print the server address
* Env <"play streams from this server using the URL \ n \ t"
<Rtspserver-> rtspurlprefix () <"<FILENAME>. \ n ";
// Create a session
SMS = createnewsms (* ENV, "test. mpg ");
Rtspserver-> addservermediasession (SMS );
// Add the session corresponding to other files...
// Loop events
Env-> taskscheduler (). doeventloop (); // does not return
Return 0;
}
Static servermediasession * createnewsms (usageenvironment & ENV, char const * filename)
{
Char const * extension = strrchr (filename ,'.');
Servermediasession * SMS = NULL;
Boolean reusesource = false; // do not reuse Source
SMS = servermediasession: createnew (ENV, filename); // create a session
//
// Add subssesion TO THE SESSION
//
If (strcmp (extension, ". AAC") = 0)
{
SMS-> addsubsession (adtsaudiofileservermediasubsession: createnew (ENV, filename, reusesource ));
}
Else if (strcmp (extension, ". 264") = 0)
{
SMS-> addsubsession (hsf-videofileservermediasubsession: createnew (ENV, filename, reusesource ));
}
Else if (strcmp (extension, ". mpg") = 0)
{
Mpeg1or2fileserverdemux * Demux
= Mpeg1or2fileserverdemux: createnew (ENV, filename, reusesource );
SMS-> addsubsession (Demux-> newvideoservermediasubsession ());
SMS-> addsubsession (Demux-> newaudioservermediasubsession ());
}
// Add support for other media formats...
Return SMS;
}
Makefile
Primary des =-I ../usageenvironment/include-I ../groupsock/include-I ../livemedia/include-I ../basicusageenvironment/include
##### Change the following for your environment:
Compile_opts = $ (primary des)-I.-O2-dsocklen_t = socklen_t-d_largefile_source = 1-d_file_offset_bits = 64
C = C
C_compiler = cc
C_flags = $ (compile_opts)
CPP = CPP
Cplusplus_compiler = g ++
Cplusplus_flags = $ (compile_opts)-wall-dbsd = 1
OBJ = o
Link = g ++-o
Link_opts =-L.
Lele_link_opts = $ (link_opts)
Library_link = ar cr
Library_link_opts =
Lib_suffix =
Libs_for_console_application =
Libs_for_gui_application =
EXE =
##### End of variables to change
Media_server = myser $ (exe)
All = $ (media_server)
ALL: $ (all)
. $ (C). $ (OBJ ):
$ (C_compiler)-C $ (c_flags) $ <
. $ (CPP). $ (OBJ ):
$ (Cplusplus_compiler)-C $ (cplusplus_flags) $ <
Media_server_objs = myser. $ (OBJ)
# Myser. $ (CPP): livemedia. HH
Usage_environment_dir = ../usageenvironment
Usage_environment_lib = $ (usage_environment_dir)/libusageenvironment. $ (lib_suffix)
Basic_usage_environment_dir = ../basicusageenvironment
Basic_usage_environment_lib = $ (basic_usage_environment_dir)/libbasicusageenvironment. $ (lib_suffix)
Livemedia_dir = ../livemedia
Livemedia_lib = $ (livemedia_dir)/liblivemedia. $ (lib_suffix)
Groupsock_dir = ../groupsock
Groupsock_lib = $ (groupsock_dir)/libgroupsock. $ (lib_suffix)
Local_libs = $ (livemedia_lib) $ (groupsock_lib )\
$ (Basic_usage_environment_lib) $ (usage_environment_lib)
Libs = $ (local_libs) $ (libs_for_console_application)
Myser $ (exe): $ (media_server_objs) $ (local_libs)
$ (Link) $ @ $ (console_link_opts) $ (media_server_objs) $ (libs)
Clean:
-Rm-RF *. $ (OBJ) $ (all) Core *. Core *~ Include /*~
##### Any additional, platform-specific rules come here: