RTPPayloadReceiver.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           RTPPayloadReceiver.cc  -  description
00003                              -------------------
00004     begin                : Fri Nov 2 2001
00005     copyright            : (C) 2001 by Matthias Oppitz
00006     email                : Matthias.Oppitz@gmx.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00023 #include <fstream>
00024 #include "RTPPayloadReceiver.h"
00025 #include "RTPPacket.h"
00026 #include "RTPInnerPacket.h"
00027 
00028 
00029 Define_Module(RTPPayloadReceiver);
00030 
00031 
00032 RTPPayloadReceiver::~RTPPayloadReceiver()
00033 {
00034     closeOutputFile();
00035     delete _packetArrival;
00036 }
00037 
00038 
00039 void RTPPayloadReceiver::initialize()
00040 {
00041     const char *fileName = par("outputFileName");
00042     openOutputFile(fileName);
00043     char logName[100];
00044     sprintf (logName, "outputLogLoss%d.log", getId());
00045     _outputLogLoss.open(logName);
00046     _packetArrival = new cOutVector("packet arrival");
00047 }
00048 
00049 
00050 void RTPPayloadReceiver::handleMessage(cMessage *msg)
00051 {
00052     RTPInnerPacket *rinp = check_and_cast<RTPInnerPacket *>(msg);
00053     if (rinp->getType() == RTPInnerPacket::RTP_INP_DATA_IN) {
00054         RTPPacket *packet = check_and_cast<RTPPacket *>(rinp->decapsulate());
00055         processPacket(packet);
00056         delete rinp;
00057     }
00058     else {
00059         error("RTPInnerPacket of wrong type received");
00060         delete rinp;
00061     }
00062 }
00063 
00064 
00065 void RTPPayloadReceiver::processPacket(RTPPacket *packet)
00066 {
00067     _packetArrival->record((double)(packet->getTimeStamp()));
00068 }
00069 
00070 
00071 void RTPPayloadReceiver::openOutputFile(const char *fileName)
00072 {
00073     _outputFileStream.open(fileName);
00074 }
00075 
00076 
00077 void RTPPayloadReceiver::closeOutputFile()
00078 {
00079     _outputFileStream.close();
00080     _outputLogLoss.close();
00081 }