|
INET Framework for OMNeT++/OMNEST
|
00001 /*************************************************************************** 00002 RTPAVProfilePayload32Receiver.cc - description 00003 ------------------- 00004 begin : Sun Jan 6 2002 00005 copyright : (C) 2002 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 00024 #include "RTPPayloadReceiver.h" 00025 #include "RTPAVProfilePayload32Receiver.h" 00026 #include "RTPPacket.h" 00027 #include "RTPMpegPacket_m.h" 00028 00029 Define_Module(RTPAVProfilePayload32Receiver); 00030 00031 int compareRTPPacketsBySequenceNumber(cObject *packet1, cObject *packet2) 00032 { 00033 return ((RTPPacket *)packet1)->getSequenceNumber() - ((RTPPacket *)packet2)->getSequenceNumber(); 00034 } 00035 00036 RTPAVProfilePayload32Receiver::~RTPAVProfilePayload32Receiver() 00037 { 00038 delete _queue; 00039 } 00040 00041 00042 void RTPAVProfilePayload32Receiver::initialize() 00043 { 00044 RTPPayloadReceiver::initialize(); 00045 _payloadType = 32; 00046 _queue = new cQueue("IncomingQueue", &compareRTPPacketsBySequenceNumber); 00047 _lowestAllowedTimeStamp = 0; 00048 _highestSequenceNumber = 0; 00049 } 00050 00051 00052 void RTPAVProfilePayload32Receiver::processPacket(RTPPacket *rtpPacket) 00053 { 00054 // the first packet sets the lowest allowed time stamp 00055 if (_lowestAllowedTimeStamp == 0) { 00056 _lowestAllowedTimeStamp = rtpPacket->getTimeStamp(); 00057 _highestSequenceNumber = rtpPacket->getSequenceNumber(); 00058 _outputLogLoss <<"sequenceNumberBase"<< rtpPacket->getSequenceNumber() << endl; 00059 } 00060 else 00061 { 00062 if (rtpPacket->getSequenceNumber() > _highestSequenceNumber+1) 00063 { 00064 for (int i = _highestSequenceNumber+1; i< rtpPacket->getSequenceNumber(); i++ ) 00065 { 00066 //char line[100]; 00067 //sprintf(line, "%i", i); 00068 _outputLogLoss << i << endl; 00069 } 00070 } 00071 } 00072 00073 if ((rtpPacket->getTimeStamp() < _lowestAllowedTimeStamp) || (rtpPacket->getSequenceNumber()<= _highestSequenceNumber)) { 00074 delete rtpPacket; 00075 } 00076 else { 00077 // is this packet from the next frame ? 00078 // this can happen when the marked packet has been 00079 // lost or arrives late 00080 bool nextTimeStamp = rtpPacket->getTimeStamp() > _lowestAllowedTimeStamp; 00081 00082 // is this packet marked, which means that it's 00083 // the last packet of this frame 00084 bool marked = rtpPacket->getMarker(); 00085 00086 // test if end of frame reached 00087 00088 // check if we received the last (= marked) 00089 // packet of the frame or 00090 // we received a packet of the next frame 00091 _highestSequenceNumber = rtpPacket->getSequenceNumber(); 00092 00093 if (nextTimeStamp || marked) { 00094 00095 // a marked packet belongs to this frame 00096 if (marked && !nextTimeStamp) { 00097 _queue->insert(rtpPacket); 00098 } 00099 00100 int pictureType = 0; 00101 int frameSize = 0; 00102 00103 // the queue contains all packets for this frame 00104 // we have received 00105 while (!_queue->empty()) { 00106 RTPPacket *readPacket = (RTPPacket *)(_queue->pop()); 00107 RTPMpegPacket *mpegPacket = (RTPMpegPacket *)(readPacket->decapsulate()); 00108 if (pictureType == 0) 00109 pictureType = mpegPacket->getPictureType(); 00110 frameSize = frameSize + mpegPacket->getPayloadLength(); 00111 00112 delete mpegPacket; 00113 delete readPacket; 00114 } 00115 00116 // we start the next frame 00117 // set the allowed time stamp 00118 if (nextTimeStamp) { 00119 _lowestAllowedTimeStamp = rtpPacket->getTimeStamp(); 00120 _queue->insert(rtpPacket); 00121 } 00122 00123 // we have calculated a frame 00124 if (frameSize > 0) { 00125 char line[100]; 00126 // what picture type is it 00127 char picture = ' '; 00128 if (pictureType == 1) 00129 picture = 'I'; 00130 else if (pictureType == 2) 00131 picture = 'P'; 00132 else if (pictureType == 3) 00133 picture = 'B'; 00134 else if (pictureType == 4) 00135 picture = 'D'; 00136 00137 // create sim line 00138 sprintf(line, "%f %i %c-Frame", simTime().dbl(), frameSize * 8, picture); 00139 // and write it to the file 00140 _outputFileStream << line << endl; 00141 } 00142 } 00143 // we are not at the end of the frame 00144 // so just insert this packet 00145 else { 00146 _queue->insert(rtpPacket); 00147 } 00148 } 00149 } 00150 00151