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

Allow to cast in HLS format when using WebRTC #80646

Merged
merged 1 commit into from
Oct 26, 2022

Conversation

felipecrs
Copy link
Contributor

Breaking change

N/A

Proposed change

See the linked issue for background, but the long story short is that casting cameras is no longer possible once you enable the native WebRTC integration.

After further analysis, it turns out that casting were being blocked by a constant check, i.e. the camera is fully able to supply a stream in HLS format but since its main format was set to WebRTC it was failing early.

This PR makes this behavior more tolerant, while still retaining the original error handle for returning a helpful message.

The format check is not decisive any longer, but instead we try to fetch a stream URL in HLS format.

If it succeeds, it means the camera is capable of providing a HLS stream and therefore it can be casted

If it fails, we still check for the original error for the sake of hinting the user on why it probably failed.

It's working normally on my main Home Assistant instance.

/cc @allenporter @dermotduffy

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)
  • Deprecation (breaking change to happen in the future)
  • 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.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (camera) you are listed as a code owner for? Thanks!

@allenporter
Copy link
Contributor

Hello, this does not address what I said in #79494 (comment)

The issue is not just how to get this working, but about the technical decisions around the entity model.

@felipecrs
Copy link
Contributor Author

I truly understand, and I wish that WebRTC streaming gets implemented. If it gets implemented, I believe streaming with both formats will have no use.

But nevertheless this is a short-term, harmless workaround that allow people to continue streaming in HLS format while using WebRTC, until the definitive solution gets implemented (which I'm assuming won't be soon).

@allenporter
Copy link
Contributor

Let me elaborate since I think it may not be clear based on your response: The first part of what I said is that there needs to be an architecture discussion to change the rules of the entity model. This is what I meant above by "The issue is not just how to get this working, but about the technical decisions around the entity model."

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Oct 24, 2022
@allenporter
Copy link
Contributor

@balloob since you added this guard, curious for your hot take.

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Yeah seems fine. I think what happened is i migrated logic from the entity, and there it used to be limited

@@ -46,15 +46,17 @@ async def async_resolve_media(self, item: MediaSourceItem) -> PlayMedia:
f"/api/camera_proxy_stream/{camera.entity_id}", camera.content_type
)

if stream_type != StreamType.HLS:
raise Unresolvable("Camera does not support MJPEG or HLS streaming.")

if "stream" not in self.hass.config.components:
raise Unresolvable("Stream integration not loaded")

try:
url = await _async_stream_endpoint_url(self.hass, camera, HLS_PROVIDER)
Copy link
Member

Choose a reason for hiding this comment

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

I'm on my phone, what does the error handling do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose it was meant to return a meaningful message to end-user (which this PR keeps).

@balloob balloob merged commit 37cfa3e into home-assistant:dev Oct 26, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix cla-signed core Hacktoberfest integration: camera new-feature Quality Scale: internal small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No longer possible to cast camera after enabling RTSPToWebRTC
4 participants