Closed entropin closed 1 year ago
Also when you send with a crossbeam chamnel to multiple receivers you do know that only one receiver will get it right?
It's sort of just a queue of items and who every pulls it out of the channel first will get it
Yes, am planning to build a broadcaster like discussed here:
https://github.com/crossbeam-rs/crossbeam-channel/issues/24
And it seems like crossbeam is more flexible than normal channels, but I could be wrong
So what I tried and failed miserably with yesterday, was to add a Vec or a HashMap to the camera, containing Option(fn). So that I can subscribe bcCamera.subscribe(callback) and send a clone of all bc_media to all functions subscribed.
But rust did not let me do that across threads.
Do you see a way of doing this without creating multiple channels and senders?
Hmm I've never tried registering callbacks. I've only ever needed callbacks that I can make a trait for.
What about
Arc<dyn FnMut(i32)>
Although I am not sure it will work the way I think
I'm not sure if its helpful but maybe also check out scoped callbacks
Closures have to be handled carefully you need to ensure that everything that goes into it has to have the right lifetime to last as long as need.
I usual try a different design. Why do you want to use a closure like this? Is there another way to do it?
I'll try some more and come back to you with a example that is not working :D
But yes. It still feels like am trying to bend Rust due to having a object oriented / static thinking :D
Ok, so the problem itself is solved :D I was thinking about it all wrong.. I just needed to do a custom impl of StreamOutput's write function, collect the BcMedia there and distribute them from there, the BcMedia was easy to clone, and I can then send them both to a video processor/filter or video server like the RTSP mod, and still get stills and issue commands.
Am basically, just testing ideas to learn Rust, I just chose a bad one :D But the wage goal that I use to learn, is to implement a custom web client with video preview and actions.
Yeah that's why it's a trait so you can implement it anyway you want. Kinda like a callback object.
Yes, so I'll attack it from a different direction :) I want to support different video filters and AI prosessing of the video but still broadcast the altered stream over rtsp.
So I'll try to find a nice way of init the rtps mod from my new "filer mod" but giving it a channel to that receives BcMedia from instead of creating it's own subscription.
If you only need read access to the BcMedia consider sharing it as an Arc or something so you don't need to clone it at all saving you some memory
Closing as it seems you found a different way to handle this. Hope it went well for you
First, change is needed for allowing for multiple video receivers.