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 #ifndef _h223types_H 19 #define _h223types_H 20 21 #include "oscl_base.h" 22 #include "oscl_mem.h" 23 #include "pvt_params.h" 24 #include "h245pri.h" 25 #include "h245_deleter.h" 26 #include "h245_copier.h" 27 28 #ifndef OSCL_SHARED_PTR_H_INCLUDED 29 #include "oscl_shared_ptr.h" 30 #endif 31 32 #ifndef OSCL_VECTOR_H_INCLUDED 33 #include "oscl_vector.h" 34 #endif 35 36 #include "oscl_map.h" 37 #ifndef PVMF_MEDIA_DATA_IMPL_H_INCLUDED 38 #include "pvmf_media_data_impl.h" 39 #endif 40 #ifndef PVMF_MEDIA_DATA_H_INCLUDED 41 #include "pvmf_media_data.h" 42 #endif 43 44 #define MAX_LCNS 5 45 #define FIRST_NULL_LCN 1000 46 #define MAX_SEGMENTABLE_LCN_NUM 2 47 48 #define H223_MAX_MUX_PDU_SIZE 512 49 #define H223_MAX_MUX_PDU_SIZE_LEVEL2 255 50 #define H223_MAX_DEMUX_PDU_SIZE 1024 51 #define H223_DEF_PDU_SIZE 240 52 53 #define H223Error_t int 54 typedef H223Error_t H223Ret_t; 55 #define H223_OK 0 56 #define H223_ERROR 1 57 #define H223_ERROR_OUT_OF_MEMORY 2 58 #define H223_ERROR_OUT_OF_DEMUX_MEMORY 3 59 #define H223_INSUFFICIENT_DATA 4 60 #define H223_ERROR_BUFFER_SZ 5 61 #define H223_STATE_BUSY 6 62 #define H223_ERROR_INVALID_LCN 7 63 #define H223_ERROR_MAX_LCNS 8 64 #define H223_ERROR_INVALID_PARAM 9 65 66 #define NO_ERR 0 67 #define CRC_ERR 1 68 #define SN_ERR 2 69 #define H223_RC_UCF 1 70 #define H223_RC_FINITE 0 71 #define H223_MUXTYPE_LCN 0 72 #define H223_MUXTYPE_SEL 1 73 74 #define MAX_H223_PDU_PACKETS_PER_SEND 20 75 #define MAX_FRAGMENTS_PER_H223_PDU_PACKET 10 76 #define H223_MAX_PDU_SIZE 254 77 #define H223_MIN_PDU_SIZE 80 78 #define H223_DEFAULT_PDU_SIZE 160 79 #define H223_MIN_SEGMENTABLE_PAYLOAD_SIZE 80 80 #define H223_DEFAULT_MT_SN -1 81 #define H223_DEFAULT_MT_NUM 0 82 83 class CPVMultiplexDescriptor : public CPVParam 84 { 85 public: 86 CPVMultiplexDescriptor(PS_MuxDescriptor desc, bool delete_multiplexEntryDescriptors = false) descriptor(desc)87 : descriptor(desc), iDelete_multiplexEntryDescriptors(delete_multiplexEntryDescriptors) {} ~CPVMultiplexDescriptor()88 ~CPVMultiplexDescriptor() 89 { 90 if (descriptor) 91 { 92 if (descriptor->size_of_multiplexEntryDescriptors) 93 { 94 for (int i = 0; i < descriptor->size_of_multiplexEntryDescriptors; i++) 95 { 96 Delete_MultiplexEntryDescriptor(&descriptor->multiplexEntryDescriptors[i]); 97 } 98 if (iDelete_multiplexEntryDescriptors) 99 { 100 OSCL_DEFAULT_FREE(descriptor->multiplexEntryDescriptors); 101 descriptor->multiplexEntryDescriptors = NULL; 102 } 103 } 104 OSCL_DEFAULT_FREE(descriptor); 105 descriptor = NULL; 106 } 107 } Copy()108 CPVParam* Copy() 109 { 110 return NULL; 111 } 112 GetDescriptor()113 PS_MuxDescriptor GetDescriptor() 114 { 115 return descriptor; 116 } 117 PS_MuxDescriptor descriptor; 118 bool iDelete_multiplexEntryDescriptors; 119 }; 120 121 class H223ChannelParam : public CPVChannelParam 122 { 123 public: 124 H223ChannelParam(TPVChannelId id, PS_H223LogicalChannelParameters lcp, PS_DataType dt); 125 H223ChannelParam(TPVChannelId id, 126 PS_H223LogicalChannelParameters lcp, 127 unsigned bitrate, 128 unsigned sample_interval); 129 130 H223ChannelParam(const H223ChannelParam & that); 131 ~H223ChannelParam(); 132 H223ChannelParam& operator =(const H223ChannelParam& that); 133 134 void SetLcnParams(PS_H223LogicalChannelParameters lcp); 135 136 void SetDataType(PS_DataType dt); 137 138 void Clear(); 139 140 PS_H223LogicalChannelParameters GetLcnParams(); 141 142 PS_DataType GetDataType(); 143 144 void SetChannelId(TPVChannelId id); 145 146 TPVChannelId GetChannelId(); 147 unsigned GetBitrate(); 148 unsigned GetSampleInterval(); 149 unsigned GetFormatSpecificInfo(uint8*& fsi); 150 private: 151 TPVChannelId lcn; 152 PS_H223LogicalChannelParameters pH223Lcp; 153 PS_DataType pDataType; 154 unsigned bitrate; 155 unsigned sample_interval; 156 }; 157 158 enum OlcState 159 { 160 OLC_IDLE = 0x1, 161 OLC_PENDING = 0x2, 162 OLC_ESTABLISHED = 0x4, 163 OLC_CLOSING = 0x8, 164 OLC_CLOSED = 0x10, 165 OLC_STATE_UNKNOWN = 0x1F 166 }; 167 168 enum MtState 169 { 170 MT_IDLE = 0x1, 171 MT_PENDING = 0x2, 172 MT_COMPLETE = 0x4, 173 MT_RELEASING = 0x8, 174 MT_RELEASED = 0x10, 175 MT_STATE_UNKNOWN = 0x1F 176 }; 177 178 class OlcParam 179 { 180 public: 181 static OlcParam* NewL(TPVDirection dir, TPVChannelId iId, H223ChannelParam* forward_params, H223ChannelParam* reverse_params = NULL); 182 ~OlcParam(); 183 void SetState(OlcState state); 184 185 TPVDirection GetDirection(); 186 TPVChannelId GetChannelId(); 187 OlcState GetState(); 188 TPVDirectionality GetDirectionality(); 189 H223ChannelParam* GetForwardParams(); 190 H223ChannelParam* GetReverseParams(); 191 void SetMtState(MtState state); 192 MtState GetMtState(); 193 void SetMtSn(int32 sn); 194 int32 GetMtSn()const; 195 void SetMtNum(uint32 num); 196 uint32 GetMtNum()const; 197 void SetReplacementFor(TPVChannelId id); 198 TPVChannelId GetReplacementFor(); 199 void InitOlc(TPVDirection dir, 200 TPVChannelId id, 201 PS_DataType dt, 202 PS_H223LogicalChannelParameters lcp, 203 TPVChannelId idRvs = CHANNEL_ID_UNKNOWN, 204 PS_DataType dtRvs = NULL, 205 PS_H223LogicalChannelParameters lcpRvs = NULL); IsMyType(int type)206 bool IsMyType(int type) 207 { 208 return type == iMyType; 209 } 210 friend class OlcList; 211 protected: 212 OlcParam(); 213 void Set(TPVDirection dir, TPVChannelId iId, H223ChannelParam* forward_params, H223ChannelParam* reverse_params); 214 int iMyType; 215 216 private: 217 TPVDirection iDir; 218 TPVChannelId iId; 219 OlcState iState; 220 H223ChannelParam* iForwardParams; 221 H223ChannelParam* iReverseParams; 222 MtState iMtState; 223 int32 iMtSn; /* while Pending, it is >0 */ 224 uint32 iMtNum; /* Is valid while pending and established */ 225 TPVChannelId iReplacementForChannelId; 226 }; 227 228 class OlcKey 229 { 230 public: OlcKey()231 OlcKey(): iDir(PV_DIRECTION_BOTH), iId(0) {} OlcKey(TPVDirection dir,TPVChannelId id)232 OlcKey(TPVDirection dir, TPVChannelId id) : iDir(dir), iId(id) {} 233 TPVDirection iDir; 234 TPVChannelId iId; 235 }; 236 237 inline int operator < (const OlcKey& a, const OlcKey& b) 238 { 239 if (a.iDir == b.iDir) 240 { 241 return (a.iId < b.iId); 242 } 243 return (a.iDir < b.iDir); 244 } 245 246 class OlcList: public Oscl_Map<OlcKey, OlcParam*, OsclMemAllocator> 247 { 248 public: 249 OlcList(); 250 ~OlcList(); 251 unsigned FindCodecs(TPVDirection dir, 252 PV2WayMediaType media_type, 253 unsigned states, 254 TPVDirection owner, 255 Oscl_Vector<OlcFormatInfo, OsclMemAllocator>& list); 256 bool FindCodec(TPVDirection dir, 257 PV2WayMediaType media_type, 258 unsigned states, 259 TPVDirection owner, 260 OlcFormatInfo& info); 261 unsigned FindOutgoingOlcsByMtState(unsigned states, 262 Oscl_Vector<OlcParam*, OsclMemAllocator>& list); 263 264 bool IsSymmetric(PV2WayMediaType media_type, 265 unsigned outgoing_states, 266 unsigned incoming_states); 267 bool IsSymmetric(PV2WayMediaType media_type, 268 TPVDirection out_owner, 269 unsigned outgoing_states, 270 TPVDirection in_owner, 271 unsigned incoming_states); 272 void Clear(); 273 274 bool HasOlcs(TPVDirection dir, 275 PV2WayMediaType media_type, 276 unsigned states); 277 bool HasOlc(TPVDirection dir, TPVChannelId lcn); 278 bool HasOlc(TPVDirection dir, TPVChannelId lcn, unsigned state); 279 void SetCurrLcn(TPVChannelId aCurLcn); 280 TPVChannelId GetNextAvailLcn(); 281 unsigned FindOlcs(TPVDirection dir, 282 PV2WayMediaType media_type, 283 unsigned states, 284 Oscl_Vector<OlcParam*, OsclMemAllocator>& list); 285 OlcParam* FindOlc(TPVDirection dir, 286 PV2WayMediaType media_type, 287 unsigned states); 288 OlcParam* FindOlcGivenChannel(TPVDirection dir, TPVChannelId lcn); 289 290 OlcParam* FindOlcByMtSn(uint32 sn); 291 292 void AppendOlc(OlcParam* param, 293 TPVDirection dir, 294 TPVChannelId id); 295 296 OlcParam* AppendOlc(TPVDirection dir, 297 TPVChannelId id, 298 PS_DataType dt, 299 PS_H223LogicalChannelParameters lcp, 300 TPVChannelId idRvs = CHANNEL_ID_UNKNOWN, 301 PS_DataType dtRvs = NULL, 302 PS_H223LogicalChannelParameters lcpRvs = NULL); 303 304 305 private: 306 TPVChannelId iCurLcn; 307 }; 308 309 310 class TPVMuxDescriptorSlot 311 { 312 public: 313 unsigned lcn; 314 unsigned min_size; 315 unsigned max_size; 316 int is_fit(unsigned that_lcn, unsigned size); 317 }; 318 319 typedef Oscl_Map<unsigned , TPVMuxDescriptorSlot, PoolMemAlloc_OsclMemAllocator_10> TPVMuxDescriptorSlotList; 320 321 class CPVMultiplexEntryDescriptor 322 { 323 public: 324 OSCL_IMPORT_REF static CPVMultiplexEntryDescriptor* NewL(PS_MultiplexEntryDescriptor descriptor, unsigned max_pdu_size); 325 OSCL_IMPORT_REF CPVMultiplexEntryDescriptor(const CPVMultiplexEntryDescriptor& that); 326 OSCL_IMPORT_REF ~CPVMultiplexEntryDescriptor(); 327 OSCL_IMPORT_REF unsigned NumLcns(); 328 OSCL_IMPORT_REF int FindLcn(uint16 channel_id, uint16 len, TPVMuxDescriptorSlot& slot_info); 329 OSCL_IMPORT_REF PS_MultiplexEntryDescriptor GetH245descriptor(); 330 private: 331 CPVMultiplexEntryDescriptor(); 332 void ConstructL(PS_MultiplexEntryDescriptor descriptor, unsigned max_pdu_size); 333 334 unsigned FindLcns( 335 PS_MultiplexElement pElement, 336 int ListSize, 337 int max_size, 338 TPVMuxDescriptorSlotList& lcns, 339 int* sublelement_size); 340 341 PS_MultiplexEntryDescriptor iDescriptor; 342 unsigned iMaxPduSize; 343 TPVMuxDescriptorSlotList iLcns; 344 }; 345 346 class CPVMultiplexEntryDescriptorVector : public Oscl_Vector<CPVMultiplexEntryDescriptor*, OsclMemAllocator> 347 { 348 public: 349 OSCL_IMPORT_REF CPVMultiplexEntryDescriptorVector(); 350 OSCL_IMPORT_REF CPVMultiplexEntryDescriptorVector(const CPVMultiplexEntryDescriptorVector& that); 351 OSCL_IMPORT_REF ~CPVMultiplexEntryDescriptorVector(); 352 OSCL_IMPORT_REF void Clear(); 353 }; 354 355 typedef PoolMemAlloc<8> PoolMemAlloc_OsclMemAllocator_8; 356 typedef PoolMemAlloc<MAX_H223_PDU_PACKETS_PER_SEND, 512> PoolMemAlloc_OsclMemAllocator_MAX_H223_PDU_PACKETS_PER_SEND; 357 typedef Oscl_Vector<OsclSharedPtr<PVMFMediaDataImpl>, OsclMemAllocator> MuxPduPacketList; 358 359 360 #endif /* _h223api_H */ 361