[英]Capture screen with CGDisplayStream
I'm trying to implement a feature in my app that will record the screen. 我正在尝试在我的应用程序中实现一个将记录屏幕的功能。 I have bits of code that I have found in some sample code and a WWDC 2012 video. 我在一些示例代码和WWDC 2012视频中找到了一些代码。
So far I have this. 到目前为止,我有这个。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Get a list of displays. Copied from working apple source code.
[self getDisplayList];
DisplayRegistrationCallBackSuccessful = NO;
// Register the event for modifying displays.
CGError err = CGDisplayRegisterReconfigurationCallback(DisplayRegisterReconfigurationCallback, NULL);
if (err == kCGErrorSuccess) {
DisplayRegistrationCallBackSuccessful = YES;
}
// Insert code here to initialize your application
const void *keys[1] = { kCGDisplayStreamSourceRect };
const void *values[1] = { CGRectCreateDictionaryRepresentation(CGRectMake(0, 0, 100, 100)) };
CFDictionaryRef properties = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
stream = CGDisplayStreamCreate(displays[0], 100, 100, '420f', properties,
^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {
NSLog(@"Next Frame"); // This line is never called.
});
runLoop = CGDisplayStreamGetRunLoopSource(stream);
CGError err = CGDisplayStreamStart(stream);
if (err == CGDisplayNoErr) {
NSLog(@"Works");
} else {
NSLog(@"Error: %d", err);
}
}
The problem I am encountering is that the callback block for the DisplayStream is not being called. 我遇到的问题是没有调用DisplayStream的回调块。 I am not getting any errors or warnings. 我没有收到任何错误或警告。 Is there something I'm missing or that I've done wrong? 有什么东西我缺少或我做错了吗?
I solved the problem by using CGDisplayStreamCreateWithDispatchQueue
and passing dispatch_queue_create("queue for dispatch", NULL);
我通过使用CGDisplayStreamCreateWithDispatchQueue
并传递dispatch_queue_create("queue for dispatch", NULL);
解决了这个问题dispatch_queue_create("queue for dispatch", NULL);
as the queue. 作为队列。
对于它的价值,看起来你正在获得runloop源,但是然后没有将它添加到当前的运行循环(CFRunLoopAddSource)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.