move imports in stream component (#27647)
This commit is contained in:
parent
4efa2f3244
commit
9aa28dfd54
9 changed files with 45 additions and 42 deletions
|
@ -4,31 +4,32 @@ import threading
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.auth.util import generate_secret
|
||||||
|
from homeassistant.const import CONF_FILENAME, EVENT_HOMEASSISTANT_STOP
|
||||||
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.loader import bind_hass
|
||||||
|
|
||||||
|
from .const import (
|
||||||
|
ATTR_ENDPOINTS,
|
||||||
|
ATTR_STREAMS,
|
||||||
|
CONF_DURATION,
|
||||||
|
CONF_LOOKBACK,
|
||||||
|
CONF_STREAM_SOURCE,
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_RECORD,
|
||||||
|
)
|
||||||
|
from .core import PROVIDERS
|
||||||
|
from .hls import async_setup_hls
|
||||||
|
from .recorder import async_setup_recorder
|
||||||
|
from .worker import stream_worker
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import uvloop
|
import uvloop
|
||||||
except ImportError:
|
except ImportError:
|
||||||
uvloop = None
|
uvloop = None
|
||||||
|
|
||||||
from homeassistant.auth.util import generate_secret
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, CONF_FILENAME
|
|
||||||
from homeassistant.core import callback
|
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
|
||||||
from homeassistant.loader import bind_hass
|
|
||||||
|
|
||||||
from .const import (
|
|
||||||
DOMAIN,
|
|
||||||
ATTR_STREAMS,
|
|
||||||
ATTR_ENDPOINTS,
|
|
||||||
CONF_STREAM_SOURCE,
|
|
||||||
CONF_DURATION,
|
|
||||||
CONF_LOOKBACK,
|
|
||||||
SERVICE_RECORD,
|
|
||||||
)
|
|
||||||
from .core import PROVIDERS
|
|
||||||
from .worker import stream_worker
|
|
||||||
from .hls import async_setup_hls
|
|
||||||
from .recorder import async_setup_recorder
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,17 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import io
|
import io
|
||||||
from typing import List, Any
|
from typing import Any, List
|
||||||
|
|
||||||
import attr
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
import attr
|
||||||
|
|
||||||
from homeassistant.core import callback
|
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
from homeassistant.util.decorator import Registry
|
from homeassistant.util.decorator import Registry
|
||||||
|
|
||||||
from .const import DOMAIN, ATTR_STREAMS
|
from .const import ATTR_STREAMS, DOMAIN
|
||||||
|
|
||||||
PROVIDERS = Registry()
|
PROVIDERS = Registry()
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from homeassistant.core import callback
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .const import FORMAT_CONTENT_TYPE
|
from .const import FORMAT_CONTENT_TYPE
|
||||||
from .core import StreamView, StreamOutput, PROVIDERS
|
from .core import PROVIDERS, StreamOutput, StreamView
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
"""Provide functionality to record stream."""
|
"""Provide functionality to record stream."""
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
import av
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
|
||||||
from .core import Segment, StreamOutput, PROVIDERS
|
from .core import PROVIDERS, Segment, StreamOutput
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -14,8 +17,6 @@ def async_setup_recorder(hass):
|
||||||
|
|
||||||
def recorder_save_worker(file_out: str, segments: List[Segment]):
|
def recorder_save_worker(file_out: str, segments: List[Segment]):
|
||||||
"""Handle saving stream."""
|
"""Handle saving stream."""
|
||||||
import av
|
|
||||||
|
|
||||||
output = av.open(file_out, "w", options={"movflags": "frag_keyframe"})
|
output = av.open(file_out, "w", options={"movflags": "frag_keyframe"})
|
||||||
output_v = None
|
output_v = None
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ from fractions import Fraction
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import av
|
||||||
|
|
||||||
from .const import AUDIO_SAMPLE_RATE
|
from .const import AUDIO_SAMPLE_RATE
|
||||||
from .core import Segment, StreamBuffer
|
from .core import Segment, StreamBuffer
|
||||||
|
|
||||||
|
@ -11,9 +13,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
def generate_audio_frame():
|
def generate_audio_frame():
|
||||||
"""Generate a blank audio frame."""
|
"""Generate a blank audio frame."""
|
||||||
from av import AudioFrame
|
|
||||||
|
|
||||||
audio_frame = AudioFrame(format="dbl", layout="mono", samples=1024)
|
audio_frame = av.AudioFrame(format="dbl", layout="mono", samples=1024)
|
||||||
# audio_bytes = b''.join(b'\x00\x00\x00\x00\x00\x00\x00\x00'
|
# audio_bytes = b''.join(b'\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
# for i in range(0, 1024))
|
# for i in range(0, 1024))
|
||||||
audio_bytes = b"\x00\x00\x00\x00\x00\x00\x00\x00" * 1024
|
audio_bytes = b"\x00\x00\x00\x00\x00\x00\x00\x00" * 1024
|
||||||
|
@ -25,7 +26,6 @@ def generate_audio_frame():
|
||||||
|
|
||||||
def create_stream_buffer(stream_output, video_stream, audio_frame):
|
def create_stream_buffer(stream_output, video_stream, audio_frame):
|
||||||
"""Create a new StreamBuffer."""
|
"""Create a new StreamBuffer."""
|
||||||
import av
|
|
||||||
|
|
||||||
a_packet = None
|
a_packet = None
|
||||||
segment = io.BytesIO()
|
segment = io.BytesIO()
|
||||||
|
@ -45,7 +45,6 @@ def create_stream_buffer(stream_output, video_stream, audio_frame):
|
||||||
|
|
||||||
def stream_worker(hass, stream, quit_event):
|
def stream_worker(hass, stream, quit_event):
|
||||||
"""Handle consuming streams."""
|
"""Handle consuming streams."""
|
||||||
import av
|
|
||||||
|
|
||||||
container = av.open(stream.source, options=stream.options)
|
container = av.open(stream.source, options=stream.options)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
"""Collection of test helpers."""
|
"""Collection of test helpers."""
|
||||||
import io
|
import io
|
||||||
|
|
||||||
|
import av
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from homeassistant.components.stream import Stream
|
from homeassistant.components.stream import Stream
|
||||||
from homeassistant.components.stream.const import DOMAIN, ATTR_STREAMS
|
from homeassistant.components.stream.const import ATTR_STREAMS, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
def generate_h264_video():
|
def generate_h264_video():
|
||||||
|
@ -11,8 +14,6 @@ def generate_h264_video():
|
||||||
|
|
||||||
See: http://docs.mikeboers.com/pyav/develop/cookbook/numpy.html
|
See: http://docs.mikeboers.com/pyav/develop/cookbook/numpy.html
|
||||||
"""
|
"""
|
||||||
import numpy as np
|
|
||||||
import av
|
|
||||||
|
|
||||||
duration = 5
|
duration = 5
|
||||||
fps = 24
|
fps = 24
|
||||||
|
|
|
@ -4,8 +4,8 @@ from urllib.parse import urlparse
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
from homeassistant.components.stream import request_stream
|
from homeassistant.components.stream import request_stream
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
"""The tests for stream."""
|
"""The tests for stream."""
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.const import CONF_FILENAME
|
|
||||||
from homeassistant.components.stream.const import (
|
from homeassistant.components.stream.const import (
|
||||||
|
ATTR_STREAMS,
|
||||||
|
CONF_LOOKBACK,
|
||||||
|
CONF_STREAM_SOURCE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_RECORD,
|
SERVICE_RECORD,
|
||||||
CONF_STREAM_SOURCE,
|
|
||||||
CONF_LOOKBACK,
|
|
||||||
ATTR_STREAMS,
|
|
||||||
)
|
)
|
||||||
|
from homeassistant.const import CONF_FILENAME
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
from homeassistant.components.stream.core import Segment
|
from homeassistant.components.stream.core import Segment
|
||||||
from homeassistant.components.stream.recorder import recorder_save_worker
|
from homeassistant.components.stream.recorder import recorder_save_worker
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue