QuantumEntangledAndy / neolink

An RTSP bridge to Reolink IP cameras
GNU Affero General Public License v3.0
354 stars 49 forks source link

Crossbeam (channels only) #9

Closed entropin closed 1 year ago

entropin commented 3 years ago

First, change is needed for allowing for multiple video receivers.

QuantumEntangledAndy commented 3 years 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

entropin commented 3 years ago

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

entropin commented 3 years ago

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?

QuantumEntangledAndy commented 3 years ago

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

QuantumEntangledAndy commented 3 years ago

I'm not sure if its helpful but maybe also check out scoped callbacks

QuantumEntangledAndy commented 3 years ago

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?

entropin commented 3 years ago

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

entropin commented 3 years ago

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.

QuantumEntangledAndy commented 3 years ago

Yeah that's why it's a trait so you can implement it anyway you want. Kinda like a callback object.

entropin commented 3 years ago

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.

QuantumEntangledAndy commented 3 years ago

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

QuantumEntangledAndy commented 1 year ago

Closing as it seems you found a different way to handle this. Hope it went well for you