1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #if !defined(H223_MULTIPLEX_H) 19 #define H223_MULTIPLEX_H 20 #include "oscl_rand.h" 21 22 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED 23 #include "pvmf_media_clock.h" 24 #endif 25 26 #include "h245pri.h" 27 #include "oscl_timer.h" 28 #include "h223types.h" 29 #include "pduparcom.h" 30 #include "lowerlayer.h" 31 #include "logicalchannel.h" 32 33 #ifndef PVMF_MEDIA_DATA_IMPL_H_INCLUDED 34 #include "pvmf_media_data_impl.h" 35 #endif 36 37 #ifndef PVLOGGER_H_INCLUDED 38 #include "pvlogger.h" 39 #endif 40 41 class MuxTableMgr; 42 43 44 typedef OsclSharedPtr<H223OutgoingChannel> H223OutgoingChannelPtr; 45 typedef OsclSharedPtr<H223IncomingChannel> H223IncomingChannelPtr; 46 typedef Oscl_Map<unsigned , OsclSharedPtr<PVMFMediaDataImpl>, PoolMemAlloc_OsclMemAllocator_10> MuxSduList; 47 class CPVH223MultiplexObserver 48 { 49 public: 50 virtual void DataReceptionStart() = 0; ~CPVH223MultiplexObserver()51 virtual ~CPVH223MultiplexObserver() {} 52 virtual void MuxSetupComplete(PVMFStatus status, TPVH223Level level) = 0; 53 virtual void MuxCloseComplete() = 0; 54 virtual void MuxErrorOccurred(TPVDirection direction, TPVMuxComponent component, PVMFStatus error, 55 uint8* info = NULL, uint info_len = 0) = 0; 56 virtual void SkewDetected(TPVChannelId lcn1, TPVChannelId lcn2, uint32 skew) = 0; 57 virtual void LcnDataDetected(TPVChannelId lcn) = 0; 58 virtual void ReceivedFormatSpecificInfo(TPVChannelId lcn, uint8* fsi, uint32 fsi_len) = 0; 59 }; 60 61 class CPVH223Multiplex : public LowerLayerObserver, 62 public H223PduParcomObserver, 63 public LogicalChannelObserver 64 { 65 public: 66 CPVH223Multiplex(TPVLoopbackMode aLoopbackMode); 67 ~CPVH223Multiplex(); SetObserver(CPVH223MultiplexObserver * observer)68 void SetObserver(CPVH223MultiplexObserver* observer) 69 { 70 iObserver = observer; 71 } 72 TPVStatusCode SetTimerRes(uint32 timer_res); 73 74 PVMFPortInterface* GetLowerLayer(); 75 76 /* LoweLayer observer virtuals */ 77 void DataReceptionStart(); 78 void LevelSetupComplete(PVMFStatus status, TPVH223Level level); 79 PVMFStatus GetOutgoingMuxPdus(MuxPduPacketList& packets); 80 void LowerLayerError(TPVDirection directions, PVMFStatus error); 81 82 /* PduParcomObserver virtuals */ 83 uint32 MuxPduIndicate(uint8* pPdu, uint32 pduSz, int32 fClosing, int32 muxCode); 84 void MuxPduErrIndicate(EMuxPduError err); 85 void MuxSetupComplete(PVMFStatus status, TPVH223Level level); GetParcomObserver()86 H223PduParcomObserver* GetParcomObserver() 87 { 88 return this; 89 } 90 91 /* LogicalChannelObserver virtuals */ 92 inline int32 GetTimestamp(); 93 void LogicalChannelError(TPVDirection direction, TPVChannelId id, PVMFStatus error); 94 void SkewDetected(TPVChannelId lcn1, TPVChannelId lcn2, uint32 skew); 95 void ReceivedFormatSpecificInfo(TPVChannelId lcn, uint8* fsi, uint32 fsi_len); 96 97 void Init(); 98 99 /* allocates resources */ 100 TPVStatusCode Open(); 101 102 /* de-allocates resources */ 103 TPVStatusCode Close(); 104 105 /* Starts active element */ 106 int Start(H223PduParcomSharedPtr parcom); 107 108 /* Stops active element */ 109 int Stop(); 110 111 TPVH223Level GetMuxLevel(); 112 113 int GetMinTimerRes(); 114 115 TPVStatusCode SetSduSize(TPVDirection direction, uint16 size, ErrorProtectionLevel_t epl); 116 117 uint16 GetSduSize(TPVDirection direction, ErrorProtectionLevel_t epl); 118 119 uint16 GetMaxSduSize(TPVDirection direction, ErrorProtectionLevel_t epl); 120 121 // Channel APIs GetMaxChannels(TPVDirection)122 unsigned GetMaxChannels(TPVDirection /*direction*/) 123 { 124 return MAX_LCNS; 125 } 126 unsigned GetNumChannels(TPVDirection direction); 127 128 TPVStatusCode OpenChannel(TPVDirection direction, TPVChannelId channel_id, H223ChannelParam* channel_param); 129 TPVStatusCode CloseChannel(TPVDirection direction, TPVChannelId channel_id); 130 PVMFStatus GetOutgoingChannel(TPVChannelId id, H223OutgoingChannelPtr& channel); 131 PVMFStatus GetIncomingChannel(TPVChannelId id, H223IncomingChannelPtr& channel); 132 TPVStatusCode StopChannel(TPVDirection /*direction*/, TPVChannelId /*channel_id*/); 133 TPVStatusCode FlushChannel(TPVDirection /*direction*/, TPVChannelId /*channel_id*/); IsValid(TPVDirection,TPVChannelId)134 bool IsValid(TPVDirection /*direction*/, TPVChannelId /*channel_id*/) 135 { 136 return false; 137 } 138 139 140 TPVStatusCode SetMaxOutgoingPduSize(uint16 Size); 141 unsigned GetMaxPduSize(TPVDirection direction); 142 143 TPVStatusCode SetIncomingMuxTableEntries(CPVMultiplexDescriptor* descriptor); 144 void SetIncomingMuxDescriptors(CPVMultiplexEntryDescriptorVector& descriptors, bool replace = true); 145 void SetOutgoingMuxDescriptors(CPVMultiplexEntryDescriptorVector& descriptors); 146 void RemoveOutgoingMuxDescriptor(uint8 muxTblNum); 147 void RemoveIncomingMuxDescriptor(uint8 muxTblNum); 148 void SetLoopbackMode(TPVLoopbackMode aLoopbackMode); 149 PS_MultiplexEntryDescriptor GetIncomingMuxDescriptor(uint16 muxTblNum); 150 151 void ResetStats(); 152 void LogStats(TPVDirection dir); 153 154 /* Set muliplex level. Can be called before the multiplex is started */ 155 void SetMultiplexLevel(TPVH223Level muxLevel); SetClock(PVMFMediaClock * aClock)156 void SetClock(PVMFMediaClock* aClock) 157 { 158 iClock = aClock; 159 } 160 void SetMultiplexingDelayMs(uint16 aDelay); 161 void SetLogicalChannelBufferingMs(uint32 aInBufferingMs, 162 uint32 aOutBufferingMs); 163 void SetBitrate(uint32 bitrate); 164 void SetInterleavingMultiplexFlags(uint16 size, uint8* flags); 165 void EnableStuffing(bool enable); 166 TPVStatusCode SetMuxLevel(TPVH223Level muxLevel); 167 void EnableStuffOnlyFirstSend(bool enable); 168 void SetMioLatency(int32 aLatency, bool aAudio); 169 protected: 170 TPVStatusCode AlPduData(H223IncomingChannel* aChannel, 171 uint8*& pdu, 172 PS_MultiplexElement pElement, 173 int n); 174 TPVStatusCode Dispatch(H223IncomingChannel* aChannel, 175 PS_MultiplexElement pElement); 176 TPVStatusCode GetAdaptationLayer(OsclSharedPtr<AdaptationLayer> &al, 177 TPVDirection aDirection, 178 PS_H223LogicalChannelParameters aH223lcnParams, 179 int32 aSdu_size, 180 uint32 aNum_media_data); 181 void MakePduData(OsclSharedPtr<PVMFMediaDataImpl>& outgoingPkt, 182 int32 max_size, 183 PS_MultiplexElement pElement, 184 MuxSduData& mux_sdu_data, 185 int* pm); 186 int MuxToALDispatch(uint8* pdu, int pdu_size, int fClosing, int muxCode); 187 int BreakPduData(uint8*& pdu, int pdu_size, PS_MultiplexElement pElement, int ListSize); 188 Mux()189 TPVStatusCode Mux() 190 { 191 return EPVT_Success; 192 } Demux()193 TPVStatusCode Demux() 194 { 195 return EPVT_Success; 196 } 197 198 199 PVMFStatus FindOutgoingChannel(TPVChannelId id, OsclSharedPtr<H223OutgoingChannel>& channel); 200 PVMFStatus FindIncomingChannel(TPVChannelId id, OsclSharedPtr<H223IncomingChannel>& channel); 201 202 MuxSduData* FindMuxSduData(TPVChannelId lcn, 203 bool segmentable, 204 uint32* index = NULL); 205 void AppendMuxSduData(MuxSduData& data); 206 void SetMuxSduData(MuxSduData& data); 207 void RemoveMuxSduData(TPVChannelId lcn, bool segmentable); 208 /* This fn checks if there is more data in the logical channel */ 209 void ReleaseMuxSdu(MuxSduData& mux_sdu_data, 210 MuxSduDataList& list, 211 unsigned index); 212 unsigned UpdateSduDataLists(); 213 214 OsclSharedPtr<PVMFMediaDataImpl> InitPduPacket(); 215 PVMFStatus CompletePduPacket(OsclSharedPtr<PVMFMediaDataImpl>& packet, int mt, int pm); 216 unsigned DispatchPduPacket(MuxPduPacketList& packets, 217 MuxSduData& mux_sdu_data, 218 PS_MultiplexEntryDescriptor entry, 219 uint32 max_size); 220 void UpdateMuxInterval(uint16 aInterval = 0); 221 void ClearSduDataLists(); 222 uint16 MuxLcnData(MuxSduDataList& list, 223 MuxPduPacketList& packets, 224 uint16 max_size); 225 226 void SetStuffingMsgHeader(); 227 228 /* Lower Layer instance which binds to TSAP */ 229 H223LowerLayer* iLowerLayer; 230 231 /* Outgoing logical channels */ 232 Oscl_Vector<H223OutgoingChannelPtr, OsclMemAllocator> iOutgoingChannels; 233 234 /* Incoming logical channels */ 235 Oscl_Vector<H223IncomingChannelPtr, OsclMemAllocator> iIncomingChannels; 236 237 int iALIndex[MAX_LCNS]; 238 239 /* Sizes of current packets being muxed */ 240 MuxSduDataList iNonSegmentableSduDataList; 241 MuxSduDataList iSegmentableSduDataList; 242 MuxSduDataList iControlSduDataList; 243 /* A '1' in the bit pos indicates data is available for this lcn */ 244 unsigned iLcnsWithData; 245 246 /* segmentable lcn ending on current pdu */ 247 H223IncomingChannel* iLcnEnd; 248 249 /* bitrate, bps */ 250 uint32 iBitrate; 251 252 /* operational state */ 253 bool iState; 254 255 /* Mux table manager*/ 256 MuxTableMgr* iMuxTblMgr; 257 258 /* SDU sizes */ 259 int iMaxAlSduSize[4]; 260 int iMaxAlSduSizeR[4]; 261 262 int iAlSduSize[4]; 263 int iAlSduSizeR[4]; 264 265 OSCL_wHeapString<OsclMemAllocator> iInstanceId; 266 267 TPVLoopbackMode iLoopbackMode; 268 269 /* Use this for aborting a segmentable mux sdu */ 270 DefFragmentAllocator iAlloc; 271 MediaFragment* iDummyFragment; 272 273 OsclMemPoolFixedChunkAllocator* iMediaDataImplMemAlloc; 274 PVMFMediaFragGroupCombinedAlloc<OsclMemAllocator>* iMuxPduPacketAlloc; 275 PVLogger *iLogger; 276 PVMFMediaClock* iClock; 277 OsclRand iRand; 278 uint16 iMinSampleInterval; 279 uint16 iNumMuxIntervalsPerTimerInterval; 280 uint16 iNumBytesPerMinSampleInterval; 281 uint16 iMultiplexingDelayMs; 282 uint32 iInLogicalChannelBufferingMs; 283 uint32 iOutLogicalChannelBufferingMs; 284 uint32 iFmStuffingRepeatInterval; 285 uint32 iFmStuffingMode; 286 uint32 iPduNum; 287 CPVH223MultiplexObserver* iObserver; 288 bool iLevelSetupComplete; 289 uint32 iInterleavingMultiplexFlagsSize; 290 uint8* iInterleavingMultiplexFlags; 291 OsclSharedPtr<PVMFMediaDataImpl> iInterleavingPacket; 292 bool iEnableStuffing; 293 bool iStuffOnlyFirstSend; 294 }; 295 296 typedef CPVH223Multiplex H223; 297 #endif 298