Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.stream.core.KeyFrameConverter Class Reference

Public Member Functions

None __init__ (self, HomeAssistant hass, StreamSettings stream_settings, DynamicStreamSettings dynamic_stream_settings)
 
bytes|None async_get_image (self, int|None width=None, int|None height=None, bool wait_for_next_keyframe=False)
 
None create_codec_context (self, VideoCodecContext codec_context)
 
None stash_keyframe_packet (self, Packet packet)
 

Static Public Member Functions

np.ndarray transform_image (np.ndarray image, int orientation)
 

Private Member Functions

None _generate_image (self, int|None width, int|None height)
 

Private Attributes

 _codec_context
 
 _dynamic_stream_settings
 
 _hass
 
 _image
 
 _lock
 
 _packet
 
 _stream_settings
 
 _turbojpeg
 

Detailed Description

Enables generating and getting an image from the last keyframe seen in the stream.

An overview of the thread and state interaction:
    the worker thread sets a packet
    get_image is called from the main asyncio loop
    get_image schedules _generate_image in an executor thread
    _generate_image will try to create an image from the packet
    _generate_image will clear the packet, so there will only be one attempt per packet
If successful, self._image will be updated and returned by get_image
If unsuccessful, get_image will return the previous image

Definition at line 419 of file core.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.components.stream.core.KeyFrameConverter.__init__ (   self,
HomeAssistant  hass,
StreamSettings  stream_settings,
DynamicStreamSettings  dynamic_stream_settings 
)
Initialize.

Definition at line 432 of file core.py.

Member Function Documentation

◆ _generate_image()

None homeassistant.components.stream.core.KeyFrameConverter._generate_image (   self,
int | None  width,
int | None  height 
)
private
Generate the keyframe image.

This is run in an executor thread, but since it is called within an
the asyncio lock from the main thread, there will only be one entry
at a time per instance.

Definition at line 489 of file core.py.

◆ async_get_image()

bytes | None homeassistant.components.stream.core.KeyFrameConverter.async_get_image (   self,
int | None   width = None,
int | None   height = None,
bool   wait_for_next_keyframe = False 
)
Fetch an image from the Stream and return it as a jpeg in bytes.

Definition at line 529 of file core.py.

◆ create_codec_context()

None homeassistant.components.stream.core.KeyFrameConverter.create_codec_context (   self,
VideoCodecContext  codec_context 
)
Create a codec context to be used for decoding the keyframes.

This is run by the worker thread and will only be called once per worker.

Definition at line 463 of file core.py.

◆ stash_keyframe_packet()

None homeassistant.components.stream.core.KeyFrameConverter.stash_keyframe_packet (   self,
Packet  packet 
)
Store the keyframe and set the asyncio.Event from the event loop.

This is called from the worker thread.

Definition at line 455 of file core.py.

◆ transform_image()

np.ndarray homeassistant.components.stream.core.KeyFrameConverter.transform_image ( np.ndarray  image,
int  orientation 
)
static
Transform image to a given orientation.

Definition at line 485 of file core.py.

Member Data Documentation

◆ _codec_context

homeassistant.components.stream.core.KeyFrameConverter._codec_context
private

Definition at line 477 of file core.py.

◆ _dynamic_stream_settings

homeassistant.components.stream.core.KeyFrameConverter._dynamic_stream_settings
private

Definition at line 453 of file core.py.

◆ _hass

homeassistant.components.stream.core.KeyFrameConverter._hass
private

Definition at line 447 of file core.py.

◆ _image

homeassistant.components.stream.core.KeyFrameConverter._image
private

Definition at line 527 of file core.py.

◆ _lock

homeassistant.components.stream.core.KeyFrameConverter._lock
private

Definition at line 450 of file core.py.

◆ _packet

homeassistant.components.stream.core.KeyFrameConverter._packet
private

Definition at line 460 of file core.py.

◆ _stream_settings

homeassistant.components.stream.core.KeyFrameConverter._stream_settings
private

Definition at line 452 of file core.py.

◆ _turbojpeg

homeassistant.components.stream.core.KeyFrameConverter._turbojpeg
private

Definition at line 449 of file core.py.


The documentation for this class was generated from the following file: