gpt4 book ai didi

ios4 - 如何从 AVCaptureAudioDataOutput 播放音频样本缓冲区

转载 作者:行者123 更新时间:2023-12-02 14:03:32 24 4
gpt4 key购买 nike

我尝试制作的应用程序的主要目标是点对点视频流。 (有点像使用蓝牙/WiFi 的 FaceTime)。

使用 AVFoundation,我能够捕获视频/音频样本缓冲区。然后我发送视频/音频样本缓冲区数据。现在的问题是在接收端处理样本缓冲区数据。

对于视频样本缓冲区,我能够从样本缓冲区获取 UIImage。但是对于音频样本缓冲区,我不知道如何处理它以便我可以播放音频。

所以问题是如何处理/播放音频样本缓冲区

现在我只是绘制波形,就像苹果的 Wavy 示例代码一样:

CMSampleBufferRef sampleBuffer;

CMItemCount numSamples = CMSampleBufferGetNumSamples(sampleBuffer);
NSUInteger channelIndex = 0;

CMBlockBufferRef audioBlockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
size_t audioBlockBufferOffset = (channelIndex * numSamples * sizeof(SInt16));
size_t lengthAtOffset = 0;
size_t totalLength = 0;
SInt16 *samples = NULL;
CMBlockBufferGetDataPointer(audioBlockBuffer, audioBlockBufferOffset, &lengthAtOffset, &totalLength, (char **)(&samples));

int numSamplesToRead = 1;
for (int i = 0; i < numSamplesToRead; i++) {

SInt16 subSet[numSamples / numSamplesToRead];
for (int j = 0; j < numSamples / numSamplesToRead; j++)
subSet[j] = samples[(i * (numSamples / numSamplesToRead)) + j];

SInt16 audioSample = [Util maxValueInArray:subSet ofSize:(numSamples / numSamplesToRead)];
double scaledSample = (double) ((audioSample / SINT16_MAX));

// plot waveform using scaledSample
[updateUI:scaledSample];
}

最佳答案

要显示视频,您可以使用(这里是:获取ARGB图片并转换为Qt(nokia qt)QImage,您可以用其他图像替换)

将其委托(delegate)给类

 - (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
<小时/>
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

CVPixelBufferLockBaseAddress(imageBuffer,0);

SVideoSample sample;

sample.pImage = (char *)CVPixelBufferGetBaseAddress(imageBuffer);
sample.bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
sample.width = CVPixelBufferGetWidth(imageBuffer);
sample.height = CVPixelBufferGetHeight(imageBuffer);

QImage img((unsigned char *)sample.pImage, sample.width, sample.height, sample.bytesPerRow, QImage::Format_ARGB32);

self->m_receiver->eventReceived(img);

CVPixelBufferUnlockBaseAddress(imageBuffer,0);
[pool drain];

关于ios4 - 如何从 AVCaptureAudioDataOutput 播放音频样本缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5598934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com