Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add screencapturekit #228

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Add screencapturekit #228

wants to merge 5 commits into from

Conversation

tmc
Copy link
Collaborator

@tmc tmc commented Nov 13, 2023

This adds screencapturekit bindings.

The example isn't fully functional.

Refs #227

@progrium
Copy link
Owner

whats wrong with the example?

@tmc
Copy link
Collaborator Author

tmc commented Nov 14, 2023

whats wrong with the example?

it doesn't actually work -- I think we need to allocate a new DispatchQueue for this and need to be able to call c fns to do that.

@sz-po
Copy link

sz-po commented Dec 29, 2023

@tmc maybe You just forgot to configure stream?

I used your code but added parameters for the SCStreamConfiguration object and it looks like the StreamDidOutputSampleBufferOfType method is called correctly and at the correct frequency. Additionally, I used a global queue, not an application. I still need to check if the buffer has the correct data, but it looks promising. If I find a moment, I can improve the example from your PR.

I remember reading somewhere on the internet that it is crucial to set minimumFrameInterval in order to receive notifications about new frames at all.

The example below is from my application, but the methods are the same.

	streamConfiguration := api.NewSCStreamConfiguration()
	streamConfiguration.SetWidth(displayWidth)
	streamConfiguration.SetHeight(displayHeight)
	streamConfiguration.SetMinimumFrameInterval(api.CMTime{Value: 1, Timescale: int32(framerate)})
	streamConfiguration.SetQueueDepth(3)

@tmc
Copy link
Collaborator Author

tmc commented Dec 29, 2023

@tmc maybe You just forgot to configure stream?

I used your code but added parameters for the SCStreamConfiguration object and it looks like the StreamDidOutputSampleBufferOfType method is called correctly and at the correct frequency. Additionally, I used a global queue, not an application. I still need to check if the buffer has the correct data, but it looks promising. If I find a moment, I can improve the example from your PR.

I remember reading somewhere on the internet that it is crucial to set minimumFrameInterval in order to receive notifications about new frames at all.

The example below is from my application, but the methods are the same.

	streamConfiguration := api.NewSCStreamConfiguration()
	streamConfiguration.SetWidth(displayWidth)
	streamConfiguration.SetHeight(displayHeight)
	streamConfiguration.SetMinimumFrameInterval(api.CMTime{Value: 1, Timescale: int32(framerate)})
	streamConfiguration.SetQueueDepth(3)

I have some further work on this branch: https://github.com/tmc/macdriver/tree/add-screencapturekit-debugging -- can you try to get it working? I think a very light wrapper might be needed for https://developer.apple.com/documentation/coremedia/1489563-cmsamplebuffercallforeachsample?language=objc to get at the sample data.

@sz-po
Copy link

sz-po commented Jan 11, 2024

Sure, but I'm receiving errors about duplicated symbols from C code during compilation, even though there is no duplication at all. I've never encountered this problem before. Do you know what could be causing it?

$ /usr/local/opt/go/libexec/bin/go build -o /Users/sz-po/Library/Caches/JetBrains/GoLand2023.2/tmp/GoLand/___build_screencap . #gosetup

# github.com/progrium/macdriver/macos/_examples/screencap
/usr/local/opt/go/libexec/pkg/tool/darwin_amd64/link: running cc failed: exit status 1
ld: warning: -no_pie is deprecated when targeting new OS versions
duplicate symbol '_callGoFunction' in:
    /var/folders/kx/mthnzv495450pln165x7hn1h0000gn/T/go-link-3764031552/000000.o
    /var/folders/kx/mthnzv495450pln165x7hn1h0000gn/T/go-link-3764031552/000001.o
duplicate symbol '_setGoCallback' in:
    /var/folders/kx/mthnzv495450pln165x7hn1h0000gn/T/go-link-3764031552/000000.o
    /var/folders/kx/mthnzv495450pln165x7hn1h0000gn/T/go-link-3764031552/000001.o
duplicate symbol '_Go_CMSampleBufferCallForEachSample' in:
    /var/folders/kx/mthnzv495450pln165x7hn1h0000gn/T/go-link-3764031552/000000.o
    /var/folders/kx/mthnzv495450pln165x7hn1h0000gn/T/go-link-3764031552/000001.o
ld: 3 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@progrium
Copy link
Owner

I've never seen it either and @tmc was able to reproduce without using macdriver at all, so I guess it's a weird cgo bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants