0

こんにちは、iOSデバイス間でビデオ通話を行うアプリを作りたいと思っています。私はたくさん検索しましたが、解決策が見つかりませんでした。私はビデオチャットがどのように機能するかを考える方法でそれを達成しようとしました. これまで、私は次のことを行ってきました (ストリーミング ボンジュール チュートリアルを使用して):

  1. 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, &currentInputAudioBufferList, 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"];
      }   
    
  2. 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]];
    
  3. これで、バイトは受信デバイスの nsstream デリゲート メソッドで受信されます

    • 今の問題は、タイがビデオチャットの仕組みなのかどうかわからないことです

    • また、受信バイトを使用してビデオとして表示する方法にも成功していません。

    • ビデオかオーディオかを知るために、「audio」と「video1」の文字列をバイトとともに送信してみました。追加の文字列を使用せずに試しました。画像は正しく受信され、表示されますが、音声が非常に歪んでいます。

    • これがビデオ チャット アプリを作成する正しい方法かどうか教えてください。はいの場合、それを使用できるようにするために何をすべきか。たとえば、オーディオ/ビデオデータを私の例のように個別に送信するのではなく、一緒に送信する必要があります。

    ここで立ち往生しているので、適切な方向を教えてください。

ありがとう (フォーマットしてすみません。試してみましたが、正しくフォーマットできませんでした)

4

1 に答える 1

0

ビデオ ストリーミング アプリは、vp8 や h.264 などのビデオ コーデックを使用します。これは、JPEG でエンコードされたフレームよりも優れています。

次のようにして、受信した NSData を表示できるはずです...

UIImage *image = [UIImage imageWithData:data];
于 2013-09-20T19:52:58.447 に答える