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 _h324utils_h 19 #define _h324utils_h 20 #include "pvt_params.h" 21 #include "h245def.h" 22 #ifndef PVLOGGER_H_INCLUDED 23 #include "pvlogger.h" 24 #endif 25 26 #include "pvt_common.h" 27 28 #define MAX_NUM_SIMULTANEOUS_CAPABILITIES 31 29 #define MAX_CONFIG_INFO_SIZE 128 30 #define MAX_H264_FORMAT_SPECIFIC_INFO_LEN 128 31 #define DEF_AL3_SEND_BUFFER_SIZE 1024 32 33 /* Generic logger macros for using across the protocol stack node */ 34 #define PVMF_INCOMING_VIDEO_LOGDATATRAFFIC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iIncomingVideoLogger,PVLOGMSG_INFO,m); 35 #define PVMF_INCOMING_AUDIO_LOGDATATRAFFIC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iIncomingAudioLogger,PVLOGMSG_INFO,m); 36 #define PVMF_OUTGOING_AUDIO_LOGDATATRAFFIC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iOutgoingAudioLogger,PVLOGMSG_INFO,m); 37 #define PVMF_OUTGOING_VIDEO_LOGDATATRAFFIC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iOutgoingVideoLogger,PVLOGMSG_INFO,m); 38 39 40 #define PV2WAY_FILLER_FSI_LEN 9 41 #define PV2WAY_FILLER_FSI {1,2,3,4,5,6,7,8,9} 42 43 44 /* Allocator for TSC */ 45 class PVMFTscAlloc : public Oscl_DefAlloc 46 { 47 public: allocate(const uint32 size)48 void* allocate(const uint32 size) 49 { 50 void* tmp = (void*)oscl_malloc(size); 51 return tmp; 52 } 53 deallocate(void * p)54 void deallocate(void* p) 55 { 56 oscl_free(p); 57 } 58 }; 59 60 /* Removed C Linkage - Glk - Due to overloaded fxns 61 #ifdef __cplusplus 62 extern "C" { 63 #endif 64 65 */ 66 struct MultiplexCapabilityInfo 67 { 68 bool iAllowAl1Video; 69 bool iAllowAl2Video; 70 bool iAllowAl3Video; 71 bool iAllowAl1Audio; 72 bool iAllowAl2Audio; 73 bool iAllowAl3Audio; 74 unsigned iMaximumAl2SDUSize; 75 unsigned iMaximumAl3SDUSize; 76 }; 77 78 typedef struct S_CapabilityIdentifierStandard 79 { 80 uint8 reserved1; 81 uint8 itu; /* 0 = t */ 82 uint8 spec_type; /* 0==recommendation */ 83 uint8 series_letter; /* h = 8 */ 84 uint32 spec_number; /* 245,241 etc */ 85 uint8 data[4]; 86 }* PS_CapabilityIdentifierStandard; 87 88 89 PVAudTypeSimple_t GetSimpleAudioType(PVAudType_t); 90 91 PVCodecType_t GetCodecType(PS_DataType pDataType); 92 PV2WayMediaType GetMediaType(PS_DataType pDataType); 93 PVCodecType_t GetVidCodecTypeFromVideoCapability(PS_VideoCapability capability); 94 PVCodecType_t GetVidCodecTypeFromCapabilityIdentifier(S_CapabilityIdentifierStandard& identifier); 95 PVCodecType_t GetAudCodecTypeFrom245Index(int32 index); 96 PVCodecType_t GetAudCodecType(PS_GenericCapability audio_capability); 97 PVCodecType_t GetAudCodecType(PS_AudioCapability audio_capability); 98 PVCodecType_t GetUiCodecTypeFrom245Index(int32 index); 99 void GetCodecInfo(PS_Capability capability, CodecCapabilityInfo& info); 100 ErrorProtectionLevel_t GetEpl(uint16 al_index); 101 void printBuffer(PVLogger* logger, const uint8* buffer, uint16 len); 102 unsigned GetFormatSpecificInfo(PS_DataType pDataType, uint8*& fsi); 103 PS_Capability LookupCapability(PS_TerminalCapabilitySet pTcs, uint16 cap_entry_num); 104 bool IsTransmitOnlyAltCapSet(PS_TerminalCapabilitySet pTcs, PS_AlternativeCapabilitySet pAltCapSet); 105 PVMFStatus VerifyCodecs(PS_TerminalCapabilitySet pTcs, 106 Oscl_Vector<OlcFormatInfo, OsclMemAllocator> codecs, 107 PVLogger *logger); 108 PVMFStatus GetCodecCapInfo(PVCodecType_t codec, 109 PS_TerminalCapabilitySet pTcs, 110 CodecCapabilityInfo& codec_info, 111 PVLogger *logger); 112 uint32 CheckAltCapSet(PS_AlternativeCapabilitySet pAltCapSet, uint32 entry); 113 PS_TerminalCapabilitySet GenerateTcs(MultiplexCapabilityInfo& mux_cap_info, 114 Oscl_Vector<CodecCapabilityInfo*, OsclMemAllocator>& outgoing_codecs, 115 Oscl_Vector<CodecCapabilityInfo*, OsclMemAllocator>& incoming_codecs); 116 void FillCapabilityTableEntry(PS_CapabilityTableEntry, CodecCapabilityInfo& codec_info, uint32 entry_num); 117 void FillCapability(CodecCapabilityInfo& codec_info, PS_Capability capability); 118 CodecCapabilityInfo* GetCodecCapabilityInfo(PS_Capability capability); 119 CodecCapabilityInfo* GetCodecCapabilityInfo(PS_GenericCapability capability); 120 void FillVideoCapability(VideoCodecCapabilityInfo& codec_info, PS_VideoCapability video_capability); 121 CodecCapabilityInfo* GetCodecCapabilityInfo(PS_VideoCapability capability); 122 void FillAudioCapability(CodecCapabilityInfo& codec_info, PS_AudioCapability audio_capability); 123 CodecCapabilityInfo* GetCodecCapabilityInfo(PS_AudioCapability capability); 124 void FillH263Capability(VideoCodecCapabilityInfo& video_codec_info, PS_H263VideoCapability h263caps); 125 CodecCapabilityInfo* GetCodecCapabilityInfo(PS_H263VideoCapability capability); 126 void FillG723Capability(PS_G7231 g723caps); 127 CodecCapabilityInfo* GetCodecCapabilityInfo(PS_G7231 capability); 128 void FillAmrCapability(PS_GenericCapability amrCaps); 129 CodecCapabilityInfo* GetCodecCapabilityInfoAmr(PS_GenericCapability capability); 130 CodecCapabilityInfo* GetCodecCapabilityInfoAvc(PS_GenericCapability capability); 131 void FillM4vCapability(VideoCodecCapabilityInfo& video_codec_info, PS_GenericCapability m4vcaps); 132 CodecCapabilityInfo* GetCodecCapabilityInfoMpeg4(PS_GenericCapability capability); 133 void FillUserInputCapability(CodecCapabilityInfo& codec_info, PS_UserInputCapability userinputCaps); 134 CodecCapabilityInfo* GetCodecCapabilityInfo(PS_UserInputCapability capability); 135 void ParseCapabilityIdentifierStandard(uint8* octet_string, uint16 octet_string_len, S_CapabilityIdentifierStandard& capabilityIdentifier); 136 unsigned GetMaxFrameRate(PS_DataType pDataType); 137 unsigned GetMaxFrameRate_H263(PS_H263VideoCapability h263caps); 138 unsigned GetMaxFrameRate_M4V(PS_GenericCapability m4vcaps); 139 unsigned GetMaxFrameRate_AVC(PS_GenericCapability avcCaps); 140 unsigned GetMaxBitrate(PS_DataType pDataType); 141 unsigned GetVideoFrameSize(PS_DataType pDataType, bool width); 142 unsigned GetVideoFrameSize_H263(PS_H263VideoCapability h263caps, bool width); 143 unsigned GetVideoFrameSize_M4V(PS_GenericCapability m4vcaps , bool width); 144 145 bool FindCodecForMediaType(PV2WayMediaType media, Oscl_Vector<CodecCapabilityInfo*, OsclMemAllocator>&list, int* index); 146 bool IsSupported(Oscl_Vector<H324ChannelParameters, PVMFTscAlloc>& list, PV2WayMediaType media, CodecCapabilityInfo& codec_info, int*index); 147 CodecCapabilityInfo* IsSupported(CodecCapabilityInfo* codecInfo, 148 Oscl_Vector<CodecCapabilityInfo*, OsclMemAllocator>& list); 149 bool IsResolutionSupported(const PVMFVideoResolution& resolution, const Oscl_Vector<PVMFVideoResolutionRange, OsclMemAllocator>& resolutions); 150 unsigned GetSampleInterval(PS_DataType pDataType); 151 bool PVCheckSH(uint8 *ptr, int32 size); 152 153 PS_H223LogicalChannelParameters 154 GetH223LogicalChannelParameters(uint8 al_index, 155 bool segmentable, 156 uint32 al_specific = 0); 157 /** Returns 1 if only one media type is present in the ACS. 158 Returns 2 if there are more than one media type 159 **/ 160 uint16 GetCodecCapabilityInfo(PS_TerminalCapabilitySet pTcs, 161 PS_AlternativeCapabilitySet pAcs, 162 Oscl_Vector<CodecCapabilityInfo*, OsclMemAllocator>& in_codecs_acs); 163 void Deallocate(Oscl_Vector<CodecCapabilityInfo*, OsclMemAllocator>& cci); 164 PVMFStatus SetFormatSpecificInfo(PS_DataType pDataType, uint8* fsi, uint32 fsi_len); 165 uint32 SetFillerFsi(uint8* dest, uint32 dest_len); 166 bool IsFillerFsi(uint8* fsi, uint32 fsi_len); 167 168 /* 169 #ifdef __cplusplus 170 } 171 #endif*/ 172 173 #define LOG_STATISTICS 174 175 #if defined(LOG_STATISTICS) 176 #define PV_STAT_SET(a, b)\ 177 a = b; 178 #else 179 #define PV_STAT_SET(a, b) 180 #endif 181 182 #if defined(LOG_STATISTICS) 183 #define PV_STAT_INCR(a, b)\ 184 a += b; 185 #else 186 #define PV_STAT_INCR(a, b) 187 #endif 188 189 #if defined(LOG_STATISTICS) 190 #define PV_STAT_INCR_COND(a, b, c)\ 191 if(c){\ 192 a += b;\ 193 } 194 #else 195 #define PV_STAT_INCR_COND(a, b, c) 196 #endif 197 198 #if defined(LOG_STATISTICS) 199 #define PV_STAT_SET_TIME(a, cond)\ 200 {\ 201 if(cond == 0){\ 202 TimeValue timenow;\ 203 a = timenow;\ 204 }\ 205 } 206 #else 207 #define PV_STAT_SET_TIME(a, cond) 208 #endif 209 210 #endif /* _h324utils_h */ 211