[Live-devel] Receive RTP Audio over TCP

Anton Parkhomenko pa.dev at datalink.ua
Mon Apr 3 08:35:40 PDT 2017


Hi!
I'am working on receiving RTP Audio with live555 library. I use 
SimpleRTPSource and Groupsock and everything is fine. But now I need TCP 
instead of UDP and I can't make it work.
 In the event loop there are RTSP server with two subsessions and subclass of 
MediaSink, which reads  RTP Audio.

In RTSPClient.cpp I found following code:

if (streamUsingTCP) {
      // Tell the subsession to receive RTP (and send/receive RTCP) over the 
RTSP stream:
      if (subsession.rtpSource() != NULL) {
	subsession.rtpSource()->setStreamSocket(fInputSocketNum, 
subsession.rtpChannelId);
	  // So that we continue to receive & handle RTSP commands and responses 
from the server
	subsession.rtpSource()->enableRTCPReports() = False;
	  // To avoid confusing the server (which won't start handling RTP/RTCP-
over-TCP until "PLAY"), don't send RTCP "RR"s yet
      }
      if (subsession.rtcpInstance() != NULL) subsession.rtcpInstance()-
>setStreamSocket(fInputSocketNum, subsession.rtcpChannelId);
      RTPInterface::setServerRequestAlternativeByteHandler(envir(), 
fInputSocketNum, handleAlternativeRequestByte, this);
    }

Here is a part of my code:

RTPSource* source = SimpleRTPSource::createNew(*env, rtpReceiveGroupsock,
                    /*rtpPayloadFormat*/8, /*samplingFrequency*/8000,
                    /*mimeType*/"PCMA", 0, false);

RTCPInstance* rtcp = RTCPInstance::createNew(*env, rtcpGroupsock,
                    /*estimatedSessionBandwidth*/64, CNAME,
                    NULL /* we're a client */, source);
    
    source->setStreamSocket(/*sockNum*/ 25000, /*streamChannelId*/ 1);
        // So that we continue to receive & handle RTSP commands and responses 
from the server
    source->enableRTCPReports() = False;
        // To avoid confusing the server (which won't start handling RTP/RTCP-
over-TCP until "PLAY"), don't send RTCP "RR"s yet
    rtcp->setStreamSocket(/*sockNum*/ 25000, /*streamChannelId*/ 2); 

sink->startPlaying(source, afterPlaying, NULL);

25000 , 1, 2 - random numbers.

My RTP streamer follows this rule:

  // We expect the following data over the TCP channel:
  //   optional RTSP command or response bytes (before the first '$' character)
  //   a '$' character
  //   a 1-byte channel id
  //   a 2-byte packet size (in network byte order)
  //   the packet data.
// However, because the socket is being read asynchronously, this data might 
arrive in pieces.

This code creates TCP socket on the same as RTSP port (554), but doesn't 
receive data. As you can see I don't use 
RTPInterface::setServerRequestAlternativeByteHandler() method.
So I have a few quastions:

1. Am I on the right way?
2. Do I need use RTPInterface::setServerRequestAlternativeByteHandler() 
method?
3. Can I use separate port for RTP Audio?



More information about the live-devel mailing list