import RTCRoomEngine
import TXLiteAVSDK_Professional
import tencent_effect_flutter
let videoFrameListener: TRTCVideoFrameListener = TRTCVideoFrameListener()
func enableTUICallKitCustomBeauty() {
TUICallEngine.createInstance().getTRTCCloudInstance().setLocalVideoProcessDelegete(videoFrameListener, pixelFormat: ._Texture_2D, bufferType: .texture)
}
func disableTUICallKitCustomBeauty() {
TUICallEngine.createInstance().getTRTCCloudInstance().setLocalVideoProcessDelegete(nil, pixelFormat: ._Texture_2D, bufferType: .texture)
}
class TRTCVideoFrameListener: NSObject, TRTCVideoFrameDelegate {
func onProcessVideoFrame(_ srcFrame: TRTCVideoFrame, dstFrame: TRTCVideoFrame) -> UInt32 {
dstFrame.textureId = GLuint(XmagicApiManager.shareSingleton().getTextureId(ConvertBeautyFrame.convertTRTCVideoFrame(trtcVideoFrame: srcFrame)))
return 0
}
}
public class ConvertBeautyFrame: NSObject {
public static func convertToTRTCPixelFormat(beautyPixelFormat: ITXCustomBeautyPixelFormat) -> TRTCVideoPixelFormat {
switch beautyPixelFormat {
case .Unknown:
return ._Unknown
case .I420:
return ._I420
case .Texture2D:
return ._Texture_2D
case .BGRA:
return ._32BGRA
case .NV12:
return ._NV12
}
}
public static func convertTRTCVideoFrame(trtcVideoFrame: TRTCVideoFrame) -> ITXCustomBeautyVideoFrame {
let beautyVideoFrame = ITXCustomBeautyVideoFrame()
beautyVideoFrame.data = trtcVideoFrame.data
beautyVideoFrame.pixelBuffer = trtcVideoFrame.pixelBuffer
beautyVideoFrame.width = UInt(trtcVideoFrame.width)
beautyVideoFrame.height = UInt(trtcVideoFrame.height)
beautyVideoFrame.textureId = trtcVideoFrame.textureId
switch trtcVideoFrame.rotation {
case ._0:
beautyVideoFrame.rotation = .rotation_0
case ._90:
beautyVideoFrame.rotation = .rotation_90
case ._180:
beautyVideoFrame.rotation = .rotation_180
case ._270:
beautyVideoFrame.rotation = .rotation_270
default:
beautyVideoFrame.rotation = .rotation_0
}
switch trtcVideoFrame.pixelFormat {
case ._Unknown:
beautyVideoFrame.pixelFormat = .Unknown
case ._I420:
beautyVideoFrame.pixelFormat = .I420
case ._Texture_2D:
beautyVideoFrame.pixelFormat = .Texture2D
case ._32BGRA:
beautyVideoFrame.pixelFormat = .BGRA
case ._NV12:
beautyVideoFrame.pixelFormat = .NV12
default:
beautyVideoFrame.pixelFormat = .Unknown
}
beautyVideoFrame.bufferType = ITXCustomBeautyBufferType(rawValue: trtcVideoFrame.bufferType.rawValue) ?? .Unknown
beautyVideoFrame.timestamp = trtcVideoFrame.timestamp
return beautyVideoFrame
}
}