Skip to content

Commit

Permalink
Bugfix camera streams (#5306)
Browse files Browse the repository at this point in the history
* fix mjpeg streams

* fix trow error on close by frontend

* fix ffmpeg
  • Loading branch information
pvizeli authored and balloob committed Jan 13, 2017
1 parent 6abad6b commit 4b43537
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 8 additions & 2 deletions homeassistant/components/camera/ffmpeg.py
Expand Up @@ -84,9 +84,15 @@ def handle_async_mjpeg_stream(self, request):
if not data:
break
response.write(data)

except asyncio.CancelledError:
_LOGGER.debug("Close stream by browser.")
response = None

finally:
self.hass.async_add_job(stream.close())
yield from response.write_eof()
yield from stream.close()
if response is not None:
yield from response.write_eof()

@property
def name(self):
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/camera/mjpeg.py
Expand Up @@ -124,9 +124,13 @@ def handle_async_mjpeg_stream(self, request):
except asyncio.TimeoutError:
raise HTTPGatewayTimeout()

except asyncio.CancelledError:
_LOGGER.debug("Close stream by browser.")
response = None

finally:
if stream is not None:
yield from stream.close()
stream.close()
if response is not None:
yield from response.write_eof()

Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/camera/synology.py
Expand Up @@ -276,9 +276,13 @@ def handle_async_mjpeg_stream(self, request):
_LOGGER.exception("Error on %s", streaming_url)
raise HTTPGatewayTimeout()

except asyncio.CancelledError:
_LOGGER.debug("Close stream by browser.")
response = None

finally:
if stream is not None:
self.hass.async_add_job(stream.release())
stream.close()
if response is not None:
yield from response.write_eof()

Expand Down

0 comments on commit 4b43537

Please sign in to comment.