iOS-VialerSIP-通过带内发送DTMF

时间:2019-01-22 09:11:23

标签: ios sip voip dtmf

我的iOS VOIP应用程序使用的是VialerSIP。

我正在尝试通过带内而不是方法发送DTMF:

- (BOOL)sendDTMF:(NSString * _Nonnull)character error:(NSError * _Nullable * _Nullable)error;

在VSLCall类中。

因为,似乎某些国家(包括我的国家)不支持:

PJMEDIA_RTP_PT_TELEPHONE_EVENTS 101

因此,我决定使用此解决方案通过带内发送DTMF: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwibuKSeg4HgAhUM6LwKHT33DOAQygQwAHoECAQQCA&url=https%3A%2F%2Ftrac.pjsip.org%2Frepos%2Fwiki%2FFAQ%23inband-dtmf&usg=AOvVaw3fYXthR0Z6btU2yOWovNIF

这样(迅速):

private func generateTone(_ callId: pjsua_call_id) -> UnsafeMutableRawPointer {
        var ci = pjsua_call_info()

        let pool = pjsua_pool_create("MyCall", 512, 512)!
        let cd = pj_pool_zalloc(pool, MemoryLayout<MyCallData>.size)!
        cd.storeBytes(of: pool.pointee, as: pj_pool_t.self)

        let aPool = cd.assumingMemoryBound(to: pj_pool_t.self)
        var aTonegen: UnsafeMutablePointer<pjmedia_port>? = cd.assumingMemoryBound(to: pjmedia_port.self)
        let aToneslot = cd.assumingMemoryBound(to: pjsua_conf_port_id.self)

        pjmedia_tonegen_create(aPool, 8000, 1, 160, 16, 0, &aTonegen)
        pjsua_conf_add_port(aPool, aTonegen!, aToneslot)

        pjsua_call_get_info(callId, &ci)
        pjsua_conf_connect(aToneslot.pointee, ci.conf_slot)

        pjsua_call_set_user_data(callId, cd)

        return cd
    }

    private func play(callId: pjsua_call_id, digits: String) {
        let cString = digits.cString(using: String.defaultCStringEncoding)!
        let newString: String = NSString(bytes: cString, length: Int(digits.count), encoding:String.Encoding.ascii.rawValue)! as String
        let key2Pointer = UnsafePointer<Int8>(newString)

        let cd = pjsua_call_get_user_data(callId) ?? generateTone(callId)

        let tonegen = cd.assumingMemoryBound(to: pjmedia_port.self)

        var tone = pjmedia_tone_digit(digit: key2Pointer.pointee, on_msec: 100, off_msec: 200, volume: 0)
        pjmedia_tonegen_play_digits(tonegen, 1, &tone, 0)
    }

    private func deinitTone(callId: pjsua_call_id) {
        guard let cd = pjsua_call_get_user_data(callId) else { return }

        let aPool = cd.assumingMemoryBound(to: pj_pool_t.self)
        let aTonegen = cd.assumingMemoryBound(to: pjmedia_port.self)
        let aToneslot = cd.assumingMemoryBound(to: pjsua_conf_port_id.self)

        pjsua_conf_remove_port(aToneslot.pointee)
        pjmedia_port_destroy(aTonegen)
        pj_pool_release(aPool)

        pjsua_call_set_user_data(callId, nil)
    }

然后,我尝试使用以下方式发送DTMF:

self.play(callId: pjsua_call_id(self.activeCall.callId), digits: numberString)

但是,当我调用此函数时,CPU溢出。我不知道为什么:(。

请给我任何建议,这将对解决我的问题大有帮助。

谢谢。

0 个答案:

没有答案