RTCPPacket.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           RTCPacket.cc  -  description
00003                              -------------------
00004     begin                : Sun Oct 21 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 
00024 #include "RTCPPacket.h"
00025 #include "reports.h"
00026 #include "sdes.h"
00027 
00028 //
00029 // RTCPPacket
00030 //
00031 
00032 // register class RTCPPacket for omnet++
00033 Register_Class(RTCPPacket);
00034 
00035 
00036 RTCPPacket::RTCPPacket(const char *name) : cPacket(name) {
00037     // initialize variables
00038     _version = 2;
00039     _padding = 0;
00040     _count = 0;
00041     _packetType = RTCP_PT_UNDEF;
00042     // rtcpLength can be calculated with cPacket::getLength()
00043 
00044     // RTCP header length size is 4 bytes
00045     // not all rtcp packets (in particular RTCPSDESPacket) have
00046     // the ssrc identifier stored in the header
00047     setByteLength(4);
00048 };
00049 
00050 
00051 RTCPPacket::RTCPPacket(const RTCPPacket& rtcpPacket) : cPacket() {
00052     setName(rtcpPacket.getName());
00053     operator=(rtcpPacket);
00054 };
00055 
00056 
00057 RTCPPacket::~RTCPPacket() {
00058 };
00059 
00060 
00061 RTCPPacket& RTCPPacket::operator=(const RTCPPacket& rtcpPacket) {
00062     cPacket::operator=(rtcpPacket);
00063     setName(rtcpPacket.getName());
00064     _version = rtcpPacket._version;
00065     _padding = rtcpPacket._padding;
00066     _count = rtcpPacket._count;
00067     _packetType = rtcpPacket._packetType;
00068     return *this;
00069 };
00070 
00071 
00072 RTCPPacket *RTCPPacket::dup() const {
00073     return new RTCPPacket(*this);
00074 };
00075 
00076 
00077 std::string RTCPPacket::info() {
00078     std::stringstream out;
00079     out << "RTCPPacket.packetType=" << _packetType;
00080     return out.str();
00081 };
00082 
00083 
00084 void RTCPPacket::dump(std::ostream& os) const {
00085     os << "RTCPPacket:" << endl;
00086     os << "  version = " << _version << endl;
00087     os << "  padding = " << _padding << endl;
00088     os << "  count = " << _count << endl;
00089     os << "  packetType = " << _packetType << endl;
00090     os << "  rtcpLength = " << getRtcpLength() << endl;
00091 };
00092 
00093 
00094 int RTCPPacket::getVersion() {
00095     return _version;
00096 };
00097 
00098 
00099 int RTCPPacket::getPadding() {
00100     return _padding;
00101 };
00102 
00103 
00104 int RTCPPacket::getCount() {
00105     return _count;
00106 };
00107 
00108 
00109 RTCPPacket::RTCP_PACKET_TYPE RTCPPacket::getPacketType() {
00110     return _packetType;
00111 };
00112 
00113 
00114 int RTCPPacket::getRtcpLength() const {
00115     // rtcpLength is the header field length
00116     // of an rtcp packet
00117     // in 32 bit words minus one
00118     return (int)(getByteLength() / 4) - 1;
00119 };
00120 
00121 
00122 //
00123 // RTCPReceiverReportPacket
00124 //
00125 
00126 Register_Class(RTCPReceiverReportPacket);
00127 
00128 
00129 RTCPReceiverReportPacket::RTCPReceiverReportPacket(const char *name) : RTCPPacket(name) {
00130     _packetType = RTCP_PT_RR;
00131     _ssrc = 0;
00132     _receptionReports = new cArray("ReceptionReports");
00133     // an empty rtcp receiver report packet is 4 bytes
00134     // longer, the ssrc identifier is stored in it
00135     addByteLength(4);
00136 };
00137 
00138 RTCPReceiverReportPacket::RTCPReceiverReportPacket(const RTCPReceiverReportPacket& rtcpReceiverReportPacket) : RTCPPacket() {
00139     _receptionReports = NULL;
00140     setName(rtcpReceiverReportPacket.getName());
00141     operator=(rtcpReceiverReportPacket);
00142 };
00143 
00144 
00145 RTCPReceiverReportPacket::~RTCPReceiverReportPacket() {
00146     delete _receptionReports;
00147 };
00148 
00149 
00150 RTCPReceiverReportPacket& RTCPReceiverReportPacket::operator=(const RTCPReceiverReportPacket& rtcpReceiverReportPacket) {
00151     RTCPPacket::operator=(rtcpReceiverReportPacket);
00152     _ssrc = rtcpReceiverReportPacket._ssrc;
00153     _receptionReports = new cArray(*(rtcpReceiverReportPacket._receptionReports));
00154     return *this;
00155 };
00156 
00157 
00158 RTCPReceiverReportPacket *RTCPReceiverReportPacket::dup() const {
00159     return new RTCPReceiverReportPacket(*this);
00160 };
00161 
00162 
00163 std::string RTCPReceiverReportPacket::info() {
00164     std::stringstream out;
00165     out << "RTCPReceiverReportPacket #rr=" << _count;
00166     return out.str();
00167 };
00168 
00169 
00170 void RTCPReceiverReportPacket::dump(std::ostream& os) const {
00171     os << "RTCPReceiverReportPacket:" << endl;
00172     for (int i = 0; i < _receptionReports->size(); i++) {
00173         if (_receptionReports->exist(i)) {
00174             ReceptionReport *rr = (ReceptionReport *)(_receptionReports->get(i));
00175             rr->dump(os);
00176         };
00177     };
00178 };
00179 
00180 
00181 uint32 RTCPReceiverReportPacket::getSSRC() {
00182     return _ssrc;
00183 };
00184 
00185 
00186 void RTCPReceiverReportPacket::setSSRC(uint32 ssrc) {
00187     _ssrc = ssrc;
00188 };
00189 
00190 
00191 void RTCPReceiverReportPacket::addReceptionReport(ReceptionReport *report) {
00192     _receptionReports->add(report);
00193     _count++;
00194     // an rtcp receiver report is 24 bytes long
00195     addByteLength(24);
00196 };
00197 
00198 
00199 cArray *RTCPReceiverReportPacket::getReceptionReports() {
00200     return new cArray(*_receptionReports);
00201 };
00202 
00203 
00204 
00205 //
00206 // RTCPSenderReportPacket
00207 //
00208 
00209 Register_Class(RTCPSenderReportPacket);
00210 
00211 
00212 RTCPSenderReportPacket::RTCPSenderReportPacket(const char *name) : RTCPReceiverReportPacket(name) {
00213     _packetType = RTCP_PT_SR;
00214     _senderReport = new SenderReport();
00215     // a sender report is 20 bytes long
00216     addByteLength(20);
00217 };
00218 
00219 
00220 RTCPSenderReportPacket::RTCPSenderReportPacket(const RTCPSenderReportPacket& rtcpSenderReportPacket) : RTCPReceiverReportPacket() {
00221     setName(rtcpSenderReportPacket.getName());
00222     operator=(rtcpSenderReportPacket);
00223 };
00224 
00225 
00226 RTCPSenderReportPacket::~RTCPSenderReportPacket() {
00227     delete _senderReport;
00228 };
00229 
00230 
00231 RTCPSenderReportPacket& RTCPSenderReportPacket::operator=(const RTCPSenderReportPacket& rtcpSenderReportPacket) {
00232     RTCPReceiverReportPacket::operator=(rtcpSenderReportPacket);
00233     _senderReport = new SenderReport(*(rtcpSenderReportPacket._senderReport));
00234     return *this;
00235 };
00236 
00237 
00238 RTCPSenderReportPacket *RTCPSenderReportPacket::dup() const {
00239     return new RTCPSenderReportPacket(*this);
00240 };
00241 
00242 
00243 std::string RTCPSenderReportPacket::info() {
00244     std::stringstream out;
00245     out << "RTCPSenderReportPacket.ssrc=" << _ssrc;
00246     return out.str();
00247 };
00248 
00249 
00250 void RTCPSenderReportPacket::dump(std::ostream& os) const {
00251     os << "RTCPSenderReportPacket:" << endl;
00252     _senderReport->dump(os);
00253     for (int i = 0; i < _receptionReports->size(); i++) {
00254         if (_receptionReports->exist(i)) {
00255             //FIXME _receptionReports->get(i)->dump(os);
00256         };
00257     };
00258 };
00259 
00260 
00261 SenderReport *RTCPSenderReportPacket::getSenderReport() {
00262     return new SenderReport(*_senderReport);
00263 };
00264 
00265 
00266 void RTCPSenderReportPacket::setSenderReport(SenderReport *report) {
00267     delete _senderReport;
00268     _senderReport = report;
00269 };
00270 
00271 
00272 
00273 //
00274 // RTCPSDESPacket
00275 //
00276 
00277 Register_Class(RTCPSDESPacket);
00278 
00279 
00280 RTCPSDESPacket::RTCPSDESPacket(const char *name) : RTCPPacket(name) {
00281     _packetType = RTCP_PT_SDES;
00282     _sdesChunks = new cArray("SDESChunks");
00283     // no addByteLength() needed, sdes chunks
00284     // directly follow the standard rtcp
00285     // header
00286 };
00287 
00288 
00289 RTCPSDESPacket::RTCPSDESPacket(const RTCPSDESPacket& rtcpSDESPacket) : RTCPPacket() {
00290     setName(rtcpSDESPacket.getName());
00291     operator=(rtcpSDESPacket);
00292 };
00293 
00294 
00295 RTCPSDESPacket::~RTCPSDESPacket() {
00296     delete _sdesChunks;
00297 };
00298 
00299 
00300 RTCPSDESPacket& RTCPSDESPacket::operator=(const RTCPSDESPacket& rtcpSDESPacket) {
00301     RTCPPacket::operator=(rtcpSDESPacket);
00302     _sdesChunks = new cArray(*(rtcpSDESPacket._sdesChunks));
00303     return *this;
00304 };
00305 
00306 
00307 RTCPSDESPacket *RTCPSDESPacket::dup() const {
00308     return new RTCPSDESPacket(*this);
00309 };
00310 
00311 
00312 std::string RTCPSDESPacket::info() {
00313     std::stringstream out;
00314     out << "RTCPSDESPacket: number of sdes chunks=" << _sdesChunks->size();
00315     return out.str();
00316 };
00317 
00318 
00319 void RTCPSDESPacket::dump(std::ostream& os) const {
00320     os << "RTCPSDESPacket:" << endl;
00321     for (int i = 0; i < _sdesChunks->size(); i++) {
00322         if (_sdesChunks->exist(i))
00323             ;//FIXME (*_sdesChunks)[i]->dump(os);
00324     }
00325 };
00326 
00327 
00328 cArray *RTCPSDESPacket::getSdesChunks() {
00329     return new cArray(*_sdesChunks);
00330 };
00331 
00332 
00333 void RTCPSDESPacket::addSDESChunk(SDESChunk *sdesChunk) {
00334     _sdesChunks->add(sdesChunk);
00335     _count++;
00336     // the size of the rtcp packet increases by the
00337     // size of the sdes chunk (including ssrc)
00338     addByteLength(sdesChunk->getLength());
00339 };
00340 
00341 
00342 
00343 //
00344 // RTCPByePacket
00345 //
00346 
00347 Register_Class(RTCPByePacket);
00348 
00349 RTCPByePacket::RTCPByePacket(const char *name) : RTCPPacket(name) {
00350     _packetType = RTCP_PT_BYE;
00351     _count = 1;
00352     _ssrc = 0;
00353     // space for the ssrc identifier
00354     addByteLength(4);
00355 };
00356 
00357 
00358 RTCPByePacket::RTCPByePacket(const RTCPByePacket& rtcpByePacket) : RTCPPacket() {
00359     setName(rtcpByePacket.getName());
00360     operator=(rtcpByePacket);
00361 };
00362 
00363 
00364 RTCPByePacket::~RTCPByePacket() {
00365 
00366 };
00367 
00368 
00369 RTCPByePacket& RTCPByePacket::operator=(const RTCPByePacket& rtcpByePacket) {
00370     RTCPPacket::operator=(rtcpByePacket);
00371     _ssrc = rtcpByePacket._ssrc;
00372     return *this;
00373 };
00374 
00375 
00376 RTCPByePacket *RTCPByePacket::dup() const {
00377     return new RTCPByePacket(*this);
00378 };
00379 
00380 
00381 uint32 RTCPByePacket::getSSRC() {
00382     return _ssrc;
00383 };
00384 
00385 
00386 void RTCPByePacket::setSSRC(uint32 ssrc) {
00387     _ssrc = ssrc;
00388 };
00389 
00390 
00391 //
00392 // RTCPCompoundPacket
00393 //
00394 
00395 Register_Class(RTCPCompoundPacket);
00396 
00397 
00398 RTCPCompoundPacket::RTCPCompoundPacket(const char *name) : cPacket(name) {
00399     _rtcpPackets = new cArray("RTCPPackets");
00400     // an empty rtcp compound packet has length 0 bytes
00401     setByteLength(0);
00402 };
00403 
00404 
00405 RTCPCompoundPacket::RTCPCompoundPacket(const RTCPCompoundPacket& rtcpCompoundPacket) : cPacket() {
00406     setName(rtcpCompoundPacket.getName());
00407     operator=(rtcpCompoundPacket);
00408 };
00409 
00410 
00411 RTCPCompoundPacket::~RTCPCompoundPacket() {
00412     delete _rtcpPackets;
00413 };
00414 
00415 
00416 RTCPCompoundPacket& RTCPCompoundPacket::operator=(const RTCPCompoundPacket& rtcpCompoundPacket) {
00417     cPacket::operator=(rtcpCompoundPacket);
00418     setByteLength(rtcpCompoundPacket.getByteLength());
00419     _rtcpPackets = new cArray(*(rtcpCompoundPacket._rtcpPackets));
00420     return *this;
00421 };
00422 
00423 
00424 RTCPCompoundPacket *RTCPCompoundPacket::dup() const {
00425     return new RTCPCompoundPacket(*this);
00426 };
00427 
00428 
00429 std::string RTCPCompoundPacket::info() {
00430     std::stringstream out;
00431     out << "RTCPCompoundPacket: number of rtcp packets=" << _rtcpPackets->size();
00432     return out.str();
00433 };
00434 
00435 
00436 void RTCPCompoundPacket::dump(std::ostream& os) const {
00437     os << "RTCPCompoundPacket:" << endl;
00438     for (int i = 0; i < _rtcpPackets->size(); i++) {
00439         if (_rtcpPackets->exist(i)) {
00440             //FIXME _rtcpPackets->get(i)->dump(os);
00441         }
00442     }
00443 };
00444 
00445 
00446 void RTCPCompoundPacket::addRTCPPacket(RTCPPacket *rtcpPacket) {
00447     //rtcpPacket->setOwner(_rtcpPackets);
00448     _rtcpPackets->add(rtcpPacket);
00449     // the size of the rtcp compound packet increases
00450     // by the size of the added rtcp packet
00451     addByteLength(rtcpPacket->getByteLength());
00452 };
00453 
00454 
00455 cArray *RTCPCompoundPacket::getRtcpPackets() {
00456     return new cArray(*_rtcpPackets);
00457 }