本文整理汇总了C++中MediaSubsession::rtpSource方法的典型用法代码示例。如果您正苦于以下问题:C++ MediaSubsession::rtpSource方法的具体用法?C++ MediaSubsession::rtpSource怎么用?C++ MediaSubsession::rtpSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MediaSubsession
的用法示例。
在下文中一共展示了MediaSubsession::rtpSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkInterPacketGaps
void checkInterPacketGaps(void* /*clientData*/) {
if (interPacketGapMaxTime == 0) return; // we're not checking
// Check each subsession, counting up how many packets have been received:
unsigned newTotNumPacketsReceived = 0;
MediaSubsessionIterator iter(*session);
MediaSubsession* subsession;
while ((subsession = iter.next()) != NULL) {
RTPSource* src = subsession->rtpSource();
if (src == NULL) continue;
newTotNumPacketsReceived += src->receptionStatsDB().totNumPacketsReceived();
}
if (newTotNumPacketsReceived == totNumPacketsReceived) {
// No additional packets have been received since the last time we
// checked, so end this stream:
*env << "Closing session, because we stopped receiving packets.\n";
interPacketGapCheckTimerTask = NULL;
sessionAfterPlaying();
} else {
totNumPacketsReceived = newTotNumPacketsReceived;
// Check again, after the specified delay:
interPacketGapCheckTimerTask
= env->taskScheduler().scheduleDelayedTask(interPacketGapMaxTime*1000000,
(TaskFunc*)checkInterPacketGaps, NULL);
}
}
示例2: beginQOSMeasurement
void beginQOSMeasurement() {
// Set up a measurement record for each active subsession:
struct timeval startTime;
gettimeofday(&startTime, NULL);
nextQOSMeasurementUSecs = startTime.tv_sec*1000000 + startTime.tv_usec;
qosMeasurementRecord* qosRecordTail = NULL;
MediaSubsessionIterator iter(*session);
MediaSubsession* subsession;
while ((subsession = iter.next()) != NULL) {
RTPSource* src = subsession->rtpSource();
#ifdef SUPPORT_REAL_RTSP
if (session->isRealNetworksRDT) src = (RTPSource*)(subsession->readSource()); // hack
#endif
if (src == NULL) continue;
qosMeasurementRecord* qosRecord
= new qosMeasurementRecord(startTime, src);
if (qosRecordHead == NULL) qosRecordHead = qosRecord;
if (qosRecordTail != NULL) qosRecordTail->fNext = qosRecord;
qosRecordTail = qosRecord;
}
// Then schedule the first of the periodic measurements:
scheduleNextQOSMeasurement();
}
示例3: checkForPacketArrival
void checkForPacketArrival(void* /*clientData*/) {
if (!notifyOnPacketArrival) return; // we're not checking
// Check each subsession, to see whether it has received data packets:
unsigned numSubsessionsChecked = 0;
unsigned numSubsessionsWithReceivedData = 0;
unsigned numSubsessionsThatHaveBeenSynced = 0;
MediaSubsessionIterator iter(*session);
MediaSubsession* subsession;
while ((subsession = iter.next()) != NULL)
{
RTPSource* src = subsession->rtpSource();
if (src == NULL) continue;
++numSubsessionsChecked;
if (src->receptionStatsDB().numActiveSourcesSinceLastReset() > 0)
{
// At least one data packet has arrived
++numSubsessionsWithReceivedData;
}
if (src->hasBeenSynchronizedUsingRTCP())
++numSubsessionsThatHaveBeenSynced;
}
unsigned numSubsessionsToCheck = numSubsessionsChecked;
// Special case for "QuickTimeFileSink"s and "AVIFileSink"s:
// They might not use all of the input sources:
if (qtOut != NULL)
numSubsessionsToCheck = qtOut->numActiveSubsessions();
else if (aviOut != NULL)
numSubsessionsToCheck = aviOut->numActiveSubsessions();
Boolean notifyTheUser;
if (!syncStreams)
notifyTheUser = numSubsessionsWithReceivedData > 0; // easy case
else
{
notifyTheUser = numSubsessionsWithReceivedData >= numSubsessionsToCheck
&& numSubsessionsThatHaveBeenSynced == numSubsessionsChecked;
// Note: A subsession with no active sources is considered to be synced
}
if (notifyTheUser)
{
struct timeval timeNow;
gettimeofday(&timeNow, NULL);
char timestampStr[100];
sprintf(timestampStr, "%ld%03ld", timeNow.tv_sec, (long)(timeNow.tv_usec/1000));
*env << (syncStreams ? "Synchronized d" : "D")
<< "ata packets have begun arriving [" << timestampStr << "]\007\n";
return;
}
// No luck, so reschedule this check again, after a delay:
int uSecsToDelay = 100000; // 100 ms
arrivalCheckTimerTask
= env->taskScheduler().scheduleDelayedTask(uSecsToDelay,
(TaskFunc*)checkForPacketArrival, NULL);
}
示例4: IsPacketArrived
bool MtkRTSPClient::IsPacketArrived()
{
MediaSubsessionIterator iter(*session);
MediaSubsession* subsession;
while ((subsession = iter.next()) != NULL)
{
RTPSource* src = subsession->rtpSource();
if (src == NULL)
continue;
if (src->receptionStatsDB().numActiveSourcesSinceLastReset() > 0)
{
return true;
}
}
return false;
}
示例5: beginQOSMeasurement
void beginQOSMeasurement(MediaSession *session, TaskToken qosMeasurementTimerTask, unsigned int qosMeasurementIntervalMS, UsageEnvironment *env) {
// Set up a measurement record for each active subsession:
struct timeval startTime;
gettimeofday(&startTime, NULL);
nextQOSMeasurementUSecs = startTime.tv_sec*1000000 + startTime.tv_usec;
qosMeasurementRecord* qosRecordTail = NULL;
MediaSubsessionIterator iter(*session);
MediaSubsession* subsession;
while ((subsession = iter.next()) != NULL) {
RTPSource* src = subsession->rtpSource();
if (src == NULL) continue;
qosMeasurementRecord* qosRecord
= new qosMeasurementRecord(startTime, src);
if (qosRecordHead == NULL) qosRecordHead = qosRecord;
if (qosRecordTail != NULL) qosRecordTail->fNext = qosRecord;
qosRecordTail = qosRecord;
}
// Then schedule the first of the periodic measurements:
scheduleNextQOSMeasurement(qosMeasurementTimerTask, qosMeasurementIntervalMS, env);
}
示例6: 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;
}
示例7: MediaNet_Thread
//.........这里部分代码省略.........
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()
<< "-" << 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);
if (socketInputBufferSize > 0)
{
// Set the RTP source's input buffer size as specified:
int socketNum
= subsession->rtpSource()->RTPgs()->socketNum();
unsigned curBufferSize
= getReceiveBufferSize(*env, socketNum);
unsigned newBufferSize
= setReceiveBufferTo(*env, socketNum, socketInputBufferSize);
*env << "Changed socket receive buffer size for the \""
<< subsession->mediumName()
<< "/" << subsession->codecName()
<< "\" subsession from "
<< curBufferSize << " to "
<< newBufferSize << " bytes\n";
}
}
}
}
else
{
mcu::tlog << _T( "Use port: " ) << (int)subsession->clientPortNum() << endl;
if (subsession->clientPortNum() == 0)
{
*env << "No client port was specified for the \""
示例8: iter
//.........这里部分代码省略.........
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());
// Set the OS's socket receive buffer sufficiently large to avoid
// incoming packets getting dropped between successive reads from this
// subsession's demuxer. Depending on the bitrate(s) that you expect,
// you may wish to tweak the "desiredReceiveBufferSize" values above.
int rtpSocketNum = subsession->rtpSource()->RTPgs()->socketNum();
int receiveBufferSize
= increaseReceiveBufferTo(*env, rtpSocketNum,
desiredReceiveBufferSize);
if (verbose > 0) {
fprintf(stderr, "Increased %s socket receive buffer to %d bytes \n",
subsession->mediumName(), receiveBufferSize);
}
if (rtspClient != NULL) {
// Issue a RTSP "SETUP" command on the chosen subsession:
if (!rtspClient->setupMediaSubsession(*subsession, False,
rtsp_transport_tcp)) break;
if (!strcmp(subsession->mediumName(), "audio"))
audiofound = 1;
if (!strcmp(subsession->mediumName(), "video"))
videofound = 1;
}
}
}
if (rtspClient != NULL) {
// Issue a RTSP aggregate "PLAY" command on the whole session:
if (!rtspClient->playMediaSession(*mediaSession)) break;
} else if (sipClient != NULL) {
sipClient->sendACK(); // to start the stream flowing
}
// Now that the session is ready to be read, do additional
// MPlayer codec-specific initialization on each subsession:
iter.reset();
while ((subsession = iter.next()) != NULL) {
if (subsession->readSource() == NULL) continue; // not reading this
unsigned flags = 0;
if (strcmp(subsession->mediumName(), "audio") == 0) {
rtpState->audioBufferQueue
= new ReadBufferQueue(subsession, demuxer, "audio");
rtpState->audioBufferQueue->otherQueue = &(rtpState->videoBufferQueue);
rtpCodecInitialize_audio(demuxer, subsession, flags);
} else if (strcmp(subsession->mediumName(), "video") == 0) {
rtpState->videoBufferQueue
= new ReadBufferQueue(subsession, demuxer, "video");
rtpState->videoBufferQueue->otherQueue = &(rtpState->audioBufferQueue);
rtpCodecInitialize_video(demuxer, subsession, flags);
}
rtpState->flags |= flags;
}
success = True;
} while (0);
if (!success) return NULL; // an error occurred
// Hack: If audio and video are demuxed together on a single RTP stream,
// then create a new "demuxer_t" structure to allow the higher-level
// code to recognize this:
if (demux_is_multiplexed_rtp_stream(demuxer)) {
stream_t* s = new_ds_stream(demuxer->video);
demuxer_t* od = demux_open(opts, s, DEMUXER_TYPE_UNKNOWN,
opts->audio_id, opts->video_id, opts->sub_id,
NULL);
demuxer = new_demuxers_demuxer(od, od, od);
}
return demuxer;
}
示例9: handDescription
bool MtkRTSPClient::handDescription(char* resultString)
{
CHECK_NULL_COND(resultString, false);
char* sdpDescription = resultString;
//LOG_DEBUG("SDP description:%s", sdpDescription);
// Create a media session object from this SDP description:
session = MediaSession::createNew(*env, sdpDescription);
if (session == NULL)
{
LOG_ERR("Failed to create a MediaSession object from the SDP description: %s", env->getResultMsg());
return false;
}
if (!session->hasSubsessions())
{
LOG_ERR("This session has no media subsessions (i.e., \"m=\" lines)");
Medium::close(session);
session = NULL;
return false;
}
/*
*TO DO:GET THE TIME RANGE
*/
fStartTime = session->playStartTime();
if (fStartTime < 0)
{
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
*/
//.........这里部分代码省略.........
示例10: 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);
//.........这里部分代码省略.........
示例11: OpenConnection
//.........这里部分代码省略.........
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;
}
}
}
while ((groupsock == NULL) && (port <= this->rtspRtpClientPortRangeEnd));
// Did we find a free port? If not, we fall back to a random port chosen
// by LIVE555.
if (groupsock != NULL)
{
delete groupsock;
groupsock = NULL;
subsession->setClientPortNum(port);
}
}
if (!subsession->initiate() || subsession->rtpSource() == NULL)
{
TCHAR *message = FormatString(_T("failed to create receiver for sub-session, 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;
}
this->logger.Log(LOGGER_VERBOSE, _T("%s: %s: created receiver for sub-session, medium = %s, codec = %s"), PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, subSessionName, subSessionCodecName);
FREE_MEM(subSessionName);
FREE_MEM(subSessionCodecName);
// set session ID, doesn't matter what
subsession->setSessionId(subsession->mediumName());
// because we're saving the incoming data, rather than playing
// it in real time, allow an especially large time threshold
// for reordering misordered incoming packets:
subsession->rtpSource()->setPacketReorderingThresholdTime(1000000); // 1 second
// set the RTP source's OS socket buffer size as appropriate
int socketNum = subsession->rtpSource()->RTPgs()->socketNum();
unsigned int currentBufferSize = getReceiveBufferSize(*this->rtspEnvironment, socketNum);
if (this->defaultBufferSize > currentBufferSize)
{
setReceiveBufferTo(*this->rtspEnvironment, socketNum, this->defaultBufferSize);
unsigned setBufferSize = getReceiveBufferSize(*this->rtspEnvironment, socketNum);
if (setBufferSize == this->defaultBufferSize)
{
this->logger.Log(LOGGER_VERBOSE, _T("%s: %s: set buffer size for sub-session, previous size = %i, requested size = %i, current size = %i"), PROTOCOL_IMPLEMENTATION_NAME, METHOD_OPEN_CONNECTION_NAME, subSessionName, currentBufferSize, this->defaultBufferSize, setBufferSize);
}
示例12: iter
Boolean MediaSession
::initiateByMediaType(char const* mimeType,
MediaSubsession*& resultSubsession,
PrioritizedRTPStreamSelector*& resultMultiSource,
int& resultMultiSourceSessionId,
int useSpecialRTPoffset) {
// Look through this session's subsessions for media that match "mimeType"
resultSubsession = NULL;
resultMultiSource = NULL;
resultMultiSourceSessionId = 0;
unsigned maxStaggerSeconds = 0;
MediaSubsessionIterator iter(*this);
MediaSubsession* subsession;
while ((subsession = iter.next()) != NULL) {
if (resultMultiSourceSessionId != 0
&& subsession->mctSLAPSessionId() != resultMultiSourceSessionId) {
// We're using a multi-source SLAP session, but this subsession
// isn't part of it
continue;
}
Boolean wasAlreadyInitiated = subsession->readSource() != NULL;
if (!wasAlreadyInitiated) {
// Try to create a source for this subsession:
if (!subsession->initiate(useSpecialRTPoffset)) return False;
}
// Make sure the source's MIME type is one that we handle:
if (strcmp(subsession->readSource()->MIMEtype(), mimeType) != 0) {
if (!wasAlreadyInitiated) subsession->deInitiate();
continue;
}
if (subsession->mctSLAPSessionId() == 0) {
// Normal case: a single session
resultSubsession = subsession;
break; // use this
} else {
// Special case: a multi-source SLAP session
resultMultiSourceSessionId = subsession->mctSLAPSessionId();
unsigned subsessionStaggerSeconds = subsession->mctSLAPStagger();
if (subsessionStaggerSeconds > maxStaggerSeconds) {
maxStaggerSeconds = subsessionStaggerSeconds;
}
}
}
if (resultSubsession == NULL && resultMultiSourceSessionId == 0) {
envir().setResultMsg("Session has no usable media subsession");
return False;
}
if (resultMultiSourceSessionId != 0) {
// We have a multi-source MCT SLAP session; create a selector for it:
unsigned seqNumStagger = computeSeqNumStagger(maxStaggerSeconds);
resultMultiSource
= PrioritizedRTPStreamSelector::createNew(envir(), seqNumStagger);
if (resultMultiSource == NULL) return False;
// Note: each subsession has its own RTCP instance; we don't return them
// Then run through the subsessions again, adding each of the sources:
iter.reset();
while ((subsession = iter.next()) != NULL) {
if (subsession->mctSLAPSessionId() == resultMultiSourceSessionId) {
resultMultiSource->addInputRTPStream(subsession->rtpSource(),
subsession->rtcpInstance());
}
}
}
return True;
}
示例13: main
//.........这里部分代码省略.........
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";
示例14: OpenStream
bool CRTSPClient::OpenStream(char* url)
{
XBMC->Log(LOG_DEBUG, "CRTSPClient::OpenStream()");
m_session=NULL;
strcpy(m_url,url);
// Open the URL, to get a SDP description:
char* sdpDescription= getSDPDescriptionFromURL(m_ourClient, url, ""/*username*/, ""/*password*/,""/*proxyServerName*/, 0/*proxyServerPortNum*/,1234/*desiredPortNum*/);
if (sdpDescription == NULL)
{
XBMC->Log(LOG_DEBUG, "Failed to get a SDP description from URL %s %s",url ,m_env->getResultMsg() );
shutdown();
return false;
}
XBMC->Log(LOG_DEBUG, "Opened URL %s %s",url,sdpDescription);
char* range=strstr(sdpDescription,"a=range:npt=");
if (range!=NULL)
{
char *pStart = range+strlen("a=range:npt=");
char *pEnd = strstr(range,"-") ;
if (pEnd!=NULL)
{
pEnd++ ;
double Start=atof(pStart) ;
double End=atof(pEnd) ;
XBMC->Log(LOG_DEBUG, "rangestart:%f rangeend:%f", Start,End);
m_duration=(long) ((End-Start)*1000.0);
}
}
// Create a media session object from this SDP description:
m_session = MediaSession::createNew(*m_env, sdpDescription);
delete[] sdpDescription;
if (m_session == NULL)
{
XBMC->Log(LOG_DEBUG, "Failed to create a MediaSession object from the SDP description:%s ",m_env->getResultMsg());
shutdown();
return false;
}
else if (!m_session->hasSubsessions())
{
XBMC->Log(LOG_DEBUG, "This session has no media subsessions");
shutdown();
return false;
}
// Then, setup the "RTPSource"s for the session:
MediaSubsessionIterator iter(*m_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)
{
XBMC->Log(LOG_DEBUG, "Ignoring %s %s %s" , subsession->mediumName(),subsession->codecName(),singleMedium);
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))
{
XBMC->Log(LOG_DEBUG, "Unable to create receiver for %s %s %s" ,subsession->mediumName(),subsession->codecName(),m_env->getResultMsg());
}
else
{
XBMC->Log(LOG_DEBUG, "Created receiver for type=%s codec=%s ports: %d %d " ,subsession->mediumName(),subsession->codecName(),subsession->clientPortNum(),subsession->clientPortNum()+1 );
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:
int socketNum= subsession->rtpSource()->RTPgs()->socketNum();
XBMC->Log(LOG_DEBUG, "rtsp:increaseReceiveBufferTo to 2000000 for s:%d",socketNum);
increaseReceiveBufferTo( *m_env, socketNum, 2000000 );
unsigned const thresh = 1000000; // 1 second
subsession->rtpSource()->setPacketReorderingThresholdTime(thresh);
if (socketInputBufferSize > 0)
//.........这里部分代码省略.........
示例15: 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();
//.........这里部分代码省略.........