MPEG2TransportStreamIndexFile ::MPEG2TransportStreamIndexFile(UsageEnvironment& env, char const* indexFileName) : Medium(env), fFileName(strDup(indexFileName)), fFid(NULL), fMPEGVersion(0), fCurrentIndexRecordNum(0), fCachedPCR(0.0f), fCachedTSPacketNumber(0), fNumIndexRecords(0) { // Get the file size, to determine how many index records it contains: u_int64_t indexFileSize = GetFileSize(indexFileName, NULL); if (indexFileSize % INDEX_RECORD_SIZE != 0) { env << "Warning: Size of the index file \"" << indexFileName << "\" (" << (unsigned)indexFileSize << ") is not a multiple of the index record size (" << INDEX_RECORD_SIZE << ")\n"; } fNumIndexRecords = (unsigned long)(indexFileSize/INDEX_RECORD_SIZE); }
ProxyRTSPClient::ProxyRTSPClient(ProxyServerMediaSession& ourServerMediaSession, char const* rtspURL, char const* username, char const* password, portNumBits tunnelOverHTTPPortNum, int verbosityLevel, int socketNumToServer) : RTSPClient(ourServerMediaSession.envir(), rtspURL, verbosityLevel, "ProxyRTSPClient", tunnelOverHTTPPortNum == (portNumBits)(~0) ? 0 : tunnelOverHTTPPortNum, socketNumToServer), fOurServerMediaSession(ourServerMediaSession), fOurURL(strDup(rtspURL)), fStreamRTPOverTCP(tunnelOverHTTPPortNum != 0), fSetupQueueHead(NULL), fSetupQueueTail(NULL), fNumSetupsDone(0), fNextDESCRIBEDelay(1), fServerSupportsGetParameter(False), fLastCommandWasPLAY(False), fResetOnNextLivenessTest(False), fLivenessCommandTask(NULL), fDESCRIBECommandTask(NULL), fSubsessionTimerTask(NULL) { if (username != NULL && password != NULL) { fOurAuthenticator = new Authenticator(username, password); } else { fOurAuthenticator = NULL; } }
void SIPClient::reset() { fWorkingAuthenticator = NULL; delete[] fInviteCmd; fInviteCmd = NULL; fInviteCmdSize = 0; delete[] fInviteSDPDescription; fInviteSDPDescription = NULL; delete[] (char*)fUserName; fUserName = strDup(fApplicationName); fUserNameSize = strlen(fUserName); fValidAuthenticator.reset(); delete[] (char*)fToTagStr; fToTagStr = NULL; fToTagStrSize = 0; fServerPortNum = 0; fServerAddress.s_addr = 0; delete[] (char*)fURL; fURL = NULL; fURLSize = 0; }
void OnDemandServerMediaSubsession ::setSDPLinesFromRTPSink(RTPSink* rtpSink, FramedSource* inputSource, unsigned estBitrate) { if (rtpSink == NULL) return; char const* mediaType = rtpSink->sdpMediaType(); unsigned char rtpPayloadType = rtpSink->rtpPayloadType(); AddressString ipAddressStr(fServerAddressForSDP); char* rtpmapLine = rtpSink->rtpmapLine(); char const* rtcpmuxLine = fMultiplexRTCPWithRTP ? "a=rtcp-mux\r\n" : ""; char const* rangeLine = rangeSDPLine(); char const* auxSDPLine = getAuxSDPLine(rtpSink, inputSource); if (auxSDPLine == NULL) auxSDPLine = ""; char const* const sdpFmt = "m=%s %u RTP/AVP %d\r\n" "c=IN IP4 %s\r\n" "b=AS:%u\r\n" "%s" "%s" "%s" "%s" "a=control:%s\r\n"; unsigned sdpFmtSize = strlen(sdpFmt) + strlen(mediaType) + 5 /* max short len */ + 3 /* max char len */ + strlen(ipAddressStr.val()) + 20 /* max int len */ + strlen(rtpmapLine) + strlen(rtcpmuxLine) + strlen(rangeLine) + strlen(auxSDPLine) + strlen(trackId()); char* sdpLines = new char[sdpFmtSize]; sprintf(sdpLines, sdpFmt, mediaType, // m= <media> fPortNumForSDP, // m= <port> rtpPayloadType, // m= <fmt list> ipAddressStr.val(), // c= address estBitrate, // b=AS:<bandwidth> rtpmapLine, // a=rtpmap:... (if present) rtcpmuxLine, // a=rtcp-mux:... (if present) rangeLine, // a=range:... (if present) auxSDPLine, // optional extra SDP line trackId()); // a=control:<track-id> delete[] (char*)rangeLine; delete[] rtpmapLine; fSDPLines = strDup(sdpLines); delete[] sdpLines; }
SimpleRTPSink::SimpleRTPSink(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat, unsigned rtpTimestampFrequency, char const* sdpMediaTypeString, char const* rtpPayloadFormatName, unsigned numChannels, Boolean allowMultipleFramesPerPacket, Boolean doNormalMBitRule) : MultiFramedRTPSink(env, RTPgs, rtpPayloadFormat, rtpTimestampFrequency, rtpPayloadFormatName, numChannels), fAllowMultipleFramesPerPacket(allowMultipleFramesPerPacket) { fSDPMediaTypeString = strDup(sdpMediaTypeString == NULL ? "unknown" : sdpMediaTypeString); fSetMBitOnLastFrames = doNormalMBitRule && strcmp(fSDPMediaTypeString, "audio") != 0; }
/** Singleton constructor */ H264VideoSink::H264VideoSink(UsageEnvironment& env, MediaSubsession& subsession, char const* streamId): MyVideoSink(env), m_fSubsession(subsession) { TRACE_INFO("Video sink constructor"); m_fStreamId = strDup(streamId); //m_bufferSize=253440;//2*DUMMY_SINK_RECEIVE_BUFFER_SIZE; //m_fPos = 0; uint8_t startCode[] = {0x00, 0x00,0x01}; //m_buffer = new unsigned char[m_bufferSize]; //m_frameQueue=new CMediaQueue(200); m_decoder=new CVideoDecoder("H264"); AddData(startCode, sizeof(startCode)); //InitializeCriticalSection(&m_criticalSection); //m_ready=1; }
AudioPortNames* AudioInputDevice::getPortNames() { WindowsAudioInputDevice::initializeIfNecessary(); AudioPortNames* portNames = new AudioPortNames; portNames->numPorts = WindowsAudioInputDevice::numInputPortsTotal; portNames->portName = new char*[WindowsAudioInputDevice::numInputPortsTotal]; // If there's more than one mixer, print only the port name. // If there's two or more mixers, also include the mixer name // (to disambiguate port names that may be the same name in different mixers) char portNameBuffer[2*MAXPNAMELEN+10/*slop*/]; char mixerNameBuffer[MAXPNAMELEN]; char const* portNameFmt; if (WindowsAudioInputDevice::numMixers <= 1) { portNameFmt = "%s"; } else { portNameFmt = "%s (%s)"; } unsigned curPortNum = 0; for (unsigned i = 0; i < WindowsAudioInputDevice::numMixers; ++i) { Mixer& mixer = WindowsAudioInputDevice::ourMixers[i]; if (WindowsAudioInputDevice::numMixers <= 1) { mixerNameBuffer[0] = '\0'; } else { strncpy(mixerNameBuffer, mixer.name, sizeof mixerNameBuffer); #if 0 // Hack: Simplify the mixer name, by truncating after the first space character: for (int k = 0; k < sizeof mixerNameBuffer && mixerNameBuffer[k] != '\0'; ++k) { if (mixerNameBuffer[k] == ' ') { mixerNameBuffer[k] = '\0'; break; } } #endif } for (unsigned j = 0; j < mixer.numPorts; ++j) { sprintf(portNameBuffer, portNameFmt, mixer.ports[j].name, mixerNameBuffer); portNames->portName[curPortNum++] = strDup(portNameBuffer); } } return portNames; }
Boolean RTSPServerWithREGISTERProxying ::weImplementREGISTER(char const* cmd/*"REGISTER" or "DEREGISTER"*/, char const* proxyURLSuffix, char*& responseStr) { // First, check whether we have already proxied a stream as "proxyURLSuffix": if (proxyURLSuffix != NULL) { ServerMediaSession* sms = lookupServerMediaSession(proxyURLSuffix); if ((strcmp(cmd, "REGISTER") == 0 && sms != NULL) || (strcmp(cmd, "DEREGISTER") == 0 && sms == NULL)) { responseStr = strDup("451 Invalid parameter"); return False; } } // Otherwise, we will implement it: responseStr = NULL; return True; }
Boolean MediaSession::parseSDPAttribute_type(char const* sdpLine) { // Check for a "a=type:broadcast|meeting|moderated|test|H.332|recvonly" line: Boolean parseSuccess = False; char *resultStr = NULL; char* buffer = strDupSize(sdpLine); if (sscanf(sdpLine, "a=type: %[^ ]", buffer) == 1) { resultStr = strDup(buffer); if (resultStr != NULL) { delete[] fMediaSessionType; fMediaSessionType = resultStr; } parseSuccess = True; } delete[] buffer; return parseSuccess; }
Boolean Groupsock::output(UsageEnvironment& env, unsigned char* buffer, unsigned bufferSize, DirectedNetInterface* interfaceNotToFwdBackTo) { do { // First, do the datagram send, to each destination: Boolean writeSuccess = True; for (destRecord* dests = fDests; dests != NULL; dests = dests->fNext) { if (!write(dests->fGroupEId.groupAddress().s_addr, dests->fGroupEId.portNum(), dests->fGroupEId.ttl(), buffer, bufferSize)) { writeSuccess = False; break; } } if (!writeSuccess) break; statsOutgoing.countPacket(bufferSize); statsGroupOutgoing.countPacket(bufferSize); // Then, forward to our members: int numMembers = 0; if (!members().IsEmpty()) { numMembers = outputToAllMembersExcept(interfaceNotToFwdBackTo, ttl(), buffer, bufferSize, ourIPAddress(env)); if (numMembers < 0) break; } if (DebugLevel >= 3) { env << *this << ": wrote " << bufferSize << " bytes, ttl " << (unsigned)ttl(); if (numMembers > 0) { env << "; relayed to " << numMembers << " members"; } env << "\n"; } return True; } while (0); if (DebugLevel >= 0) { // this is a fatal error UsageEnvironment::MsgString msg = strDup(env.getResultMsg()); env.setResultMsg("Groupsock write failed: ", msg); delete[] (char*)msg; } return False; }
void QueueServerMediaSubsession::checkForAuxSDPLine1() { char const* dasl; if (fAuxSDPLine != NULL) { // Signal the event loop that we're done: setDoneFlag(); } else if (fDummyRTPSink != NULL && (dasl = fDummyRTPSink->auxSDPLine()) != NULL) { fAuxSDPLine = strDup(dasl); fDummyRTPSink = NULL; // Signal the event loop that we're done: setDoneFlag(); } else { // try again after a brief delay: int uSecsToDelay = 100000; // 100 ms nextTask() = envir().taskScheduler().scheduleDelayedTask( uSecsToDelay,(TaskFunc*)checkForAuxSDPLine, this); } }
OggFile::OggFile(UsageEnvironment& env, char const* fileName, onCreationFunc* onCreation, void* onCreationClientData) : Medium(env), fFileName(strDup(fileName)), fOnCreation(onCreation), fOnCreationClientData(onCreationClientData) { fTrackTable = new OggTrackTable; fDemuxesTable = HashTable::create(ONE_WORD_HASH_KEYS); FramedSource* inputSource = ByteStreamFileSource::createNew(envir(), fileName); if (inputSource == NULL) { // The specified input file does not exist! fParserForInitialization = NULL; handleEndOfBosPageParsing(); // we have no file, and thus no tracks, but we still need to signal this } else { // Initialize ourselves by parsing the file's headers: fParserForInitialization = new OggFileParser(*this, inputSource, handleEndOfBosPageParsing, this); } }
char const* H264MediaSubsession::sdpLines() { if (fSDPLines == NULL) { AddressString ipAddressStr(fServerAddressForSDP); const char* rtpmapLine = "a=rtpmap:96 H264/90000\r\n"; char const* rangeLine = rangeSDPLine(); char const* const sdpFmt = "m=%s %u RTP/AVP %d\r\n" "c=IN IP4 %s\r\n" "b=AS:%u\r\n" "%s" "%s" "%s" "a=control:%s\r\n"; unsigned sdpFmtSize = strlen(sdpFmt) + strlen(mediaType) + 5 /* max short len */ + 3 /* max char len */ + strlen(ipAddressStr.val()) + 20 /* max int len */ + strlen(rtpmapLine) + strlen(rangeLine) + strlen(auxSDPLine()) + strlen(trackId()); char* sdpLines = new char[sdpFmtSize]; sprintf(sdpLines, sdpFmt, mediaType, // m= <media> fPortNumForSDP, // m= <port> rtpPayloadType, // m= <fmt list> ipAddressStr.val(), // c= address m_Watcher->GetVideoBitrate(), // b=AS:<bandwidth> rtpmapLine, // a=rtpmap:... (if present) rangeLine, // a=range:... (if present) auxSDPLine(), // optional extra SDP line trackId()); // a=control:<track-id> delete[] (char*)rangeLine; fSDPLines = strDup(sdpLines); delete[] sdpLines; } return fSDPLines; }
char* SIPClient::invite(char const* url, Authenticator* authenticator) { // First, check whether "url" contains a username:password to be used: char* username; char* password; if (authenticator == NULL && parseSIPURLUsernamePassword(url, username, password)) { char* result = inviteWithPassword(url, username, password); delete[] username; delete[] password; // they were dynamically allocated return result; } if (!processURL(url)) return NULL; delete[] (char*)fURL; fURL = strDup(url); fURLSize = strlen(fURL); fCallId = our_random32(); fFromTag = our_random32(); return invite1(authenticator); }
node* process(node* root, char *word ) { int c; if(root==NULL) { root=(node*)malloc(sizeof(node)); root->str=strDup(root->str,word); root->count=1; root->left=NULL; root->right=NULL; } else if((c=strcmp(root->str,word)) < 0) root->right=process(root->right,word); else if(c > 0) root->left=process(root->left,word); else root->count++; return root; }
void BasicHashTable::assignKey(TableEntry *entry, char const *key) { // The way we assign the key depends upon its type: if (fKeyType == STRING_HASH_KEYS) { entry->key = strDup(key); } else if (fKeyType == ONE_WORD_HASH_KEYS) { entry->key = key; } else if (fKeyType > 0) { unsigned *keyFrom = (unsigned *)key; unsigned *keyTo = new unsigned[fKeyType]; for (int i = 0; i < fKeyType; ++i) keyTo[i] = keyFrom[i]; entry->key = (char const *)keyTo; } }
Locale::Locale(char const* newLocale, LocaleCategory category) { #ifndef LOCALE_NOT_USED #ifndef XLOCALE_NOT_USED int categoryMask; switch (category) { case All: { categoryMask = LC_ALL_MASK; break; } case Numeric: { categoryMask = LC_NUMERIC_MASK; break; } } fLocale = newlocale(categoryMask, newLocale, NULL); fPrevLocale = uselocale(fLocale); #else switch (category) { case All: { fCategoryNum = LC_ALL; break; } case Numeric: { fCategoryNum = LC_NUMERIC; break; } } fPrevLocale = strDup(setlocale(fCategoryNum, NULL)); setlocale(fCategoryNum, newLocale); #endif #endif }
MediaSession::MediaSession(UsageEnvironment& env) : Medium(env), fSubsessionsHead(NULL), fSubsessionsTail(NULL), fConnectionEndpointName(NULL), fMaxPlayStartTime(0.0f), fMaxPlayEndTime(0.0f), fScale(1.0f), fMediaSessionType(NULL), fSessionName(NULL), fSessionDescription(NULL), fControlPath(NULL) { fSourceFilterAddr.s_addr = 0; // Get our host name, and use this for the RTCP CNAME: const unsigned maxCNAMElen = 100; char CNAME[maxCNAMElen+1]; #ifndef CRIS gethostname((char*)CNAME, maxCNAMElen); #else // "gethostname()" isn't defined for this platform sprintf(CNAME, "unknown host %d", (unsigned)(our_random()*0x7FFFFFFF)); #endif CNAME[maxCNAMElen] = '\0'; // just in case fCNAME = strDup(CNAME); }
Boolean RTSPRegisterSender::setRequestFields(RequestRecord* request, char*& cmdURL, Boolean& cmdURLWasAllocated, char const*& protocolStr, char*& extraHeaders, Boolean& extraHeadersWereAllocated) { if (strcmp(request->commandName(), "REGISTER") == 0) { RequestRecord_REGISTER* request_REGISTER = (RequestRecord_REGISTER*) request; setBaseURL(request_REGISTER->rtspURLToRegister()); cmdURL = (char*)url(); cmdURLWasAllocated = False; // Generate the "Transport:" header that will contain our REGISTER-specific parameters. This will be "extraHeaders". // First, generate the "proxy_url_suffix" parameter string, if any: char* proxyURLSuffixParameterStr; if (request_REGISTER->proxyURLSuffix() == NULL) { proxyURLSuffixParameterStr = strDup(""); } else { char const* proxyURLSuffixParameterFmt = "; proxy_url_suffix=%s"; unsigned proxyURLSuffixParameterSize = strlen(proxyURLSuffixParameterFmt) + strlen(request_REGISTER->proxyURLSuffix()); proxyURLSuffixParameterStr = new char[proxyURLSuffixParameterSize]; sprintf(proxyURLSuffixParameterStr, proxyURLSuffixParameterFmt, request_REGISTER->proxyURLSuffix()); } char const* transportHeaderFmt = "Transport: %spreferred_delivery_protocol=%s%s\r\n"; unsigned transportHeaderSize = strlen(transportHeaderFmt) + 100/*conservative*/ + strlen(proxyURLSuffixParameterStr); char* transportHeaderStr = new char[transportHeaderSize]; sprintf(transportHeaderStr, transportHeaderFmt, request_REGISTER->reuseConnection() ? "reuse_connection; " : "", request_REGISTER->requestStreamingViaTCP() ? "interleaved" : "udp", proxyURLSuffixParameterStr); delete[] proxyURLSuffixParameterStr; extraHeaders = transportHeaderStr; extraHeadersWereAllocated = True; return True; } else { return RTSPClient::setRequestFields(request, cmdURL, cmdURLWasAllocated, protocolStr, extraHeaders, extraHeadersWereAllocated); } }
char const* MPEG4ESVideoRTPSink::auxSDPLine() { // Generate a new "a=fmtp:" line each time, using our own 'configuration' information (if we have it), // otherwise parameters from our framer source (in case they've changed since the last time that // we were called): unsigned configLength = fNumConfigBytes; unsigned char* config = fConfigBytes; if (fProfileAndLevelIndication == 0 || config == NULL) { // We need to get this information from our framer source: MPEG4VideoStreamFramer* framerSource = (MPEG4VideoStreamFramer*)fSource; if (framerSource == NULL) return NULL; // we don't yet have a source fProfileAndLevelIndication = framerSource->profile_and_level_indication(); if (fProfileAndLevelIndication == 0) return NULL; // our source isn't ready config = framerSource->getConfigBytes(configLength); if (config == NULL) return NULL; // our source isn't ready } char const* fmtpFmt = "a=fmtp:%d " "profile-level-id=%d;" "config="; unsigned fmtpFmtSize = strlen(fmtpFmt) + 3 /* max char len */ + 3 /* max char len */ + 2*configLength /* 2*, because each byte prints as 2 chars */ + 2 /* trailing \r\n */; char* fmtp = new char[fmtpFmtSize]; sprintf(fmtp, fmtpFmt, rtpPayloadType(), fProfileAndLevelIndication); char* endPtr = &fmtp[strlen(fmtp)]; for (unsigned i = 0; i < configLength; ++i) { sprintf(endPtr, "%02X", config[i]); endPtr += 2; } sprintf(endPtr, "\r\n"); delete[] fFmtpSDPLine; fFmtpSDPLine = strDup(fmtp); delete[] fmtp; return fFmtpSDPLine; }
RTPSink::RTPSink(UsageEnvironment& env, Groupsock* rtpGS, unsigned char rtpPayloadType, unsigned rtpTimestampFrequency, char const* rtpPayloadFormatName, unsigned numChannels) : MediaSink(env), fRTPInterface(this, rtpGS), fRTPPayloadType(rtpPayloadType), fPacketCount(0), fOctetCount(0), fTotalOctetCount(0), fTimestampFrequency(rtpTimestampFrequency), fNextTimestampHasBeenPreset(True), fNumChannels(numChannels) { fRTPPayloadFormatName = strDup(rtpPayloadFormatName == NULL ? "???" : rtpPayloadFormatName); gettimeofday(&fCreationTime, NULL); fTotalOctetCountStartTime = fCreationTime; fSeqNo = (u_int16_t)our_random(); fSSRC = our_random32(); fTimestampBase = our_random32(); fTransmissionStatsDB = new RTPTransmissionStatsDB(*this); }
// A special version of "parseTransportHeader()", used just for parsing the "Transport:" header in an incoming "REGISTER" command: void parseTransportHeaderForREGISTER(char const* buf, Boolean &reuseConnection, Boolean& deliverViaTCP, char*& proxyURLSuffix) { // Initialize the result parameters to default values: reuseConnection = False; deliverViaTCP = False; proxyURLSuffix = NULL; // First, find "Transport:" while (1) { if (*buf == '\0') return; // not found if (*buf == '\r' && *(buf+1) == '\n' && *(buf+2) == '\r') return; // end of the headers => not found if (_strncasecmp(buf, "Transport:", 10) == 0) break; ++buf; } // Then, run through each of the fields, looking for ones we handle: char const* fields = buf + 10; while (*fields == ' ') ++fields; char* field = strDupSize(fields); while (sscanf(fields, "%[^;\r\n]", field) == 1) { if (strcmp(field, "reuse_connection") == 0) { reuseConnection = True; } else if (_strncasecmp(field, "preferred_delivery_protocol=udp", 31) == 0) { deliverViaTCP = False; } else if (_strncasecmp(field, "preferred_delivery_protocol=interleaved", 39) == 0) { deliverViaTCP = True; } else if (_strncasecmp(field, "proxy_url_suffix=", 17) == 0) { delete[] proxyURLSuffix; proxyURLSuffix = strDup(field+17); } fields += strlen(field); while (*fields == ';' || *fields == ' ' || *fields == '\t') ++fields; // skip over separating ';' chars or whitespace if (*fields == '\0' || *fields == '\r' || *fields == '\n') break; } delete[] field; }
Boolean RTSPDeregisterSender::setRequestFields(RequestRecord* request, char*& cmdURL, Boolean& cmdURLWasAllocated, char const*& protocolStr, char*& extraHeaders, Boolean& extraHeadersWereAllocated) { if (strcmp(request->commandName(), "DEREGISTER") == 0) { RequestRecord_DEREGISTER* request_DEREGISTER = (RequestRecord_DEREGISTER*)request; setBaseURL(request_DEREGISTER->rtspURLToDeregister()); cmdURL = (char*)url(); cmdURLWasAllocated = False; // Generate the "Transport:" header that will contain our DEREGISTER-specific parameters. This will be "extraHeaders". // First, generate the "proxy_url_suffix" parameter string, if any: char* proxyURLSuffixParameterStr; if (request_DEREGISTER->proxyURLSuffix() == NULL) { proxyURLSuffixParameterStr = strDup(""); } else { char const* proxyURLSuffixParameterFmt = "proxy_url_suffix=%s"; unsigned proxyURLSuffixParameterSize = strlen(proxyURLSuffixParameterFmt) + strlen(request_DEREGISTER->proxyURLSuffix()); proxyURLSuffixParameterStr = new char[proxyURLSuffixParameterSize]; sprintf(proxyURLSuffixParameterStr, proxyURLSuffixParameterFmt, request_DEREGISTER->proxyURLSuffix()); } char const* transportHeaderFmt = "Transport: %s\r\n"; unsigned transportHeaderSize = strlen(transportHeaderFmt) + strlen(proxyURLSuffixParameterStr); char* transportHeaderStr = new char[transportHeaderSize]; sprintf(transportHeaderStr, transportHeaderFmt, proxyURLSuffixParameterStr); delete[] proxyURLSuffixParameterStr; extraHeaders = transportHeaderStr; extraHeadersWereAllocated = True; return True; } else { return RTSPClient::setRequestFields(request, cmdURL, cmdURLWasAllocated, protocolStr, extraHeaders, extraHeadersWereAllocated); } }
/*! Creates a new expression struct with the given type @param type the type of data to be stored in the expression @return the new expression struct */ inline expression* newExpressionOfType (datatype type) { exprvals ev; switch(type) { case TYPE_NIL: break; case TYPE_EXP: ev.expval = NULL; break; case TYPE_LAZ: ev.lazval = newLazyExpression(); break; case TYPE_INT: ev.intval = 0; break; case TYPE_FLO: ev.floval = 0; break; case TYPE_STR: ev.strval = newString(strDup("")); break; case TYPE_ARR: ev.arrval = newArray(0); break; case TYPE_DAT: ev.datval = time(NULL); break; case TYPE_OBJ: // TODO break; case TYPE_FUN: ev.funval = newTapFunction(NULL, 0, 0, newExpressionNil()); break; case TYPE_TYP: ev.intval = TYPE_UNK; break; } return newExpressionAll(type, &ev, NULL, 0); // set the value to null until a real value is given and set the next expression to null }
char const* MPEG4ESVideoRTPSink::auxSDPLine() { // Generate a new "a=fmtp:" line each time, using parameters from // our framer source (in case they've changed since the last time that // we were called): MPEG4VideoStreamFramer* framerSource = (MPEG4VideoStreamFramer*)fSource; if (framerSource == NULL) return NULL; // we don't yet have a source u_int8_t profile_level_id = framerSource->profile_and_level_indication(); if (profile_level_id == 0) return NULL; // our source isn't ready unsigned configLength; unsigned char* config = framerSource->getConfigBytes(configLength); if (config == NULL) return NULL; // our source isn't ready char const* fmtpFmt = "a=fmtp:%d " "profile-level-id=%d;" "config="; unsigned fmtpFmtSize = strlen(fmtpFmt) + 3 /* max char len */ + 3 /* max char len */ + 2*configLength /* 2*, because each byte prints as 2 chars */ + 2 /* trailing \r\n */; char* fmtp = new char[fmtpFmtSize]; sprintf(fmtp, fmtpFmt, rtpPayloadType(), profile_level_id); char* endPtr = &fmtp[strlen(fmtp)]; for (unsigned i = 0; i < configLength; ++i) { sprintf(endPtr, "%02X", config[i]); endPtr += 2; } sprintf(endPtr, "\r\n"); delete[] fAuxSDPLine; fAuxSDPLine = strDup(fmtp); delete[] fmtp; return fAuxSDPLine; }
H264VideoRTPSink ::H264VideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs, unsigned char rtpPayloadFormat, unsigned profile_level_id, char const* sprop_parameter_sets_str) : VideoRTPSink(env, RTPgs, rtpPayloadFormat, 90000, "H264"), fOurFragmenter(NULL) { // Set up the "a=fmtp:" SDP line for this stream: char const* fmtpFmt = "a=fmtp:%d packetization-mode=1" ";profile-level-id=%06X" ";sprop-parameter-sets=%s\r\n"; unsigned fmtpFmtSize = strlen(fmtpFmt) + 3 /* max char len */ + 8 /* max unsigned len in hex */ + strlen(sprop_parameter_sets_str); char* fmtp = new char[fmtpFmtSize]; sprintf(fmtp, fmtpFmt, rtpPayloadFormat, profile_level_id, sprop_parameter_sets_str); fFmtpSDPLine = strDup(fmtp); delete[] fmtp; }
char* RTSPServer::rtspURLPrefix(int clientSocket) const { struct sockaddr_in ourAddress; if (clientSocket < 0) { // Use our default IP address in the URL: ourAddress.sin_addr.s_addr = ReceivingInterfaceAddr != 0 ? ReceivingInterfaceAddr : ourIPAddress(envir()); // hack } else { SOCKLEN_T namelen = sizeof ourAddress; getsockname(clientSocket, (struct sockaddr*)&ourAddress, &namelen); } char urlBuffer[100]; // more than big enough for "rtsp://<ip-address>:<port>/" portNumBits portNumHostOrder = ntohs(fServerPort.num()); if (portNumHostOrder == 554 /* the default port number */) { sprintf(urlBuffer, "rtsp://%s/", our_inet_ntoa(ourAddress.sin_addr)); } else { sprintf(urlBuffer, "rtsp://%s:%hu/", our_inet_ntoa(ourAddress.sin_addr), portNumHostOrder); } return strDup(urlBuffer); }
Boolean MediaSubsession::parseSDPAttribute_rtpmap(char const* sdpLine) { // Check for a "a=rtpmap:<fmt> <codec>/<freq>" line: // (Also check without the "/<freq>"; RealNetworks omits this) // Also check for a trailing "/<numChannels>". Boolean parseSuccess = False; // 获取编码类型和时钟频率. unsigned rtpmapPayloadFormat; char* codecName = strDupSize(sdpLine); // ensures we have enough space unsigned rtpTimestampFrequency = 0; unsigned numChannels = 1; if (sscanf(sdpLine, "a=rtpmap: %u %[^/]/%u/%u", &rtpmapPayloadFormat, codecName, &rtpTimestampFrequency, &numChannels) == 4 || sscanf(sdpLine, "a=rtpmap: %u %[^/]/%u", &rtpmapPayloadFormat, codecName, &rtpTimestampFrequency) == 3 || sscanf(sdpLine, "a=rtpmap: %u %s", &rtpmapPayloadFormat, codecName) == 2) { parseSuccess = True; if (rtpmapPayloadFormat == fRTPPayloadFormat) { // This "rtpmap" matches our payload format, so set our // codec name and timestamp frequency: // (First, make sure the codec name is upper case) { Locale l("POSIX"); for (char* p = codecName; *p != '\0'; ++p) *p = toupper(*p); } delete[] fCodecName; fCodecName = strDup(codecName); fRTPTimestampFrequency = rtpTimestampFrequency; fNumChannels = numChannels; } } delete[] codecName; return parseSuccess; }
void getSDPDescription(RTSPClient::responseHandler* afterFunc) { extern char* proxyServerName; if (proxyServerName != NULL) { // Tell the SIP client about the proxy: NetAddressList addresses(proxyServerName); if (addresses.numAddresses() == 0) { ourSIPClient->envir() << "Failed to find network address for \"" << proxyServerName << "\"\n"; } else { NetAddress address = *(addresses.firstAddress()); unsigned proxyServerAddress // later, allow for IPv6 ##### = *(unsigned*)(address.data()); extern unsigned short proxyServerPortNum; if (proxyServerPortNum == 0) proxyServerPortNum = 5060; // default ourSIPClient->setProxyServer(proxyServerAddress, proxyServerPortNum); } } extern unsigned short desiredPortNum; unsigned short clientStartPortNum = desiredPortNum; if (clientStartPortNum == 0) clientStartPortNum = 8000; // default ourSIPClient->setClientStartPortNum(clientStartPortNum); extern char const* streamURL; char const* username = ourAuthenticator == NULL ? NULL : ourAuthenticator->username(); char const* password = ourAuthenticator == NULL ? NULL : ourAuthenticator->password(); char* result; if (username != NULL && password != NULL) { result = ourSIPClient->inviteWithPassword(streamURL, username, password); } else { result = ourSIPClient->invite(streamURL); } int resultCode = result == NULL ? -1 : 0; afterFunc(NULL, resultCode, strDup(result)); }
char* SIPClient::createAuthenticatorString(Authenticator const* authenticator, char const* cmd, char const* url) { if (authenticator != NULL && authenticator->realm() != NULL && authenticator->nonce() != NULL && authenticator->username() != NULL && authenticator->password() != NULL) { // We've been provided a filled-in authenticator, so use it: char const* const authFmt = "Proxy-Authorization: Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", response=\"%s\", uri=\"%s\"\r\n"; char const* response = authenticator->computeDigestResponse(cmd, url); unsigned authBufSize = strlen(authFmt) + strlen(authenticator->username()) + strlen(authenticator->realm()) + strlen(authenticator->nonce()) + strlen(url) + strlen(response); char* authenticatorStr = new char[authBufSize]; sprintf(authenticatorStr, authFmt, authenticator->username(), authenticator->realm(), authenticator->nonce(), response, url); authenticator->reclaimDigestResponse(response); return authenticatorStr; } return strDup(""); }