3

我正在使用正在流式传输到另一个程序的 Live555 访问视频服务器。我想向视频服务器发送 rtsp PAUSE 和 PLAY 命令以停止流式传输到任何其他程序。这可能吗?我的代码似乎没有做任何事情。我可以连接到服务器,服务器会验证我是否收到了完整的 PAUSE 命令:

视频服务器.h

//must make this store session so we can access the session in the static
//callbacks 
class MyRTSPClient: public RTSPClient{
protected:
  MyRTSPClient(UsageEnvironment& env, char const* rtspURL,
    int verbosityLevel, char const* applicationName, portNumBits tunnelOverHTTPPortNum):
  RTSPClient(env, rtspURL, verbosityLevel, applicationName, tunnelOverHTTPPortNum)
    {

    }

public:

  MediaSession* session_;

  bool sessionStarted_;

  static MyRTSPClient* createNew(UsageEnvironment& env, char const* rtspURL,
                                     int verbosityLevel = 0,
                                     char const* applicationName = NULL,
                                     portNumBits tunnelOverHTTPPortNum = 0) 
    {
      return new MyRTSPClient(env, rtspURL, verbosityLevel, applicationName,     tunnelOverHTTPPortNum);
      }

};


class VideoServer
{

public:

  VideoServer();


private:
  TaskScheduler* scheduler_;
  UsageEnvironment* env_;
  MyRTSPClient* rtspClient_;
  char eventLoopWatchVariable;

  //Asynchronously start the connection
  void StartConnection();

  static void callbackDESCRIBE(RTSPClient* rtspClient, int resultCode, char* resultString);

  static void callbackPAUSEPLAY(RTSPClient* rtspClient, int resultCode, char* resultString);
};

视频服务器.cpp

VideoServer::VideoServer()
{
  eventLoopWatchVariable = 0;
  scheduler_ = BasicTaskScheduler::createNew();
  env_ = BasicUsageEnvironment::createNew(*scheduler_);

  //create rtsp client with default params and our url and environment
  rtspClient_ = MyRTSPClient::createNew(*env_, 
      MINI_HARV_AXIS_RTSP_URL, 4, "jtalon5");

  //call description to initialize the session

  if (rtspClient_ == NULL) {
    std::cout << "Failed to create a RTSP client for URL \"" << 
    MINI_HARV_AXIS_RTSP_URL << std::endl;
    return;
  }
  std::cout << "made the client!" << std::endl;
  // Next, send a RTSP "DESCRIBE" command, to get a SDP description for the stream.
  // Note that this command - like all RTSP commands - is sent asynchronously; we do    not block, waiting for a response.
  // Instead, the following function call returns immediately, and we handle the RTSP response later, from within the event loop:
  rtspClient_->sendDescribeCommand(callbackDESCRIBE); 

  //start doEventLoop in separate thread so it is not blocking
  boost::thread thr1(&MiniHarvAxisInterface::StartConnection, this);

}

void VideoServer::StartConnection()
{
  env_->taskScheduler().doEventLoop(&eventLoopWatchVariable);
}

void MiniHarvAxisInterface::callbackDESCRIBE(RTSPClient* rtspClient, int resultCode, char* resultString) 
{
  std::cout << "describe" << resultString << std::endl;
  UsageEnvironment& env = rtspClient->envir();

  char* const sdpDescription = resultString;
  ((MyRTSPClient*)rtspClient)->session_ = MediaSession::createNew(env, sdpDescription);
  ((MyRTSPClient*)rtspClient)->sessionStarted_ = true;

  if(((MyRTSPClient*)rtspClient)->session_ == NULL)
    std::cout << "did not create session" << std::endl;
  else
    std::cout << "created session" << std::endl;

  rtspClient->sendPauseCommand(*((MyRTSPClient*)rtspClient)->session_, &callbackPAUSEPLAY);
}

void MiniHarvAxisInterface::callbackPAUSEPLAY(RTSPClient* rtspClient, int resultCode, char* resultString)
{
  //do nothing
}

似乎我只能暂停和播放我在此过程中创建的流。使用Live555是这种情况吗?

4

1 回答 1

0

是的,这在 Live555 中是可能的。

默认情况下,除非您重新定义 pauseStream 函数,否则 Live555 什么都不做(请参阅下面 Live555 源代码中的 pauseStream 函数中的注释):

// default implementation: do nothing

您必须创建自己的会话类,并且必须重新定义 pauseStream 函数,如下例所示:

您的媒体会话 .h 文件应类似于:

#include <MediaSubsession.hh>
class YOURMediaSubsession: public MediaSubsession {

... //You can leave this empty if you like

private:

...

  virtual void pauseStream(unsigned /*clientSessionId*/,void* /*streamToken*/);
};

您的媒体会话 .cpp 文件应类似于:

#include <YOURMediaSubsession.hh>
void YOURMediaSubsession::pauseStream(unsigned /*clientSessionId*/,
                    void* /*streamToken*/) {
  // default implementation: do nothing
}

您可以在此函数中添加您喜欢的任何内容,无论是停止/终止所有流,还是让编码器保持编码和同一帧,以产生流暂停预设时间的错觉是都由你定。

请注意,我可以在您的代码中看到您使用的是默认 MediaSession 类,如下面的代码所示:

((MyRTSPClient*)rtspClient)->session_ = MediaSession::createNew(env, sdpDescription);

您将需要基于 MediaSession 类构建自己的 YOURMediaSubsession 类,以重新定义 pauseStream 函数,如上所示,然后您执行暂停,而不是 live555。它应该看起来更像:

((MyRTSPClient*)rtspClient)->session_ = YOURMediaSubsession::createNew(env, sdpDescription);
于 2015-06-12T02:06:11.687 回答