int main(void) { int status,i; RTPSession s; RTPSessionParams sessparams; RTPUDPv4TransmissionParams transparams; char blaai[100]; transparams.SetPortbase(10000); sessparams.SetOwnTimestampUnit(1.0/8000.0); sessparams.SetUsePollThread(true); sessparams.SetMaximumPacketSize(10000); status = s.Create(sessparams,&transparams); s.SetLocalName((const uint8_t *)"Jori Liesenborgs",16); s.SetLocalEMail((const uint8_t *)"*****@*****.**",20); s.SetLocalNote((const uint8_t *)"Blaai",5); s.SetNameInterval(3); s.SetEMailInterval(5); s.SetNoteInterval(2); status = s.AddDestination(RTPIPv4Address(ntohl(inet_addr("192.168.2.115")),5000)); //status = s.AddDestination(RTPIPv4Address(ntohl(inet_addr("127.0.0.1")),7000)); int snd = open("/dev/dsp",O_RDWR); int val; val = 0; status = ioctl(snd,SNDCTL_DSP_STEREO,&val); val = 8; status = ioctl(snd,SNDCTL_DSP_SAMPLESIZE,&val); val = 8000; status = ioctl(snd,SNDCTL_DSP_SPEED,&val); val = 7 | (128<<16); ioctl(snd,SNDCTL_DSP_SETFRAGMENT,&val); i = 0; while (i++ < 40000) { if (i == 1000) { //std::cout <<"Disabling note" << std::endl; s.SetNoteInterval(0); } uint8_t data[PACKSIZE]; RTPTime t1 = RTPTime::CurrentTime(); status = read(snd,data,PACKSIZE); RTPTime t2 = RTPTime::CurrentTime(); t2 -= t1; printf("%d.%06d\n",t2.GetSeconds(),t2.GetMicroSeconds()); status = s.SendPacket(data,PACKSIZE,1,false,PACKSIZE); } close(snd); printf("Destroying...\n"); s.BYEDestroy(RTPTime(10,0),(const uint8_t *)"Leaving session",16); return 0; }
// Create a new RTP session. If multicast is not being used then multicastIP // should be set to an empty string. static RTPSession createRtpSession(const std::string& multicastIP, unsigned int port) { RTPSession session; //if (setenv("LOGNAME", "video", 0) != 0) { // throw std::runtime_error("Error setting LOGNAME environment variable"); //} // Set up session params RTPSessionParams sessionparams; sessionparams.SetUsePollThread(false); sessionparams.SetMaximumPacketSize(1400); sessionparams.SetAcceptOwnPackets(true); sessionparams.SetOwnTimestampUnit(1.0f/900000.0f); sessionparams.SetResolveLocalHostname(false); sessionparams.SetSessionBandwidth(9000000); sessionparams.SetReceiveMode(RTPTransmitter::AcceptAll); RTPUDPv4TransmissionParams transparams; transparams.SetPortbase(port); int status = session.Create(sessionparams, &transparams); if (status < 0) { throw std::runtime_error("Error creating RTP session"); } // Join multicast groups if they are specified if (multicastIP.size() > 0) { if (!session.SupportsMulticasting()) { throw std::runtime_error("Multicast not supported!"); } else { int joinip = ntohl(inet_addr(multicastIP.c_str())); RTPIPv4Address joinaddr(joinip, port); int jstatus = session.JoinMulticastGroup(joinaddr); if (jstatus < 0) { throw std::runtime_error("Unable to join multicast group"); } } } return session; }
} int MP3MediaSubSession::InitRTPSession() { //setup session parameters RTPSessionParams sessParams; sessParams.SetOwnTimestampUnit(1.0 / 8000.0); //30 video frames per second sessParams.SetUsePollThread(1); // background thread to call virtual callbacks - set by default, but just to be sure sessParams.SetMaximumPacketSize(MAX_PACKET_SIZE); //setup transmission parameters RTPUDPv4TransmissionParams transParams; transParams.SetPortbase(portNum_); //CREATE THE SESSION int errcode = theRTPSession_.Create(sessParams, &transParams); if ( errcode < 0 ) { string stdErrStr = RTPGetErrorString(errcode); RTSPDEBUG("[Error] : %s", stdErrStr.c_str()); return ERR_RTSP_CRAETE_RTP_SESSION; //unable to create the session }