maltejur / discord-screenaudio

A custom discord client that supports streaming with audio on Linux.
1.1k stars 35 forks source link

Change the way the Virtual-Mic works #26

Open Curve opened 2 years ago

Curve commented 2 years ago

Currently the virtual microphone is spawned as a sub-process¹, which I'd argue is not the nicest solution.

Since v1.3 rohrkabel has made several improvements that ensure safe-usage of the library (i.e. no exceptions in other threads, no access to non-ready objects, channels for safe inter-thread communication)

So you may consider to upgrade to v1.3 / the latest commit at the time of writing, as it includes a small change to simplify the channel receival process and make use of the channels.
Which would eliminate the need for a virtual-mic sub-process and will make the code cleaner, easier to understand and easier to debug².

Also, a few other small improvement suggestions:

¹ https://github.com/maltejur/discord-screenaudio/blob/master/src/discordpage.cpp#L131

² Especially this section could use some refactoring in case you want to move it into it's own thread instead of a sub-process

³ https://en.cppreference.com/w/cpp/container/map/erase, "3) Removes the element (if one exists) with the key equivalent to key."

maltejur commented 2 years ago

Oh hey good to see you here :)

You are totally right, the virtmic code currently is a bit hacky and could definitely could be improved a lot. I already saw the improvements to the thread behavior in your repo, but so far I haven't gotten to implement it because there was other stuff to do and the virtmic currently just works (unlike the other stuff). I adapted the virtmic code from the pre v1.0 virtmic example and back then I just couldn't get it to run in a thread, so thats why it runs in a separate process currently. I will probably just create it from scratch again, using your new examples as reference.

Also, you may as well just consider to just link the target application to Discords Input, that would eliminate the need for a virtual-mic all together

That sounds interesting, but I am not sure how I would achieve that. I don't want discord to use the application audio as the users microphone, but instead feed the audio track of the virtmic directly into the desktop capture.

Curve commented 2 years ago

I don't want discord to use the application audio as the users microphone, but instead feed the audio track of the virtmic directly into the desktop capture.

In that case scrap that idea ^^