CVOpenGLESTextureCacheCreateTextureFromImage on iPad2 is too slow ,it needs almost 30 ms, too crazy

后端 未结 1 1943
灰色年华
灰色年华 2021-01-01 04:24

I use opengl es to display bgr24 data on iPad, I am new about opengl es ,so in display video part I use code from RosyWriter one APPLE sample. It works, but the CVOpenGLESTe

相关标签:
1条回答
  • 2021-01-01 04:55

    With my research in these day, I find why CVOpenGLESTextureCacheCreateTextureFromImage cost much time, when the data is big, here is 3M, the allocation, copy and move operation which cost is considerable, especially Copy operation. Then with pixel buffer pool greatly improve performance of CVOpenGLESTextureCacheCreateTextureFromImage from 30ms to 5ms, the same level with glTexImage2D(). My solution as following:

    NSMutableDictionary*     attributes;
    attributes = [NSMutableDictionary dictionary];
    
    
    [attributes setObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey];
    [attributes setObject:[NSNumber numberWithInt:videoWidth] forKey: (NSString*)kCVPixelBufferWidthKey];
    [attributes setObject:[NSNumber numberWithInt:videoHeight] forKey: (NSString*)kCVPixelBufferHeightKey];
    
    CVPixelBufferPoolCreate(kCFAllocatorDefault, NULL, (CFDictionaryRef) attributes, &bufferPool);
    
    CVPixelBufferPoolCreatePixelBuffer (NULL,bufferPool,&pixelBuffer);
    
    CVPixelBufferLockBaseAddress(pixelBuffer,0);
    
    UInt8 * baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer);
    
    memcpy(baseAddress, bgraData, bytesByRow * videoHeight);
    
    CVPixelBufferUnlockBaseAddress(pixelBuffer,0);
    

    with this new created pixelBuffer you can make it fast.

    Add following configures to attribtes can make its performance to the best, less than 1ms.

     NSDictionary *IOSurfaceProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                                                            [NSNumber numberWithBool:YES], @"IOSurfaceOpenGLESFBOCompatibility",[NSNumber numberWithBool:YES], @"IOSurfaceOpenGLESTextureCompatibility",nil];
    
    [attributes setObject:IOSurfaceProperties forKey:(NSString*)kCVPixelBufferIOSurfacePropertiesKey];
    
    0 讨论(0)
提交回复
热议问题