1

我正在尝试将从 iPhone 麦克风录制的音频发送到网络摄像机。我有一个 sdk(用 c 编写)以便与相机通信,这是我需要传递数据的函数。我们正在谈论发送实时音频。

    /*
@Name: FosSdk_SendTalkData.
@Description: Send the data of talk.
@param handle: the handle of current connection information.
@param data: The data need to send.
@param len: Len of data.
@return: Please refer to the enum of FOSCMD_RESULT to get more information.
*/
FOSSDK FOSCMD_RESULT FOSAPI FosSdk_SendTalkData(FOSHANDLE handle, char *data, int len);

这是Swift签名(我目前正在使用 swift )

FosSdk_SendTalkData(handle: UInt32, data: UnsafeMutablePointer<Int8>!, len: Int32)

如何从 iPhone 麦克风录制音频并将音频缓冲区正确传递给 sendTalkData?提前感谢您的任何澄清/帮助。

编辑

我管理了如何使用AVFoundationAVCaptureAudioDataOutputSampleBufferDelegate函数获取音频缓冲区,从中我获得了一个样本缓冲区。但是,我的实现不起作用。我注意到的一件事是将长度参数传递给 sendTalkFunction 时应用程序崩溃。例如,如果我将 Int32(1) 作为长度传递,应用程序不会崩溃,但是传递 Int32(1) 没有任何意义。

这段代码对我有很大帮助,但是它有点旧,所以我需要重新编辑http://timestocomemobile.com/2014/10/swift-data-to-c-pointer-and-back-。 html

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {

    guard let blockBufferRef = CMSampleBufferGetDataBuffer(sampleBuffer) else {return}
    let lengthOfBlock = CMBlockBufferGetDataLength(blockBufferRef)

    guard let data = NSMutableData(length: Int(lengthOfBlock)) else {return}
    CMBlockBufferCopyDataBytes(blockBufferRef, 0, lengthOfBlock, data.mutableBytes)

    // I need to pass the data as UnsafeMutablePointer<Int8> type
    let dataUnsafeMutablePointer = data.mutableBytes.assumingMemoryBound(to: Int8.self)

    FosSdk_SendTalkData(CameraConfigurationManager.mhandle, dataUnsafeMutablePointer, Int32(lengthOfBlock))

}

AVCaptureSessions 正在正确启动,我可以看到每 tot 毫秒收集一次 sampleBuffers。我只需要正确填充函数参数并使这些音频缓冲区在网络摄像机上播放

4

0 回答 0