Code Monkey home page Code Monkey logo

rohrkabel's Introduction

πŸ‘‹ Welcome to my GitHub Profile!

I'm Noah, a C++ Enthusiast and Software Engineering Student from Germany


πŸ”¨ Some stuff I'm working on


🀝 Check out my friends



rohrkabel's People

Contributors

curve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rohrkabel's Issues

[Feature Request] V4L support

It would be nice to be able to capture V4L devices like WebCams and capture cards. The way this works on Pipewire seems similar to how audio works. One example here. I'd like to be able to list v4l devices (name and uuid) and be able to capture video from a v4l device specified by uuid (and perhaps select framerate and resolution mode if that is supported)

Question: How to delete a link?

Hi, thanks a lot for your library!

I am not that familiar with C++ and Pipewire so sorry if the answer is trivial. But after looking at the link-app-to-mic example, I cant figure out how to delete a link again without deleting the whole microphone (I am searching for something like this). Is this something still missing in the library or am I just doing something wrong?

Can't build example

build/_deps/rohrkabel-src/include/rohrkabel/context.hpp:26:45: error: declaration of β€˜std::shared_ptrpipewire::core pipewire::context::core()’ changes meaning of β€˜core’ [-fpermissive]
[build] 26 | [[nodiscard]] std::shared_ptr core();

Thread-Loop Improvements

Rohrkabel needs some heavy improvements regarding the Thread-Loop.

The current support for the thread-loop is a bit unintuitive, namely the following things are not as clear and simple as I'd like them to be:

  • Thread Loop
    • All created objects (through core::create(_simple)) are not safe to be deleted without locking the thread-loop
      This means that one has to lock the thread-loop and then explicitly delete the created object
      This is a big caveat and can cause problems when a user is not aware of this, also it's really ugly.
    • When using any form of events the callback for the event will be called from the thread-loops thread.
      This is really problematic because you can't update from within it.
  • Exceptions
    Generally, I'd like to avoid throwing exceptions where possible. Currently we throw on pw_proxy_events::error.
    This is problematic when the thread-loop is used because the exception can then not be properly caught.

    I'd like to replace the exceptions, maybe we could make the constructor of proxy, node, etc. private and have a static method create / bind that returns a tl::expected and constructs the object - It would then return the exception when an error was thrown.
    However this would require create to wait for the object to be successfully bound/created to know if it has an error (i.e. update the core, which in turn would also complicate things a little)

(implemented in f531d2c)

Possible Solutions

1. Revert the thread-loop changes and bring back call_safe.

Pros:

  • Would circumvent the events issue.

Cons:

  • call_safe had it's own caveats and things I didn't like about it
  • Not as elegant as I'd like it to be

2. Make object constructors (i.e. node, port, ...) private and use static method to instantiate the object

And return shared_ptr that has custom deleter to make sure object is deleted safely.

Pros:

  • Would solve the destruction thread-safety issue
  • Is somewhat elegant

Cons:

  • Would not solve the events issue

3. The pipewire-rs appraoch

See https://pipewire.pages.freedesktop.org/pipewire-rs/pipewire/channel/index.html#examples

Design:

  • Channel

    • Can send and receive messages to/from the main-loop
      • The exchanged messages can be of any arbitrary type
        • In case the channel tries to send a pipewire-object (i.e. node, device, proxy) we throw a compile-time error (in case the passed object is not a const-reference or borrow_ptr) to make sure the passed object stays in the loop thread
  • Required changes to current code

    • Core, Context, Registry should assert that the main-loop they get bound to was initialized on the same thread.
    • main_loop::run() should assert that the creation thread is also the execution thread

Pros:

  • Is pretty elegant
  • Solves the events issue
  • Would have no additional impact on the current implementation

Cons:

  • None

4. Design all inherently unsafe methods to be async

Design:

  • All unsafe methods will ...
    • ... (in case the loop is a thread_loop) lock the core and bind / create the object, then unlock it and return the not yet evaluated result
      • we can not wait for the object to be evaluated here because it would not work when called from an event
    • ... (in case the loop is a main_loop) bind / create the object, trigger an update and return the promise
  • The promise can be waited upon (i.e. promise::get(), promise::wait()
    • However it would assert if called from within the thread-loops thread.
  • The promise has a method promise::error() that takes a callback which is invoked in case of an error
  • The promise has a method promise::then() that takes a callback which is invoked once the result is ready
    • The promise will have a state which will live until the callback has been called
    • This would ensure that the objects destructor is called from within the thread-loops thread (as long as the object is not movable, copyable, ...)
    • This would be safe to use even from within the thread-loops thread

Pros:

  • inherently solves some issues the call_safe mechanism had (namely that the object is guaranteed to die within the thread-loops thread)
  • may be a little more intuitive than the call_safe approach, as all functions that would require special care would return a promise

Cons:

  • Callback Hell
  • More complex and while it's a little harder to mess things up with this approach (in comparison to call_safe) it's still easy to do things wrong by accident
  • Will make the code way more complex depending on how it's implemented (would best be implemented with templates, which will in turn bring caveats when used on all major classes)
  • Also not the most elegant solution

This issue currently serves as an outlet for my ideas regarding this issue.
I will keep updating this post with ideas that come to mind and will leave it open until I have found a solution that I'm pleased with.

πŸ’‘ Help is always appreciated!

In case you're reading this issue and have any ideas or suggestions on how to tackle this problem, feel free to comment!

Current proposed solution

After some back and forth I think I will settle with solution 3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.