1 /** 2 * Copyright (C) 2022 The Android Open Source Project 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 express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef IMSMEDIA_VIDEO_UTIL_H_INCLUDED 18 #define IMSMEDIA_VIDEO_UTIL_H_INCLUDED 19 20 #include <stdint.h> 21 #include <ImsMediaDefine.h> 22 #include <VideoConfig.h> 23 24 #define MAX_CONFIG_LEN 256 25 #define MAX_CONFIG_INDEX 3 26 #define MAX_VIDEO_WIDTH 1920 27 #define MAX_VIDEO_HEIGHT 1920 28 #define MAX_WAIT_RESTART 1000 29 #define MAX_WAIT_CAMERA 1000 30 #define MAX_RTP_PAYLOAD_BUFFER_SIZE (MAX_VIDEO_WIDTH * MAX_VIDEO_HEIGHT * 3 >> 1) 31 32 enum kVideoResolution 33 { 34 /* video resolu tion is not defined */ 35 kVideoResolutionInvalid, 36 kVideoResolutionSqcifLandscape, // 128x92 37 kVideoResolutionSqcifPortrait, // 92x128 38 kVideoResolutionQcifLandscape, // 176x144 39 kVideoResolutionQcifPortrait, // 144x176 40 kVideoResolutionQvgaLandscape, // 320x240 41 kVideoResolutionQvgaPortrait, // 240x320 42 kVideoResolutionSifLandscape, // 352x240 43 kVideoResolutionSifPortrait, // 240x352 44 kVideoResolutionCifLandscape, // 352x288 45 kVideoResolutionCifPortrait, // 288x352 46 kVideoResolutionVgaLandscape, // 640x480 47 kVideoResolutionVgaPortrait, // 480x640 48 kVideoResolutionHdLandscape, // 1280x720 49 kVideoResolutionHdPortrait, // 720x1280 50 kVideoResolutionFhdLandscape, // 1920x1280 51 kVideoResolutionFhdPortrait, // 1280x1920 52 }; 53 54 enum kConfigFrameType 55 { 56 kConfigSps = 0, 57 kConfigPps = 1, 58 kConfigVps = 2, 59 }; 60 61 struct tCodecConfig 62 { 63 uint32_t nWidth; 64 uint32_t nHeight; 65 uint32_t nProfile; 66 uint32_t nLevel; 67 }; 68 69 enum kRtcpFeedbackType 70 { 71 kRtcpFeedbackNone = 0, 72 kRtpFbNack = 1, // Generic NACK 73 kRtpFbTmmbr = 3, // Temoporary Maximum Media Stream Bitrate Request 74 kRtpFbTmmbn = 4, // Temoporary Maximum Media Stream Bitrate Notification 75 kPsfbBoundary = 10, 76 kPsfbPli = 11, // Picture Loss Indication 77 kPsfbSli = 12, // Slice Loss Indication 78 kPsfbRrsi = 13, // Reference Picture Selection Indication 79 kPsfbFir = 14, // Full Intra Request - same as "fast video update" 80 kPsfbTstr = 15, // Temporal-Spatial Tradeoff Request - used for changing framerate 81 kPsfbTstn = 16, // Temporal-Spatial Tradeoff Noficiation 82 kPsfbVbcm = 17, // Video Back Channel Message 83 }; 84 85 enum kNackRequestType 86 { 87 kRequestSendNackNone = 0, 88 kRequestInitialNack, 89 kRequestSecondNack, 90 kRequestPli, 91 }; 92 93 struct NackParams 94 { 95 public: NackParamsNackParams96 NackParams() : 97 PID(0), 98 BLP(0), 99 nSecNackCnt(0), 100 bNackReport(false) 101 { 102 } NackParamsNackParams103 NackParams(const NackParams& p) 104 { 105 PID = p.PID; 106 BLP = p.BLP; 107 nSecNackCnt = p.nSecNackCnt; 108 bNackReport = p.bNackReport; 109 } NackParamsNackParams110 NackParams(uint16_t f, uint16_t b, uint16_t cnt, bool r) : 111 PID(f), 112 BLP(b), 113 nSecNackCnt(cnt), 114 bNackReport(r) 115 { 116 } 117 uint16_t PID; 118 uint16_t BLP; 119 uint16_t nSecNackCnt; 120 bool bNackReport; 121 }; 122 123 struct TmmbrParams 124 { 125 public: 126 TmmbrParams(uint32_t ss = 0, uint32_t e = 0, uint32_t m = 0, uint32_t o = 0) : ssrcTmmbrParams127 ssrc(ss), 128 exp(e), 129 mantissa(m), 130 overhead(o) 131 { 132 } TmmbrParamsTmmbrParams133 TmmbrParams(const TmmbrParams& p) 134 { 135 ssrc = p.ssrc; 136 exp = p.exp; 137 mantissa = p.mantissa; 138 overhead = p.overhead; 139 } 140 uint32_t ssrc; 141 uint32_t exp; 142 uint32_t mantissa; 143 uint32_t overhead; 144 }; 145 146 enum kCameraFacing 147 { 148 kCameraFacingFront = 0, 149 kCameraFacingRear, 150 }; 151 152 struct InternalRequestEventParam 153 { 154 public: InternalRequestEventParamInternalRequestEventParam155 InternalRequestEventParam() : 156 type(0), 157 value(0) 158 { 159 } InternalRequestEventParamInternalRequestEventParam160 InternalRequestEventParam(uint32_t t, uint32_t v) : 161 type(t), 162 value(v) 163 { 164 } InternalRequestEventParamInternalRequestEventParam165 InternalRequestEventParam(uint32_t t, const NackParams& params) : 166 type(t), 167 nackParams(params) 168 { 169 } InternalRequestEventParamInternalRequestEventParam170 InternalRequestEventParam(uint32_t t, const TmmbrParams& params) : 171 type(t), 172 tmmbrParams(params) 173 { 174 } 175 uint32_t type; 176 union 177 { 178 uint32_t value; 179 NackParams nackParams; 180 TmmbrParams tmmbrParams; 181 }; 182 }; 183 184 /** 185 * @brief Utility class for video codec operation. 186 */ 187 class ImsMediaVideoUtil 188 { 189 public: 190 ImsMediaVideoUtil(); 191 ~ImsMediaVideoUtil(); 192 static int32_t ConvertCodecType(int32_t type); 193 static uint32_t GetResolutionFromSize(uint32_t nWidth, uint32_t nHeight); 194 static ImsMediaResult ParseAvcSpropParam(const char* szSpropparam, tCodecConfig* pInfo); 195 static ImsMediaResult ParseHevcSpropParam(const char* szSpropparam, tCodecConfig* pInfo); 196 static bool ParseAvcSps(uint8_t* pbBuffer, uint32_t nBufferSize, tCodecConfig* pInfo); 197 static bool ParseHevcSps(uint8_t* pbBuffer, uint32_t nBufferSize, tCodecConfig* pInfo); 198 static char* GenerateVideoSprop(VideoConfig* pVideoConfig); 199 static void ConvertBitrateToPower( 200 const uint32_t nInputBitrate, uint32_t& nOutExp, uint32_t& nOutMantissa); 201 }; 202 203 #endif // IMSMEDIA_VIDEOUTIL_H_INCLUDED