ccrtp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ccrtp-devel] about rtplisten and rtpsend, for help


From: karl
Subject: [Ccrtp-devel] about rtplisten and rtpsend, for help
Date: Fri, 20 Dec 2002 15:34:54 +0800

 
Hello,
I'm sorry to trouble you.
I hava a problem as follow:
I need a program that receive RTP packets and store it to a file. I have downloaded the ccRTP demo, and hava installed it in TurboLinux 6.0.
I have compiled them already. But I don't know why the "rtplisten" and "rtpsend" cannot run correctly. When the rtpsend put packets the rtplisten can't received them. 
 
Would you like to help me?
Thanks for your help!
 
Karl
20/12/2002
 
////////////////////////////////
 
My rtplisten.cpp is here:
 
#include <cstdlib>
#include <ccrtp/rtp.h>
 
#ifdef  CCXX_NAMESPACES
using namespace ost;
using namespace std;
#endif
class Sender: public RTPSession, public TimerPort {
public:
 Sender(const unsigned char* data, const InetHostAddress& ia,
        tpport_t port, uint32 tstamp, uint16 count):
  RTPSession(InetHostAddress("127.0.0.1"),8000),
  packetsPerSecond(20)
 {
  uint32 timestamp = tstamp? tstamp : 0;
  
  cout << "My SSRC identifier is: "
       << hex << (int)getLocalSSRC() << endl;
 
  defaultApplication().setSDESItem(SDESItemTypeTOOL,
       "rtpsend demo app.");
  setSchedulingTimeout(10000);
  setExpireTimeout(1000000);
  
  if ( !addDestination(ia,port) ) {
   cerr << "Could not connect" << endl;
   exit();
  }
  
  setPayloadFormat(StaticPayloadFormat(sptPCMU));
  startRunning();
 
  uint16 tstampInc = getCurrentRTPClockRate()/packetsPerSecond;
  uint32 period = 1000/packetsPerSecond;
  TimerPort::setTimer(period);
  for ( int i = 0; i < count ; i++ ) {
   putData(timestamp + i*tstampInc,
    data,strlen((char *)data) + 1);
   Thread::sleep(TimerPort::getTimer());
   TimerPort::incTimer(period);
  }
 }
 
private:
 const uint16 packetsPerSecond;
};
 
int
main(int argc, char *argv[])
{
 cout << "rtpsend..." << endl;
 
 if (argc != 6) {
  cerr << "Syntax: " << "data host port timestamp count" << endl;
  exit(1);
 }
 
 Sender sender((unsigned char *)argv[1], InetHostAddress(argv[2]),
        atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
 
 cout << "I have sent " << argv[5]
      << " RTP packets containing \"" << argv[1]
      << "\", with timestamp " << argv[4]
      << " to " << argv[2] << ":" << argv[3]
      << endl;
}
///////////////////////
My rtpsend.cpp is here:
 
#include <cstdlib>
#include <ccrtp/rtp.h>
 
#ifdef  CCXX_NAMESPACES
using namespace ost;
using namespace std;
#endif
 
class Listener: RTPSession {
public:
 Listener(InetHostAddress& ia, tpport_t port):
  RTPSocket(ia,port)
 {
  cout << "My SSRC identifier is: "
       << hex << (int)getLocalSSRC() << endl;
 
  defaultApplication().setSDESItem(SDESItemTypeTOOL,
       "rtplisten demo app.");
  setExpireTimeout(1000000);
 
  setPayloadFormat(StaticPayloadFormat(sptPCMU));
  startRunning();
  for (;;) {
   const AppDataUnit* adu;
   while ( (adu = getData(getFirstTimestamp())) ) {
    cerr << "I got an app. data unit with "
         << adu->getSize()
         << " payload octets from "
         << hex << (int)adu->getSource().getID()
         << "@" << dec <<
     adu->getSource().getNetworkAddress()
         << ":"
         << adu->getSource().getDataTransportPort()
         << endl;
    delete adu;
   }
   Thread::sleep(7);
  }
 }
 
 // redefined from IncomingDataQueue
 void onNewSyncSource(const SyncSource& src)
 {
  cout << "* New synchronization source: " <<
       hex << (int)src.getID() << endl;
 }
 
 // redefined from QueueRTCPManager
 void
 onGotSR(SyncSource& source, SendReport& SR, uint8 blocks)
 {
  RTPSession::onGotSR(source,SR,blocks);
  cout << "I got an SR RTCP report from "
       << hex << (int)source.getID() << "@"
       << dec
       << source.getNetworkAddress() << ":"
       << source.getControlTransportPort() << endl;
 }
 
 // redefined from QueueRTCPManager
 void
 onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks)
 {
  RTPSession::onGotRR(source,RR,blocks);
  cout << "I got an RR RTCP report from "
       << hex << (int)source.getID() << "@"
       << dec
       << source.getNetworkAddress() << ":"
       << source.getControlTransportPort() << endl;
 }
 
 // redefined from QueueRTCPManager
 bool
 onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len)
 {
  bool result = RTPSession::onGotSDESChunk(source,chunk,len);
  cout << "I got a SDES chunk from "
       << hex << (int)source.getID() << "@"
       << dec
       << source.getNetworkAddress() << ":"
       << source.getControlTransportPort() << endl;
  return result;
 }
 
 void
 onGotGoodbye(const SyncSource& source, const std::string& reason)
 {
  cout << "I got a Goodbye packet from "
       << hex << (int)source.getID() << "@"
       << dec
       << source.getNetworkAddress() << ":"
       << source.getControlTransportPort() << endl;
  cout << "   Goodbye reason: \"" << reason << "\"" << endl;
 }
};
 
int
main(int argc, char *argv[])
{
 cout << "rtplisten" << endl;
 
 if (argc != 3) {
  cerr << "Syntax: " << " ip port" << endl;
  exit(1);
 } else {
  cout << "Press Ctrl-C to finish." << endl;
 }
 
 InetHostAddress ia(argv[1]);
 Listener foo(ia,atoi(argv[2]));
 return 0;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]