音频流在哪里添加了libjingle?

时间:2016-12-20 21:57:56

标签: swift libjingle

我无法找到音频流添加到“发言人”的位置。我有可能修改流并稍后自己添加它吗?我觉得libjingle正在处理流并添加它。

我添加了代码的libjingle部分:

import AVFoundation
import UIKit

let TAG = "ViewController"
let AUDIO_TRACK_ID = TAG + "AUDIO"
let LOCAL_MEDIA_STREAM_ID = TAG + "STREAM"

class ViewController: UIViewController, RTCSessionDescriptionDelegate, RTCPeerConnectionDelegate {

    var mediaStream: RTCMediaStream!
    var localAudioTrack: RTCAudioTrack!
    var remoteAudioTrack: RTCAudioTrack!
    var renderer: RTCEAGLVideoView!
    var renderer_sub: RTCEAGLVideoView!
    var roomName: String!    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        initWebRTC();
        sigConnect(wsUrl: "http://192.168.1.59:3000");

        localAudioTrack = peerConnectionFactory.audioTrack(withID: AUDIO_TRACK_ID)
        mediaStream = peerConnectionFactory.mediaStream(withLabel: LOCAL_MEDIA_STREAM_ID)
        mediaStream.addAudioTrack(localAudioTrack)
    }

    var peerConnectionFactory: RTCPeerConnectionFactory! = nil
    var peerConnection: RTCPeerConnection! = nil
    var pcConstraints: RTCMediaConstraints! = nil
    var audioConstraints: RTCMediaConstraints! = nil
    var mediaConstraints: RTCMediaConstraints! = nil

    var wsServerUrl: String! = nil
    var peerStarted: Bool = false

    func initWebRTC() {
        RTCPeerConnectionFactory.initializeSSL()
        peerConnectionFactory = RTCPeerConnectionFactory()

        pcConstraints = RTCMediaConstraints()
        audioConstraints = RTCMediaConstraints()
        mediaConstraints = RTCMediaConstraints(
            mandatoryConstraints: [
                RTCPair(key: "OfferToReceiveAudio", value: "true"),
            ],
            optionalConstraints: nil)
    }

    func prepareNewConnection() -> RTCPeerConnection {
        var icsServers: [RTCICEServer] = []

        icsServers.append(RTCICEServer(uri: NSURL(string: "stun:stun.l.google.com:19302") as URL!, username: "",
        password: ""))

        let rtcConfig: RTCConfiguration = RTCConfiguration()
        rtcConfig.tcpCandidatePolicy = RTCTcpCandidatePolicy.disabled
        rtcConfig.bundlePolicy = RTCBundlePolicy.maxBundle
        rtcConfig.rtcpMuxPolicy = RTCRtcpMuxPolicy.require

        peerConnection = peerConnectionFactory.peerConnection(withICEServers: icsServers, constraints: pcConstraints, delegate: self)
        peerConnection.add(mediaStream);
        return peerConnection;
    }


    func peerConnection(_ peerConnection: RTCPeerConnection!, signalingStateChanged stateChanged: RTCSignalingState) {
    }

    func peerConnection(_ peerConnection: RTCPeerConnection!, iceConnectionChanged newState: RTCICEConnectionState) {
    }

    func peerConnection(_ peerConnection: RTCPeerConnection!, iceGatheringChanged newState: RTCICEGatheringState) {
    }

    func peerConnection(_ peerConnection: RTCPeerConnection!, gotICECandidate candidate: RTCICECandidate!) {
        if (candidate != nil) {
            print("iceCandidate: " + candidate.description)
            let json:[String: AnyObject] = [
                "type" : "candidate" as AnyObject,
                "sdpMLineIndex" : candidate.sdpMLineIndex as AnyObject,
                "sdpMid" : candidate.sdpMid as AnyObject,
                "candidate" : candidate.sdp as AnyObject
            ]
            sigSend(msg: json as NSDictionary)
        } else {
            print("End of candidates. -------------------")
        }
    }

    func peerConnection(_ peerConnection: RTCPeerConnection!, addedStream stream: RTCMediaStream!) {
        if (peerConnection == nil) {
            return
        }

        if (stream.audioTracks.count > 1) {
            print("Weird-looking stream: " + stream.description)
            return
        }
    }

    func peerConnection(_ peerConnection: RTCPeerConnection!, removedStream stream: RTCMediaStream!) {
    }

    func peerConnection(_ peerConnection: RTCPeerConnection!, didOpen dataChannel: RTCDataChannel!) {
    }

    func peerConnection(onRenegotiationNeeded peerConnection: RTCPeerConnection!) {

    }
}

我的想法是我可以在此命令下捕获函数中的音频流。那是对的吗?另外,我可以手动将流添加到扬声器吗?

 func peerConnection(_ peerConnection: RTCPeerConnection!, addedStream stream: RTCMediaStream!) {
            if (peerConnection == nil) {
                return
            }

            if (stream.audioTracks.count > 1) {
                print("Weird-looking stream: " + stream.description)
                return
            }
        }

1 个答案:

答案 0 :(得分:1)

连接webRTC调用时,Webrtc堆栈使用平台API播放或录制音频。你只能控制像

这样的东西
  1. 将音频流静音或取消静音
  2. 使用系统API增加或减少音量或更改音频配置
  3. 您无法手动将流添加到扬声器,但您可以选择将默认音频输出更改为扬声器或耳机,以便将webrtc音频重定向到正确的输出。这可以使用avfoundation API来完成