hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
180 stars 72 forks source link

[Support] Screen recording on Linux (Wayland) using GStreamer and Pipewire... DBUS is really important here... #224

Closed sblantipodi closed 6 months ago

sblantipodi commented 1 year ago

Hi, thank you for making the effort of releasing a Java binding for DBUS...

I would like to record the screen on Linux (wayland) using GStreamer and Pipewire... This solution seems the best possible on wayland but it heavily requires DBUS...

this is a working snippet of a python program https://gitlab.gnome.org/-/snippets/19 that records the screen...

Basically it set up DBus messages to control and acquire the pipewire source to pass into the GStreamer pipeline description.

Are there some examples that can help me understanding how this dbus binding work?

How can I control the pipewire source using this DBUS binding and pass it to GStreamer?

I hope that someone can help here...

I know that issues are not the best way to get help but I think that this can be useful to many people. :)

hypfvieh commented 1 year ago

I can't help much here. I don't have any setup which uses wayland or pipewire.

I would start with investigating the available interfaces on the bus using d-feet or similar dbus-browser. According to the python code there should be several bus objects (e.g. org.freedesktop.portal.Desktop) which you have to query.

After that, I would use the InterfaceCodeGenerator (part of dbus-java-utils) to create proper Java interfaces for those bus objects. With these interfaces it should be possible to adapt the python sample to Java (maybe some trail and error is needed).

sblantipodi commented 1 year ago

hi @hypfvieh thank you very much for the answer, I appreciate it.

Is there a mailing list where we can discuss about these things? :) I don't know if the issue is the best place to do it and I don't want to bother here.

I am trying to generate the interfaces for org.freedesktop.portal.Desktop with this command:

mvn exec:java \
   -Dexec.mainClass="org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator" \
   -Dexec.executable="java" \
   -Dexec.args="--system --outputDir /tmp/classes org.freedesktop /org/freedesktop" 

but I have this error:

[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< com.github.hypfvieh:dbus-java-utils >-----------------
[INFO] Building dbus-java-utils 4.3.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:3.1.0:java (default-cli) @ dbus-java-utils ---
15:59:20.863 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Introspecting: { Interface: /org/freedesktop, Busname: org.freedesktop }
15:59:20.874 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-jnr-unixsocket for address unix:path=/var/run/dbus/system_bus_socket
15:59:20.945 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] ERROR o.f.d.u.g.InterfaceCodeGenerator - Failure in DBus Communications. 
org.freedesktop.dbus.errors.ServiceUnknown: The name org.freedesktop was not provided by any .service files
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484)
        at org.freedesktop.dbus.errors.Error.getException(Error.java:116)
        at org.freedesktop.dbus.errors.Error.throwException(Error.java:143)
        at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:206)
        at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:89)
        at jdk.proxy3/jdk.proxy3.$Proxy42.Introspect(Unknown Source)
        at org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main(InterfaceCodeGenerator.java:563)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:279)
        at java.base/java.lang.Thread.run(Thread.java:1623)

it works well if I generate the interfaces for org.bluez

hypfvieh commented 1 year ago

There is no mailing list, forum etc. just this bugtracker - this project is too small for any additional communication platform (and I'm the only maintainer). Therefore it is completely fine to ask questions in the bug tracker.

You are using the wrong bus type and the wrong busname. The org.freedesktop.portal.Desktop is only visible on the session bus (therefore you have to use --session instead of --system). Then you also have to specify the correct bus name which is org.freedesktop.portal.Desktop and the correct path/org/freedesktop/portal/desktop (as seen in d-feet). Additionally I would add the "--all" flag to create any interface file (you don't know yet which you will need).

In the end the command line should look like this:

mvn exec:java -Dexec.mainClass="org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator" -Dexec.executable="java" -Dexec.args="--all --session --outputDir /tmp/classes org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop"