【发布时间】:2013-02-01 16:16:59
【问题描述】:
嗨,我想制作一个在 iOS 设备之间进行视频通话的应用程序。我研究过 opentok 和 idoubs,但我想从一开始就自己做。我搜索了很多,但找不到任何解决方案。我试图以一种我认为视频聊天的方式来实现这一点。到目前为止,我已经完成了以下事情(通过使用 streaming bonjour 教程):
-
创建 avcapture 会话并在
中获取 cmsamplebufferref 数据- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{ if( captureOutput == _captureOutput ){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); //Lock the image buffer// CVPixelBufferLockBaseAddress(imageBuffer,0); //Get information about the image// uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); size_t width = CVPixelBufferGetWidth(imageBuffer); size_t height = CVPixelBufferGetHeight(imageBuffer); //Create a CGImageRef from the CVImageBufferRef// CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); CGImageRef newImage = CGBitmapContextCreateImage(newContext); //We release some components CGContextRelease(newContext); CGColorSpaceRelease(colorSpace); previewImage= [UIImage imageWithCGImage:newImage scale:1.0 orientation:UIImageOrientationRight]; CGImageRelease(newImage); [uploadImageView performSelectorOnMainThread:@selector(setImage:) withObject:previewImage waitUntilDone:YES]; //We unlock the image buffer// CVPixelBufferUnlockBaseAddress(imageBuffer,0); [pool drain]; [self sendMIxedData:@"video1"]; } else if( captureOutput == _audioOutput){ dataA= [[NSMutableData alloc] init]; CMBlockBufferRef blockBuffer; CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, ¤tInputAudioBufferList, sizeof(currentInputAudioBufferList), NULL, NULL, 0, &blockBuffer); //CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &bufferList, sizeof(bufferList), NULL, NULL, 0, &blockBuffer); for (int y = 0; y < currentInputAudioBufferList.mNumberBuffers; y++) { AudioBuffer audioBuffer = currentInputAudioBufferList.mBuffers[y]; Float32 *frame = (Float32*)audioBuffer.mData; [dataA appendBytes:frame length:audioBuffer.mDataByteSize]; } [self sendMIxedData:@"audio"]; } -
现在 sendMixeddata 方法正在将这些视频/音频字节写入 NSStream。
NSData *data = UIImageJPEGRepresentation([self scaleAndRotateImage:previewImage], 1.0); const uint8_t *message1 = (const uint8_t *)[@"video1" UTF8String]; [_outStream write:message1 maxLength:strlen((char *)message1)]; [_outStream write:(const uint8_t *)[data bytes] maxLength:[data length]]; const uint8_t *message1 = (const uint8_t *)[@"audio" UTF8String]; [_outStream write:message1 maxLength:strlen((char *)message1)]; [_outStream write:(const uint8_t *)[dataA bytes] maxLength:[dataA length]]; -
现在字节在接收设备上的 nsstream 委托方法中接收
现在的问题是我不知道这是不是视频聊天的工作方式 与否
我也没有成功如何使用接收字节来显示 作为视频。
我尝试发送“audio”和“video1”字符串以及要知道的字节 如果它的视频或音频。我也尝试过不使用额外的字符串。 图像被正确接收和显示,但音频如此 扭曲的。
请告诉我这是否是制作视频聊天应用程序的正确方法或 不是 。如果是,我应该怎么做才能使它可用。例如 :我应该一起发送音频/视频数据而不是单独发送 我的例子。我在这里使用简单的 bonjour 教程,但我将如何 用真实的服务器实现同样的效果
当我被困在这里时,请指导我正确的方向。
谢谢 (抱歉格式化。我试过但无法正确格式化)
【问题讨论】:
标签: ios4 video-streaming audiounit nsstream