RFC2250.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: RFC2250.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #include "RFC2250.hpp" 00045 #define MAX_RTP_PAYLOAD_SIZE (1488-2-4) //1488 is maximum, but on RTX, we need 2 bytes for real rtpSeqNo 00046 //and 4 bytes is for RFC2250 audio specific header 00047 00048 00049 RFC2250::RFC2250():PacketizationLayer() { 00050 payload_buffer = new u8[MAX_RTP_PAYLOAD_SIZE]; 00051 payload_buffer_size = 0; 00052 buffer_flag = false; 00053 first = true; 00054 new_packet = true; 00055 au_dts = 0; 00056 au_cts = 0; 00057 } 00058 00059 00060 RFC2250::~RFC2250() { 00061 if(payload_buffer) 00062 delete[] payload_buffer; 00063 } 00064 00065 00066 SLPacket * RFC2250::createSLPacket(u8 * payload, size_t size, bool fragment, u32 frag_offset) { 00067 00068 if(first) { 00069 fragment = true; 00070 first = false; 00071 return NULL; // FIXME do we need to send the header in an RTP packet ?? I don't think so! 00072 } 00073 if(fragment) { 00074 if(payload_buffer_size == 0) { //means that buffer is empty, just send act. payload 00075 buffer_flag = false; 00076 return new SLPacket(SLPacketHeader(packetSeqNumber++), payload, size, &frag_offset, 4); 00077 } 00078 else { //send old payload, then store the act. one 00079 SLPacket *slp = new SLPacket(SLPacketHeader(packetSeqNumber++), payload_buffer, 00080 payload_buffer_size, &frag_offset, 4); 00081 memcpy(payload_buffer, payload, size); 00082 payload_buffer_size = size; 00083 buffer_flag = true; 00084 return slp; 00085 } 00086 } 00087 else { 00088 if(buffer_flag) { 00089 SLPacket *slp = new SLPacket(SLPacketHeader(packetSeqNumber++), payload_buffer, 00090 payload_buffer_size, &frag_offset, 4); 00091 memcpy(payload_buffer, payload, size); 00092 payload_buffer_size = size; 00093 buffer_flag = false; 00094 return slp; 00095 } 00096 else { 00097 if((size+payload_buffer_size) < getMaxPacketPayloadSize()) { //cumulative fill-up of MTU 00098 memcpy(payload_buffer+payload_buffer_size, payload, size); 00099 payload_buffer_size += size; 00100 return NULL; 00101 } 00102 else if (payload_buffer_size > 0) { 00103 SLPacket *slp = new SLPacket(SLPacketHeader(packetSeqNumber++), payload_buffer, 00104 payload_buffer_size, &frag_offset, 4); 00105 memcpy(payload_buffer, payload, size); 00106 payload_buffer_size = size; 00107 return slp; 00108 } 00109 } 00110 } 00111 return new SLPacket(SLPacketHeader(packetSeqNumber++), payload, size, &frag_offset, 4); 00112 } 00113 00114 00116 SLPacketList RFC2250::createSLPacketList(AU * au) { 00117 SLPacketList slpl; 00118 // copied and adapted from MOH 00119 u32 unitSize = au->size; 00120 /*frag_offset is RFC2250 specific info 00121 * It is irrelevant for RFC3016 */ 00122 u32 frag_offset = 0; 00123 00124 if (au->size <= getMaxPacketPayloadSize()) { 00125 dprintf_full(" RFC2250::createSLPacketList creates single SLPacket of size %i\n", unitSize); 00126 SLPacket *packet = createSLPacket(au->payload, unitSize, false, frag_offset); 00127 if(new_packet){ 00128 au_dts = au->dts; 00129 au_cts = au->cts; 00130 new_packet = false; 00131 } 00132 if(packet) { 00133 SLPacketHeader & slph = packet->getSLPacketHeader(); 00134 slph.accessUnitStartFlag = true; 00135 slph.accessUnitEndFlag = true; 00136 00137 // FIXME: how to know if this is true? 00138 slph.randomAccessPointFlag = true; 00139 slph.decodingTimeStampFlag = true; 00140 slph.decodingTimeStamp = au_dts; 00141 slph.compositionTimeStamp = au_cts; 00142 slph.compositionTimeStampFlag = true; 00143 slpl.push_back(packet); //add this packet 00144 new_packet = true; 00145 } 00146 00147 // pLayer->sendSLPackets(slpl); 00148 } else { 00149 u32 maxsize = getMaxPacketPayloadSize(); 00150 u8 * payload = au->payload; 00151 bool first = true; 00152 int currentSize = 0; 00153 while (unitSize) { 00154 if (unitSize <= maxsize) { // last packet 00155 currentSize = unitSize; 00156 } else { // first or intermediate packet 00157 currentSize = maxsize; 00158 } 00159 SLPacket * packet = createSLPacket(payload, currentSize, true, frag_offset); 00160 frag_offset += currentSize; 00161 SLPacketHeader & slph = packet->getSLPacketHeader(); 00162 if (unitSize <= maxsize) { // last packet 00163 slph.accessUnitEndFlag = true; 00164 slph.accessUnitStartFlag = false; 00165 slph.randomAccessPointFlag = false; 00166 slph.decodingTimeStampFlag = false; 00167 slph.compositionTimeStampFlag = false; 00168 } 00169 else { // first or intermediate packet 00170 if (first) { 00171 slph.accessUnitStartFlag = true; 00172 00173 // FIXME: how to know if this is true? 00174 slph.randomAccessPointFlag = true; 00175 slph.decodingTimeStampFlag = true; 00176 slph.compositionTimeStampFlag = true; 00177 first = false; 00178 } 00179 else { // intermediate packet 00180 slph.accessUnitStartFlag = false; 00181 slph.randomAccessPointFlag = false; 00182 slph.decodingTimeStampFlag = false; 00183 slph.compositionTimeStampFlag = false; 00184 } 00185 slph.accessUnitEndFlag = false; 00186 } 00187 slph.decodingTimeStamp = au->dts; 00188 slph.compositionTimeStamp = au->cts; 00189 slpl.push_back(packet); 00190 00191 // pLayer->sendSLPackets(slpl); 00192 unitSize -= currentSize; 00193 payload += currentSize; 00194 } // while unitSize 00195 } 00196 return slpl; 00197 } 00198 00199 00200 00201 00202 u32 RFC2250::getMaxPacketPayloadSize() 00203 { 00204 return MAX_RTP_PAYLOAD_SIZE; 00205 }; 00206 00207 u32 RFC2250::getPacketizationType() 00208 { 00209 return 2250; 00210 }