【问题标题】:CVPixelBufferUnlockBaseAddress - Block UICVPixelBufferUnlockBaseAddress - 块 UI
【发布时间】:2015-05-12 06:17:51
【问题描述】:

我正在努力调试一个奇怪的问题。在CVPixelBufferUnlockBaseAddress(imageBuffer,0); 之后的captureOutput:didOutputSampleBuffer:fromConnection: 中,整个UI 停止响应触摸。相机预览可以工作,但我所有的按钮都停止响应,我什至添加了一个 UITapGesture 也无法工作。我尝试将其放入调度中,但仍然没有成功。

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection
{
    if (state != CAMERA) {
        return;
    }

    if (self.state != CAMERA_DECODING)
    {
        self.state = CAMERA_DECODING;
    }


    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    //Lock the image buffer
    CVPixelBufferLockBaseAddress(imageBuffer,0);
    //Get information about the image
    baseAddress = (uint8_t *)CVPixelBufferGetBaseAddressOfPlane(imageBuffer,0);

    int pixelFormat = CVPixelBufferGetPixelFormatType(imageBuffer);
    switch (pixelFormat) {
        case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:

            //NSLog(@"Capture pixel format=NV12");
            bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer,0);
            width = bytesPerRow;//CVPixelBufferGetWidthOfPlane(imageBuffer,0);
            height = CVPixelBufferGetHeightOfPlane(imageBuffer,0);
            break;
        case kCVPixelFormatType_422YpCbCr8:


            //NSLog(@"Capture pixel format=UYUY422");
            bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer,0);
            width = CVPixelBufferGetWidth(imageBuffer);
            height = CVPixelBufferGetHeight(imageBuffer);
            int len = width*height;
            int dstpos=1;
            for (int i=0;i<len;i++){
                baseAddress[i]=baseAddress[dstpos];
                dstpos+=2;
            }

            break;
        default:
            //  NSLog(@"Capture pixel format=RGB32");
            break;
    }

    unsigned char *pResult=NULL;

    int resLength = MWB_scanGrayscaleImage(baseAddress,width,height, &pResult);

    CVPixelBufferUnlockBaseAddress(imageBuffer,0);

【问题讨论】:

    标签: ios xcode video-capture avcaptureoutput


    【解决方案1】:

    这可能是因为您在主线程上运行所有操作。
    为会话创建输出,您有机会在另一个队列上运行回调:

    AVCaptureVideoDataOutput * dataOutput = [[AVCaptureVideoDataOutput alloc] init];
                [dataOutput setAlwaysDiscardsLateVideoFrames:YES];
                [dataOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
    dispatch_queue_t queue = dispatch_queue_create("it.CloudInTouchLabs.avsession", DISPATCH_QUEUE_SERIAL);
                [dataOutput setSampleBufferDelegate:(id)self queue:queue];
                if ([captureSession_ canAddOutput:dataOutput]) {
                    [captureSession_ addOutput:dataOutput];
                }
    

    在这个示例中,我创建了一个串行队列。

    【讨论】:

    • 这就是问题所在。谢谢。
    猜你喜欢
    • 2013-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多