goodrobots / visiond

Python/Gstreamer based project to stream video from embedded system cameras in various ways
MIT License
9 stars 3 forks source link

Add zeroconf support - broadcast streams #21

Closed fnoop closed 4 years ago

fnoop commented 4 years ago

visiond should broadcast available streams, so other clients can pick it up such as -api. I think camera-manager also does something similar - look at what they're broadcasting as they might have an established format that GCS will pick up.

fnoop commented 4 years ago

DCM looks to create an avahi link and publish through avahi: https://github.com/Dronecode/camera-manager/blob/master/src/avahi_publisher.cpp

fnoop commented 4 years ago

Try and use the same python zeroconf mechanism as -api: https://github.com/goodrobots/maverick-api/blob/master/maverick_api/modules/api/discovery/discovery_zeroconf.py

SamuelDudley commented 4 years ago

@fnoop Okay... Fixed some errors from last night https://github.com/goodrobots/visiond/tree/zeroconf_WIP

The general flow is that app.py starts up. This then creates the zeroconf service advertiser for visiond: https://github.com/goodrobots/visiond/blob/zeroconf_WIP/modules/app.py#L51

When the zeroconf service advertiser starts it will publish the following info: https://github.com/goodrobots/visiond/blob/zeroconf_WIP/modules/advertise.py#L28 e.g. not a lot of data. Feel free to change that as you see fit..

app.py continues down to here post stream creation: https://github.com/goodrobots/visiond/blob/zeroconf_WIP/modules/app.py#L183 at this point we send an update to the service with the stream details. Note I'm not sure what info you need to extract from the stream to properly connect to it in -web so I have left that up to you. We can reach into the stream object and extract the info or make a property that will return the required info.

Anyway, you can see that the info is stored in a dictionary. This is then sent to the zeroconf service advertiser via the update method. This in turn puts that dictionary into a queue that is read by the zeroconf service advertiser thread https://github.com/goodrobots/visiond/blob/zeroconf_WIP/modules/advertise.py#L57 if the queue is empty it will block for 2 seconds, otherwise it will use the content of the dictionary to update the service info. https://github.com/goodrobots/visiond/blob/zeroconf_WIP/modules/advertise.py#L61

fnoop commented 4 years ago

Look at dronecode camera-manager for hints on service discovery: https://camera-manager.dronecode.org/en/guide/rtsp.html https://camera-manager.dronecode.org/en/test/manual_tests.html#list-available-streams-with-avahi

fnoop commented 4 years ago

@SamuelDudley could you possibly put the zeroconf stuff behind a config param that we can use to turn it on/off?

SamuelDudley commented 4 years ago

Done https://github.com/goodrobots/visiond/commit/626e1bccb695fb6466d0c02995f6f6739b0cb2dc

fnoop commented 4 years ago

Thanks :)

I'll see if I can delve down into mdns a bit more and find out why this is the case. It may be that we have to change strategy and instead create an avahi client that registers the service with avahi-daemon. Then from then on avahi-daemon will do the responses, and it avoids running multiple mdns responders on the same system.

fnoop commented 4 years ago

Fixed service conflict with avahi.

SamuelDudley commented 4 years ago

Do we need to make that change in -api?

Edit: Nevermind! I can see you have resolved it. Thanks!