-
-
Notifications
You must be signed in to change notification settings - Fork 90
library: add Camera Entry #375
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3d2e4a2
library: add Camera Entry
halfmexican 5377b22
update devel manifest
halfmexican fb9aa7f
update manifest
halfmexican ac3a0df
remove box
halfmexican 2888b31
add comment
halfmexican fe08a6e
main.js: use snake case
halfmexican 47ed0ee
main.js: use snake case
halfmexican 0befd9b
Apply suggestions from code review
halfmexican f0b8699
main.js: apply code review suggestions
halfmexican d82c08c
start fixing manifest
halfmexican 6911a3c
rename pw_remote
halfmexican d685771
remove await
halfmexican 3441ff8
add default case
halfmexican cf15fc5
remove console.log statement
halfmexican 24c7636
manifest: use latest release of gst-plugins-rs
halfmexican e2591d7
small things
sonnyp 8e2f025
Merge branch 'main' into halfmexican/camera
sonnyp 4bb92a2
Merge branch 'main' into halfmexican/camera
sonnyp 2fd4e56
Merge branch 'main' into halfmexican/camera
sonnyp 8f71c50
missing await
sonnyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using Gtk 4.0; | ||
| using Adw 1; | ||
|
|
||
| Adw.StatusPage { | ||
| title: _("Camera"); | ||
| description: _("Access the Camera"); | ||
| margin-top: 48; | ||
|
|
||
| Box { | ||
| orientation: vertical; | ||
| halign: center; | ||
|
|
||
| Picture output { | ||
| margin-bottom: 30; | ||
| width-request: 360; | ||
| height-request: 240; | ||
| } | ||
|
|
||
| Button button { | ||
| label: _("Access Camera"); | ||
| margin-bottom: 42; | ||
| halign: center; | ||
| styles ["suggested-action"] | ||
| } | ||
|
|
||
| LinkButton { | ||
| label: "API Reference"; | ||
| uri: "https://libportal.org/method.Portal.access_camera.html"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import Gio from "gi://Gio"; | ||
| import Xdp from "gi://Xdp"; | ||
| import XdpGtk from "gi://XdpGtk4"; | ||
| import GObject from "gi://GObject"; | ||
| import Gst from "gi://Gst"; | ||
|
|
||
| Gst.init(null); | ||
| Gio._promisify(Xdp.Portal.prototype, "access_camera", "access_camera_finish"); | ||
|
|
||
| const portal = new Xdp.Portal(); | ||
| const parent = XdpGtk.parent_new_gtk(workbench.window); | ||
|
|
||
| const output = workbench.builder.get_object("output"); | ||
| const button = workbench.builder.get_object("button"); | ||
|
|
||
| button.connect("clicked", () => { | ||
| accessCamera().catch(logError); | ||
| }); | ||
|
|
||
| async function accessCamera() { | ||
| if (!portal.is_camera_present()) { | ||
| console.log("No Camera detected"); | ||
| return; | ||
| } | ||
|
|
||
| const success = await portal.access_camera( | ||
| parent, | ||
| Xdp.CameraFlags.NONE, | ||
| null, | ||
| ); | ||
|
|
||
| if (!success) { | ||
| console.log("Permission denied"); | ||
| return; | ||
| } | ||
|
|
||
| await handleCamera(); | ||
| } | ||
|
|
||
| async function handleCamera() { | ||
| const fd_pipewire_remote = portal.open_pipewire_remote_for_camera(); | ||
| console.log("Pipewire remote opened for camera"); | ||
|
|
||
| // Create the pipeline | ||
| const pipeline = new Gst.Pipeline(); | ||
|
|
||
| // Create elements | ||
| const source = Gst.ElementFactory.make("pipewiresrc", "source"); | ||
| const queue = Gst.ElementFactory.make("queue", "queue"); // add a queue element | ||
| const paintable_sink = Gst.ElementFactory.make( | ||
| "gtk4paintablesink", | ||
| "paintable_sink", | ||
| ); | ||
| const glsinkbin = Gst.ElementFactory.make("glsinkbin", "glsinkbin"); | ||
|
|
||
| // Set up and Link Pipeline | ||
| source.set_property("fd", fd_pipewire_remote); // fd_pipewire_remote is the file descriptor obtained from libportal | ||
| glsinkbin.set_property("sink", paintable_sink); | ||
|
|
||
| pipeline.add(source); | ||
| pipeline.add(queue); | ||
| pipeline.add(glsinkbin); | ||
| source.link(queue); | ||
| queue.link(glsinkbin); | ||
|
|
||
| const paintable = new GObject.Value(); | ||
| paintable_sink.get_property("paintable", paintable); | ||
| output.paintable = paintable.get_object(); | ||
|
|
||
| // Start the pipeline | ||
| pipeline.set_state(Gst.State.PLAYING); | ||
|
|
||
| // Handle cleanup on application exit | ||
| output.connect("destroy", () => { | ||
| pipeline.set_state(Gst.State.NULL); | ||
| }); | ||
|
|
||
| // Set up the bus | ||
| const bus = pipeline.get_bus(); | ||
| bus.add_signal_watch(); | ||
| bus.connect("message", (self, message) => { | ||
| // Check the message type | ||
| const message_type = message.type; | ||
|
|
||
| // Handle different message types | ||
| switch (message_type) { | ||
| case Gst.MessageType.ERROR: { | ||
| const errorMessage = message.parse_error(); | ||
| console.error(errorMessage[0].toString()); | ||
| break; | ||
| } | ||
| case Gst.MessageType.EOS: { | ||
| console.log("End of stream"); | ||
| break; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "Camera", | ||
| "category": "platform", | ||
| "description": "Access the Camera", | ||
| "panels": [ | ||
| "code", | ||
| "preview" | ||
| ], | ||
| "autorun": true | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.