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

Minor change to still image on mjpeg #18602

Merged
merged 2 commits into from
Nov 21, 2018
Merged

Minor change to still image on mjpeg #18602

merged 2 commits into from
Nov 21, 2018

Conversation

nragon
Copy link
Contributor

@nragon nragon commented Nov 20, 2018

Hello,

May I suggest this "minor" improvement o still images.
Instead of finding on data structure for start and end, all the time, lets search for the end in chunks.
That's the approach I'm using both for HA and my motion/object detection system.

All the best,
Nuno

@homeassistant
Copy link
Contributor

Hi @nragon,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@ghost ghost added the in progress label Nov 20, 2018
end_idx = chunk.find(data_end)
if end_idx != -1:
return data[data.find(data_start):] + chunk[:end_idx + 2]

Choose a reason for hiding this comment

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

blank line contains whitespace

@ghost ghost assigned balloob Nov 21, 2018
@balloob
Copy link
Member

balloob commented Nov 21, 2018

Good idea! Looks good.

@balloob balloob merged commit 1ad3c3b into home-assistant:dev Nov 21, 2018
@ghost ghost removed the in progress label Nov 21, 2018
@luca-angemi
Copy link
Contributor

I've been testing this in 0.84.0b4.
The still image doesn't appear and with reverting to 0.83 the image appears.
No change in configuration, no errors in the logs.

Am I missing something?

@balloob
Copy link
Member

balloob commented Dec 11, 2018

Okay, will revert this then.

balloob added a commit that referenced this pull request Dec 11, 2018
balloob added a commit that referenced this pull request Dec 11, 2018
@balloob balloob mentioned this pull request Dec 11, 2018
@nragon
Copy link
Contributor Author

nragon commented Dec 11, 2018

Well, at least we should not look for start all the time.
Can it be the case when end(\xff and \xd9) comes in different chunks? (This requires looking into data array for end and only once for start)
Or when end is present and start is not? (This can be fixed without looking into data array)

@vMeph
Copy link

vMeph commented Dec 11, 2018

using 0.84.0b4 version and sense versions 0.83.3 my camera preview wont work

camera_image: camera.test_camera
entities:
  - entity: switch.mar
    icon: 'mdi:lightbulb'
  - switch.qt
id: 583965b4f34948bc885fbb395bc9
title: Test Camera
type: picture-glance
aspect_ratio: 16x9

if you click on blank image you can see the camera working, it seems thecamera_image: isnt working, shows blank image

dev info:

Log Details (ERROR)
Tue Dec 11 2018 15:38:34 GMT+0000 (Greenwich Mean Time)

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
OSError: [Errno 113] Host is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 181, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f7de95588>: Failed to establish a new connection: [Errno 113] Host is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.1.5', port=5236): Max retries exceeded with url: /video (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7de95588>: Failed to establish a new connection: [Errno 113] Host is unreachable',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 390, in start
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_app.py", line 366, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 106, in impl
    return await handler(request)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/static.py", line 66, in staticresource_middleware
    return await handler(request)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/real_ip.py", line 34, in real_ip_middleware
    return await handler(request)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/ban.py", line 67, in ban_middleware
    return await handler(request)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/auth.py", line 99, in auth_middleware
    return await handler(request)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/view.py", line 118, in handle
    result = await result
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 407, in get
    return await self.handle(request, camera)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 424, in handle
    image = await camera.async_camera_image()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/mjpeg.py", line 99, in async_camera_image
    self.camera_image)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/mjpeg.py", line 125, in camera_image
    self._mjpeg_url, auth=auth, stream=True, timeout=10)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.1.5', port=5236): Max retries exceeded with url: /video (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7de95588>: Failed to establish a new connection: [Errno 113] Host is unreachable',))```

balloob added a commit that referenced this pull request Dec 12, 2018
balloob added a commit that referenced this pull request Dec 12, 2018
@balloob balloob mentioned this pull request Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants