Hi, everyone!
I thought I posted the code first, it's better. This is the code of the program I've worked with :
#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"
#include <stdio.h>
UsageEnvironment* env;
Boolean reuseFirstSource = False;
Boolean iFramesOnly = False;
static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,
char const* streamName, char* inputFileName); // fwd
char* getFileName(int choice);
char* getFileName(int choice)
{
char* inputFile = "";
switch(choice){
case 1: inputFile = "A.mp3";
break;
case 2: inputFile = "B.mp3";
break;
case 3: inputFile = "C.mp3";
break;
}
return inputFile;
}
int main(int argc, char** argv) {
// Begin by setting up our usage environment:
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
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:
RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554, authDB, 45);
if (rtspServer == NULL) {
*env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
exit(1);
}
char const* descriptionString = "Session streamed by \"testOnDemandRTSPServer\"";
{
char const* streamName = "mp3AudioTest";
char* inputFileName=argv[100];
ServerMediaSession* sms
= ServerMediaSession::createNew(*env, streamName, streamName, descriptionString);
Boolean useADUs = False;
Interleaving* interleaving = NULL;
#ifdef STREAM_USING_ADUS
useADUs = True;
#ifdef INTERLEAVE_ADUS
unsigned char interleaveCycle[] = {0,2,1,3}; // or choose your own...
unsigned const interleaveCycleSize
= (sizeof interleaveCycle)/(sizeof (unsigned char));
interleaving = new Interleaving(interleaveCycleSize, interleaveCycle);
#endif
#endif
sms->addSubsession(MP3AudioFileServerMediaSubsession::createNew(*env, inputFileName, reuseFirstSource, useADUs, interleaving));
rtspServer->addServerMediaSession(sms);
announceStream(rtspServer, sms, streamName, inputFileName);
}
env->taskScheduler().doEventLoop(); // does not return
return 0; // only to prevent compiler warning
}
static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,
char const* streamName, char* inputFileName) {
char* url = rtspServer->rtspURL(sms);
UsageEnvironment& env = rtspServer->envir();
int choice;
env << "Which file to play?\r\n";
env << "Menu : \n";
env << "1. A\n";
env << "2. B\n";
env << "3. C\n";
scanf("%d", &choice);
inputFileName = getFileName(choice);
env << "\n\"" << streamName << "\" stream, from the file \""
<< inputFileName << "\"\n";
env << "Play this stream using the URL \"" << url << "\"\n";
delete[] url;
}
After that I compiled it, and the output is like this :
Which file to play?
Menu :
1. A
2. B
3. C
3
"mp3AudioTest" stream, from the file "C.mp3"
Play this stream using the URL "rtsp://10.10.10.101:8554/mp3AudioTest"
Segmentation fault (core dumped)
Ok. Now I talk about the functionality of the program :
This is the program that let the user choose the audio file, then play. I pull up the server first, choose the file name (as you see, I enter "3" and the file name returned is "C.mp3"). After that, I open the client and play the file. But it can't play and server returned message : Segmentation fault (core dumped)
I do a Google search and I found that this caused by pointer error (using non-pointer for pointer, maybe not exactly what I read, because I can't find the article which talk about this again). I re-check my program, but can't see where is the pointer error.
May everyone give me a hand on this problem? Thanks a lot.