Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed May 31, 2024
2 parents 290e3f2 + c9764c1 commit cd6c426
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ You can then use the web interface at `http://localhost:5000` where localhost is

See [basic usage](#basic-usage) for additional information or visit the [wiki page](https://github.com/mrlt8/docker-wyze-bridge/wiki/Home-Assistant) for additional information on using the bridge as a Home Assistant Add-on.

## What's Changed in v2.9.4

- Adjust AV sync issue/delay when audio is enabled. (#1231) Thanks @delmlund!

## What's Changed in v2.9.3

- FIX: Clear the retain flag from MQTT Discovery which was causing commands to be resent to the bridge on startup for some users. (#1182)
Expand Down
2 changes: 1 addition & 1 deletion app/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=2.9.3
VERSION=2.9.4
MTX_TAG=1.8.2
IOS_VERSION=17.1.1
APP_VERSION=2.50.6.1
Expand Down
6 changes: 3 additions & 3 deletions app/wyzebridge/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def get_ffmpeg_cmd(
- list of str: complete ffmpeg command that is ready to run as subprocess.
"""

flags = "-fflags +flush_packets+nobuffer+genpts -flags +low_delay"
flags = "-fflags +flush_packets+nobuffer -flags +low_delay"
livestream = get_livestream_cmd(uri)
audio_in = "-f lavfi -i anullsrc=cl=mono" if livestream else ""
audio_out = "aac"
thread_queue = "-thread_queue_size 1k -analyzeduration 32 -probesize 32"
thread_queue = "-thread_queue_size 8 -analyzeduration 32 -probesize 32"
if audio and "codec" in audio:
audio_in = f"{thread_queue} -f {audio['codec']} -ac 1 -ar {audio['rate']} -i /tmp/{uri}_audio.pipe"
audio_out = audio["codec_out"] or "copy"
Expand Down Expand Up @@ -62,7 +62,7 @@ def get_ffmpeg_cmd(
+ (["-map", "1:a", "-c:a", audio_out] if audio_in else [])
+ (a_options if audio and audio_out != "copy" else [])
+ ["-fps_mode", "passthrough", "-flush_packets", "1"]
+ ["-rtbufsize", "1", "-max_interleave_delta", "0"]
+ ["-rtbufsize", "1"]
+ ["-f", "tee"]
+ [rtsp_ss + livestream]
)
Expand Down
27 changes: 13 additions & 14 deletions app/wyzecam/iotc.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,12 @@ def _video_frame_slow(self, frame_info) -> Optional[bool]:
self.frame_ts = float(f"{frame_info.timestamp}.{frame_info.timestamp_ms}")
gap = time.time() - self.frame_ts

if frame_info.is_keyframe:
return

if gap > 5:
logger.warning("[video] super slow")
self.clear_buffer()
if gap > 1:
logger.debug(f"[video] slow {gap=}")
self.flush_pipe("audio")
self.flush_pipe("audio", gap)
if gap > 0:
self._sleep_buffer += gap

Expand Down Expand Up @@ -560,19 +557,20 @@ def clear_buffer(self) -> None:
self.sync_camera_time(True)
tutk.av_client_clean_buf(self.tutk_platform_lib, self.av_chan_id)

def flush_pipe(self, pipe_type: str = "audio"):
def flush_pipe(self, pipe_type: str = "audio", gap: float = 0):
if pipe_type == "audio" and not self.audio_pipe_ready:
return

fifo = f"/tmp/{self.pipe_name}_{pipe_type}.pipe"
size = (round(abs(gap)) * 320) if gap else 7680

try:
with io.open(fifo, "rb") as pipe:
set_non_blocking(pipe.fileno())
while data_read := pipe.read(7680):
while data_read := pipe.read(size):
logger.debug(f"Flushed {len(data_read)} from {pipe_type} pipe")
if pipe_type == "audio":
self.audio_pipe_ready = False
if gap:
break
except Exception as e:
logger.warning(f"Flushing Error: {e}")

Expand Down Expand Up @@ -610,10 +608,10 @@ def recv_audio_pipe(self) -> None:
try:
with open(fifo_path, "wb", buffering=0) as audio_pipe:
set_non_blocking(audio_pipe)
self.audio_pipe_ready = True
for frame_data, _ in self.recv_audio_data():
with contextlib.suppress(BlockingIOError):
audio_pipe.write(frame_data)
self.audio_pipe_ready = True

except IOError as ex:
if ex.errno != errno.EPIPE: # Broken pipe
Expand All @@ -629,20 +627,21 @@ def _audio_frame_slow(self, frame_info) -> Optional[bool]:
if frame_info.timestamp < 1591069888:
return

gap = self.frame_ts - float(f"{frame_info.timestamp}.{frame_info.timestamp_ms}")
gap = float(f"{frame_info.timestamp}.{frame_info.timestamp_ms}") - self.frame_ts

if abs(gap) > 10:
if abs(gap) > 5:
logger.debug(f"[audio] out of sync {gap=}")
self.clear_buffer()

if gap < -1:
logger.debug(f"[audio] behind video.. {gap=}")
self.tutk_platform_lib.avClientCleanAudioBuf(self.av_chan_id)
self.flush_pipe("audio")
self.flush_pipe("audio", gap)

if gap > 0:
self._sleep_buffer += gap
if gap > 1:
logger.debug(f"[audio] ahead of video.. {gap=}")
self._sleep_buffer += gap
time.sleep(gap / 2)

def get_audio_sample_rate(self) -> int:
"""Attempt to get the audio sample rate."""
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ services:
- API_KEY=
# [OPTIONAL] IP Address of the host to enable WebRTC e.g.,:
# - WB_IP=192.168.1.122
# WebUI and Stream authentication:
- WB_AUTH=True # Set to false to disable web and stream auth.
# WB_USERNAME=
# WB_PASSWORD=
4 changes: 4 additions & 0 deletions home_assistant/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## What's Changed in v2.9.4

- Adjust AV sync issue/delay when audio is enabled. (#1231) Thanks @delmlund!

## What's Changed in v2.9.3

- FIX: Clear the retain flag from MQTT Discovery which was causing commands to be resent to the bridge on startup for some users. (#1182)
Expand Down
2 changes: 1 addition & 1 deletion home_assistant/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: WebRTC/RTSP/RTMP/LL-HLS bridge for Wyze cams in a docker container
slug: docker_wyze_bridge
url: https://github.com/mrlt8/docker-wyze-bridge
image: mrlt8/wyze-bridge
version: 2.9.3
version: 2.9.4
arch:
- armv7
- aarch64
Expand Down

0 comments on commit cd6c426

Please sign in to comment.