CMBufferQueueCreate需要什么参数?

时间:2011-01-14 12:49:05

标签: iphone objective-c ios4

关于iOS SDK CMBufferQueueCreate

Reading the documentation,它表示需要getDuration和版本,其他所有回调都可以为NULL。

但运行以下代码:

CFAllocatorRef allocator;
CMBufferCallbacks *callbacks;
callbacks = malloc(sizeof(CMBufferCallbacks));
callbacks->version = 0;
callbacks->getDuration = timeCallback;
callbacks->refcon = NULL;
callbacks->getDecodeTimeStamp = NULL;
callbacks->getPresentationTimeStamp = NULL;
callbacks->isDataReady = NULL;
callbacks->compare = NULL;
callbacks->dataBecameReadyNotification = NULL;

CMItemCount capacity = 4;

OSStatus s = CMBufferQueueCreate(allocator, capacity, callbacks, queue);

NSLog(@"QUEUE: %x", queue);
NSLog(@"STATUS: %i", s);

with timeCallback:

CMTime timeCallback(CMBufferRef buf, void *refcon){
    return CMTimeMake(1, 1);
}

和队列是:

CMBufferQueueRef* queue;

队列创建失败(queue = 0)并返回状态:

kCMBufferQueueError_RequiredParameterMissing = -12761,

callbacks变量已正确初始化,至少调试器是这样说的。

是否有人使用CMBufferQueue

1 个答案:

答案 0 :(得分:1)

据推测,参数没有任何问题。至少与你所写的相同,在CMBufferQueue.h中说明了所需的参数。但看起来你传递一个空指针作为CMBufferQueueRef *参数。我已按如下方式更新了您的示例,它似乎创建了消息循环OK。

CMBufferQueueRef queue;
CFAllocatorRef allocator = kCFAllocatorDefault;
CMBufferCallbacks *callbacks;
callbacks = malloc(sizeof(CMBufferCallbacks));
callbacks->version = 0;
callbacks->getDuration = timeCallback;
callbacks->refcon = NULL;
callbacks->getDecodeTimeStamp = NULL;
callbacks->getPresentationTimeStamp = NULL;
callbacks->isDataReady = NULL;
callbacks->compare = NULL;
callbacks->dataBecameReadyNotification = NULL;

CMItemCount capacity = 4;

OSStatus s = CMBufferQueueCreate(allocator, capacity, callbacks, &queue);

NSLog(@"QUEUE: %x", queue);
NSLog(@"STATUS: %i", s);

时间回调仍然相同。

它看起来不像主题启动器,但我希望它能帮助其他人。