Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rtsptowebrtc integration #59660

Merged
merged 21 commits into from
Jan 1, 2022
Merged

Conversation

allenporter
Copy link
Contributor

@allenporter allenporter commented Nov 14, 2021

Proposed change

Add a new integration rtsptowebrtc which is an integration similar to stream, that supports other integrations. Unlike stream, however, this relies on an external server for decoding the stream contents and the integration itself acts as a passthrough for initiating the stream only. This effectively pulls the custom component https://github.com/AlexxIT/WebRTC into core. See home-assistant/architecture#658 for detailed proposal. This is the initial integration that supports a config flow based configuration for an external RTSPtoWebRTC server.

The rtsptowebrtc integration. does not expose entities or devices itself, but instead offers API methods for other integrations to call: Namely, given an sdp offer and an RTSP URL, get back an sdp answer. This is integration can easily interoperate with the API added as part of home-assistant/architecture#640 used by nest battery cameras. There is also an additional method for determining if a stream source is supported based on checking its prefix.

There are other possible future additions that can happen in followup PRs, depending on additional feedback from the architecture discussion:

  • Can add support for discovery, for an add-on
  • Can be added into camera as proposed in the architecture discussion, if we think that is useful
  • If camera integration is not desired, this can be used by individual camera implementations like nest that could offer webrtc support for older cameras.
  • Improved fallback between camera stream types to gracefully handle user error or misconfiguration

Integration has 100% test coverage, and static typing support from the start.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@allenporter
Copy link
Contributor Author

One other thought I had was to make this even more independent of RTSPtoWebRTC so that it could be used with other servers. (e.g. is it possible to configure this component to use Janus as your rtsp to webrtc system? I haven't looked at that yet, but could structure the code to make it a little more clear this could be possible)

return self.async_abort(reason="single_instance_allowed")

if user_input is not None:
await self.async_set_unique_id(DOMAIN)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other thought here is to do some kind of url validation or health checking of this backend at this point when not using discovery.

@allenporter allenporter marked this pull request as draft November 22, 2021 02:32
@allenporter allenporter removed the request for review from hunterjm November 22, 2021 02:32
@allenporter allenporter marked this pull request as ready for review November 22, 2021 05:59
@allenporter allenporter changed the title Add webrtc internal integration Add rtsptowebrtc integration Nov 24, 2021
@bdraco
Copy link
Member

bdraco commented Nov 24, 2021

Are there plans to make an addon that runs the https://github.com/deepch/RTSPtoWebRTC server? Right now its a big ask for users to figure out how to build/install it

@bdraco
Copy link
Member

bdraco commented Nov 24, 2021

I think it would be helpful to show the user where the server they configured to use is at?

Screen Shot 2021-11-24 at 11 01 27

Screen Shot 2021-11-24 at 11 01 11

@bdraco
Copy link
Member

bdraco commented Nov 24, 2021

I shutdown the server and there was no feedback in the UI that it wasn't online
Screen Shot 2021-11-24 at 11 02 35

@allenporter
Copy link
Contributor Author

Are there plans to make an addon that runs the https://github.com/deepch/RTSPtoWebRTC server? Right now its a big ask for users to figure out how to build/install it

Yes, that is definitely part of the plan. My assumption is we can add discovery for it as well to make this nice and simple to setup.

I shutdown the server and there was no feedback in the UI that it wasn't online Screen Shot 2021-11-24 at 11 02 35

Great point, I would love your advice here. Here are my current thoughts:

  • I just added a heartbeat method on the Client library that gets a 200 or raises an exception
  • I was considering using in the config flow to validate the url
  • Was thinking about suing during integration setup to verify the server is alive
  • Does it make sense to expose any information after startup? e.g. background poll. Or expose a device for the server, entity or system health integration? I am not sure what the best practice is here

@bdraco
Copy link
Member

bdraco commented Nov 24, 2021

  • I was considering using in the config flow to validate the url

Maybe a single connect and make sure the /stream url is working, otherwise raise ConfigEntryNotReady with a human readable string so they can figure out whats broken?

@allenporter
Copy link
Contributor Author

  • I was considering using in the config flow to validate the url

Maybe a single connect and make sure the /stream url is working, otherwise raise ConfigEntryNotReady with a human readable string so they can figure out whats broken?

I am proposing to hit /static instead just to get a 200 back:
https://github.com/allenporter/rtsp-to-webrtc-client/blob/8414d9234d3f7817bab7753eef6b5c6c27351e77/rtsp_to_webrtc/client.py#L54
thinking that will reduce spam on the server side if missing url parameters.

We have a couple exception types: "Can't talk to the server" vs "server returned a response that was a failure". etc

@allenporter
Copy link
Contributor Author

I think it would be helpful to show the user where the server they configured to use is at?

Screen Shot 2021-11-24 at 11 01 27 Screen Shot 2021-11-24 at 11 01 11

I've set the url as the config entry title to address this.

@allenporter
Copy link
Contributor Author

allenporter commented Nov 24, 2021

  • I was considering using in the config flow to validate the url

Maybe a single connect and make sure the /stream url is working, otherwise raise ConfigEntryNotReady with a human readable string so they can figure out whats broken?

I am proposing to hit /static instead just to get a 200 back: https://github.com/allenporter/rtsp-to-webrtc-client/blob/8414d9234d3f7817bab7753eef6b5c6c27351e77/rtsp_to_webrtc/client.py#L54 thinking that will reduce spam on the server side if missing url parameters.

We have a couple exception types: "Can't talk to the server" vs "server returned a response that was a failure". etc

I've updated this so this health check happens in the config flow and on startup. There are no ongoing checks after startup however.

@bdraco
Copy link
Member

bdraco commented Nov 24, 2021

There are no ongoing checks after startup however.

Seems fine to me. I think thats enough for the user to figure out what went wrong even if they have to restart

@bdraco
Copy link
Member

bdraco commented Nov 24, 2021

[GIN] 2021/11/24 - 13:48:32 | 200 |         165µs |       127.0.0.1 | GET      "/static/"
[GIN] 2021/11/24 - 13:48:32 | 200 |     160.083µs |       127.0.0.1 | GET      "/static/"

checks seem to work ok

allenporter and others added 21 commits January 1, 2022 10:09
Add the webrtc integration. This integration proxies the
signal 'offer' from the client to a RTSPtoWebRTCP server that
returns an 'answer'.

The RTSPtoWebRTC server is a go binary based on pion, and this is
what is currently used by the WebRTC custom_component:
https://github.com/AlexxIT/WebRTC
https://github.com/deepch/RTSPtoWebRTC
This is to reflect naming as one type of approach to webrtc since other webrtc integrations would look very different.
Co-authored-by: J. Nick Koston <nick@koston.org>
@allenporter allenporter merged commit c7b991f into home-assistant:dev Jan 1, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants