| | |
| | | |
| | | void usage(UsageEnvironment& env, char const* progName) |
| | | { |
| | | LOG_DEBUG << "Usage: " << progName << " <rtsp-url-1> ... <rtsp-url-N>"; |
| | | LOG_DEBUG << "\t(where each <rtsp-url-i> is a \"rtsp://\" URL)"; |
| | | LOG_DEBUG << "Usage: " << progName << " <rtsp-url-1> ... <rtsp-url-N>" << std::endl; |
| | | LOG_DEBUG << "\t(where each <rtsp-url-i> is a \"rtsp://\" URL)" << std::endl; |
| | | } |
| | | |
| | | char eventLoopWatchVariable = 0; |
| | |
| | | RTSPClient* rtspClient = ourRTSPClient::createNew(env, _rtspConfig); |
| | | if (rtspClient == NULL) |
| | | { |
| | | LOG_ERROR << "Failed to create a RTSP client for URL \"" << _rtspConfig.rtspURL.c_str() << "\": " << env.getResultMsg(); |
| | | LOG_ERROR << "Failed to create a RTSP client for URL \"" << _rtspConfig.rtspURL.c_str() << "\": " << env.getResultMsg() << std::endl; |
| | | return; |
| | | } |
| | | |
| | |
| | | |
| | | if (resultCode != 0) |
| | | { |
| | | LOG_WARN << *rtspClient << "Failed to get a SDP description: " << resultString; |
| | | LOG_WARN << *rtspClient << "Failed to get a SDP description: " << resultString << std::endl; |
| | | delete[] resultString; |
| | | break; |
| | | } |
| | | |
| | | char* const sdpDescription = resultString; |
| | | LOG_INFO << *rtspClient << "Got a SDP description:\n" << sdpDescription; |
| | | LOG_INFO << *rtspClient << "Got a SDP description:\n" << sdpDescription << std::endl; |
| | | |
| | | // Create a media session object from this SDP description: |
| | | scs.session = MediaSession::createNew(env, sdpDescription); |
| | | delete[] sdpDescription; // because we don't need it anymore |
| | | if (scs.session == NULL) |
| | | { |
| | | LOG_ERROR << *rtspClient << "Failed to create a MediaSession object from the SDP description: " << env.getResultMsg(); |
| | | LOG_ERROR << *rtspClient << "Failed to create a MediaSession object from the SDP description: " << env.getResultMsg() << std::endl; |
| | | break; |
| | | } |
| | | else if (!scs.session->hasSubsessions()) |
| | | { |
| | | LOG_WARN << *rtspClient << "This session has no media subsessions (i.e., no \"m=\" lines)"; |
| | | LOG_WARN << *rtspClient << "This session has no media subsessions (i.e., no \"m=\" lines)" << std::endl; |
| | | break; |
| | | } |
| | | |
| | |
| | | { |
| | | if (!scs.subsession->initiate()) |
| | | { |
| | | LOG_ERROR << *rtspClient << "Failed to initiate the \"" << *scs.subsession << "\" subsession: " << env.getResultMsg(); |
| | | LOG_ERROR << *rtspClient << "Failed to initiate the \"" << *scs.subsession << "\" subsession: " << env.getResultMsg() << std::endl; |
| | | setupNextSubsession(rtspClient); // give up on this subsession; go to the next one |
| | | } |
| | | else |
| | | { |
| | | LOG_INFO << *rtspClient << "Initiated the \"" << *scs.subsession << "\" subsession ("; |
| | | LOG_INFO << *rtspClient << "Initiated the \"" << *scs.subsession << "\" subsession (" << std::endl; |
| | | if (scs.subsession->rtcpIsMuxed()) |
| | | LOG_INFO << "client port " << scs.subsession->clientPortNum(); |
| | | LOG_INFO << "client port " << scs.subsession->clientPortNum() << std::endl; |
| | | else |
| | | LOG_INFO << "client ports " << scs.subsession->clientPortNum() << "-" << scs.subsession->clientPortNum()+1; |
| | | LOG_INFO << ")"; |
| | | LOG_INFO << "client ports " << scs.subsession->clientPortNum() << "-" << scs.subsession->clientPortNum()+1 << std::endl; |
| | | LOG_INFO << ")" << std::endl; |
| | | |
| | | // Continue setting up this subsession, by sending a RTSP "SETUP" command: |
| | | rtspClient->sendSetupCommand(*scs.subsession, continueAfterSETUP, False, REQUEST_STREAMING_OVER_TCP); |
| | |
| | | |
| | | if (resultCode != 0) |
| | | { |
| | | LOG_ERROR << *rtspClient << "Failed to set up the \"" << *scs.subsession << "\" subsession: " << resultString; |
| | | LOG_ERROR << *rtspClient << "Failed to set up the \"" << *scs.subsession << "\" subsession: " << resultString << std::endl; |
| | | break; |
| | | } |
| | | |
| | | LOG_INFO << *rtspClient << "Set up the \"" << *scs.subsession << "\" subsession ("; |
| | | LOG_INFO << *rtspClient << "Set up the \"" << *scs.subsession << "\" subsession (" << std::endl; |
| | | if (scs.subsession->rtcpIsMuxed()) |
| | | { |
| | | LOG_INFO << "client port " << scs.subsession->clientPortNum(); |
| | | LOG_INFO << "client port " << scs.subsession->clientPortNum() << std::endl; |
| | | } |
| | | else |
| | | { |
| | | LOG_INFO << "client ports " << scs.subsession->clientPortNum() << "-" << scs.subsession->clientPortNum()+1; |
| | | LOG_INFO << "client ports " << scs.subsession->clientPortNum() << "-" << scs.subsession->clientPortNum()+1 << std::endl; |
| | | } |
| | | LOG_INFO << ")"; |
| | | LOG_INFO << ")" << std::endl; |
| | | |
| | | // Having successfully setup the subsession, create a data sink for it, and call "startPlaying()" on it. |
| | | // (This will prepare the data sink to receive data; the actual flow of data from the client won't start happening until later, |
| | |
| | | if (scs.subsession->sink == NULL) |
| | | { |
| | | LOG_ERROR << *rtspClient << "Failed to create a data sink for the \"" << *scs.subsession |
| | | << "\" subsession: " << env.getResultMsg(); |
| | | << "\" subsession: " << env.getResultMsg() << std::endl; |
| | | break; |
| | | } |
| | | |
| | | LOG_INFO << *rtspClient << "Created a data sink for the \"" << *scs.subsession << "\" subsession"; |
| | | LOG_INFO << *rtspClient << "Created a data sink for the \"" << *scs.subsession << "\" subsession" << std::endl; |
| | | scs.subsession->miscPtr = rtspClient; // a hack to let subsession handler functions get the "RTSPClient" from the subsession |
| | | scs.subsession->sink->startPlaying(*(scs.subsession->readSource()), |
| | | subsessionAfterPlaying, scs.subsession); |
| | |
| | | |
| | | if (resultCode != 0) |
| | | { |
| | | LOG_ERROR << *rtspClient << "Failed to start playing session: " << resultString; |
| | | LOG_ERROR << *rtspClient << "Failed to start playing session: " << resultString << std::endl; |
| | | break; |
| | | } |
| | | |
| | |
| | | scs.streamTimerTask = env.taskScheduler().scheduleDelayedTask(uSecsToDelay, (TaskFunc*)streamTimerHandler, rtspClient); |
| | | } |
| | | |
| | | LOG_INFO << *rtspClient << "Started playing session"; |
| | | LOG_INFO << *rtspClient << "Started playing session" << std::endl; |
| | | if (scs.duration > 0) |
| | | { |
| | | LOG_INFO << " (for up to " << scs.duration << " seconds)"; |
| | | LOG_INFO << " (for up to " << scs.duration << " seconds)" << std::endl; |
| | | } |
| | | LOG_INFO << "..."; |
| | | LOG_INFO << "..." << std::endl; |
| | | |
| | | success = True; |
| | | } |
| | |
| | | RTSPClient* rtspClient = (RTSPClient*)subsession->miscPtr; |
| | | UsageEnvironment& env = rtspClient->envir(); // alias |
| | | |
| | | LOG_INFO << *rtspClient << "Received RTCP \"BYE\" on \"" << *subsession << "\" subsession"; |
| | | LOG_INFO << *rtspClient << "Received RTCP \"BYE\" on \"" << *subsession << "\" subsession" << std::endl; |
| | | |
| | | // Now act as if the subsession had closed: |
| | | subsessionAfterPlaying(subsession); |
| | |
| | | } |
| | | } |
| | | |
| | | LOG_NOTICE << *rtspClient << "Closing the stream."; |
| | | LOG_NOTICE << *rtspClient << "Closing the stream." << std::endl; |
| | | Medium::close(rtspClient); |
| | | // Note that this will also cause this stream's "StreamClientState" structure to get reclaimed. |
| | | |
| | |
| | | // We've just received a frame of data. (Optionally) print out information about it: |
| | | #ifdef DEBUG_PRINT_EACH_RECEIVED_FRAME |
| | | if (fStreamId != NULL) |
| | | LOG_DEBUG << "Stream \"" << fStreamId << "\"; "; |
| | | LOG_DEBUG << "\t" << fSubsession.mediumName() << "/" << fSubsession.codecName() << ":\tReceived " << frameSize << " bytes"; |
| | | LOG_DEBUG << "Stream \"" << fStreamId << "\"; " << std::endl; |
| | | LOG_DEBUG << "\t" << fSubsession.mediumName() << "/" << fSubsession.codecName() << ":\tReceived " << frameSize << " bytes" << std::endl; |
| | | if (numTruncatedBytes > 0) |
| | | LOG_DEBUG << " (with " << numTruncatedBytes << " bytes truncated)"; |
| | | LOG_DEBUG << " (with " << numTruncatedBytes << " bytes truncated)" << std::endl; |
| | | |
| | | char uSecsStr[6+1]; // used to output the 'microseconds' part of the presentation time |
| | | sprintf(uSecsStr, "%06u", (unsigned)presentationTime.tv_usec); |
| | | LOG_DEBUG << "\tPresentation time: " << (int)presentationTime.tv_sec << "." << uSecsStr; |
| | | LOG_DEBUG << "\tPresentation time: " << (int)presentationTime.tv_sec << "." << uSecsStr << std::endl; |
| | | if (fSubsession.rtpSource() != NULL && !fSubsession.rtpSource()->hasBeenSynchronizedUsingRTCP()) |
| | | { |
| | | LOG_DEBUG << "\tPTS not RTCP-synchronized"; // mark the debugging output to indicate that this presentation time is not RTCP-synchronized |
| | | LOG_DEBUG << "\tPTS not RTCP-synchronized" << std::endl; // mark the debugging output to indicate that this presentation time is not RTCP-synchronized |
| | | } |
| | | #ifdef DEBUG_PRINT_NPT |
| | | LOG_DEBUG << "\tNPT: " << fSubsession.getNormalPlayTime(presentationTime); |
| | | LOG_DEBUG << "\tNPT: " << fSubsession.getNormalPlayTime(presentationTime) << std::endl; |
| | | #endif |
| | | #endif |
| | | |