From d053d88ce96d64f67c1e3c81a10728a0c32d5052 Mon Sep 17 00:00:00 2001 From: Alex X Date: Tue, 11 Nov 2025 15:48:12 +0300 Subject: [PATCH] Add support maxwidth/maxheight settings for homekit source --- internal/homekit/homekit.go | 2 ++ pkg/homekit/helpers.go | 7 +++++-- pkg/homekit/producer.go | 6 ++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/homekit/homekit.go b/internal/homekit/homekit.go index 9a221c4f..4de49624 100644 --- a/internal/homekit/homekit.go +++ b/internal/homekit/homekit.go @@ -134,6 +134,8 @@ func streamHandler(rawURL string) (core.Producer, error) { client, err := homekit.Dial(rawURL, srtp.Server) if client != nil && rawQuery != "" { query := streams.ParseQuery(rawQuery) + client.MaxWidth = core.Atoi(query.Get("maxwidth")) + client.MaxHeight = core.Atoi(query.Get("maxheight")) client.Bitrate = parseBitrate(query.Get("bitrate")) } diff --git a/pkg/homekit/helpers.go b/pkg/homekit/helpers.go index 2a2268d6..625e3ab7 100644 --- a/pkg/homekit/helpers.go +++ b/pkg/homekit/helpers.go @@ -67,10 +67,10 @@ func audioToMedia(codecs []camera.AudioCodecConfiguration) *core.Media { return media } -func trackToVideo(track *core.Receiver, video0 *camera.VideoCodecConfiguration) *camera.VideoCodecConfiguration { +func trackToVideo(track *core.Receiver, video0 *camera.VideoCodecConfiguration, maxWidth, maxHeight int) *camera.VideoCodecConfiguration { profileID := video0.CodecParams[0].ProfileID[0] level := video0.CodecParams[0].Level[0] - attrs := video0.VideoAttrs[0] + var attrs camera.VideoCodecAttributes if track != nil { profile := h264.GetProfileLevelID(track.Codec.FmtpLine) @@ -90,6 +90,9 @@ func trackToVideo(track *core.Receiver, video0 *camera.VideoCodecConfiguration) } for _, s := range video0.VideoAttrs { + if (maxWidth > 0 && int(s.Width) > maxWidth) || (maxHeight > 0 && int(s.Height) > maxHeight) { + continue + } if s.Width > attrs.Width || s.Height > attrs.Height { attrs = s } diff --git a/pkg/homekit/producer.go b/pkg/homekit/producer.go index 04719612..d50ce9ec 100644 --- a/pkg/homekit/producer.go +++ b/pkg/homekit/producer.go @@ -29,7 +29,9 @@ type Client struct { stream *camera.Stream - Bitrate int // in bits/s + MaxWidth int + MaxHeight int + Bitrate int // in bits/s } func Dial(rawURL string, server *srtp.Server) (*Client, error) { @@ -115,7 +117,7 @@ func (c *Client) Start() error { } videoTrack := c.trackByKind(core.KindVideo) - videoCodec := trackToVideo(videoTrack, &c.videoConfig.Codecs[0]) + videoCodec := trackToVideo(videoTrack, &c.videoConfig.Codecs[0], c.MaxWidth, c.MaxHeight) audioTrack := c.trackByKind(core.KindAudio) audioCodec := trackToAudio(audioTrack, &c.audioConfig.Codecs[0])