ccrtp-devel
[Top][All Lists]
Advanced

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

[Ccrtp-devel] ccrtp program crashes


From: Chris Read
Subject: [Ccrtp-devel] ccrtp program crashes
Date: Wed, 13 Feb 2002 08:41:45 -0800 (PST)

I have encountered some segmentation crashes using my
program (modified from rtpsend/rtpreceive) under Red
Hat 7.2.  I had been working on 6.2 and didn't have
any problems, but after I started using
7.2, the programs I'm working on do a segmentation
violation as they exit--meaning that they seem to run,
but after running the last statement in my file they
crash.  My guess is that it is a problem with a
destructor that is being called automatically, but I
can't find it.  It would probably be easier if I could
make gdb run, but since the rtpsend/rtpreceive
programs are really scripts, I haven't been able to
use gdb effectively.

Has anyone seen these kinds of problem?  Any
suggestions?

Also, can I use ccrtp to do unicast RTP?  When I use
the local machine's IP address I get packets through,
but when I use a different machine as destination or
source, the program aborts.  On the other hand if I
use a multicast IP address it doesn't abort, at least
if I'm running as root.  Suggestions?

- Chris

P.S.  I have attached my evaluation programs

__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com
#include <iostream.h>
#include <fstream.h>

#include "rtp.h"
#include <cstdlib>

#ifdef  CCXX_NAMESPACES
using namespace ost;
#endif

const int BLOCKSIZE = 1024;
int PERIOD = 200;

/**
 * @brief This class sends a file via RTP Packets - and it could fail!
 **/
class Sender: RTPSocket , TimerPort {
public:
        Sender( ifstream& inFile,
                const InetHostAddress& ia, tpport_t port) :
                RTPSocket(ia)
        {

        cerr << "Here 4a\n";

                uint32 rawblock[BLOCKSIZE];
                unsigned char *block = (unsigned char *)&rawblock[0];
                uint32 *i = &rawblock[0];
                uint32 *n = &rawblock[1];
                char *pblock = (char *)&rawblock[2];
                
        cerr << "Here 4b\n";

                setTimeout(0);
                setExpired(1000000);
                
                if ( Connect(ia,port) < 0 ) {
                        cerr << "Could not connect" << endl;
                        exit(0);
                }

        cerr << "Here 5\n";
                TimerPort::setTimer(PERIOD);

                *i = 0;
                *n = 1;
                *pblock = 0;
                while(*n != 0) {
                        inFile.read((char *)&rawblock[2], BLOCKSIZE);
                        *n = inFile.gcount();
                        putPacket((*i * 90 * PERIOD), RTP_PAYLOAD_JPEG, 
(unsigned char *)&rawblock[0], *n+8);
                        //putPacket((*i * (BLOCKSIZE + 8) * 100), 
RTP_PAYLOAD_JPEG, (unsigned char *)&rawblock[0], *n+8);
                        cerr << "Packet " << *i << ": " << *n << " bytes" << 
endl;
                        //      ccxx_sleep(1000);
                        ccxx_sleep(TimerPort::getTimer());
                        TimerPort::incTimer(PERIOD);
                        (*i)++;
                }
                cerr << "All sent\n";
                // Allow the service thread to run
                while (isSending())
                        ccxx_sleep(100);
                ccxx_sleep(100); // One last sleep, for the receiver's sake
                cerr << "Done sleeping\n";
        }
};

void MyExit(void) { cerr << "atexit()\n"; }

int
main(int argc, char *argv[])
{
        atexit(&MyExit);
        cerr << "Here 1\n";
        if (argc != 4 && argc != 5) { 
                cerr << "Syntax: " << argv[0] << " filename host port [period]" 
<< endl;
                exit(1);
        }
        if (argc == 5) PERIOD = atoi(argv[4]);  

        cerr << "Here 2\n";

        ifstream fs(argv[1]);           // Open input file
        if (!fs) {
                cerr << "Unable to open " << argv[1] << " for input" << endl;
                exit(1);
        }

        cerr << "Here 3\n";

        Sender sender(fs, InetHostAddress(argv[2]), atoi(argv[3]));
        cerr << "Done sending\n";
        fs.close();
        cerr << "Closed fs\n";
        return 0;

}
#include <iostream.h>

#include "rtp.h"
#include <fstream.h>
#include <cstdlib>

#ifdef  CCXX_NAMESPACES
using namespace ost;
#endif

const int BLOCKSIZE = 1024;

class Listener: RTPSocket {
private:
        enum { SIZE = 8192 };
        unsigned char buffer[SIZE];
public:
        Listener(ofstream& outFile, InetHostAddress& ia, tpport_t port) : 
RTPSocket(ia,port)
        {
                uint32 *n = (uint32 *)&buffer[4];
                uint32 *i = (uint32 *)&buffer[0];
                uint32 tS;
                uint16 sN;
                uint16 nextSn = 0;
                uint16 next = 0;

                cerr << "Here 2" << endl;
                Connect(ia,port);
                
                *n = 1;
                while (*n) {
                        tS = getFirstTimestamp();
                        sN = getFirstSequence();
                        if (tS && sN != nextSn) cerr << "Stamp: " << tS << ", 
Sequence: " << sN << endl;
                        if (tS || sN) cerr << "Stamp: " << tS << ", Sequence: " 
<< sN << endl;
                        if ( getPacket(tS, buffer, SIZE) ) {
                                nextSn = sN + 1;
//                              cerr << "Rx: *n=" << *n << ", *i=" << *i << 
endl;
                                while (next < *i) cerr << "Missed " << next++ 
<< endl;
                                cerr << "Got " << *i << endl;
                                next++;
                                outFile.seekp(*i * BLOCKSIZE);
                                outFile.write((char *)&buffer[8], *n);
//                              cerr << "Wrote to file" << endl;
                                
                        } else {
                        //      cerr << "no packet at " << tS << endl;
                                *n = 0xffffffff;
                        }
                        ccxx_sleep(10);
                }
        }
        
};

int
main(int argc, char *argv[])
{
        if (argc != 4) { 
                cerr << "Syntax: filereceive <file> <ip> <port>" << endl;
                exit(1);
        }

        ofstream fs(argv[1]);           // Open output file
        if (!fs) {
                cerr << "Unable to open " << argv[1] << " for output" << endl;
                exit(1);
        }
        cerr << "Here 0" << endl;

        InetHostAddress ia(argv[2]);
        cerr << "Here 1 - " << ia << endl;

        Listener foo(fs, ia, atoi(argv[3]));
}

reply via email to

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