mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Fix camera mjpeg stream handling (#18076)
* Fix handle_async_mjpeg_stream * Lint
This commit is contained in:
parent
32ee4f0714
commit
f516550f9f
@ -299,7 +299,8 @@ class Camera(Entity):
|
|||||||
a direct stream from the camera.
|
a direct stream from the camera.
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.handle_async_still_stream(request, self.frame_interval)
|
return await self.handle_async_still_stream(
|
||||||
|
request, self.frame_interval)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
@ -59,8 +59,7 @@ class AmcrestCam(Camera):
|
|||||||
"""Return an MJPEG stream."""
|
"""Return an MJPEG stream."""
|
||||||
# The snapshot implementation is handled by the parent class
|
# The snapshot implementation is handled by the parent class
|
||||||
if self._stream_source == STREAM_SOURCE_LIST['snapshot']:
|
if self._stream_source == STREAM_SOURCE_LIST['snapshot']:
|
||||||
await super().handle_async_mjpeg_stream(request)
|
return await super().handle_async_mjpeg_stream(request)
|
||||||
return
|
|
||||||
|
|
||||||
if self._stream_source == STREAM_SOURCE_LIST['mjpeg']:
|
if self._stream_source == STREAM_SOURCE_LIST['mjpeg']:
|
||||||
# stream an MJPEG image stream directly from the camera
|
# stream an MJPEG image stream directly from the camera
|
||||||
@ -69,10 +68,10 @@ class AmcrestCam(Camera):
|
|||||||
stream_coro = websession.get(
|
stream_coro = websession.get(
|
||||||
streaming_url, auth=self._token, timeout=TIMEOUT)
|
streaming_url, auth=self._token, timeout=TIMEOUT)
|
||||||
|
|
||||||
await async_aiohttp_proxy_web(self.hass, request, stream_coro)
|
return await async_aiohttp_proxy_web(
|
||||||
|
self.hass, request, stream_coro)
|
||||||
|
|
||||||
else:
|
# streaming via ffmpeg
|
||||||
# streaming via fmpeg
|
|
||||||
from haffmpeg import CameraMjpeg
|
from haffmpeg import CameraMjpeg
|
||||||
|
|
||||||
streaming_url = self._camera.rtsp_url(typeno=self._resolution)
|
streaming_url = self._camera.rtsp_url(typeno=self._resolution)
|
||||||
@ -80,9 +79,11 @@ class AmcrestCam(Camera):
|
|||||||
await stream.open_camera(
|
await stream.open_camera(
|
||||||
streaming_url, extra_cmd=self._ffmpeg_arguments)
|
streaming_url, extra_cmd=self._ffmpeg_arguments)
|
||||||
|
|
||||||
await async_aiohttp_proxy_stream(
|
try:
|
||||||
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
'multipart/x-mixed-replace;boundary=ffserver')
|
||||||
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -101,9 +101,11 @@ class ArloCam(Camera):
|
|||||||
await stream.open_camera(
|
await stream.open_camera(
|
||||||
video.video_url, extra_cmd=self._ffmpeg_arguments)
|
video.video_url, extra_cmd=self._ffmpeg_arguments)
|
||||||
|
|
||||||
await async_aiohttp_proxy_stream(
|
try:
|
||||||
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
'multipart/x-mixed-replace;boundary=ffserver')
|
||||||
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -98,9 +98,11 @@ class CanaryCamera(Camera):
|
|||||||
self._live_stream_session.live_stream_url,
|
self._live_stream_session.live_stream_url,
|
||||||
extra_cmd=self._ffmpeg_arguments)
|
extra_cmd=self._ffmpeg_arguments)
|
||||||
|
|
||||||
await async_aiohttp_proxy_stream(
|
try:
|
||||||
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
'multipart/x-mixed-replace;boundary=ffserver')
|
||||||
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_SESSION_RENEW)
|
@Throttle(MIN_TIME_BETWEEN_SESSION_RENEW)
|
||||||
|
@ -134,8 +134,7 @@ class MjpegCamera(Camera):
|
|||||||
"""Generate an HTTP MJPEG stream from the camera."""
|
"""Generate an HTTP MJPEG stream from the camera."""
|
||||||
# aiohttp don't support DigestAuth -> Fallback
|
# aiohttp don't support DigestAuth -> Fallback
|
||||||
if self._authentication == HTTP_DIGEST_AUTHENTICATION:
|
if self._authentication == HTTP_DIGEST_AUTHENTICATION:
|
||||||
await super().handle_async_mjpeg_stream(request)
|
return await super().handle_async_mjpeg_stream(request)
|
||||||
return
|
|
||||||
|
|
||||||
# connect to stream
|
# connect to stream
|
||||||
websession = async_get_clientsession(self.hass)
|
websession = async_get_clientsession(self.hass)
|
||||||
|
@ -221,9 +221,11 @@ class ONVIFHassCamera(Camera):
|
|||||||
await stream.open_camera(
|
await stream.open_camera(
|
||||||
self._input, extra_cmd=self._ffmpeg_arguments)
|
self._input, extra_cmd=self._ffmpeg_arguments)
|
||||||
|
|
||||||
await async_aiohttp_proxy_stream(
|
try:
|
||||||
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
'multipart/x-mixed-replace;boundary=ffserver')
|
||||||
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -139,9 +139,11 @@ class RingCam(Camera):
|
|||||||
await stream.open_camera(
|
await stream.open_camera(
|
||||||
self._video_url, extra_cmd=self._ffmpeg_arguments)
|
self._video_url, extra_cmd=self._ffmpeg_arguments)
|
||||||
|
|
||||||
await async_aiohttp_proxy_stream(
|
try:
|
||||||
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
'multipart/x-mixed-replace;boundary=ffserver')
|
||||||
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -92,7 +92,7 @@ class SynologyCamera(Camera):
|
|||||||
websession = async_get_clientsession(self.hass, self._verify_ssl)
|
websession = async_get_clientsession(self.hass, self._verify_ssl)
|
||||||
stream_coro = websession.get(streaming_url)
|
stream_coro = websession.get(streaming_url)
|
||||||
|
|
||||||
await async_aiohttp_proxy_web(self.hass, request, stream_coro)
|
return await async_aiohttp_proxy_web(self.hass, request, stream_coro)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -158,7 +158,9 @@ class XiaomiCamera(Camera):
|
|||||||
await stream.open_camera(
|
await stream.open_camera(
|
||||||
self._last_url, extra_cmd=self._extra_arguments)
|
self._last_url, extra_cmd=self._extra_arguments)
|
||||||
|
|
||||||
await async_aiohttp_proxy_stream(
|
try:
|
||||||
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
'multipart/x-mixed-replace;boundary=ffserver')
|
||||||
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
@ -144,7 +144,9 @@ class YiCamera(Camera):
|
|||||||
await stream.open_camera(
|
await stream.open_camera(
|
||||||
self._last_url, extra_cmd=self._extra_arguments)
|
self._last_url, extra_cmd=self._extra_arguments)
|
||||||
|
|
||||||
await async_aiohttp_proxy_stream(
|
try:
|
||||||
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
'multipart/x-mixed-replace;boundary=ffserver')
|
||||||
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user