ios - CVPixelBufferUnlockBaseAddress - Block UI -
i'm struggling debug weird problem. in captureoutput:didoutputsamplebuffer:fromconnection:
right after cvpixelbufferunlockbaseaddress(imagebuffer,0);
entire ui stops responding touches. camera preview works buttons stop responding , added uitapgesture , not work. tried putting dispatch still no success.
- (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 image buffer cvpixelbufferlockbaseaddress(imagebuffer,0); //get information 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; (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);
probably happening because running operations on main thread.
creating output session have opportunity run callback on queue:
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]; }
in sample create serial queue.
Comments
Post a Comment