myser.cpp 和makefile 放在live\mediaServer檔案夾中
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;
//建立任務調用器
scheduler = BasicTaskScheduler::createNew();
//建立互動環境
env = BasicUsageEnvironment::createNew(*scheduler);
//建立RTSP伺服器
rtspServer = RTSPServer::createNew(*env,554); //使用554端口
if(rtspServer == NULL)
{
rtspServer = RTSPServer::createNew(*env,8554); //554端口被占用,就使用8554端口
}
//列印伺服器位址
*env << "Play streams from this server using the URL\n\t"
<< rtspServer->rtspURLPrefix() << "<filename>.\n";
//建立session
sms = createNewSMS(*env, "test.mpg");
rtspServer->addServerMediaSession(sms);
//添加其它檔案對應的session...
//進行事件循環
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; //不重用source
sms = ServerMediaSession::createNew(env, fileName); //建立一個session
//
//在session中添加subssesion
//
if(strcmp(extension, ".aac") == 0)
{
sms->addSubsession(ADTSAudioFileServerMediaSubsession::createNew(env, fileName, reuseSource));
}
else if(strcmp(extension, ".264") == 0)
{
sms->addSubsession(H264VideoFileServerMediaSubsession::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());
}
//添加其它媒體格式支援...
return sms;
}
makefile
INCLUDES = -I../UsageEnvironment/include -I../groupsock/include -I../liveMedia/include -I../BasicUsageEnvironment/include
##### Change the following for your environment:
COMPILE_OPTS = $(INCLUDES) -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.
CONSOLE_LINK_OPTS = $(LINK_OPTS)
LIBRARY_LINK = ar cr
LIBRARY_LINK_OPTS =
LIB_SUFFIX = a
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)[email protected] $(CONSOLE_LINK_OPTS) $(MEDIA_SERVER_OBJS) $(LIBS)
clean:
-rm -rf *.$(OBJ) $(ALL) core *.core *~ include/*~
##### Any additional, platform-specific rules come here: