How does it work? in my M1 laptop
CFMutableDictionaryRef matching = IOServiceMatching("IODPDevice");
ioiteratort iter = 99;
kernreturnt err = IOServiceGetMatchingServices( kIOMasterPortDefault, matching, &iter ); //You got back empty iterator here
ioservicet serv;
serv = IOIteratorNext( iter );
BTW, you can get some display information from NSScreen, but not EDID.
Post
Replies
Boosts
Views
Activity
It is a launchd daemon, something like this, handler ignored since client apps can talk to it:
int main(int argc, const char *argv[])
{
syslog(logLevel, "😎 L%d: start XpcEndPoint", __LINE__);
const char *name = "com.me.driver.myaudio.xpc.XpcEndpoint";
/*dispatch_queue_t queue = dispatch_queue_create("TestXPC", 0);*/
xpc_connection_t service = xpc_connection_create_mach_service(name, DISPATCH_TARGET_QUEUE_DEFAULT, XPC_CONNECTION_MACH_SERVICE_LISTENER);
if (!service)
{
syslog(logLevel, "😎 failed to create service");
return;
}
/*xpc_connection_activate(service);
xpc_connection_set_context(service, this);
auto pSrv = this;*/
xpc_connection_set_event_handler(service, ^(xpc_object_t connection) {
xpc_connection_set_context((xpc_connection_t)connection, pSrv);
XpcServer::new_connection_handler((xpc_connection_t)connection);
});
xpc_connection_resume(service);
dispatch_main();
xpc_release(service);
}
=====the launchdaemon plist =========
?xml version="1.0" encoding="UTF-8"?
!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ...
plist version="1.0"
dict
keyLabel/key
stringcom.me.driver.myaudio.xpc.XpcEndpoint/string
keyMachServices/key
dict
keycom.me.driver.myaudio.xpc.XpcEndpoint/key
true/
/dict
keyProgramArguments/key
array
string/Library/Audio/Plug-Ins/HAL/MyAudio.driver/Contents/XPCServices/XpcEndpoint.xpc/Contents/MacOS/XpcEndpoint/string
/array
keyProcessType/key
stringAdaptive/string
keyKeepAlive/key
true/
/dict
/plist
====Add in the log===== // The bold lines were restart
2021-03-21 18:43:43.277902-0600 0x75d Default 0x0 278 0 com.apple.audio.Core-Audio-Driver-Service: (MyAudio) 😎 PrepareXPCServer ===
2021-03-21 18:43:43.277997-0600 0x75d Default 0x0 278 0 com.apple.audio.Core-Audio-Driver-Service: (MyAudio) 😎 L210: sending XPC message: dictionary: 0x7feb1ee041f0 { count = 3, transaction: 0, voucher = 0x0, contents =
2021-03-21 18:44:53.343469-0600 0x1822 Default 0x0 607 0 com.apple.audio.Core-Audio-Driver-Service: (MyAudio) 😎 L210: sending XPC message: dictionary: 0x7fb308609080 { count = 3, transaction: 0, voucher = 0x0, contents =
2021-03-21 18:44:54.924630-0600 0x343 Default 0x0 80 0 XpcAgent: 😎 L14: start XpcEndPoint :
2021-03-21 18:44:54.924649-0600 0x343 Default 0x0 80 0 XpcAgent: 😎 XpcServer constructor 0x7fef83f04080
2021-03-21 18:44:54.924664-0600 0x343 Default 0x0 80 0 XpcAgent: 😎 XpcServer::Run
2021-03-21 18:44:54.925038-0600 0x1840 Default 0x0 80 0 XpcAgent: 😎 L66: Client Msg: dictionary: 0x7fef83f04c00 { count = 3, transaction: 1, voucher = 0x7fef83f04350, contents =
2021-03-21 18:44:54.925042-0600 0x1842 Default 0x0 80 0 XpcAgent: 😎 L66: Client Msg: dictionary: 0x7fef83e04100 { count = 3, transaction: 1, voucher = 0x7fef83e04230, contents =
2021-03-21 18:44:54.925086-0600 0x1840 Default 0x0 80 0 XpcAgent: 😎 L119 dealWithRegistration: size of table = 1
2021-03-21 18:44:54.925108-0600 0x1840 Default 0x0 80 0 XpcAgent: 😎 L137 reply client: dictionary: 0x7fef83e04a30 { count = 3, transaction: 1, voucher = 0x7fef83f04350, contents =
2021-03-21 18:44:54.925150-0600 0x1822 Default 0x0 607 0 com.apple.audio.Core-Audio-Driver-Service: (MyAudio) 😎 L215: XPC replied: dictionary: 0x7fb308609930 { count = 3, transaction: 0, voucher = 0x0, contents =
2021-03-21 18:44:54.925155-0600 0x1822 Default 0x0 607 0 com.apple.audio.Core-Audio-Driver-Service: (MyAudio) 😎 Registrated XPC service successfully!
2021-03-21 18:44:54.967501-0600 0x1861 Default 0x0 609 0 XpcAgent: 😎 L14: start XpcEndPoint :
2021-03-21 18:44:54.967511-0600 0x1861 Default 0x0 609 0 XpcAgent: 😎 XpcServer constructor 0x7fc56a5045a0
2021-03-21 18:44:54.967515-0600 0x1861 Default 0x0 609 0 XpcAgent: 😎 XpcServer::Run
2021-03-21 18:44:54.968272-0600 0x187a Default 0x0 609 0 XpcAgent: 😎 L66: Client Msg: dictionary: 0x7fc56a704980 { count = 3, transaction: 1, voucher = 0x7fc56a704470, contents =
2021-03-21 18:44:54.968311-0600 0x187a Default 0x0 609 0 XpcAgent: 😎 L119 dealWithRegistration: size of table = 1
2021-03-21 18:44:54.968335-0600 0x187a Default 0x0 609 0 XpcAgent: 😎 L137 reply client: dictionary: 0x7fc56b8043a0 { count = 3, transaction: 1, voucher = 0x7fc56a704470, contents =
2021-03-21 18:44:54.968908-0600 0x1855 Default 0x0 610 0 com.apple.audio.Core-Audio-Driver-Service: (MyAudio) 😎 L215: XPC replied: dictionary: 0x7fe3d6804670 { count = 3, transaction: 0, voucher = 0x0, contents =
2021-03-21 18:44:54.968913-0600 0x1855 Default 0x0 610 0 com.apple.audio.Core-Audio-Driver-Service: (MyAudio) 😎 Registrated XPC service successfully!
2021-03-21 18:44:54.968931-0600 0x1855 Default 0x0 610 0 com.apple.audio.Core-Audio-Driver-Service: (MyAudio) 😎 Done with PrepareXPCServer, moved on!
2021-03-21 18:45:04.981495-0600 0x1dcd Default 0x0 680 0 XpcAgent: 😎 L14: start XpcEndPoint :
2021-03-21 18:45:04.981511-0600 0x1dcd Default 0x0 680 0 XpcAgent: 😎 XpcServer constructor 0x7fb23f504380
2021-03-21 18:45:04.981516-0600 0x1dcd Default 0x0 680 0 XpcAgent: 😎 XpcServer::Run
Thanks eskimo,
This is the launchd plist
?xml version="1.0" encoding="UTF-8"?
!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ...
plist version="1.0"
dict
keyLabel/key
stringcom.me.driver.myaudio.xpc.XpcEndpoint/string
keyMachServices/key
dict
keycom.me.driver.myaudio.xpc.XpcEndpoint/key
true/
/dict
keyProgramArguments/key
array
string/Library/Audio/Plug-Ins/HAL/MyAudio.driver/Contents/XPCServices/XpcEndpoint.xpc/Contents/MacOS/XpcEndpoint/string
/array
keyProcessType/key
stringAdaptive/string
keyKeepAlive/key
true/
/dict
/plist
I don’t understand what you mean by this. Please clarify.
That means I didn't post the event handler callback so that we can focus on the restart issue, the callback is working as expected, other clients can connect to it, send XPC message and get response.
Again, my problem is the XpcService restarts unpredictably, once it restarts, the data kept in the XpcService(basically the hash route table for delivering msg from one client to other subscribed client) will lost, if the Xpc service could start with launchd, keep live until system restart/shutdown, it will be ideal.
I can see VTEncoderXPCService/VTDecoderXPCService in activity monitor, I guess those Video Tool Box services might have the same requirements.
Thanks, took the lesson, purchased a network drive as the time machine backup and turned the time machine always on.
Thanks to eskimo, I'll need redo it since deleted my stuff accidentally two weeks ago and just got chance get back to this thing.
Got time to dig into the problem, it turns out the restarting of XPC service was caused by xpc_release the connection which leads to the XPC service crash, any safe way to release a connection? tried try/catch and it didn't work.
Thanks, my project disabled the ARC (not under my control) and I have to release everything by myself except smart pointer, and it is mostly using C++ instead of Objective-C.
If I send dictionary with content of xpc_dictionary_set_data, will retain keep the data memory from freeing immediately after releasing the dictionary, currently I'm sending data buffer to other side, I have to make a copy of the data in receiver side to avoid recv side data copying crash (does xpc recv use the data copy or share the data reference/pointer with sender?).
BTW, could I send CMSampleBufferRef via xpc_dictionary?
Steven
figured out, the multi-cast UDP
Never mind, I'm sending surface instead and it is working
How do I avoid IOSurfaceCreateXPCObject crash? right now it is my headache issue.
Thanks, I posted the screenshot since it contains the error information which might help understanding the problem.
BTW, that surfaceObj was from callback block of
CGDisplayStreamCreateWithDispatchQueue, and its value is not null but not sure if it is valid.
auto dspref = CGDisplayStreamCreateWithDispatchQueue(
displayId,
captureWidth,
captureHeight,
'420v',
opts,
dispatch_queue_create("my_display_data", DISPATCH_QUEUE_SERIAL),
^( CGDisplayStreamFrameStatus status, uint64_t time, IOSurfaceRef surfaceObj, CGDisplayStreamUpdateRef ref )
{
'
Do we have any API to check if it is valid to avoid crash?
Do we need release this surfaceObj after sent out the XPC message? I suppose system do the maintenance job for the callback block.
Again, ARC was disabled.
-Steven
Great, CFRetain fixed the occasional crash issue.
Thanks to Quinn :)
I have the same problem, even adjust bitrate it will not work, I set the min bitrate to 2Mbps, the actual is about 0.5Mbps, I'm on Monterey 12.0.1
One extra question, same code of screen capture, xpc module of standalone video tool box H264 encoder (running in native M1 or Intel mode), the video quality of Intel is very good, but with M1, the video is way too blurry, anyone has idea of why this is happening?
BTW, I tried openssl s_client to connect the server, it works ok w/o handshaking complain.
openssl s_client -connect 192.168.68.107:7554
but nw_parameters_create_secure_tcp won't work