ServerMediaSession* DynamicRTSPServer::lookupServerMediaSession(char const* streamName) { // First, check whether the specified "streamName" exists as a local file: FILE* fid = fopen(streamName, "rb"); Boolean fileExists = fid != NULL; // Next, check whether we already have a "ServerMediaSession" for this file: ServerMediaSession* sms = RTSPServer::lookupServerMediaSession(streamName); Boolean smsExists = sms != NULL; // Handle the four possibilities for "fileExists" and "smsExists": if (!fileExists) { if (smsExists) { // "sms" was created for a file that no longer exists. Remove it: removeServerMediaSession(sms); } return NULL; } else { if (!smsExists) { // Create a new "ServerMediaSession" object for streaming from the named file. sms = createNewSMS(envir(), streamName, fid); addServerMediaSession(sms); } fclose(fid); return sms; } }
ServerMediaSession* DynamicRTSPServer ::lookupServerMediaSession(char const* streamName, Boolean isFirstLookupInSession) { // First, check whether the specified "streamName" exists as a local file: FILE* fid = fopen(streamName, "rb"); Boolean fileExists = fid != NULL; ALOGE("lookupServerMediaSession streamName: %s, %p", streamName, fid); // Next, check whether we already have a "ServerMediaSession" for this file: ServerMediaSession* sms = RTSPServer::lookupServerMediaSession(streamName); Boolean smsExists = sms != NULL; // Handle the four possibilities for "fileExists" and "smsExists": if (!fileExists) { if (smsExists) { // "sms" was created for a file that no longer exists. Remove it: removeServerMediaSession(sms); sms = NULL; } if (sms == NULL) { sms = createNewSMS(envir(), streamName, fid, mH264Pool); addServerMediaSession(sms); } return sms; } else { if (smsExists && isFirstLookupInSession) { // Remove the existing "ServerMediaSession" and create a new one, in case the underlying // file has changed in some way: removeServerMediaSession(sms); sms = NULL; } if (sms == NULL) { sms = createNewSMS(envir(), streamName, fid, mH264Pool); addServerMediaSession(sms); } fclose(fid); return sms; } }
void LiveRtspServer::addRtspMediaSession(const Channel& channel) { const std::string sSessionName = channel.ChannelName; // Next, check whether we already have an RTSP "ServerMediaSession" for this media stream: ServerMediaSession* sms = RTSPServer::lookupServerMediaSession(sSessionName.c_str()); Boolean bSmsExists = sms != NULL; if (!bSmsExists) { VLOG(2) << "Creating Session " << sSessionName << " on RTSP server"; // Create a new "ServerMediaSession" object for streaming from the named file. sms = createNewSMS(envir(), *this, channel, m_pFactory, m_pGlobalRateControl); VLOG(2) << "Adding ServerMediaSession " << sSessionName; addServerMediaSession(sms); announceStream(this, sms, sSessionName.c_str()); } else { LOG(WARNING) << "Session " << sSessionName << " already exists on RTSP server"; } }