00001 /*************************************************************************** 00002 sdes.cc - description 00003 ------------------- 00004 begin : Tue Oct 23 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 00023 #include <string.h> 00024 #include "sdes.h" 00025 00026 Register_Class(SDESItem); 00027 00028 00029 SDESItem::SDESItem() : cObject() { 00030 _type = SDES_UNDEF; 00031 _length = 2; 00032 _content = ""; 00033 }; 00034 00035 00036 SDESItem::SDESItem(SDES_ITEM_TYPE type, const char *content) : cObject() { 00037 _type = type; 00038 _content = content; 00039 // an sdes item requires one byte for the type field, 00040 // one byte for the length field and bytes for 00041 // the content string 00042 _length = 2 + strlen(_content); 00043 }; 00044 00045 00046 SDESItem::SDESItem(const SDESItem& sdesItem) : cObject() { 00047 operator=(sdesItem); 00048 }; 00049 00050 00051 SDESItem::~SDESItem() { 00052 }; 00053 00054 00055 SDESItem& SDESItem::operator=(const SDESItem& sdesItem) { 00056 cObject::operator=(sdesItem); 00057 _type = sdesItem._type; 00058 _length = sdesItem._length; 00059 _content = opp_strdup(sdesItem._content); 00060 return *this; 00061 }; 00062 00063 00064 SDESItem *SDESItem::dup() const { 00065 return new SDESItem(*this); 00066 }; 00067 00068 00069 std::string SDESItem::info() { 00070 std::stringstream out; 00071 out << "SDESItem=" << _content; 00072 return out.str(); 00073 }; 00074 00075 00076 void SDESItem::dump(std::ostream& os) { 00077 os << "SDESItem:" << endl; 00078 os << " type = " << _type << endl; 00079 os << " content = " << _content << endl; 00080 }; 00081 00082 00083 SDESItem::SDES_ITEM_TYPE SDESItem::getType() { 00084 return _type; 00085 }; 00086 00087 00088 const char *SDESItem::getContent() { 00089 return opp_strdup(_content); 00090 }; 00091 00092 00093 int SDESItem::getLength() { 00094 // bytes needed for this sdes item are 00095 // one byte for type, one for length 00096 // and the string 00097 return _length + 2; 00098 }; 00099 00100 00101 // 00102 // SDESChunk 00103 // 00104 00105 Register_Class(SDESChunk); 00106 00107 00108 SDESChunk::SDESChunk(const char *name, uint32 ssrc) : cArray(name) { 00109 _ssrc = ssrc; 00110 _length = 4; 00111 }; 00112 00113 00114 SDESChunk::SDESChunk(const SDESChunk& sdesChunk) : cArray(sdesChunk) { 00115 setName(sdesChunk.getName()); 00116 operator=(sdesChunk); 00117 }; 00118 00119 00120 SDESChunk::~SDESChunk() { 00121 }; 00122 00123 00124 SDESChunk& SDESChunk::operator=(const SDESChunk& sdesChunk) { 00125 cArray::operator=(sdesChunk); 00126 _ssrc = sdesChunk._ssrc; 00127 _length = sdesChunk._length; 00128 return *this; 00129 }; 00130 00131 00132 SDESChunk *SDESChunk::dup() const { 00133 return new SDESChunk(*this); 00134 }; 00135 00136 00137 std::string SDESChunk::info() { 00138 std::stringstream out; 00139 out << "SDESChunk.ssrc=" << _ssrc << " items=" << size(); 00140 return out.str(); 00141 }; 00142 00143 00144 void SDESChunk::dump(std::ostream& os) { 00145 os << "SDESChunk:" << endl; 00146 os << " ssrc = " << _ssrc << endl; 00147 for (int i = 0; i < size(); i++) { 00148 if (exist(i)) { 00149 //FIXME get(i)->dump(os); 00150 }; 00151 }; 00152 }; 00153 00154 00155 void SDESChunk::addSDESItem(SDESItem *sdesItem) { 00156 for (int i = 0; i < size(); i++) { 00157 if (exist(i)) { 00158 SDESItem *compareItem = (SDESItem *)(get(i)); 00159 if (compareItem->getType() == sdesItem->getType()) { 00160 remove(compareItem); 00161 _length = _length - compareItem->getLength(); 00162 delete compareItem; 00163 }; 00164 } 00165 }; 00166 00167 //sdesItem->setOwner(this); 00168 add(sdesItem); 00169 _length = _length + (sdesItem->getLength()); 00170 00171 }; 00172 00173 00174 uint32 SDESChunk::getSSRC() { 00175 return _ssrc; 00176 }; 00177 00178 00179 void SDESChunk::setSSRC(uint32 ssrc) { 00180 _ssrc = ssrc; 00181 }; 00182 00183 00184 int SDESChunk::getLength() { 00185 return _length; 00186 };