ccrtp-devel
[Top][All Lists]
Advanced

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

[Ccrtp-devel] Problem about ccrtp fails to work on Debian


From: Kun Niu
Subject: [Ccrtp-devel] Problem about ccrtp fails to work on Debian
Date: Fri, 25 Jan 2008 01:14:30 +0800

Dear all,
I'm trying to implement a program so that I can make use of rtp for
both sending and receiving message within the same rtpsession.
My ccrtp version is 1.6.
My OS is Debian 4.0.
I can see that after receiving the first three packages, I fail to the
packages that follow up.
Would anyone please point out my error please?
Thanks in advance.
My program is like this:
#include <ccrtp/rtp.h>
#include <ctime>
#include <cstdio>
#include <iostream>

#ifdef CCXX_NAMESPACES
using namespace ost;
using namespace std;
#endif

const int ONE_BASE = 33634;
const int ANOTHER_BASE = 32522;

class Recv_Thread : public Thread
{
private:
    RTPSession *socket;
protected:
    void run(void)
    {
        if(socket != NULL)
        {
            int ssrc = socket->getLocalSSRC();
            for(int i = 0; true; i++)
            {
                const AppDataUnit *adu = NULL;
                while(NULL == adu)
                {
                    Thread::sleep(1000);
                    adu = socket->getData(socket->getFirstTimestamp());
                }
                time_t receiving_time = time(NULL);
                char tmstring[30];
                strftime(tmstring,30,"%X",localtime(&receiving_time));
                cout << "Rx ("<<hex<<(int)ssrc
                     << "): [receiving at " << tmstring << "]: "
                     <<adu->getData() << endl;
                delete adu;
            }
        }
    }
public:
    Recv_Thread(RTPSession *socket_) : Thread()
    {
        this->socket = socket_;
    }
    ~Recv_Thread()
    {
        terminate();
    }
};

class Send_Thread : public Thread
{
private:
    RTPSession *socket;
protected:
    void run(void)
    {
        if(socket != NULL)
        {
            unsigned int timestamp = 0;
            for(int i = 0; true; i++)
            {
                int ssrc = socket->getLocalSSRC();
                unsigned char salute[50];
                snprintf((char *)salute,50,
                         "Hello, brave gnu world (#%u)!",i);
                time_t sending_time = time(NULL);
                // get timestamp to send salute
                if ( 0 == i )
                {
                    timestamp = socket->getCurrentTimestamp();
                }
                else
                {
                    // increment for 1 second
                    timestamp += socket->getCurrentRTPClockRate();
                }
                socket->putData(timestamp, salute, strlen((char *)salute)+1);
                char tmstring[30];
                strftime(tmstring,30,"%X",
                         localtime(&sending_time));
                cout << "Tx ("<<hex<< (int)ssrc
                     << "): sending salute " << "no " << dec << i
                     << ", at " << tmstring
                     << "..." << endl;
                Thread::sleep(2000);
            }
        }
    }
public:
    Send_Thread(RTPSession *socket_) : Thread()
    {
        this->socket = socket_;
    }
    virtual ~Send_Thread()
    {
        terminate();
    }
};


int main()
{
    InetHostAddress local_ip ("127.0.0.1");
    RTPSession *session1 = new RTPSession(local_ip, ONE_BASE);
    RTPSession *session2 = new RTPSession(local_ip, ANOTHER_BASE);
    session1->setSchedulingTimeout(20000);
    session2->setSchedulingTimeout(20000);
    session1->setExpireTimeout(3000000);
    session2->setExpireTimeout(3000000);
    session1->addDestination(local_ip, ANOTHER_BASE);
    session2->addDestination(local_ip, ONE_BASE);
    session1->setPayloadFormat(StaticPayloadFormat(sptMP2T));
    session2->setPayloadFormat(StaticPayloadFormat(sptMP2T));
    session1->startRunning();
    cout<<"session1: "<<"The queue is "
        <<(session1->isActive()? "" : "in")
        <<" active."<<endl;
    session2->startRunning();
    cout<<"session2: "<<"The queue is "
        <<(session2->isActive()? "" : "in")
        <<" active."<<endl;
    Send_Thread *thread1 = new Send_Thread(session1);
    Recv_Thread *thread2 = new Recv_Thread(session1);
    Send_Thread *thread3 = new Send_Thread(session2);
    Recv_Thread *thread4 = new Recv_Thread(session2);
    thread1->start();
    thread2->start();
    thread3->start();
    thread4->start();
    cin.get();
    delete thread1;
    delete thread2;
    delete thread3;
    delete thread4;
    delete session1;
    delete session2;
    return 0;
}
And here's part of my program's output:
session1: The queue is  active.
session2: The queue is  active.
Tx (89249946): sending salute no 0, at 01:03:23...
Tx (26028fdb): sending salute no 0, at 01:03:23...
Rx (89249946): [receiving at 01:03:24]: Hello, brave gnu world (#0)!
Rx (26028fdb): [receiving at 01:03:24]: Hello, brave gnu world (#0)!
Tx (89249946): sending salute no 1, at 01:03:25...
Tx (26028fdb): sending salute no 1, at 01:03:25...
Rx (89249946): [receiving at 01:03:26]: Hello, brave gnu world (#1)!
Rx (26028fdb): [receiving at 01:03:26]: Hello, brave gnu world (#1)!
Tx (89249946): sending salute no 2, at 01:03:27...
Tx (26028fdb): sending salute no 2, at 01:03:27...
Rx (89249946): [receiving at 01:03:28]: Hello, brave gnu world (#2)!
Rx (26028fdb): [receiving at 01:03:28]: Hello, brave gnu world (#2)!
Tx (89249946): sending salute no 3, at 01:03:29...
Tx (26028fdb): sending salute no 3, at 01:03:29...
Tx (26028fdb): sending salute no 4, at 01:03:31...
Tx (89249946): sending salute no 4, at 01:03:31...
Tx (26028fdb): sending salute no 5, at 01:03:33...
Tx (89249946): sending salute no 5, at 01:03:33...


-- 
失业
         牛坤
MSN:address@hidden

reply via email to

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