zoukankan      html  css  js  c++  java
  • live传264流

    简单的rtsp服务器客户    https://github.com/fengweiyu/RTSP

    264 flv等简单解析

    simplest_mediadata_test-master

    1、更简单的看看

     https://hub.fastgit.org/ImSjt/RtspServer

    2、 要看https://blog.csdn.net/gavinr/article/details/7186843

    通过改testH264VideoStreamer和testProgs\testOnDemandRTSPServer.cpp

    加入斜体的那一段

    #include <liveMedia.hh>
    #include <BasicUsageEnvironment.hh>
    #include <GroupsockHelper.hh>
    
    UsageEnvironment* env;
    char const* inputFileName = "test.264";
    H264VideoStreamFramer* videoSource;
    RTPSink* videoSink;
    
    void play(); // forward
    static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,
        char const* streamName, char const* inputFileName) {
        char* url = rtspServer->rtspURL(sms);
        UsageEnvironment& env = rtspServer->envir();
        env << "\n\"" << streamName << "\" stream, from the file \""
            << inputFileName << "\"\n";
        env << "Play this stream using the URL \"" << url << "\"\n";
        delete[] url;
    };
    int main(int argc, char** argv) {
      // Begin by setting up our usage environment:
      TaskScheduler* scheduler = BasicTaskScheduler::createNew();
      env = BasicUsageEnvironment::createNew(*scheduler);
    
      // Create 'groupsocks' for RTP and RTCP:
      struct sockaddr_storage destinationAddress;
      destinationAddress.ss_family = AF_INET;
      ((struct sockaddr_in&)destinationAddress).sin_addr.s_addr = chooseRandomIPv4SSMAddress(*env);
      // Note: This is a multicast address.  If you wish instead to stream
      // using unicast, then you should use the "testOnDemandRTSPServer"
      // test program - not this test program - as a model.
    
      const unsigned short rtpPortNum = 18888;
      const unsigned short rtcpPortNum = rtpPortNum+1;
      const unsigned char ttl = 255;
    
      const Port rtpPort(rtpPortNum);
      const Port rtcpPort(rtcpPortNum);
    
      Groupsock rtpGroupsock(*env, destinationAddress, rtpPort, ttl);
      rtpGroupsock.multicastSendOnly(); // we're a SSM source
      Groupsock rtcpGroupsock(*env, destinationAddress, rtcpPort, ttl);
      rtcpGroupsock.multicastSendOnly(); // we're a SSM source
    
      // Create a 'H264 Video RTP' sink from the RTP 'groupsock':
      OutPacketBuffer::maxSize = 100000;
      videoSink = H264VideoRTPSink::createNew(*env, &rtpGroupsock, 96);
    
      // Create (and start) a 'RTCP instance' for this RTP sink:
      const unsigned estimatedSessionBandwidth = 500; // in kbps; for RTCP b/w share
      const unsigned maxCNAMElen = 100;
      unsigned char CNAME[maxCNAMElen+1];
      gethostname((char*)CNAME, maxCNAMElen);
      CNAME[maxCNAMElen] = '\0'; // just in case
      RTCPInstance* rtcp
      = RTCPInstance::createNew(*env, &rtcpGroupsock,
                    estimatedSessionBandwidth, CNAME,
                    videoSink, NULL /* we're a server */,
                    True /* we're a SSM source */);
      // Note: This starts RTCP running automatically
    
      RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554);
      if (rtspServer == NULL) {
        *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
        exit(1);
      }
      ServerMediaSession* sms
        = ServerMediaSession::createNew(*env, "testStream", inputFileName,
               "Session streamed by \"testH264VideoStreamer\"",
                           True /*SSM*/);
      sms->addSubsession(PassiveServerMediaSubsession::createNew(*videoSink, rtcp));
      rtspServer->addServerMediaSession(sms);
    
      char* url = rtspServer->rtspURL(sms);
      *env << "Play this stream using the URL \"" << url << "\"\n";
      delete[] url;
    
      // Start the streaming:
      *env << "Beginning streaming...\n";
      play();
      // A H.264 video elementary stream:
      { 
          char const* descriptionString
              = "Session streamed by \"testOnDemandRTSPServer\"";
          Boolean reuseFirstSource = False;
          char const* streamName = "h264ESVideoTest";
          char const* inputFileName = "test.264";
          ServerMediaSession* sms
              = ServerMediaSession::createNew(*env, streamName, streamName,
                  descriptionString);
          sms->addSubsession(H264VideoFileServerMediaSubsession
              ::createNew(*env, inputFileName, reuseFirstSource));
          rtspServer->addServerMediaSession(sms);
    
          announceStream(rtspServer, sms, streamName, inputFileName);
      }
      env->taskScheduler().doEventLoop(); // does not return
    
      return 0; // only to prevent compiler warning
    }
    
    void afterPlaying(void* /*clientData*/) {
      *env << "...done reading from file\n";
      videoSink->stopPlaying();
      Medium::close(videoSource);
      // Note that this also closes the input file that this source read from.
    
      // Start playing once again:
      play();
    }
    
    void play() {
      // Open the input file as a 'byte-stream file source':
      ByteStreamFileSource* fileSource
        = ByteStreamFileSource::createNew(*env, inputFileName);
      if (fileSource == NULL) {
        *env << "Unable to open file \"" << inputFileName
             << "\" as a byte-stream file source\n";
        exit(1);
      }
    
      FramedSource* videoES = fileSource;
    
      // Create a framer for the Video Elementary Stream:
      videoSource = H264VideoStreamFramer::createNew(*env, videoES);
    
      // Finally, start playing:
      *env << "Beginning to read from file...\n";
      videoSink->startPlaying(*videoSource, afterPlaying, videoSink);
    }
  • 相关阅读:
    [华为oj]放苹果
    [华为oj]iNOC产品部-杨辉三角的变形
    值传递和引用传递
    Struts2+Jquery+Json集成
    使用堆栈结构进行字符串表达式("7*2-5*3-3+6/3")的计算
    使用环形链表解决约瑟夫(丢手帕)问题
    tomcat配置数据源
    ORA-01652:无法通过128(在表空间TEMP中)扩展temp段
    (转)Java 代码优化过程的实例介绍
    (转)走进JVM,浅水也能捉鱼
  • 原文地址:https://www.cnblogs.com/cnchengv/p/15586208.html
Copyright © 2011-2022 走看看