本文整理汇总了C++中MediaSubsession::codecName方法的典型用法代码示例。如果您正苦于以下问题:C++ MediaSubsession::codecName方法的具体用法?C++ MediaSubsession::codecName怎么用?C++ MediaSubsession::codecName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MediaSubsession
的用法示例。
在下文中一共展示了MediaSubsession::codecName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupStreams
bool CRTSPClient::setupStreams()
{
//setup streams
XBMC->Log(LOG_DEBUG, "CRTSPClient::setupStreams()");
Boolean madeProgress=False;
MediaSubsessionIterator iter(*m_session);
MediaSubsession *subsession;
while ((subsession = iter.next()) != NULL)
{
if (subsession->clientPortNum() == 0) continue; // port # was not set
if (!clientSetupSubsession(m_ourClient, subsession, streamUsingTCP))
{
XBMC->Log(LOG_DEBUG, "Failed to setup %s %s %s" ,subsession->mediumName(),subsession->codecName(),m_env->getResultMsg() );;
}
else
{
XBMC->Log(LOG_DEBUG, "Setup %s %s %d %d" ,subsession->mediumName(),subsession->codecName(),subsession->clientPortNum(),subsession->clientPortNum()+1);;
madeProgress = True;
}
}
if (!madeProgress)
{
shutdown();
return false;
}
return true;
}
示例2: setupStreams
BOOL setupStreams( unsigned *pResponseCode /*= NULL*/ )
{
MediaSubsessionIterator iter(*session);
MediaSubsession *subsession;
Boolean madeProgress = False;
BOOL bResult = TRUE;
while ((subsession = iter.next()) != NULL)
{
if (subsession->clientPortNum() == 0) continue; // port # was not set
if ( !clientSetupSubsession(ourClient, subsession, streamUsingTCP, pResponseCode ) )
{
*env << "Failed to setup \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession: " << env->getResultMsg() << "\n";
bResult = FALSE;
}
else
{
*env << "Setup \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession (client ports " << subsession->clientPortNum()
<< "-" << subsession->clientPortNum()+1 << ")\n";
madeProgress = True;
bResult = TRUE;
}
}
//if (!madeProgress)
// return bResult;
return bResult;
}
示例3: bad_alloc
DefaultSink::DefaultSink(UsageEnvironment & env,
MediaSubsession & subsession,
char const * sink_url,
char const * stream_id)
: MediaSink(env),
_subsession(subsession),
_receive_buffer(RECEIVE_BUFFER_SIZE),
_stream_id(stream_id),
_writer(libc2rtsp::sink::SinkFactory().gen(sink_url)),
_verbose(true),
_sprop_parameter_sets(),
_have_written_first_frame(false)
{
if (::strcmp(subsession.codecName(), "H264") == 0) {
// For H.264 video stream, we use a special sink that adds 'start codes',
// and (at the start) the SPS and PPS NAL units:
_sprop_parameter_sets.emplace_back(std::string(subsession.fmtp_spropparametersets()));
} else if (::strcmp(subsession.codecName(), "H265") == 0) {
// For H.265 video stream, we use a special sink that adds 'start codes',
// and (at the start) the VPS, SPS, and PPS NAL units:
_sprop_parameter_sets.emplace_back(std::string(subsession.fmtp_spropvps())); // VPS
_sprop_parameter_sets.emplace_back(std::string(subsession.fmtp_spropsps())); // SPS
_sprop_parameter_sets.emplace_back(std::string(subsession.fmtp_sproppps())); // PPS
} else {
crLogE("DefaultSink::DefaultSink() Unsupported subsession: {}/{}",
subsession.mediumName(), subsession.codecName());
throw std::bad_alloc();
}
}
示例4: OnDemandServerMediaSubsession
ProxyServerMediaSubsession
::ProxyServerMediaSubsession(MediaSubsession& mediaSubsession,
portNumBits initialPortNum, Boolean multiplexRTCPWithRTP)
: OnDemandServerMediaSubsession(mediaSubsession.parentSession().envir(), True/*reuseFirstSource*/,
initialPortNum, multiplexRTCPWithRTP),
fClientMediaSubsession(mediaSubsession), fCodecName(strDup(mediaSubsession.codecName())),
fNext(NULL), fHaveSetupStream(False) {
}
示例5: setupStreams
void setupStreams() {
MediaSubsessionIterator iter(*session);
MediaSubsession *subsession;
Boolean madeProgress = False;
while ((subsession = iter.next()) != NULL) {
if (subsession->clientPortNum() == 0) continue; // port # was not set
if (!clientSetupSubsession(ourClient, subsession, streamUsingTCP)) {
*env << "Failed to setup \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession: " << env->getResultMsg() << "\n";
} else {
*env << "Setup \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession (client ports " << subsession->clientPortNum()
<< "-" << subsession->clientPortNum()+1 << ")\n";
madeProgress = True;
}
}
if (!madeProgress) shutdown();
}
示例6: subsessionByeHandler
void subsessionByeHandler(void* clientData) {
struct timeval timeNow;
gettimeofday(&timeNow, NULL);
unsigned secsDiff = timeNow.tv_sec - startTime.tv_sec;
MediaSubsession* subsession = (MediaSubsession*)clientData;
*env << "Received RTCP \"BYE\" on \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession (after " << secsDiff
<< " seconds)\n";
// Act now as if the subsession had closed:
subsessionAfterPlaying(subsession);
}
示例7: continueAfterDESCRIBE
void ProxyServerMediaSession::continueAfterDESCRIBE(char const* sdpDescription) {
describeCompletedFlag = 1;
// Create a (client) "MediaSession" object from the stream's SDP description ("resultString"), then iterate through its
// "MediaSubsession" objects, to set up corresponding "ServerMediaSubsession" objects that we'll use to serve the stream's tracks.
do {
fClientMediaSession = MediaSession::createNew(envir(), sdpDescription);
if (fClientMediaSession == NULL) break;
MediaSubsessionIterator iter(*fClientMediaSession);
for (MediaSubsession* mss = iter.next(); mss != NULL; mss = iter.next()) {
ServerMediaSubsession* smss = new ProxyServerMediaSubsession(*mss);
addSubsession(smss);
if (fVerbosityLevel > 0) {
envir() << *this << " added new \"ProxyServerMediaSubsession\" for "
<< mss->protocolName() << "/" << mss->mediumName() << "/" << mss->codecName() << " track\n";
}
}
} while (0);
}
示例8: handDescription
//.........这里部分代码省略.........
fStartTime = 0.0f;
}
fEndTime= session->playEndTime();
if (fEndTime <= 0)
{
fEndTime = -1.0f;
}
{
/*send setup requesst count*/
iSetupCount = 0;
}
// Then, setup the "RTPSource"s for the session:
MediaSubsessionIterator iter(*(session));
MediaSubsession *subsession = NULL;
RtspReqSender *senderSave = pRtspReqSender->getNext();
if (senderSave == NULL)
{
LOG_ERR("error");
return false;
}
CmdSenderDecorator *senderMove = pRtspReqSender;
while ((subsession = iter.next()) != NULL)
{
if (!subsession->initiate(-1))
{
LOG_ERR("warning");
continue;
}
if (subsession->rtpSource() != NULL)
{
#if 0
// Because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// (1 second) for reordering misordered incoming packets:
unsigned const thresh = 1000000; // 1 second
subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);
#endif
#if 0
// Set the RTP source's OS socket buffer size as appropriate - either if we were explicitly asked (using -B),
// or if the desired FileSink buffer size happens to be larger than the current OS socket buffer size.
// (The latter case is a heuristic, on the assumption that if the user asked for a large FileSink buffer size,
// then the input data rate may be large enough to justify increasing the OS socket buffer size also.)
int socketNum = subsession->rtpSource()->RTPgs()->socketNum();
unsigned curBufferSize = getReceiveBufferSize(*env, socketNum);
LOG_DEBUG("old receive buffer size:%d", curBufferSize);
if (fileSinkBufferSize > curBufferSize)
{
unsigned newBufferSize = setReceiveBufferTo(*env, socketNum, fileSinkBufferSize);
LOG_DEBUG("new receive buffer size:%d", newBufferSize);
}
#else
int socketNum = subsession->rtpSource()->RTPgs()->socketNum();
unsigned newBufferSize = setReceiveBufferTo(*env, socketNum, maxBufSize);
LOG_DEBUG("new receive buffer size:%d", newBufferSize);
#endif
}
if (subsession->readSource() == NULL)
{
LOG_ERR("warning");
continue; // was not initiated
}
/*
*TO DO:SET UP SUBSESSION
*/
SetupSender *setupSender = new SetupSender(*senderSave);
if (setupSender == NULL)
{
LOG_ERR("warning");
continue;
}
sender->RecordSender(setupSender);
senderMove->setNext(setupSender);
senderMove = setupSender;
setupSender->setRspHandler(respHandler);
setupSender->setSubsession(subsession);
if (bUseTcp == true)
{
if (subsession->clientPortNum() != 0)
{
LOG_DEBUG("sub session %p using tcp port :%d!", subsession, subsession->clientPortNum());
setupSender->setParam(false, true, false);
}
}
iSetupCount++;
LOG_DEBUG("subsession, name:%s, codec:%s", subsession->mediumName(), subsession->codecName());
}
return true;
}
示例9: printQOSData
void printQOSData(int exitCode) {
*env << "begin_QOS_statistics\n";
// Print out stats for each active subsession:
qosMeasurementRecord* curQOSRecord = qosRecordHead;
if (session != NULL) {
MediaSubsessionIterator iter(*session);
MediaSubsession* subsession;
while ((subsession = iter.next()) != NULL) {
RTPSource* src = subsession->rtpSource();
if (src == NULL) continue;
*env << "subsession\t" << subsession->mediumName()
<< "/" << subsession->codecName() << "\n";
unsigned numPacketsReceived = 0, numPacketsExpected = 0;
if (curQOSRecord != NULL) {
numPacketsReceived = curQOSRecord->totNumPacketsReceived;
numPacketsExpected = curQOSRecord->totNumPacketsExpected;
}
*env << "num_packets_received\t" << numPacketsReceived << "\n";
*env << "num_packets_lost\t" << int(numPacketsExpected - numPacketsReceived) << "\n";
if (curQOSRecord != NULL) {
unsigned secsDiff = curQOSRecord->measurementEndTime.tv_sec
- curQOSRecord->measurementStartTime.tv_sec;
int usecsDiff = curQOSRecord->measurementEndTime.tv_usec
- curQOSRecord->measurementStartTime.tv_usec;
double measurementTime = secsDiff + usecsDiff/1000000.0;
*env << "elapsed_measurement_time\t" << measurementTime << "\n";
*env << "kBytes_received_total\t" << curQOSRecord->kBytesTotal << "\n";
*env << "measurement_sampling_interval_ms\t" << qosMeasurementIntervalMS << "\n";
if (curQOSRecord->kbits_per_second_max == 0) {
// special case: we didn't receive any data:
*env <<
"kbits_per_second_min\tunavailable\n"
"kbits_per_second_ave\tunavailable\n"
"kbits_per_second_max\tunavailable\n";
} else {
*env << "kbits_per_second_min\t" << curQOSRecord->kbits_per_second_min << "\n";
*env << "kbits_per_second_ave\t"
<< (measurementTime == 0.0 ? 0.0 : 8*curQOSRecord->kBytesTotal/measurementTime) << "\n";
*env << "kbits_per_second_max\t" << curQOSRecord->kbits_per_second_max << "\n";
}
*env << "packet_loss_percentage_min\t" << 100*curQOSRecord->packet_loss_fraction_min << "\n";
double packetLossFraction = numPacketsExpected == 0 ? 1.0
: 1.0 - numPacketsReceived/(double)numPacketsExpected;
if (packetLossFraction < 0.0) packetLossFraction = 0.0;
*env << "packet_loss_percentage_ave\t" << 100*packetLossFraction << "\n";
*env << "packet_loss_percentage_max\t"
<< (packetLossFraction == 1.0 ? 100.0 : 100*curQOSRecord->packet_loss_fraction_max) << "\n";
RTPReceptionStatsDB::Iterator statsIter(src->receptionStatsDB());
// Assume that there's only one SSRC source (usually the case):
RTPReceptionStats* stats = statsIter.next(True);
if (stats != NULL) {
*env << "inter_packet_gap_ms_min\t" << stats->minInterPacketGapUS()/1000.0 << "\n";
struct timeval totalGaps = stats->totalInterPacketGaps();
double totalGapsMS = totalGaps.tv_sec*1000.0 + totalGaps.tv_usec/1000.0;
unsigned totNumPacketsReceived = stats->totNumPacketsReceived();
*env << "inter_packet_gap_ms_ave\t"
<< (totNumPacketsReceived == 0 ? 0.0 : totalGapsMS/totNumPacketsReceived) << "\n";
*env << "inter_packet_gap_ms_max\t" << stats->maxInterPacketGapUS()/1000.0 << "\n";
}
curQOSRecord = curQOSRecord->fNext;
}
}
}
*env << "end_QOS_statistics\n";
delete qosRecordHead;
}
示例10: continueAfterDESCRIBE
void continueAfterDESCRIBE(RTSPClient*, int resultCode, char* resultString) {
if (resultCode != 0) {
*env << "Failed to get a SDP description from URL \"" << streamURL << "\": " << resultString << "\n";
shutdown();
}
char* sdpDescription = resultString;
*env << "Opened URL \"" << streamURL << "\", returning a SDP description:\n" << sdpDescription << "\n";
// Create a media session object from this SDP description:
session = MediaSession::createNew(*env, sdpDescription);
delete[] sdpDescription;
if (session == NULL) {
*env << "Failed to create a MediaSession object from the SDP description: " << env->getResultMsg() << "\n";
shutdown();
} else if (!session->hasSubsessions()) {
*env << "This session has no media subsessions (i.e., \"m=\" lines)\n";
shutdown();
}
// Then, setup the "RTPSource"s for the session:
MediaSubsessionIterator iter(*session);
MediaSubsession *subsession;
Boolean madeProgress = False;
char const* singleMediumToTest = singleMedium;
while ((subsession = iter.next()) != NULL) {
// If we've asked to receive only a single medium, then check this now:
if (singleMediumToTest != NULL) {
if (strcmp(subsession->mediumName(), singleMediumToTest) != 0) {
*env << "Ignoring \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession, because we've asked to receive a single " << singleMedium
<< " session only\n";
continue;
} else {
// Receive this subsession only
singleMediumToTest = "xxxxx";
// this hack ensures that we get only 1 subsession of this type
}
}
if (desiredPortNum != 0) {
subsession->setClientPortNum(desiredPortNum);
desiredPortNum += 2;
}
if (createReceivers) {
if (!subsession->initiate(simpleRTPoffsetArg)) {
*env << "Unable to create receiver for \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession: " << env->getResultMsg() << "\n";
} else {
*env << "Created receiver for \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession (client ports " << subsession->clientPortNum()
<< "-" << subsession->clientPortNum()+1 << ")\n";
madeProgress = True;
if (subsession->rtpSource() != NULL) {
// Because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// (1 second) for reordering misordered incoming packets:
unsigned const thresh = 1000000; // 1 second
subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);
// Set the RTP source's OS socket buffer size as appropriate - either if we were explicitly asked (using -B),
// or if the desired FileSink buffer size happens to be larger than the current OS socket buffer size.
// (The latter case is a heuristic, on the assumption that if the user asked for a large FileSink buffer size,
// then the input data rate may be large enough to justify increasing the OS socket buffer size also.)
int socketNum = subsession->rtpSource()->RTPgs()->socketNum();
unsigned curBufferSize = getReceiveBufferSize(*env, socketNum);
if (socketInputBufferSize > 0 || fileSinkBufferSize > curBufferSize) {
unsigned newBufferSize = socketInputBufferSize > 0 ? socketInputBufferSize : fileSinkBufferSize;
newBufferSize = setReceiveBufferTo(*env, socketNum, newBufferSize);
if (socketInputBufferSize > 0) { // The user explicitly asked for the new socket buffer size; announce it:
*env << "Changed socket receive buffer size for the \""
<< subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession from "
<< curBufferSize << " to "
<< newBufferSize << " bytes\n";
}
}
}
}
} else {
if (subsession->clientPortNum() == 0) {
*env << "No client port was specified for the \""
<< subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession. (Try adding the \"-p <portNum>\" option.)\n";
} else {
madeProgress = True;
}
}
}
if (!madeProgress) shutdown();
// Perform additional 'setup' on each subsession, before playing them:
setupStreams();
//.........这里部分代码省略.........
示例11: OpenConnection
int CMPIPTV_RTSP::OpenConnection(void)
{
this->logger.Log(LOGGER_INFO, METHOD_START_FORMAT, PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME);
this->isRtspSessionSetup = false;
// LIVE555 works with char, not with TCHAR
char *tempRtspUrl = ConvertToMultiByte(this->rtspUrl);
if (tempRtspUrl == NULL)
{
return STATUS_ERROR;
}
// start LIVE555 worker thread
this->rtspSchedulerThreadHandle = CreateThread(
NULL, // default security attributes
0, // use default stack size
&CMPIPTV_RTSP::RtspSchedulerWorker, // thread function name
this, // argument to thread function
0, // use default creation flags
&this->rtspSchedulerThreadId); // returns the thread identifier
if (this->rtspSchedulerThreadHandle == NULL)
{
this->logger.Log(LOGGER_ERROR, _T("%s: %s: failed to create RTSP scheduler thread, error = %i"), PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, GetLastError());
return STATUS_ERROR;
}
this->rtspClient = MPRTSPClient::createNew(this, *this->rtspEnvironment, tempRtspUrl);
FREE_MEM(tempRtspUrl);
if (
this->rtspClient == NULL ||
SendRtspCommand(METHOD_OPEN_CONNECTION_NAME, _T("OPTIONS")) != STATUS_OK ||
SendRtspCommand(METHOD_OPEN_CONNECTION_NAME, _T("DESCRIBE")) != STATUS_OK
)
{
CloseConnection();
return STATUS_ERROR;
}
this->rtspSession = MediaSession::createNew(*this->rtspEnvironment, this->rtspResponseResultString);
if (this->rtspSession == NULL || !this->rtspSession->hasSubsessions())
{
this->LogRtspMessage(LOGGER_ERROR, METHOD_OPEN_CONNECTION_NAME, this->rtspSession == NULL ? _T("failed to create session") : _T("session doesn't have sub-sessions"));
CloseConnection();
return STATUS_ERROR;
}
// Setup the RTP source for the session. Only one sub-session expected/supported.
MediaSubsessionIterator iter(*this->rtspSession);
MediaSubsession *subsession = NULL;
FramedSource *rtspSource = NULL;
while ((subsession = iter.next()) != NULL)
{
#ifdef _MBCS
TCHAR *subSessionName = ConvertToMultiByteA(subsession->mediumName());
TCHAR *subSessionCodecName = ConvertToMultiByteA(subsession->codecName());
#else
TCHAR *subSessionName = ConvertToUnicodeA(subsession->mediumName());
TCHAR *subSessionCodecName = ConvertToUnicodeA(subsession->codecName());
#endif
if (_tcsncicmp(subSessionName, _T("video"), 5) != 0 || _tcsncicmp(subSessionCodecName, _T("MP2T"), 4) != 0)
{
TCHAR *message = FormatString(_T("sub-session medium or codec not supported, medium = %s, codec = %s"), subSessionName, subSessionCodecName);
this->LogRtspMessage(LOGGER_ERROR, METHOD_OPEN_CONNECTION_NAME, message);
FREE_MEM(message);
FREE_MEM(subSessionName);
FREE_MEM(subSessionCodecName);
continue;
}
// If a client port is configured, find a free pair of ports in the range.
// The first port is used for RTP; the second port is used for RTCP. Once
// we find one free port, we assume the next one is also free.
if (this->rtspRtpClientPortRangeStart > 0)
{
struct in_addr destinationAddress;
destinationAddress.s_addr = our_inet_addr("127.0.0.1");
unsigned int port = this->rtspRtpClientPortRangeStart;
Groupsock *groupsock = NULL;
do
{
this->logger.Log(LOGGER_VERBOSE, _T("%s: %s: RTP client port %u"), PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, port);
// special construction force not reuse same UDP port
{
NoReuse noReuse(*this->rtspEnvironment);
groupsock = new Groupsock(*this->rtspEnvironment, destinationAddress, port, 1);
}
if (groupsock == NULL || groupsock->socketNum() == -1)
{
this->logger.Log(LOGGER_WARNING, _T("%s: %s: RTP client port %u occupied, trying next even port"), PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, port);
port += 2;
if (groupsock != NULL)
{
delete groupsock;
groupsock = NULL;
}
}
}
//.........这里部分代码省略.........
示例12: MediaNet_Thread
//.........这里部分代码省略.........
*env << "Opened URL \"" << pThis->m_strRTSPUrlA.c_str()
<< "\", returning a SDP description:\n" << sdpDescription << "\n";
// Create a media session object from this SDP description:
session = MediaSession::createNew(*env, sdpDescription);
delete[] sdpDescription;
if (session == NULL)
{
*env << "Failed to create a MediaSession object from the SDP description: " << env->getResultMsg() << "\n";
pThis->SetRtspStatus( RTSPStatus_Error_Connect_Srv );
break;
}
else if (!session->hasSubsessions())
{
*env << "This session has no media subsessions (i.e., \"m=\" lines)\n";
pThis->SetRtspStatus( RTSPStatus_Error_Connect_Srv );
break;
}
// Then, setup the "RTPSource"s for the session:
MediaSubsessionIterator iter(*session);
MediaSubsession *subsession;
Boolean madeProgress = False;
char const* singleMediumToTest = singleMedium;
while ((subsession = iter.next()) != NULL)
{
// If we've asked to receive only a single medium, then check this now:
if (singleMediumToTest != NULL)
{
if (strcmp(subsession->mediumName(), singleMediumToTest) != 0)
{
*env << "Ignoring \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession, because we've asked to receive a single " << singleMedium
<< " session only\n";
continue;
}
else
{
// Receive this subsession only
singleMediumToTest = "xxxxx";
// this hack ensures that we get only 1 subsession of this type
}
}
desiredPortNum = 0;
if (desiredPortNum != 0)
{
subsession->setClientPortNum(desiredPortNum);
desiredPortNum += 2;
}
if (true)
{
if (!subsession->initiate(simpleRTPoffsetArg))
{
*env << "Unable to create receiver for \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession: " << env->getResultMsg() << "\n";
}
else
{
*env << "Created receiver for \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession (client ports " << subsession->clientPortNum()
示例13: iter
extern "C" demuxer_t* demux_open_rtp(demuxer_t* demuxer) {
struct MPOpts *opts = demuxer->opts;
Boolean success = False;
do {
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
if (scheduler == NULL) break;
UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
if (env == NULL) break;
RTSPClient* rtspClient = NULL;
SIPClient* sipClient = NULL;
if (demuxer == NULL || demuxer->stream == NULL) break; // shouldn't happen
demuxer->stream->eof = 0; // just in case
// Look at the stream's 'priv' field to see if we were initiated
// via a SDP description:
char* sdpDescription = (char*)(demuxer->stream->priv);
if (sdpDescription == NULL) {
// We weren't given a SDP description directly, so assume that
// we were given a RTSP or SIP URL:
char const* protocol = demuxer->stream->streaming_ctrl->url->protocol;
char const* url = demuxer->stream->streaming_ctrl->url->url;
extern int verbose;
if (strcmp(protocol, "rtsp") == 0) {
rtspClient = RTSPClient::createNew(*env, verbose, "MPlayer");
if (rtspClient == NULL) {
fprintf(stderr, "Failed to create RTSP client: %s\n",
env->getResultMsg());
break;
}
sdpDescription = openURL_rtsp(rtspClient, url);
} else { // SIP
unsigned char desiredAudioType = 0; // PCMU (use 3 for GSM)
sipClient = SIPClient::createNew(*env, desiredAudioType, NULL,
verbose, "MPlayer");
if (sipClient == NULL) {
fprintf(stderr, "Failed to create SIP client: %s\n",
env->getResultMsg());
break;
}
sipClient->setClientStartPortNum(8000);
sdpDescription = openURL_sip(sipClient, url);
}
if (sdpDescription == NULL) {
fprintf(stderr, "Failed to get a SDP description from URL \"%s\": %s\n",
url, env->getResultMsg());
break;
}
}
// Now that we have a SDP description, create a MediaSession from it:
MediaSession* mediaSession = MediaSession::createNew(*env, sdpDescription);
if (mediaSession == NULL) break;
// Create a 'RTPState' structure containing the state that we just created,
// and store it in the demuxer's 'priv' field, for future reference:
RTPState* rtpState = new RTPState;
rtpState->sdpDescription = sdpDescription;
rtpState->rtspClient = rtspClient;
rtpState->sipClient = sipClient;
rtpState->mediaSession = mediaSession;
rtpState->audioBufferQueue = rtpState->videoBufferQueue = NULL;
rtpState->flags = 0;
rtpState->firstSyncTime.tv_sec = rtpState->firstSyncTime.tv_usec = 0;
demuxer->priv = rtpState;
int audiofound = 0, videofound = 0;
// Create RTP receivers (sources) for each subsession:
MediaSubsessionIterator iter(*mediaSession);
MediaSubsession* subsession;
unsigned desiredReceiveBufferSize;
while ((subsession = iter.next()) != NULL) {
// Ignore any subsession that's not audio or video:
if (strcmp(subsession->mediumName(), "audio") == 0) {
if (audiofound) {
fprintf(stderr, "Additional subsession \"audio/%s\" skipped\n", subsession->codecName());
continue;
}
desiredReceiveBufferSize = 100000;
} else if (strcmp(subsession->mediumName(), "video") == 0) {
if (videofound) {
fprintf(stderr, "Additional subsession \"video/%s\" skipped\n", subsession->codecName());
continue;
}
desiredReceiveBufferSize = 2000000;
} else {
continue;
}
if (rtsp_port)
subsession->setClientPortNum (rtsp_port);
if (!subsession->initiate()) {
fprintf(stderr, "Failed to initiate \"%s/%s\" RTP subsession: %s\n", subsession->mediumName(), subsession->codecName(), env->getResultMsg());
} else {
fprintf(stderr, "Initiated \"%s/%s\" RTP subsession on port %d\n", subsession->mediumName(), subsession->codecName(), subsession->clientPortNum());
//.........这里部分代码省略.........
示例14: OpenConnection
int CMPIPTV_RTSP::OpenConnection(void)
{
this->logger.Log(LOGGER_INFO, METHOD_START_FORMAT, PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME);
int result = STATUS_OK;
this->rtspClient = RTSPClient::createNew(*this->rtspEnvironment);
result |= (this->rtspClient == NULL);
if (result == STATUS_OK)
{
// RTSPClient works with char, not with TCHAR
char *tempRtspUrl = ConvertToMultiByte(this->rtspUrl);
result |= (tempRtspUrl == NULL);
if (result == STATUS_OK)
{
char* optionsResult = this->rtspClient->sendOptionsCmd(tempRtspUrl, NULL, NULL, NULL, this->receiveDataTimeout / 2000);
result |= (optionsResult == NULL);
if (result != STATUS_OK)
{
TCHAR *message = FormatString(METHOD_MESSAGE_FORMAT, PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, _T("error occured while sending OPTIONS command"));
this->LogRtspMessage(LOGGER_ERROR, message);
FREE_MEM(message);
}
else
{
TCHAR *message = FormatString(METHOD_MESSAGE_FORMAT, PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, _T("OPTIONS result"));
this->LogFullRtspMessage(LOGGER_VERBOSE, message, optionsResult);
FREE_MEM(message);
char *describeResult = this->rtspClient->describeURL(tempRtspUrl, NULL, FALSE, this->receiveDataTimeout / 2000);
result |= (describeResult == NULL);
if (result != STATUS_OK)
{
TCHAR *message = FormatString(METHOD_MESSAGE_FORMAT, PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, _T("error occured while sending DESCRIBE command"));
this->LogRtspMessage(LOGGER_ERROR, message);
FREE_MEM(message);
}
else
{
TCHAR *message = FormatString(METHOD_MESSAGE_FORMAT, PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, _T("DESCRIBE result"));
this->LogFullRtspMessage(LOGGER_VERBOSE, message, describeResult);
FREE_MEM(message);
this->rtspSession = MediaSession::createNew(*this->rtspEnvironment, describeResult);
result |= (this->rtspSession == NULL);
if (result != STATUS_OK)
{
TCHAR *message = FormatString(METHOD_MESSAGE_FORMAT, PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, _T("error occured while creating new session"));
this->LogRtspMessage(LOGGER_ERROR, message);
FREE_MEM(message);
}
else
{
result |= (!this->rtspSession->hasSubsessions());
if (result != STATUS_OK)
{
this->logger.Log(LOGGER_ERROR, METHOD_MESSAGE_FORMAT, PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, _T("session doesn't have subsessions"));
}
else
{
// Then, setup the "RTPSource"s for the session:
MediaSubsessionIterator iter(*this->rtspSession);
MediaSubsession *subsession = NULL;
while ((result == STATUS_OK) && ((subsession = iter.next()) != NULL))
{
char *tempSubSessionName = (char *)subsession->mediumName();
char *tempSubSessionCodecName = (char *)subsession->codecName();
#ifdef _MBCS
TCHAR *subSessionName = ConvertToMultiByteA(tempSubSessionName);
TCHAR *subSessionCodecName = ConvertToMultiByteA(tempSubSessionCodecName);
#else
TCHAR *subSessionName = ConvertToUnicodeA(tempSubSessionName);
TCHAR *subSessionCodecName = ConvertToUnicodeA(tempSubSessionCodecName);
#endif
if (!subsession->initiate())
{
result = STATUS_ERROR;
TCHAR *message = FormatString(_T("%s: %s: unable to create receiver for subsession '%s', codec '%s'"), PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, subSessionName, subSessionCodecName);
this->LogRtspMessage(LOGGER_ERROR, message);
FREE_MEM(message);
}
else
{
this->logger.Log(LOGGER_VERBOSE, _T("%s: %s: created receiver for subsession '%s', codec '%s'"), PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, subSessionName, subSessionCodecName);
// set session ID, doesn't matter what
subsession->sessionId = tempSubSessionName;
if (subsession->rtpSource() != NULL)
{
// because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// (1 second) for reordering misordered incoming packets:
unsigned const thresh = 1000000; // 1 second
subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);
//.........这里部分代码省略.........
示例15: main
//.........这里部分代码省略.........
= getSDPDescriptionFromURL(ourClient, url, username, password,
proxyServerName, proxyServerPortNum,
desiredPortNum);
if (sdpDescription == NULL) {
*env << "Failed to get a SDP description from URL \"" << url
<< "\": " << env->getResultMsg() << "\n";
shutdown();
}
*env << "Opened URL \"" << url
<< "\", returning a SDP description:\n" << sdpDescription << "\n";
// Create a media session object from this SDP description:
session = MediaSession::createNew(*env, sdpDescription);
delete[] sdpDescription;
if (session == NULL) {
*env << "Failed to create a MediaSession object from the SDP description: " << env->getResultMsg() << "\n";
shutdown();
} else if (!session->hasSubsessions()) {
*env << "This session has no media subsessions (i.e., \"m=\" lines)\n";
shutdown();
}
// Then, setup the "RTPSource"s for the session:
MediaSubsessionIterator iter(*session);
MediaSubsession *subsession;
Boolean madeProgress = False;
char const* singleMediumToTest = singleMedium;
while ((subsession = iter.next()) != NULL) {
// If we've asked to receive only a single medium, then check this now:
if (singleMediumToTest != NULL) {
if (strcmp(subsession->mediumName(), singleMediumToTest) != 0) {
*env << "Ignoring \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession, because we've asked to receive a single " << singleMedium
<< " session only\n";
continue;
} else {
// Receive this subsession only
singleMediumToTest = "xxxxx";
// this hack ensures that we get only 1 subsession of this type
}
}
if (desiredPortNum != 0) {
subsession->setClientPortNum(desiredPortNum);
desiredPortNum += 2;
}
if (createReceivers) {
if (!subsession->initiate(simpleRTPoffsetArg)) {
*env << "Unable to create receiver for \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession: " << env->getResultMsg() << "\n";
} else {
*env << "Created receiver for \"" << subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession (client ports " << subsession->clientPortNum()
<< "-" << subsession->clientPortNum()+1 << ")\n";
madeProgress = True;
if (subsession->rtpSource() != NULL) {
// Because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// (1 second) for reordering misordered incoming packets:
unsigned const thresh = 1000000; // 1 second