Compare commits

..

213 Commits

Author SHA1 Message Date
Alex X fa580c516e Update version to 1.9.9 2025-03-10 05:51:40 +03:00
Alex X 7f4c450553 Merge pull request #1629 from hsakoh/feature/addSwitchBotSupport
Add client for SwitchBot Camera WebRTC
2025-03-09 18:48:40 +03:00
Alex X 761ff7ed5a Update readme for SwitchBot 2025-03-09 18:48:18 +03:00
Alex X 117d767f05 Code refactoring for SwitchBot format support #1629 2025-03-09 18:44:32 +03:00
Alex X 8405bfe6f9 Merge pull request #1632 from Klutrem/master
feat: x-www-form-urlencoded support
2025-03-09 17:46:46 +03:00
Alex X ccdb1479f7 Code refactoring for RtspToWeb format support #1632 2025-03-09 17:46:13 +03:00
Alex X c8f68f44af Optimize imports 2025-03-09 17:26:06 +03:00
Alex X 3954a555f8 Fix extra slash for RTSP SETUP #1236 2025-03-09 17:08:25 +03:00
Alex X b6934922fa Improve ONVIF server #1304 2025-03-09 16:26:10 +03:00
Alex X 944e6f5569 Update Reolink links in the docs 2025-03-09 11:40:23 +03:00
Alex X d51b36e80d Add readme to RTMP module 2025-03-09 07:21:10 +03:00
Alex X c9724e2024 Fix RTMP server handshake for FFmpeg #1318 2025-03-09 07:20:40 +03:00
Alex X 830e476120 Fix data race for memory logger #1487 2025-03-08 14:11:29 +03:00
Alex X fe2e372997 Add examples to streams module readme 2025-03-08 07:31:49 +03:00
Alex X a15deedf0d Fix YAML patch in some cases #1626 2025-03-07 21:44:23 +03:00
klutrem 22bf8163cd returned url variable name 2025-03-06 16:08:43 +03:00
klutrem b8390331af feat: x-www-form-urlencoded support 2025-03-06 16:03:44 +03:00
hsakoh 47b740ff35 Add client for SwitchBot Camera WebRTC (supports special SessionDescription). 2025-03-05 09:32:33 +09:00
Alex X 39c14e6556 Fix support streaming to YouTube #1574 2025-03-01 21:36:32 +03:00
Alex X 57cd791348 Fix ONVIF client GetCapabilities request 2025-03-01 20:00:59 +03:00
Alex X 3c612e284e Update dependencies 2025-02-27 21:43:30 +03:00
Alex X 8cd1ab5c8f Update go build version to 1.24 2025-02-27 21:05:10 +03:00
Alex X a6c22cadb8 Merge pull request #1620 from DRuggeri/master
Correct slight syntax error in example
2025-02-27 20:37:27 +03:00
Alex X a628ecf72b Update readme about new WebRTC default settings and filters logic 2025-02-27 15:56:40 +03:00
Daniel Ruggeri 8d70233d83 Correct slight syntax error in example 2025-02-27 06:35:30 -06:00
Alex X ae89600201 Fix WebUI editor after Save 2025-02-27 15:01:05 +03:00
Alex X 934d43b525 Update WebRTC server operation in closed docker containers 2025-02-27 14:30:56 +03:00
Alex X 858c04bacf Fix situation when WebRTC candidate pair changes multiple times #1282 2025-02-26 21:39:56 +03:00
Alex X 2a5355b1f8 Fix WebRTC server with static UDP port 2025-02-26 21:34:46 +03:00
Alex X 5cf2ac4c3e Fix escape quotes for DOT format #1603 2025-02-26 17:00:05 +03:00
Alex X 71173da5ad Add useful links to webrtc readme 2025-02-26 15:52:04 +03:00
Alex X e304f4f34f Add support creality format for webrtc client #1600 2025-02-25 19:40:19 +03:00
Alex X 7d37f645ba Improved limited HomeKit server support for open source projects 2025-02-25 19:26:30 +03:00
Alex X c50738005d Update mDNS server handler 2025-02-25 16:16:38 +03:00
Alex X effff6f88d Fix concurrent SRTP sessions map read and map write #1489 2025-02-24 22:04:14 +03:00
Alex X 45b223a2ef Fix panic on reading nil TLV8 #1507 2025-02-24 21:55:10 +03:00
Alex X 90544ba713 Fix panic for concurrent streams map read and map write #1612 2025-02-24 21:02:33 +03:00
Alex X e55c2e9598 Merge pull request #1438 from huynhquangtoan/master
Fix "panic: send on closed channel"
2025-02-24 20:27:53 +03:00
Alex X 6ee52474e1 Code refactoring for panic: send on closed channel 2025-02-24 18:13:16 +03:00
Alex X 4bf9f0b96c Merge pull request #1137 from felipecrs/patch-2
Add note about requesting multiple backchannel on Dahua Doorbell
2025-02-24 17:13:33 +03:00
Alex X 79e2fa89df Merge pull request #1167 from skrashevich/feat-logging-to-file
feat(logging): add file output option for logging configuration
2025-02-24 16:25:20 +03:00
Alex X 2ad0ded73f Merge branch 'master' into feat-logging-to-file 2025-02-24 16:25:08 +03:00
Alex X 1ab05e5c3b Merge pull request #1205 from skrashevich/fix-keep-netmap-selections
fix(network): preserve selected nodes and edges on data reload
2025-02-24 16:23:19 +03:00
Alex X 4b4a1644ff Code refactoring for network view 2025-02-24 16:21:12 +03:00
Alex X 7fd0ec8ce6 Code refactoring for logs to file 2025-02-24 15:21:37 +03:00
Alex X 2d1e08b50e Merge pull request #1223 from robvanoostenrijk/freebsd-builds
FreeBSD Binaries (Attempt #2)
2025-02-24 12:44:59 +03:00
Alex X b881c52118 Code refactoring for FreeBSD binaries 2025-02-24 12:44:09 +03:00
Alex X 6fb59949a2 Rewrite exec handler 2025-02-23 21:16:53 +03:00
Alex X 7d41dc21c1 Merge pull request #1264 from OnFreund/patch-1
Install ffplay in container
2025-02-22 12:28:54 +03:00
Alex X 6365968dc3 Merge pull request #1253 from jamal/nest-rtsp
nest: add support for RTSP cameras
2025-02-22 11:41:24 +03:00
Alex X 1abb3c8c22 Code refactoring for Nest RTSP source 2025-02-22 11:39:32 +03:00
Alex X 33f4bb45d1 Merge pull request #1284 from skrashevich/fix-apiinit-datarace
refactor(api): move port extraction logic to Init function for prevent data race
2025-02-21 15:50:22 +03:00
Alex X 4897994b35 Merge pull request #1432 from seydx/rtsp-backchannel 2025-02-18 17:08:37 +03:00
Alex X 0a773c82af Code refactoring for RTSP backchannel 2025-02-18 16:59:00 +03:00
seydx b34d970076 remove duplicated code 2025-02-18 11:52:57 +01:00
Alex X 19cf781431 Merge pull request #1511 from fmcloudconsulting/fix/rtsp-server-interleaved
Accept rtsp client without interleaved parameter
2025-02-18 12:50:51 +03:00
Alex X 637e65e5a0 Code refactoring for RTSP transport header processing 2025-02-18 12:49:33 +03:00
Alex X b3f83fd363 Merge pull request #1522 from subbyte/authlog
Improve RTSP server authentication handling and auditing
2025-02-18 12:26:54 +03:00
Alex X 02ac3a6814 Code refactoring for RTSP auth 2025-02-18 12:24:06 +03:00
Alex X 97891d36ab Merge pull request #1607 from felipecrs/patch-3
Fix typo in RTMP docs
2025-02-18 11:05:57 +03:00
Felipe Santos 65c87d5e0f Fix typo in RTMP docs 2025-02-17 18:07:31 -03:00
Alex X ae3b53540e Merge pull request #1543 from cavefire/h200-child-devices
Fix H200 + D230 Doorbell stream
2025-02-17 17:09:20 +03:00
Alex X 0e9009b0de Merge pull request #1568 from seydx/ring
Ring: Fix snapshot producer MarshalJSON and prevent nil reference during stop
2025-02-17 17:08:26 +03:00
Alex X be2864c34b Code refactoring after #1588 2025-02-17 17:07:36 +03:00
Alex X c9bdac2e03 Merge pull request #1588 from thomaspurchas/master
Handle malformed fmtp lines
2025-02-17 17:03:01 +03:00
seydx 040de3d973 Merge branch 'AlexxIT:master' into rtsp-backchannel 2025-02-10 17:11:40 +01:00
seydx 1703380ebc Merge branch 'AlexxIT:master' into ring 2025-02-10 17:11:20 +01:00
Alex X e935885cd3 Update general H265 support for WebRTC #1439 2025-02-10 17:11:08 +01:00
Julian da809bb9d7 Update build.yml
Fix 
Build binaries
This request has been automatically failed because it uses a deprecated version of `actions/upload-artifact: v3`. Learn more: https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/
2025-02-10 17:11:08 +01:00
Thomas Purchas c39c9aa1da Handle malformed fmtp lines 2025-02-08 23:12:45 +00:00
Alex X ad61662cc4 Update general H265 support for WebRTC #1439 2025-02-07 10:17:15 +03:00
Alex X e42bcd0115 Merge pull request #1580 from notjulian/master
Update build.yml
2025-02-03 09:20:19 +03:00
seydx ad8c025393 Add backchannel support for rtsp server 2025-02-03 00:03:17 +01:00
Alex X 1b0db3c8b0 Add readme for V4L2 module 2025-02-03 00:02:05 +01:00
Alex X f9a8c1969c Improve delay for MSE player 2025-02-03 00:02:05 +01:00
Alex X 645c11f0bd Ignore unknown NAL unit types for RTP/H264 #1570 2025-02-03 00:02:05 +01:00
Alex X ece49a158e Add support H264, H265, NV12 for V4L2 source #1546 2025-02-03 00:02:05 +01:00
Alex X b139b8fdd6 Add readme for V4L2 module 2025-02-02 23:56:07 +01:00
Alex X b14aa4f0dc Improve delay for MSE player 2025-02-02 23:56:07 +01:00
Alex X 9b392a22e1 Ignore unknown NAL unit types for RTP/H264 #1570 2025-02-02 23:56:07 +01:00
Alex X 36547a7343 Add support H264, H265, NV12 for V4L2 source #1546 2025-02-02 23:56:07 +01:00
Julian 876390aa68 Update build.yml
Fix 
Build binaries
This request has been automatically failed because it uses a deprecated version of `actions/upload-artifact: v3`. Learn more: https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/
2025-02-02 22:15:19 +00:00
Alex X 297ecfbae3 Add readme for V4L2 module 2025-02-02 15:41:30 +03:00
Alex X eeb0012e7f Improve delay for MSE player 2025-02-02 14:46:37 +03:00
Alex X 35cf82f11c Ignore unknown NAL unit types for RTP/H264 #1570 2025-02-02 11:01:44 +03:00
Alex X 82f6c2c550 Add support H264, H265, NV12 for V4L2 source #1546 2025-01-26 16:09:50 +03:00
seydx 3e3988a67f minor improvements 2025-01-25 16:11:39 +01:00
seydx 2f4694dc95 Merge branch 'master' into rtsp-backchannel 2025-01-25 14:20:12 +01:00
Alex X f072dab07b Correcting code formatting after #1567 2025-01-25 11:18:51 +03:00
Alex X fc02e6f4a5 Merge pull request #1567 from seydx/ring
Add Ring camera integration
2025-01-25 11:12:04 +03:00
seydx 0651a09a3c add snapshot producer 2025-01-24 22:35:04 +01:00
seydx 2c5f1e0417 add 2fa 2025-01-24 19:37:17 +01:00
seydx c9682ca64d remove unnecessary prints and use mutex for ws 2025-01-24 18:02:47 +01:00
seydx bceb024588 enable speaker for two way audio 2025-01-24 17:37:50 +01:00
seydx 17bba4d4a2 skip empty ICE candidates 2025-01-24 12:47:25 +01:00
seydx 485448cbc7 initial ring implementation 2025-01-24 12:38:45 +01:00
seydx 244dad447b Merge branch 'master' into rtsp-backchannel 2025-01-12 08:19:45 +01:00
Alex X 22e63a7367 Fix comment about OpenIPC 2025-01-10 19:57:10 +03:00
Alex X 83907132b5 Update about packed and planar YUV formats 2025-01-10 15:01:01 +03:00
Alex X 7dc9beb171 Add ws and ffmpeg modules to go2rtc_mjpeg 2025-01-10 14:56:42 +03:00
Alex X 0664e46a4b Fix v4l2 source for MIPS 2025-01-10 12:57:37 +03:00
Timo Christeleit 2ca97a42c5 Update pkg/tapo/client.go
Co-authored-by: Sergey Vilgelm <523825+SVilgelm@users.noreply.github.com>
2025-01-09 09:44:23 +01:00
Alex X 773e415dff Code refactoring for v4l2 device 2025-01-09 07:18:36 +03:00
Xiaokui Shu 9e673559c4 Improve log formatting with Msgf 2025-01-08 21:31:37 -05:00
Alex X 879ef603fe Update v4l2 discovery 2025-01-09 00:34:10 +03:00
Alex X 7e0a163f12 Add support mips arch for v4l2 source 2025-01-09 00:28:33 +03:00
Timo Christeleit 8e4088e08f fix tapo h200 + d230 doorbell stream 2025-01-08 11:03:17 +01:00
Alex X 59161c663b Add support framerate param for v4l2 source 2025-01-08 08:35:42 +03:00
Alex X 93252fc5d2 Change ListSizes function for V4L2 device 2025-01-08 08:35:19 +03:00
Alex X e4b8d1807d Add support snapshot for raw image format 2025-01-08 08:35:08 +03:00
Alex X 33e0ccdd10 Fix build for mipsle 2025-01-07 00:19:53 +03:00
Alex X d59139a2ab Add support v4l2 source 2025-01-06 23:47:35 +03:00
Alex X df831833b1 Collect list of dependency license 2025-01-06 19:31:03 +03:00
Alex X c065db6da1 Code refactoring after #1539 2025-01-06 06:32:13 +03:00
Alex X a55be809f3 Merge pull request #1539 from BrunoTCouto/onvif-RateControl
fix(onvif): Add RateControl to fix Unifi Protect integration
2025-01-06 06:30:29 +03:00
Bruno Tomassetti Couto a9e1ebc0a8 Improve ONVIF server by adding rate control for video encoder configuration 2025-01-05 22:54:20 -03:00
Alex X 55af09a350 Add support fix JPEG from some MJPEG sources 2025-01-05 11:03:44 +03:00
Alex X 199fdd6728 Update version to 1.9.8 2025-01-03 16:24:31 +03:00
Alex X 4035e91672 Fix ONVIF XML tag parsing in some cases 2025-01-03 15:08:38 +03:00
Alex X bc9194d740 Update go dependencies 2025-01-03 13:57:15 +03:00
Alex X f601c47218 Improve ONVIF server 2025-01-03 13:19:40 +03:00
huynhquangtoan 066d559377 Merge branch 'AlexxIT:master' into master 2024-12-31 10:16:29 +07:00
Alex X 2c3219ffcb Merge pull request #1520 from acortelyou/feat/unifi
Extend onvif server to support Unifi Protect
2024-12-30 20:33:33 +03:00
Alex Cortelyou cf88bf9c23 Remove inaccurate comments 2024-12-29 16:22:49 -08:00
Alex Cortelyou b8303b9a22 Remove optional fields, normalize indentation 2024-12-29 16:16:49 -08:00
Alex X a3f084dcde RTMP server enhancement to support OpenIPC cameras 2024-12-29 22:37:04 +03:00
Alex X 0d6b8fc6fc Fix OPUS/48000/1 for RTSP from some cameras #1506 2024-12-29 11:44:56 +03:00
Xiaokui Shu 261a936bb8 Add rtsp server failed auth logging 2024-12-25 17:09:23 -05:00
Alex Cortelyou 159d9425a7 Remove non-essential fields 2024-12-24 11:08:18 -08:00
Alex Cortelyou 3a50b3678d Extend onvif server to support Unifi Protect 2024-12-23 23:43:39 -08:00
fmcloudconsulting 6fa352f407 fix: don't require unicast param and fix typo (tr instead of transport) 2024-12-17 19:06:15 +01:00
fmcloudconsulting 4b80b2c233 fix: typo 2024-12-17 17:36:18 +01:00
fmcloudconsulting d881755503 chore: lint 2024-12-17 17:30:10 +01:00
fmcloudconsulting fd125ecc68 fix: return 461 if client requested an invalid transport method 2024-12-17 17:28:13 +01:00
fmcloudconsulting 29f7f1a57d feat: accept rtsp client without interleaved parameter 2024-12-16 22:50:35 +01:00
Alex X 8ecaabfce9 Add support VIGI cameras #1470 2024-12-16 20:25:01 +03:00
seydx 1797ff67c0 Merge branch 'master' into rtsp-backchannel 2024-12-14 11:30:37 +01:00
Alex X f1ba5e95ec Fix parsing RTSP Transport header #1235 2024-12-06 12:34:31 +03:00
Alex X d8c0f9d1d9 Update support doorbird source #1060 2024-12-05 10:55:14 +03:00
Rob van Oostenrijk df4b5fc87d Merge branch 'master' into freebsd-builds 2024-12-01 07:19:40 +04:00
Alex X d7cdc8b3b0 Merge pull request #1477 from oeiber/patch-1
Removing additional '&' in rawURL
2024-11-24 19:00:38 +03:00
oeiber 5b53ca7cf1 Removing double additional '&' in rawURL 2024-11-24 16:19:58 +01:00
Alex X 194d1dae51 Add support doorbird source #1060 2024-11-24 13:09:13 +03:00
seydx 61322ede6c Merge branch 'AlexxIT:master' into rtsp-backchannel 2024-11-15 01:06:50 +01:00
Alex X a8edaedc8b Fix broken incoming sources after v1.9.7 #1458 2024-11-15 01:05:50 +01:00
Alex X 25145f72e5 Fix broken incoming sources after v1.9.7 #1458 2024-11-14 19:39:26 +03:00
seydx 3ddf8b5922 Merge branch 'master' into rtsp-backchannel 2024-11-13 11:23:16 +01:00
Alex X dbe9e4aade Update version to 1.9.7 2024-11-11 20:20:53 +03:00
Alex X 715be4dad0 Merge pull request #1450 from edenhaus/ffmpeg-codec-not-matched-error
Lower codec not matched error for ffmpeg to debug
2024-11-11 18:05:52 +03:00
Alex X 570b7d0d97 Code refactoring for #1450 2024-11-11 17:49:22 +03:00
Alex X 80ac0ab17f Merge pull request #1448 from edenhaus/imporve-codec-not-matched-error
Improve codec not matched error by including kind
2024-11-11 16:37:25 +03:00
Alex X 9ee8174d5f Code refactoring for #1448 2024-11-11 16:36:51 +03:00
Robert Resch 831aa03c9f Implement suggestion 2024-11-11 11:16:12 +01:00
Robert Resch d372597bdb Lower codec not matched error for ffmpeg to debug 2024-11-11 09:27:21 +01:00
Alex X 172437b6fc Merge pull request #1449 from amarshall/credentials-dir
Read from credential files
2024-11-11 07:11:29 +03:00
Andrew Marshall 7640a42bfc Read from credential files
See https://systemd.io/CREDENTIALS/. This will also work for Docker
Secrets by setting `CREDENTIALS_DIRECTORY=/run/secrets`.
2024-11-10 17:33:22 -05:00
Robert Resch fde04bd625 Improve codec not matched error by including kind 2024-11-10 19:27:59 +01:00
Alex X ad14a5ccba Merge pull request #1447 from Jerome1998/patch-1
Updated Roborock part in the README.md file
2024-11-10 16:44:16 +03:00
Jerome 2348d12e9d Update README.md 2024-11-10 13:13:31 +01:00
Alex X 5cafc05e13 Merge pull request #1446 from eltociear/patch-1
docs: update README.md
2024-11-10 07:08:37 +03:00
Ikko Eltociear Ashimine e982257271 docs: update README.md
shapshot -> snapshot
2024-11-10 09:00:37 +09:00
Alex X 340fd81778 Fix loop request, ex. camera1: ffmpeg:camera1 2024-11-09 18:17:41 +03:00
MrToan 223f94077f Fix "panic: send on closed channel" 2024-11-07 08:49:06 +07:00
seydx f13aa21d0f Add backchannel support for rtsp server 2024-11-03 16:33:08 +01:00
Alex X 2c34a17d88 Fix stop for webrtc stream #1428 2024-11-02 20:50:33 +03:00
Alex X 6b005a666e Fix yet another broken SDP from CN cameras #1426 2024-11-01 12:09:44 +03:00
Alex X 1d1bcb0a63 Code refactoring for UnmarshalSDP 2024-11-01 12:08:06 +03:00
Alex X 3f5f1328e7 Fix webrtc:ws source after 1.9.5 #1425 2024-10-31 20:09:11 +03:00
Alex X 8cca8decde Update version to 1.9.6 2024-10-29 17:50:00 +03:00
Alex X be5bbd3b9b Fix FFmpeg tests 2024-10-29 14:39:54 +03:00
Alex X 3f94a754e4 Fix WebRTC card stuck in loading #1417 2024-10-29 14:39:37 +03:00
Alex X 780f378fb1 Update version to 1.9.5 2024-10-28 22:47:55 +03:00
Alex X b874c17bcb Update dependencies 2024-10-28 22:47:36 +03:00
Alex X 16e4831499 Add the option to pass ICE servers with an async WebRTC offer #1408 2024-10-24 23:31:21 +03:00
Alex X 9d709f0db8 Merge pull request #1407 from edenhaus/streams-api-multiple-sources
Extend streams API to allow multiple sources
2024-10-24 20:47:19 +03:00
Alex X a8d394efd7 Update PUT /api/streams for support multiple src params 2024-10-24 20:46:31 +03:00
Robert Resch 95a5283c86 Extend streams API to allow multiple sources 2024-10-22 16:31:31 +02:00
Alex X ef7d898747 Merge pull request #1355 from michelepra/concurrent_map_fix
data race for streams map
2024-09-27 21:11:18 +03:00
Michele Prà 388c408080 defer used wisely 2024-09-27 18:14:41 +02:00
Alex X 7b77e41253 Add support arm/v6 to Dockerfile 2024-09-22 07:24:25 +03:00
Alex X c0bfebf3a4 Merge pull request #1362 from edenhaus/armhf
Build the docker image for linux/arm/v6
2024-09-20 13:50:02 +03:00
Robert Resch 6f9f1c3a35 Build the docker image for linux/arm/v6 2024-09-19 16:48:37 +02:00
Michele Prà 8128edad43 Update streams.go 2024-09-16 16:42:22 +02:00
Michele Prà eb8a13d8c2 data race for streams map
https://go.dev/doc/articles/race_detector
2024-09-16 12:42:34 +02:00
Alex X 8399edce6a Fix RTSP AAC audio from very buggy noname camera #1328 2024-09-05 11:58:05 +03:00
Alex X 2311d5eabe Change go version to 1.20 for Windows 7 support 2024-09-01 17:54:01 +03:00
Alex X afc8f4fdf6 Merge pull request #1297 from cthach/fix-nest-extend-stream
fix(nest): Resource leak due to lack of closing HTTP response bodies
2024-08-07 16:38:38 +03:00
Chris Thach 66de2f91b6 Fix resource leak in Nest source due to lack of closing HTTP response bodies 2024-08-06 22:25:55 +00:00
Alex X bd88695e59 Fix AnnexB parsing in some cases 2024-08-04 10:18:24 +03:00
Sergey Krashevich 23e8f7e0aa refactor(api): move port extraction logic to Init function for prevent data race 2024-07-28 05:34:49 +03:00
Alex X d559ec0208 Fix wrong media values in SDP for some cameras #1278 2024-07-26 17:00:16 +03:00
Alex X ed99025bd6 Add support S16LE (PCM-LE) for RTSP server 2024-07-26 14:47:42 +03:00
Alex X 57d48f53e0 Fix PCM audio quality for WebRTC 2024-07-26 14:15:53 +03:00
Alex X 68fa42249e Fix PCM audio from Hikvision cameras 2024-07-26 14:01:43 +03:00
Alex X c5bc761a52 Fix RTSP MJPEG source quality in some cases #559 2024-07-26 07:55:15 +03:00
Alex X 3762bdbccd Fix mjpeg source for Foscam G2 camera #1258 2024-07-18 13:52:50 +03:00
On Freund c81caa4d2c Install ffplay in container 2024-07-17 13:37:56 +03:00
Jamal Fanaian 13dd3084c2 Carry protocol info in stream URL 2024-07-11 18:47:05 -07:00
Jamal Fanaian e1021a96af go fmt 2024-07-11 17:58:31 -07:00
Jamal Fanaian 5b0781253f Add support for Nest cameras with RTSP 2024-07-11 17:54:04 -07:00
Rob van Oostenrijk a04b7eed28 Update README.md 2024-06-22 19:23:14 +04:00
Rob van Oostenrijk c47427633c Update build.sh 2024-06-22 19:20:39 +04:00
Rob van Oostenrijk 56e2c6650d Update build.cmd 2024-06-22 19:15:07 +04:00
Rob van Oostenrijk 82f0fb8a79 Merge branch 'AlexxIT:master' into master 2024-06-22 18:23:28 +04:00
Sergey Krashevich 0e5b293b1f fix(network): preserve selected nodes and edges on data reload 2024-06-19 12:20:04 +03:00
Alex X eaae7aee39 Fix stream info for publishing RTMP 2024-06-19 06:53:27 +03:00
Sergey Krashevich ac798d9d6d fix(log): handle log file open error by writing to stdout 2024-06-06 19:07:09 +03:00
Sergey Krashevich e46fc13fea fix(log): ensure fallback to stdout if log file open fails 2024-06-06 18:25:30 +03:00
Sergey Krashevich bce0b4a8a0 feat(logging): add file output option for logging configuration 2024-06-06 18:20:44 +03:00
Felipe Santos 562046c278 Fix link to audio codec change tip 2024-05-24 10:12:34 -03:00
Felipe Santos 4cc28977cb Add note about unicast=true&proto=Onvif 2024-05-24 10:10:21 -03:00
Felipe Santos 3ce4624aee Add note about requesting multiple backchannel on Dahua Doorbell 2024-05-24 10:03:51 -03:00
Rob van Oostenrijk 2b8ced9c59 Update build.yml 2024-05-06 08:06:08 +04:00
154 changed files with 6279 additions and 1425 deletions
+6 -5
View File
@@ -19,7 +19,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with: { go-version: '1.22' }
with: { go-version: '1.24' }
- name: Build go2rtc_win64
env: { GOOS: windows, GOARCH: amd64 }
@@ -29,7 +29,7 @@ jobs:
with: { name: go2rtc_win64, path: go2rtc.exe }
- name: Build go2rtc_win32
env: { GOOS: windows, GOARCH: 386 }
env: { GOOS: windows, GOARCH: 386, GOTOOLCHAIN: go1.20.14 }
run: go build -ldflags "-s -w" -trimpath
- name: Upload go2rtc_win32
uses: actions/upload-artifact@v4
@@ -85,7 +85,7 @@ jobs:
with: { name: go2rtc_linux_mipsel, path: go2rtc }
- name: Build go2rtc_mac_amd64
env: { GOOS: darwin, GOARCH: amd64 }
env: { GOOS: darwin, GOARCH: amd64, GOTOOLCHAIN: go1.20.14 }
run: go build -ldflags "-s -w" -trimpath
- name: Upload go2rtc_mac_amd64
uses: actions/upload-artifact@v4
@@ -102,14 +102,14 @@ jobs:
env: { GOOS: freebsd, GOARCH: amd64 }
run: go build -ldflags "-s -w" -trimpath
- name: Upload go2rtc_freebsd_amd64
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with: { name: go2rtc_freebsd_amd64, path: go2rtc }
- name: Build go2rtc_freebsd_arm64
env: { GOOS: freebsd, GOARCH: arm64 }
run: go build -ldflags "-s -w" -trimpath
- name: Upload go2rtc_freebsd_arm64
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with: { name: go2rtc_freebsd_arm64, path: go2rtc }
docker-master:
@@ -159,6 +159,7 @@ jobs:
platforms: |
linux/amd64
linux/386
linux/arm/v6
linux/arm/v7
linux/arm64/v8
push: ${{ github.event_name != 'pull_request' }}
+1 -1
View File
@@ -26,7 +26,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.24'
- name: Build Go binary
run: go build -ldflags "-s -w" -trimpath -o ./go2rtc
+1
View File
@@ -4,6 +4,7 @@
go2rtc.yaml
go2rtc.json
go2rtc_freebsd*
go2rtc_linux*
go2rtc_mac*
go2rtc_win*
+15 -16
View File
@@ -2,14 +2,19 @@
# 0. Prepare images
ARG PYTHON_VERSION="3.11"
ARG GO_VERSION="1.22"
ARG NGROK_VERSION="3"
FROM python:${PYTHON_VERSION}-alpine AS base
FROM ngrok/ngrok:${NGROK_VERSION}-alpine AS ngrok
ARG GO_VERSION="1.24"
# 1. Build go2rtc binary
# 1. Download ngrok binary (for support arm/v6)
FROM alpine AS ngrok
ARG TARGETARCH
ARG TARGETOS
ADD https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-${TARGETOS}-${TARGETARCH}.tgz /
RUN tar -xzf /ngrok-v3-stable-${TARGETOS}-${TARGETARCH}.tgz -C /bin
# 2. Build go2rtc binary
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS build
ARG TARGETPLATFORM
ARG TARGETOS
@@ -30,21 +35,14 @@ COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath
# 2. Collect all files
FROM scratch AS rootfs
COPY --from=build /build/go2rtc /usr/local/bin/
COPY --from=ngrok /bin/ngrok /usr/local/bin/
# 3. Final image
FROM base
FROM python:${PYTHON_VERSION}-alpine AS base
# Install ffmpeg, tini (for signal handling),
# and other common tools for the echo source.
# alsa-plugins-pulse for ALSA support (+0MB)
# font-droid for FFmpeg drawtext filter (+2MB)
RUN apk add --no-cache tini ffmpeg bash curl jq alsa-plugins-pulse font-droid
RUN apk add --no-cache tini ffmpeg ffplay bash curl jq alsa-plugins-pulse font-droid
# Hardware Acceleration for Intel CPU (+50MB)
ARG TARGETARCH
@@ -56,7 +54,8 @@ RUN if [ "${TARGETARCH}" = "amd64" ]; then apk add --no-cache libva-intel-driver
# Hardware: AMD and NVidia VDPAU (not sure about this)
# RUN libva-vdpau-driver mesa-vdpau-gallium (+150MB total)
COPY --from=rootfs / /
COPY --from=build /build/go2rtc /usr/local/bin/
COPY --from=ngrok /bin/ngrok /usr/local/bin/
ENTRYPOINT ["/sbin/tini", "--"]
VOLUME /config
+24 -16
View File
@@ -115,8 +115,8 @@ Ultimate camera streaming application with support RTSP, WebRTC, HomeKit, FFmpeg
Download binary for your OS from [latest release](https://github.com/AlexxIT/go2rtc/releases/):
- `go2rtc_win64.zip` - Windows 64-bit
- `go2rtc_win32.zip` - Windows 32-bit
- `go2rtc_win64.zip` - Windows 10+ 64-bit
- `go2rtc_win32.zip` - Windows 7+ 32-bit
- `go2rtc_win_arm64.zip` - Windows ARM 64-bit
- `go2rtc_linux_amd64` - Linux 64-bit
- `go2rtc_linux_i386` - Linux 32-bit
@@ -124,8 +124,10 @@ Download binary for your OS from [latest release](https://github.com/AlexxIT/go2
- `go2rtc_linux_arm` - Linux ARM 32-bit (ex. Raspberry 32-bit OS)
- `go2rtc_linux_armv6` - Linux ARMv6 (for old Raspberry 1 and Zero)
- `go2rtc_linux_mipsel` - Linux MIPS (ex. [Xiaomi Gateway 3](https://github.com/AlexxIT/XiaomiGateway3), [Wyze cameras](https://github.com/gtxaspec/wz_mini_hacks))
- `go2rtc_mac_amd64.zip` - Mac Intel 64-bit
- `go2rtc_mac_arm64.zip` - Mac ARM 64-bit
- `go2rtc_mac_amd64.zip` - macOS 10.13+ Intel 64-bit
- `go2rtc_mac_arm64.zip` - macOS ARM 64-bit
- `go2rtc_freebsd_amd64.zip` - FreeBSD 64-bit
- `go2rtc_freebsd_arm64.zip` - FreeBSD ARM 64-bit
Don't forget to fix the rights `chmod +x go2rtc_xxx_xxx` on Linux and Mac.
@@ -170,7 +172,7 @@ Available modules:
- [api](#module-api) - HTTP API (important for WebRTC support)
- [rtsp](#module-rtsp) - RTSP Server (important for FFmpeg support)
- [webrtc](#module-webrtc) - WebRTC Server
- [mp4](#module-mp4) - MSE, MP4 stream and MP4 shapshot Server
- [mp4](#module-mp4) - MSE, MP4 stream and MP4 snapshot Server
- [hls](#module-hls) - HLS TS or fMP4 stream Server
- [mjpeg](#module-mjpeg) - MJPEG Server
- [ffmpeg](#source-ffmpeg) - FFmpeg integration
@@ -231,7 +233,7 @@ streams:
sonoff_camera: rtsp://rtsp:12345678@192.168.1.123/av_stream/ch0
dahua_camera:
- rtsp://admin:password@192.168.1.123/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
- rtsp://admin:password@192.168.1.123/cam/realmonitor?channel=1&subtype=1
- rtsp://admin:password@192.168.1.123/cam/realmonitor?channel=1&subtype=1#backchannel=0
amcrest_doorbell:
- rtsp://username:password@192.168.1.123:554/cam/realmonitor?channel=1&subtype=0#backchannel=0
unifi_camera: rtspx://192.168.1.123:7441/fD6ouM72bWoFijxK
@@ -241,7 +243,7 @@ streams:
**Recommendations**
- **Amcrest Doorbell** users may want to disable two way audio, because with an active stream you won't have a call button working. You need to add `#backchannel=0` to the end of your RTSP link in YAML config file
- **Dahua Doorbell** users may want to change backchannel [audio codec](https://github.com/AlexxIT/go2rtc/issues/52)
- **Dahua Doorbell** users may want to change [audio codec](https://github.com/AlexxIT/go2rtc/issues/49#issuecomment-2127107379) for proper 2-way audio. Make sure not to request backchannel multiple times by adding `#backchannel=0` to other stream sources of the same doorbell. The `unicast=true&proto=Onvif` is preferred for 2-way audio as this makes the doorbell accept multiple codecs for the incoming audio
- **Reolink** users may want NOT to use RTSP protocol at all, some camera models have a very awful unusable stream implementation
- **Ubiquiti UniFi** users may want to disable HTTPS verification. Use `rtspx://` prefix instead of `rtsps://`. And don't use `?enableSrtp` [suffix](https://github.com/AlexxIT/go2rtc/issues/81)
- **TP-Link Tapo** users may skip login and password, because go2rtc support login [without them](https://drmnsamoliu.github.io/video.html)
@@ -350,7 +352,7 @@ streams:
mjpeg: ffmpeg:http://185.97.122.128/cgi-bin/faststream.jpg#video=h264
# [RTSP] video with rotation, should be transcoded, so select H264
rotate: ffmpeg:rtsp://rtsp:12345678@192.168.1.123/av_stream/ch0#video=h264#rotate=90
rotate: ffmpeg:rtsp://12345678@192.168.1.123/av_stream/ch0#video=h264#rotate=90
```
All trascoding formats has [built-in templates](https://github.com/AlexxIT/go2rtc/blob/master/internal/ffmpeg/ffmpeg.go): `h264`, `h265`, `opus`, `pcmu`, `pcmu/16000`, `pcmu/48000`, `pcma`, `pcma/16000`, `pcma/48000`, `aac`, `aac/16000`.
@@ -648,10 +650,11 @@ This source type support Roborock vacuums with cameras. Known working models:
- Roborock S6 MaxV - only video (the vacuum has no microphone)
- Roborock S7 MaxV - video and two way audio
- Roborock Qrevo MaxV - video and two way audio
Source support load Roborock credentials from Home Assistant [custom integration](https://github.com/humbertogontijo/homeassistant-roborock). Otherwise, you need to log in to your Roborock account (MiHome account is not supported). Go to: go2rtc WebUI > Add webpage. Copy `roborock://...` source for your vacuum and paste it to `go2rtc.yaml` config.
Source support load Roborock credentials from Home Assistant [custom integration](https://github.com/humbertogontijo/homeassistant-roborock) or the [core integration](https://www.home-assistant.io/integrations/roborock). Otherwise, you need to log in to your Roborock account (MiHome account is not supported). Go to: go2rtc WebUI > Add webpage. Copy `roborock://...` source for your vacuum and paste it to `go2rtc.yaml` config.
If you have graphic pin for your vacuum - add it as numeric pin (lines: 123, 456, 678) to the end of the roborock-link.
If you have graphic pin for your vacuum - add it as numeric pin (lines: 123, 456, 789) to the end of the roborock-link.
#### Source: WebRTC
@@ -679,13 +682,18 @@ Supports connection to [Wyze](https://www.wyze.com/) cameras, using WebRTC proto
Supports [Amazon Kinesis Video Streams](https://aws.amazon.com/kinesis/video-streams/), using WebRTC protocol. You need to specify signalling WebSocket URL with all credentials in query params, `client_id` and `ice_servers` list in [JSON format](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer).
**switchbot**
Support connection to [SwitchBot](https://us.switch-bot.com/) cameras that are based on Kinesis Video Streams. Specifically, this includes [Pan/Tilt Cam Plus 2K](https://us.switch-bot.com/pages/switchbot-pan-tilt-cam-plus-2k) and [Pan/Tilt Cam Plus 3K](https://us.switch-bot.com/pages/switchbot-pan-tilt-cam-plus-3k). `Outdoor Spotlight Cam 1080P`, `Outdoor Spotlight Cam 2K`, `Pan/Tilt Cam`, `Pan/Tilt Cam 2K`, `Indoor Cam` are based on Tuya, so this feature is not available.
```yaml
streams:
webrtc-whep: webrtc:http://192.168.1.123:1984/api/webrtc?src=camera1
webrtc-go2rtc: webrtc:ws://192.168.1.123:1984/api/ws?src=camera1
webrtc-openipc: webrtc:ws://192.168.1.123/webrtc_ws#format=openipc#ice_servers=[{"urls":"stun:stun.kinesisvideo.eu-north-1.amazonaws.com:443"}]
webrtc-wyze: webrtc:http://192.168.1.123:5000/signaling/camera1?kvs#format=wyze
webrtc-kinesis: webrtc:wss://...amazonaws.com/?...#format=kinesis#client_id=...#ice_servers=[{...},{...}]
webrtc-whep: webrtc:http://192.168.1.123:1984/api/webrtc?src=camera1
webrtc-go2rtc: webrtc:ws://192.168.1.123:1984/api/ws?src=camera1
webrtc-openipc: webrtc:ws://192.168.1.123/webrtc_ws#format=openipc#ice_servers=[{"urls":"stun:stun.kinesisvideo.eu-north-1.amazonaws.com:443"}]
webrtc-wyze: webrtc:http://192.168.1.123:5000/signaling/camera1?kvs#format=wyze
webrtc-kinesis: webrtc:wss://...amazonaws.com/?...#format=kinesis#client_id=...#ice_servers=[{...},{...}]
webrtc-switchbot: webrtc:wss://...amazonaws.com/?...#format=switchbot#resolution=hd#client_id=...#ice_servers=[{...},{...}]
```
**PS.** For `kinesis` sources you can use [echo](#source-echo) to get connection params using `bash`/`python` or any other script language.
@@ -880,7 +888,7 @@ Read more about [codecs filters](#codecs-filters).
You can get any stream as RTMP-stream: `rtmp://192.168.1.123/{stream_name}`. Only H264/AAC codecs supported right now.
[Incoming stream](#incoming-sources) in RTMP-format tested only with [OBS Studio](https://obsproject.com/) and Dahua camera. Different FFmpeg versions has differnt problems with this format.
[Incoming stream](#incoming-sources) in RTMP-format tested only with [OBS Studio](https://obsproject.com/) and Dahua camera. Different FFmpeg versions has different problems with this format.
```yaml
rtmp:
+26
View File
@@ -0,0 +1,26 @@
package main
import (
"github.com/AlexxIT/go2rtc/internal/api"
"github.com/AlexxIT/go2rtc/internal/api/ws"
"github.com/AlexxIT/go2rtc/internal/app"
"github.com/AlexxIT/go2rtc/internal/ffmpeg"
"github.com/AlexxIT/go2rtc/internal/mjpeg"
"github.com/AlexxIT/go2rtc/internal/streams"
"github.com/AlexxIT/go2rtc/internal/v4l2"
"github.com/AlexxIT/go2rtc/pkg/shell"
)
func main() {
app.Init()
streams.Init()
api.Init()
ws.Init()
ffmpeg.Init()
mjpeg.Init()
v4l2.Init()
shell.RunUntilSignal()
}
+5
View File
@@ -0,0 +1,5 @@
## Example
```shell
go run examples/onvif_client/main.go http://admin:password@192.168.10.90 GetAudioEncoderConfigurations
```
+75
View File
@@ -0,0 +1,75 @@
package main
import (
"log"
"net/url"
"os"
"github.com/AlexxIT/go2rtc/pkg/onvif"
)
func main() {
var rawURL = os.Args[1]
var operation = os.Args[2]
var token string
if len(os.Args) > 3 {
token = os.Args[3]
}
client, err := onvif.NewClient(rawURL)
if err != nil {
log.Panic(err)
}
var b []byte
switch operation {
case onvif.ServiceGetServiceCapabilities:
b, err = client.MediaRequest(operation)
case onvif.DeviceGetCapabilities,
onvif.DeviceGetDeviceInformation,
onvif.DeviceGetDiscoveryMode,
onvif.DeviceGetDNS,
onvif.DeviceGetHostname,
onvif.DeviceGetNetworkDefaultGateway,
onvif.DeviceGetNetworkInterfaces,
onvif.DeviceGetNetworkProtocols,
onvif.DeviceGetNTP,
onvif.DeviceGetScopes,
onvif.DeviceGetServices,
onvif.DeviceGetSystemDateAndTime,
onvif.DeviceSystemReboot:
b, err = client.DeviceRequest(operation)
case onvif.MediaGetProfiles,
onvif.MediaGetVideoEncoderConfigurations,
onvif.MediaGetVideoSources,
onvif.MediaGetVideoSourceConfigurations,
onvif.MediaGetAudioEncoderConfigurations,
onvif.MediaGetAudioSources,
onvif.MediaGetAudioSourceConfigurations:
b, err = client.MediaRequest(operation)
case onvif.MediaGetProfile:
b, err = client.GetProfile(token)
case onvif.MediaGetVideoSourceConfiguration:
b, err = client.GetVideoSourceConfiguration(token)
case onvif.MediaGetStreamUri:
b, err = client.GetStreamUri(token)
case onvif.MediaGetSnapshotUri:
b, err = client.GetSnapshotUri(token)
default:
log.Printf("unknown action\n")
}
if err != nil {
log.Printf("%s\n", err)
}
u, err := url.Parse(rawURL)
if err != nil {
log.Fatal(err)
}
if err = os.WriteFile(u.Hostname()+"_"+operation+".xml", b, 0644); err != nil {
log.Printf("%s\n", err)
}
}
+28 -26
View File
@@ -1,48 +1,50 @@
module github.com/AlexxIT/go2rtc
go 1.22
go 1.20
require (
github.com/asticode/go-astits v1.13.0
github.com/expr-lang/expr v1.16.9
github.com/gorilla/websocket v1.5.1
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
github.com/mattn/go-isatty v0.0.20
github.com/miekg/dns v1.1.59
github.com/pion/ice/v2 v2.3.24
github.com/pion/interceptor v0.1.29
github.com/pion/rtcp v1.2.14
github.com/pion/rtp v1.8.6
github.com/pion/sdp/v3 v3.0.9
github.com/pion/srtp/v2 v2.0.18
github.com/miekg/dns v1.1.63
github.com/pion/ice/v2 v2.3.37
github.com/pion/interceptor v0.1.37
github.com/pion/rtcp v1.2.15
github.com/pion/rtp v1.8.11
github.com/pion/sdp/v3 v3.0.10
github.com/pion/srtp/v2 v2.0.20
github.com/pion/stun v0.6.1
github.com/pion/webrtc/v3 v3.2.40
github.com/pion/webrtc/v3 v3.3.5
github.com/rs/zerolog v1.33.0
github.com/sigurn/crc16 v0.0.0-20240131213347-83fcde1e29d1
github.com/sigurn/crc8 v0.0.0-20220107193325-2243fe600f9f
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/tadglines/go-pkgs v0.0.0-20210623144937-b983b20f54f9
golang.org/x/crypto v0.24.0
golang.org/x/crypto v0.33.0
gopkg.in/yaml.v3 v3.0.1
)
require (
github.com/asticode/go-astikit v0.30.0 // indirect
github.com/asticode/go-astikit v0.52.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/pion/datachannel v1.5.6 // indirect
github.com/pion/dtls/v2 v2.2.11 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/pion/datachannel v1.5.10 // indirect
github.com/pion/dtls/v2 v2.2.12 // indirect
github.com/pion/logging v0.2.3 // indirect
github.com/pion/mdns v0.0.12 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/sctp v1.8.16 // indirect
github.com/pion/transport/v2 v2.2.5 // indirect
github.com/pion/sctp v1.8.36 // indirect
github.com/pion/transport/v2 v2.2.10 // indirect
github.com/pion/transport/v3 v3.0.7 // indirect
github.com/pion/turn/v2 v2.1.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/tools v0.22.0 // indirect
github.com/wlynxg/anet v0.0.5 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/tools v0.24.0 // indirect
)
+59 -90
View File
@@ -1,92 +1,88 @@
github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflxkRsZA=
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astikit v0.52.0 h1:kTl2XjgiVQhUl1H7kim7NhmTtCMwVBbPrXKqhQhbk8Y=
github.com/asticode/go-astikit v0.52.0/go.mod h1:fV43j20UZYfXzP9oBn33udkvCvDvCDhzjVqoLFuuYZE=
github.com/asticode/go-astits v1.13.0 h1:XOgkaadfZODnyZRR5Y0/DWkA9vrkLLPLeeOvDwfKZ1c=
github.com/asticode/go-astits v1.13.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/expr-lang/expr v1.16.5 h1:m2hvtguFeVaVNTHj8L7BoAyt7O0PAIBaSVbjdHgRXMs=
github.com/expr-lang/expr v1.16.5/go.mod h1:uCkhfG+x7fcZ5A5sXHKuQ07jGZRl6J0FCAaf2k4PtVQ=
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/miekg/dns v1.1.59 h1:C9EXc/UToRwKLhK5wKU/I4QVsBUc8kE6MkHBkeypWZs=
github.com/miekg/dns v1.1.59/go.mod h1:nZpewl5p6IvctfgrckopVx2OlSEHPRO/U4SYkRklrEk=
github.com/pion/datachannel v1.5.6 h1:1IxKJntfSlYkpUj8LlYRSWpYiTTC02nUrOE8T3DqGeg=
github.com/pion/datachannel v1.5.6/go.mod h1:1eKT6Q85pRnr2mHiWHxJwO50SfZRtWHTsNIVb/NfGW4=
github.com/miekg/dns v1.1.63 h1:8M5aAw6OMZfFXTT7K5V0Eu5YiiL8l7nUAkyN6C9YwaY=
github.com/miekg/dns v1.1.63/go.mod h1:6NGHfjhpmr5lt3XPLuyfDJi5AXbNIPM9PY6H6sF1Nfs=
github.com/pion/datachannel v1.5.10 h1:ly0Q26K1i6ZkGf42W7D4hQYR90pZwzFOjTq5AuCKk4o=
github.com/pion/datachannel v1.5.10/go.mod h1:p/jJfC9arb29W7WrxyKbepTU20CFgyx5oLo8Rs4Py/M=
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
github.com/pion/dtls/v2 v2.2.10 h1:u2Axk+FyIR1VFTPurktB+1zoEPGIW3bmyj3LEFrXjAA=
github.com/pion/dtls/v2 v2.2.10/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE=
github.com/pion/dtls/v2 v2.2.11 h1:9U/dpCYl1ySttROPWJgqWKEylUdT0fXp/xst6JwY5Ks=
github.com/pion/dtls/v2 v2.2.11/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE=
github.com/pion/ice/v2 v2.3.19 h1:1GoMRTMnB6bCP4aGy2MjxK3w4laDkk+m7svJb/eqybc=
github.com/pion/ice/v2 v2.3.19/go.mod h1:KXJJcZK7E8WzrBEYnV4UtqEZsGeWfHxsNqhVcVvgjxw=
github.com/pion/ice/v2 v2.3.24 h1:RYgzhH/u5lH0XO+ABatVKCtRd+4U1GEaCXSMjNr13tI=
github.com/pion/ice/v2 v2.3.24/go.mod h1:KXJJcZK7E8WzrBEYnV4UtqEZsGeWfHxsNqhVcVvgjxw=
github.com/pion/interceptor v0.1.29 h1:39fsnlP1U8gw2JzOFWdfCU82vHvhW9o0rZnZF56wF+M=
github.com/pion/interceptor v0.1.29/go.mod h1:ri+LGNjRUc5xUNtDEPzfdkmSqISixVTBF/z/Zms/6T4=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk=
github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE=
github.com/pion/ice/v2 v2.3.37 h1:ObIdaNDu1rCo7hObhs34YSBcO7fjslJMZV0ux+uZWh0=
github.com/pion/ice/v2 v2.3.37/go.mod h1:mBF7lnigdqgtB+YHkaY/Y6s6tsyRyo4u4rPGRuOjUBQ=
github.com/pion/interceptor v0.1.37 h1:aRA8Zpab/wE7/c0O3fh1PqY0AJI3fCSEM5lRWJVorwI=
github.com/pion/interceptor v0.1.37/go.mod h1:JzxbJ4umVTlZAf+/utHzNesY8tmRkM2lVmkS82TTj8Y=
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
github.com/pion/logging v0.2.3 h1:gHuf0zpoh1GW67Nr6Gj4cv5Z9ZscU7g/EaoC/Ke/igI=
github.com/pion/logging v0.2.3/go.mod h1:z8YfknkquMe1csOrxK5kc+5/ZPAzMxbKLX5aXpbpC90=
github.com/pion/mdns v0.0.12 h1:CiMYlY+O0azojWDmxdNr7ADGrnZ+V6Ilfner+6mSVK8=
github.com/pion/mdns v0.0.12/go.mod h1:VExJjv8to/6Wqm1FXK+Ii/Z9tsVk/F5sD/N70cnYFbk=
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4=
github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE=
github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4=
github.com/pion/rtcp v1.2.15 h1:LZQi2JbdipLOj4eBjK4wlVoQWfrZbh3Q6eHtWtJBZBo=
github.com/pion/rtcp v1.2.15/go.mod h1:jlGuAjHMEXwMUHK78RgX0UmEJFV4zUKOFHR7OP+D3D0=
github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/rtp v1.8.6 h1:MTmn/b0aWWsAzux2AmP8WGllusBVw4NPYPVFFd7jUPw=
github.com/pion/rtp v1.8.6/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/sctp v1.8.13/go.mod h1:YKSgO/bO/6aOMP9LCie1DuD7m+GamiK2yIiPM6vH+GA=
github.com/pion/sctp v1.8.16 h1:PKrMs+o9EMLRvFfXq59WFsC+V8mN1wnKzqrv+3D/gYY=
github.com/pion/sctp v1.8.16/go.mod h1:P6PbDVA++OJMrVNg2AL3XtYHV4uD6dvfyOovCgMs0PE=
github.com/pion/sdp/v3 v3.0.9 h1:pX++dCHoHUwq43kuwf3PyJfHlwIj4hXA7Vrifiq0IJY=
github.com/pion/sdp/v3 v3.0.9/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M=
github.com/pion/srtp/v2 v2.0.18 h1:vKpAXfawO9RtTRKZJbG4y0v1b11NZxQnxRl85kGuUlo=
github.com/pion/srtp/v2 v2.0.18/go.mod h1:0KJQjA99A6/a0DOVTu1PhDSw0CXF2jTkqOoMg3ODqdA=
github.com/pion/rtp v1.8.11 h1:17xjnY5WO5hgO6SD3/NTIUPvSFw/PbLsIJyz1r1yNIk=
github.com/pion/rtp v1.8.11/go.mod h1:8uMBJj32Pa1wwx8Fuv/AsFhn8jsgw+3rUC2PfoBZ8p4=
github.com/pion/sctp v1.8.36 h1:owNudmnz1xmhfYje5L/FCav3V9wpPRePHle3Zi+P+M0=
github.com/pion/sctp v1.8.36/go.mod h1:cNiLdchXra8fHQwmIoqw0MbLLMs+f7uQ+dGMG2gWebE=
github.com/pion/sdp/v3 v3.0.10 h1:6MChLE/1xYB+CjumMw+gZ9ufp2DPApuVSnDT8t5MIgA=
github.com/pion/sdp/v3 v3.0.10/go.mod h1:88GMahN5xnScv1hIMTqLdu/cOcUkj6a9ytbncwMCq2E=
github.com/pion/srtp/v2 v2.0.20 h1:HNNny4s+OUmG280ETrCdgFndp4ufx3/uy85EawYEhTk=
github.com/pion/srtp/v2 v2.0.20/go.mod h1:0KJQjA99A6/a0DOVTu1PhDSw0CXF2jTkqOoMg3ODqdA=
github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4=
github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8=
github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g=
github.com/pion/transport/v2 v2.2.2/go.mod h1:OJg3ojoBJopjEeECq2yJdXH9YVrUJ1uQ++NjXLOUorc=
github.com/pion/transport/v2 v2.2.3/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0=
github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0=
github.com/pion/transport/v2 v2.2.5 h1:iyi25i/21gQck4hfRhomF6SktmUQjRsRW4WJdhfc3Kc=
github.com/pion/transport/v2 v2.2.5/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0=
github.com/pion/transport/v2 v2.2.10 h1:ucLBLE8nuxiHfvkFKnkDQRYWYfp8ejf4YBOPfaQpw6Q=
github.com/pion/transport/v2 v2.2.10/go.mod h1:sq1kSLWs+cHW9E+2fJP95QudkzbK7wscs8yYgQToO5E=
github.com/pion/transport/v3 v3.0.1/go.mod h1:UY7kiITrlMv7/IKgd5eTUcaahZx5oUN3l9SzK5f5xE0=
github.com/pion/transport/v3 v3.0.2 h1:r+40RJR25S9w3jbA6/5uEPTzcdn7ncyU44RWCbHkLg4=
github.com/pion/transport/v3 v3.0.2/go.mod h1:nIToODoOlb5If2jF9y2Igfx3PFYWfuXi37m0IlWa/D0=
github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1o0=
github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo=
github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY=
github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc=
github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY=
github.com/pion/webrtc/v3 v3.2.39 h1:Lf2SIMGdE3M9VNm48KpoX5pR8SJ6TsMnktzOkc/oB0o=
github.com/pion/webrtc/v3 v3.2.39/go.mod h1:AQ8p56OLbm3MjhYovYdgPuyX6oc+JcKx/HFoCGFcYzA=
github.com/pion/webrtc/v3 v3.2.40 h1:Wtfi6AZMQg+624cvCXUuSmrKWepSB7zfgYDOYqsSOVU=
github.com/pion/webrtc/v3 v3.2.40/go.mod h1:M1RAe3TNTD1tzyvqHrbVODfwdPGSXOUo/OgpoGGJqFY=
github.com/pion/webrtc/v3 v3.3.5 h1:ZsSzaMz/i9nblPdiAkZoP+E6Kmjw+jnyq3bEmU3EtRg=
github.com/pion/webrtc/v3 v3.3.5/go.mod h1:liNa+E1iwyzyXqNUwvoMRNQ10x8h8FOeJKL8RkIbamE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sigurn/crc16 v0.0.0-20240131213347-83fcde1e29d1 h1:NVK+OqnavpyFmUiKfUMHrpvbCi2VFoWTrcpI7aDaJ2I=
@@ -96,59 +92,45 @@ github.com/sigurn/crc8 v0.0.0-20220107193325-2243fe600f9f/go.mod h1:vQhwQ4meQEDf
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tadglines/go-pkgs v0.0.0-20210623144937-b983b20f54f9 h1:aeN+ghOV0b2VCmKKO3gqnDQ8mLbpABZgRR2FVYx4ouI=
github.com/tadglines/go-pkgs v0.0.0-20210623144937-b983b20f54f9/go.mod h1:roo6cZ/uqpwKMuvPG0YmzI5+AmUiMWfjCBZpGXqbTxE=
github.com/wlynxg/anet v0.0.3/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -160,44 +142,31 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
+1 -1
View File
@@ -4,7 +4,7 @@
# only debian 13 (trixie) has latest ffmpeg
# https://packages.debian.org/trixie/ffmpeg
ARG DEBIAN_VERSION="trixie-slim"
ARG GO_VERSION="1.22-bookworm"
ARG GO_VERSION="1.24-bookworm"
ARG NGROK_VERSION="3"
FROM debian:${DEBIAN_VERSION} AS base
+2 -4
View File
@@ -69,6 +69,8 @@ func Init() {
}
if cfg.Mod.Listen != "" {
_, port, _ := net.SplitHostPort(cfg.Mod.Listen)
Port, _ = strconv.Atoi(port)
go listen("tcp", cfg.Mod.Listen)
}
@@ -92,10 +94,6 @@ func listen(network, address string) {
log.Info().Str("addr", address).Msg("[api] listen")
if network == "tcp" {
Port = ln.Addr().(*net.TCPAddr).Port
}
server := http.Server{
Handler: Handler,
ReadHeaderTimeout: 5 * time.Second, // Example: Set to 5 seconds
+2 -1
View File
@@ -1,8 +1,9 @@
package api
import (
"github.com/AlexxIT/go2rtc/www"
"net/http"
"github.com/AlexxIT/go2rtc/www"
)
func initStatic(staticDir string) {
+8 -8
View File
@@ -1,6 +1,7 @@
package ws
import (
"encoding/json"
"io"
"net/http"
"net/url"
@@ -38,20 +39,19 @@ type Message struct {
Value any `json:"value,omitempty"`
}
func (m *Message) String() string {
func (m *Message) String() (value string) {
if s, ok := m.Value.(string); ok {
return s
}
return ""
return
}
func (m *Message) GetString(key string) string {
if v, ok := m.Value.(map[string]any); ok {
if s, ok := v[key].(string); ok {
return s
}
func (m *Message) Unmarshal(v any) error {
b, err := json.Marshal(m.Value)
if err != nil {
return err
}
return ""
return json.Unmarshal(b, v)
}
type WSHandler func(tr *Transport, msg *Message) error
+3 -3
View File
@@ -19,15 +19,15 @@ go2rtc -c log.format=text -c /config/go2rtc.yaml -c rtsp.listen='' -c /usr/local
## Environment variables
Also go2rtc support templates for using environment variables in any part of config:
There is support for loading external variables into the config. First, they will be attempted to be loaded from [credential files](https://systemd.io/CREDENTIALS). If `CREDENTIALS_DIRECTORY` is not set, then the key will be loaded from an environment variable. If no environment variable is set, then the string will be left as-is.
```yaml
streams:
camera1: rtsp://rtsp:${CAMERA_PASSWORD}@192.168.1.123/av_stream/ch0
rtsp:
username: ${RTSP_USER:admin} # "admin" if env "RTSP_USER" not set
password: ${RTSP_PASS:secret} # "secret" if env "RTSP_PASS" not set
username: ${RTSP_USER:admin} # "admin" if "RTSP_USER" not set
password: ${RTSP_PASS:secret} # "secret" if "RTSP_PASS" not set
```
## JSON Schema
+2 -2
View File
@@ -18,7 +18,7 @@ func LoadConfig(v any) {
}
}
func PatchConfig(key string, value any, path ...string) error {
func PatchConfig(path []string, value any) error {
if ConfigPath == "" {
return errors.New("config file disabled")
}
@@ -26,7 +26,7 @@ func PatchConfig(key string, value any, path ...string) error {
// empty config is OK
b, _ := os.ReadFile(ConfigPath)
b, err := yaml.Patch(b, key, value, path...)
b, err := yaml.Patch(b, path, value)
if err != nil {
return err
}
+33 -15
View File
@@ -3,12 +3,14 @@ package app
import (
"io"
"os"
"strings"
"sync"
"github.com/mattn/go-isatty"
"github.com/rs/zerolog"
)
var MemoryLog = newBuffer(16)
var MemoryLog = newBuffer()
func GetLogger(module string) zerolog.Logger {
if s, ok := modules[module]; ok {
@@ -38,11 +40,17 @@ func initLogger() {
var writer io.Writer
switch modules["output"] {
switch output, path, _ := strings.Cut(modules["output"], ":"); output {
case "stderr":
writer = os.Stderr
case "stdout":
writer = os.Stdout
case "file":
if path == "" {
path = "go2rtc.log"
}
// if fail - only MemoryLog will be available
writer, _ = os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
}
timeFormat := modules["time"]
@@ -99,15 +107,19 @@ var modules = map[string]string{
"time": zerolog.TimeFormatUnixMs,
}
const chunkSize = 1 << 16
const (
chunkCount = 16
chunkSize = 1 << 16
)
type circularBuffer struct {
chunks [][]byte
r, w int
mu sync.Mutex
}
func newBuffer(chunks int) *circularBuffer {
b := &circularBuffer{chunks: make([][]byte, 0, chunks)}
func newBuffer() *circularBuffer {
b := &circularBuffer{chunks: make([][]byte, 0, chunkCount)}
// create first chunk
b.chunks = append(b.chunks, make([]byte, 0, chunkSize))
return b
@@ -116,16 +128,17 @@ func newBuffer(chunks int) *circularBuffer {
func (b *circularBuffer) Write(p []byte) (n int, err error) {
n = len(p)
b.mu.Lock()
// check if chunk has size
if len(b.chunks[b.w])+n > chunkSize {
// increase write chunk index
if b.w++; b.w == cap(b.chunks) {
if b.w++; b.w == chunkCount {
b.w = 0
}
// check overflow
if b.r == b.w {
// increase read chunk index
if b.r++; b.r == cap(b.chunks) {
if b.r++; b.r == chunkCount {
b.r = 0
}
}
@@ -140,29 +153,34 @@ func (b *circularBuffer) Write(p []byte) (n int, err error) {
}
b.chunks[b.w] = append(b.chunks[b.w], p...)
b.mu.Unlock()
return
}
func (b *circularBuffer) WriteTo(w io.Writer) (n int64, err error) {
for i := b.r; ; {
var nn int
if nn, err = w.Write(b.chunks[i]); err != nil {
return
}
n += int64(nn)
buf := make([]byte, 0, chunkCount*chunkSize)
// use temp buffer inside mutex because w.Write can take some time
b.mu.Lock()
for i := b.r; ; {
buf = append(buf, b.chunks[i]...)
if i == b.w {
break
}
if i++; i == cap(b.chunks) {
if i++; i == chunkCount {
i = 0
}
}
return
b.mu.Unlock()
nn, err := w.Write(buf)
return int64(nn), err
}
func (b *circularBuffer) Reset() {
b.mu.Lock()
b.chunks[0] = b.chunks[0][:0]
b.r = 0
b.w = 0
b.mu.Unlock()
}
+36
View File
@@ -0,0 +1,36 @@
package doorbird
import (
"net/url"
"github.com/AlexxIT/go2rtc/internal/streams"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/doorbird"
)
func Init() {
streams.RedirectFunc("doorbird", func(rawURL string) (string, error) {
u, err := url.Parse(rawURL)
if err != nil {
return "", err
}
// https://www.doorbird.com/downloads/api_lan.pdf
switch u.Query().Get("media") {
case "video":
u.Path = "/bha-api/video.cgi"
case "audio":
u.Path = "/bha-api/audio-receive.cgi"
default:
return "", nil
}
u.Scheme = "http"
return u.String(), nil
})
streams.HandleFunc("doorbird", func(source string) (core.Producer, error) {
return doorbird.Dial(source)
})
}
-39
View File
@@ -1,39 +0,0 @@
package exec
import (
"errors"
"net/url"
"os"
"os/exec"
"syscall"
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
)
// closer support custom killsignal with custom killtimeout
type closer struct {
cmd *exec.Cmd
query url.Values
}
func (c *closer) Close() (err error) {
sig := os.Kill
if s := c.query.Get("killsignal"); s != "" {
sig = syscall.Signal(core.Atoi(s))
}
log.Trace().Msgf("[exec] kill with signal=%d", sig)
err = c.cmd.Process.Signal(sig)
if s := c.query.Get("killtimeout"); s != "" {
timeout := time.Duration(core.Atoi(s)) * time.Second
timer := time.AfterFunc(timeout, func() {
log.Trace().Msgf("[exec] kill after timeout=%s", s)
_ = c.cmd.Process.Kill()
})
defer timer.Stop() // stop timer if Wait ends before timeout
}
return errors.Join(err, c.cmd.Wait())
}
+38 -25
View File
@@ -9,10 +9,9 @@ import (
"io"
"net/url"
"os"
"os/exec"
"slices"
"strings"
"sync"
"syscall"
"time"
"github.com/AlexxIT/go2rtc/internal/app"
@@ -50,7 +49,7 @@ func Init() {
log = app.GetLogger("exec")
}
func execHandle(rawURL string) (core.Producer, error) {
func execHandle(rawURL string) (prod core.Producer, err error) {
rawURL, rawQuery, _ := strings.Cut(rawURL, "#")
query := streams.ParseQuery(rawQuery)
@@ -68,39 +67,55 @@ func execHandle(rawURL string) (core.Producer, error) {
rawURL = rawURL[:i] + "rtsp://127.0.0.1:" + rtsp.Port + path + rawURL[i+8:]
}
args := shell.QuoteSplit(rawURL[5:]) // remove `exec:`
cmd := exec.Command(args[0], args[1:]...)
cmd := shell.NewCommand(rawURL[5:]) // remove `exec:`
cmd.Stderr = &logWriter{
buf: make([]byte, 512),
debug: log.Debug().Enabled(),
}
if s := query.Get("killsignal"); s != "" {
sig := syscall.Signal(core.Atoi(s))
cmd.Cancel = func() error {
log.Debug().Msgf("[exec] kill with signal=%d", sig)
return cmd.Process.Signal(sig)
}
}
if s := query.Get("killtimeout"); s != "" {
cmd.WaitDelay = time.Duration(core.Atoi(s)) * time.Second
}
if query.Get("backchannel") == "1" {
return stdin.NewClient(cmd)
}
cl := &closer{cmd: cmd, query: query}
if path == "" {
return handlePipe(rawURL, cmd, cl)
prod, err = handlePipe(rawURL, cmd)
} else {
prod, err = handleRTSP(rawURL, cmd, path)
}
return handleRTSP(rawURL, cmd, cl, path)
if err != nil {
_ = cmd.Close()
}
return
}
func handlePipe(source string, cmd *exec.Cmd, cl io.Closer) (core.Producer, error) {
func handlePipe(source string, cmd *shell.Command) (core.Producer, error) {
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
rc := struct {
rd := struct {
io.Reader
io.Closer
}{
// add buffer for pipe reader to reduce syscall
bufio.NewReaderSize(stdout, core.BufferSize),
cl,
// stop cmd on close pipe call
cmd,
}
log.Debug().Strs("args", cmd.Args).Msg("[exec] run pipe")
@@ -111,9 +126,8 @@ func handlePipe(source string, cmd *exec.Cmd, cl io.Closer) (core.Producer, erro
return nil, err
}
prod, err := magic.Open(rc)
prod, err := magic.Open(rd)
if err != nil {
_ = rc.Close()
return nil, fmt.Errorf("exec/pipe: %w\n%s", err, cmd.Stderr)
}
@@ -127,7 +141,7 @@ func handlePipe(source string, cmd *exec.Cmd, cl io.Closer) (core.Producer, erro
return prod, nil
}
func handleRTSP(source string, cmd *exec.Cmd, cl io.Closer, path string) (core.Producer, error) {
func handleRTSP(source string, cmd *shell.Command, path string) (core.Producer, error) {
if log.Trace().Enabled() {
cmd.Stdout = os.Stdout
}
@@ -153,23 +167,22 @@ func handleRTSP(source string, cmd *exec.Cmd, cl io.Closer, path string) (core.P
return nil, err
}
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()
timeout := time.NewTimer(30 * time.Second)
defer timeout.Stop()
select {
case <-time.After(time.Minute):
case <-timeout.C:
// haven't received data from app in timeout
log.Error().Str("source", source).Msg("[exec] timeout")
_ = cl.Close()
return nil, errors.New("exec: timeout")
case <-done:
// limit message size
case <-cmd.Done():
// app fail before we receive any data
return nil, fmt.Errorf("exec/rtsp\n%s", cmd.Stderr)
case prod := <-waiter:
// app started successfully
log.Debug().Stringer("launch", time.Since(ts)).Msg("[exec] run rtsp")
setRemoteInfo(prod, source, cmd.Args)
prod.OnClose = cl.Close
prod.OnClose = cmd.Close
return prod, nil
}
}
@@ -230,7 +243,7 @@ func trimSpace(b []byte) []byte {
func setRemoteInfo(info core.Info, source string, args []string) {
info.SetSource(source)
if i := slices.Index(args, "-i"); i > 0 && i < len(args)-1 {
if i := core.Index(args, "-i"); i > 0 && i < len(args)-1 {
rawURL := args[i+1]
if u, err := url.Parse(rawURL); err == nil && u.Host != "" {
info.SetRemoteAddr(u.Host)
+6 -2
View File
@@ -2,7 +2,6 @@ package ffmpeg
import (
"net/url"
"slices"
"strings"
"github.com/AlexxIT/go2rtc/internal/api"
@@ -44,7 +43,7 @@ func Init() {
return "", err
}
args := parseArgs(url[7:])
if slices.Contains(args.Codecs, "auto") {
if core.Contains(args.Codecs, "auto") {
return "", nil // force call streams.HandleFunc("ffmpeg")
}
return "exec:" + args.String(), nil
@@ -180,6 +179,7 @@ func parseArgs(s string) *ffmpeg.Args {
Version: verAV,
}
var source = s
var query url.Values
if i := strings.IndexByte(s, '#'); i >= 0 {
query = streams.ParseQuery(s[i+1:])
@@ -222,6 +222,10 @@ func parseArgs(s string) *ffmpeg.Args {
default:
s += "?video&audio"
}
s += "&source=ffmpeg:" + url.QueryEscape(source)
for _, v := range query["query"] {
s += "&" + v
}
args.Input = inputTemplate("rtsp", s, query)
} else if i = strings.Index(s, "?"); i > 0 {
switch s[:i] {
+132 -74
View File
@@ -31,7 +31,7 @@ func TestParseArgsFile(t *testing.T) {
{
name: "[FILE] video will be transcoded to H265 and rotate 270º, audio will be skipped",
source: "/media/bbb.mp4#video=h265#rotate=-90",
expect: `ffmpeg -hide_banner -re -i /media/bbb.mp4 -c:v libx265 -g 50 -profile:v main -level:v 5.1 -preset:v superfast -tune:v zerolatency -an -vf "transpose=2" -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
expect: `ffmpeg -hide_banner -re -i /media/bbb.mp4 -c:v libx265 -g 50 -profile:v main -level:v 5.1 -preset:v superfast -tune:v zerolatency -pix_fmt:v yuv420p -an -vf "transpose=2" -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[FILE] video will be output for MJPEG to pipe, audio will be skipped",
@@ -53,85 +53,143 @@ func TestParseArgsFile(t *testing.T) {
}
func TestParseArgsDevice(t *testing.T) {
// [DEVICE] video will be output for MJPEG to pipe, with size 1920x1080
args := parseArgs("device?video=0&video_size=1920x1080")
require.Equal(t, `ffmpeg -hide_banner -f dshow -video_size 1920x1080 -i "video=0" -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [DEVICE] video will be transcoded to H265 with framerate 20, audio will be skipped
//args = parseArgs("device?video=0&video_size=1280x720&framerate=20#video=h265#audio=pcma")
args = parseArgs("device?video=0&framerate=20#video=h265")
require.Equal(t, `ffmpeg -hide_banner -f dshow -framerate 20 -i "video=0" -c:v libx265 -g 50 -profile:v main -level:v 5.1 -preset:v superfast -tune:v zerolatency -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
args = parseArgs("device?video=FaceTime HD Camera&audio=Microphone (High Definition Audio Device)")
require.Equal(t, `ffmpeg -hide_banner -f dshow -i "video=FaceTime HD Camera:audio=Microphone (High Definition Audio Device)" -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
tests := []struct {
name string
source string
expect string
}{
{
name: "[DEVICE] video will be output for MJPEG to pipe, with size 1920x1080",
source: "device?video=0&video_size=1920x1080",
expect: `ffmpeg -hide_banner -f dshow -video_size 1920x1080 -i "video=0" -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[DEVICE] video will be transcoded to H265 with framerate 20, audio will be skipped",
source: "device?video=0&framerate=20#video=h265",
expect: `ffmpeg -hide_banner -f dshow -framerate 20 -i "video=0" -c:v libx265 -g 50 -profile:v main -level:v 5.1 -preset:v superfast -tune:v zerolatency -pix_fmt:v yuv420p -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[DEVICE] video/audio",
source: "device?video=FaceTime HD Camera&audio=Microphone (High Definition Audio Device)",
expect: `ffmpeg -hide_banner -f dshow -i "video=FaceTime HD Camera:audio=Microphone (High Definition Audio Device)" -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
args := parseArgs(test.source)
require.Equal(t, test.expect, args.String())
})
}
}
func TestParseArgsIpCam(t *testing.T) {
// [HTTP] video will be copied
args := parseArgs("http://example.com")
require.Equal(t, `ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i http://example.com -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [HTTP-MJPEG] video will be transcoded to H264
args = parseArgs("http://example.com#video=h264")
require.Equal(t, `ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i http://example.com -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency -pix_fmt:v yuv420p -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [HLS] video will be copied, audio will be skipped
args = parseArgs("https://example.com#video=copy")
require.Equal(t, `ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i https://example.com -c:v copy -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [RTSP] video will be copied without transcoding codecs
args = parseArgs("rtsp://example.com")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types video+audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [RTSP] video with resize to 1280x720, should be transcoded, so select H265
args = parseArgs("rtsp://example.com#video=h265#width=1280#height=720")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types video -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:v libx265 -g 50 -profile:v main -level:v 5.1 -preset:v superfast -tune:v zerolatency -an -vf "scale=1280:720" -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [RTSP] video will be copied, changing RTSP transport from TCP to UDP+TCP
args = parseArgs("rtsp://example.com#input=rtsp/udp")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types video+audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -i rtsp://example.com -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [RTMP] video will be copied, changing RTSP transport from TCP to UDP+TCP
args = parseArgs("rtmp://example.com#input=rtsp/udp")
require.Equal(t, `ffmpeg -hide_banner -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -i rtmp://example.com -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
tests := []struct {
name string
source string
expect string
}{
{
name: "[HTTP] video will be copied",
source: "http://example.com",
expect: `ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i http://example.com -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[HTTP-MJPEG] video will be transcoded to H264",
source: "http://example.com#video=h264",
expect: `ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i http://example.com -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency -pix_fmt:v yuv420p -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[HLS] video will be copied, audio will be skipped",
source: "https://example.com#video=copy",
expect: `ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i https://example.com -c:v copy -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[RTSP] video will be copied without transcoding codecs",
source: "rtsp://example.com",
expect: `ffmpeg -hide_banner -allowed_media_types video+audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[RTSP] video with resize to 1280x720, should be transcoded, so select H265",
source: "rtsp://example.com#video=h265#width=1280#height=720",
expect: `ffmpeg -hide_banner -allowed_media_types video -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:v libx265 -g 50 -profile:v main -level:v 5.1 -preset:v superfast -tune:v zerolatency -pix_fmt:v yuv420p -an -vf "scale=1280:720" -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[RTSP] video will be copied, changing RTSP transport from TCP to UDP+TCP",
source: "rtsp://example.com#input=rtsp/udp",
expect: `ffmpeg -hide_banner -allowed_media_types video+audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -i rtsp://example.com -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[RTMP] video will be copied, changing RTSP transport from TCP to UDP+TCP",
source: "rtmp://example.com#input=rtsp/udp",
expect: `ffmpeg -hide_banner -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -i rtmp://example.com -c copy -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
args := parseArgs(test.source)
require.Equal(t, test.expect, args.String())
})
}
}
func TestParseArgsAudio(t *testing.T) {
// [AUDIO] audio will be transcoded to AAC, video will be skipped
args := parseArgs("rtsp:///example.com#audio=aac")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a aac -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [AUDIO] audio will be transcoded to AAC/16000, video will be skipped
args = parseArgs("rtsp:///example.com#audio=aac/16000")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a aac -ar:a 16000 -ac:a 1 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [AUDIO] audio will be transcoded to OPUS, video will be skipped
args = parseArgs("rtsp:///example.com#audio=opus")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a libopus -application:a lowdelay -min_comp 0 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [AUDIO] audio will be transcoded to PCMU, video will be skipped
args = parseArgs("rtsp:///example.com#audio=pcmu")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a pcm_mulaw -ar:a 8000 -ac:a 1 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [AUDIO] audio will be transcoded to PCMU/16000, video will be skipped
args = parseArgs("rtsp:///example.com#audio=pcmu/16000")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a pcm_mulaw -ar:a 16000 -ac:a 1 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [AUDIO] audio will be transcoded to PCMU/48000, video will be skipped
args = parseArgs("rtsp:///example.com#audio=pcmu/48000")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a pcm_mulaw -ar:a 48000 -ac:a 1 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [AUDIO] audio will be transcoded to PCMA, video will be skipped
args = parseArgs("rtsp:///example.com#audio=pcma")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a pcm_alaw -ar:a 8000 -ac:a 1 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [AUDIO] audio will be transcoded to PCMA/16000, video will be skipped
args = parseArgs("rtsp:///example.com#audio=pcma/16000")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a pcm_alaw -ar:a 16000 -ac:a 1 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
// [AUDIO] audio will be transcoded to PCMA/48000, video will be skipped
args = parseArgs("rtsp:///example.com#audio=pcma/48000")
require.Equal(t, `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp:///example.com -c:a pcm_alaw -ar:a 48000 -ac:a 1 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`, args.String())
tests := []struct {
name string
source string
expect string
}{
{
name: "[AUDIO] audio will be transcoded to AAC, video will be skipped",
source: "rtsp://example.com#audio=aac",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a aac -vn -f adts -`,
},
{
name: "[AUDIO] audio will be transcoded to AAC/16000, video will be skipped",
source: "rtsp://example.com#audio=aac/16000",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a aac -ar:a 16000 -ac:a 1 -vn -f adts -`,
},
{
name: "[AUDIO] audio will be transcoded to OPUS, video will be skipped",
source: "rtsp://example.com#audio=opus",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a libopus -application:a lowdelay -min_comp 0 -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`,
},
{
name: "[AUDIO] audio will be transcoded to PCMU, video will be skipped",
source: "rtsp://example.com#audio=pcmu",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a pcm_mulaw -ar:a 8000 -ac:a 1 -vn -f wav -`,
},
{
name: "[AUDIO] audio will be transcoded to PCMU/16000, video will be skipped",
source: "rtsp://example.com#audio=pcmu/16000",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a pcm_mulaw -ar:a 16000 -ac:a 1 -vn -f wav -`,
},
{
name: "[AUDIO] audio will be transcoded to PCMU/48000, video will be skipped",
source: "rtsp://example.com#audio=pcmu/48000",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a pcm_mulaw -ar:a 48000 -ac:a 1 -vn -f wav -`,
},
{
name: "[AUDIO] audio will be transcoded to PCMA, video will be skipped",
source: "rtsp://example.com#audio=pcma",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a pcm_alaw -ar:a 8000 -ac:a 1 -vn -f wav -`,
},
{
name: "[AUDIO] audio will be transcoded to PCMA/16000, video will be skipped",
source: "rtsp://example.com#audio=pcma/16000",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a pcm_alaw -ar:a 16000 -ac:a 1 -vn -f wav -`,
},
{
name: "[AUDIO] audio will be transcoded to PCMA/48000, video will be skipped",
source: "rtsp://example.com#audio=pcma/48000",
expect: `ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://example.com -c:a pcm_alaw -ar:a 48000 -ac:a 1 -vn -f wav -`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
args := parseArgs(test.source)
require.Equal(t, test.expect, args.String())
})
}
}
func TestParseArgsHwVaapi(t *testing.T) {
+6 -6
View File
@@ -103,7 +103,7 @@ func apiPair(id, url string) error {
streams.New(id, conn.URL())
return app.PatchConfig(id, conn.URL(), "streams")
return app.PatchConfig([]string{"streams", id}, conn.URL())
}
func apiUnpair(id string) error {
@@ -112,7 +112,7 @@ func apiUnpair(id string) error {
return errors.New(api.StreamNotFound)
}
rawURL := findHomeKitURL(stream)
rawURL := findHomeKitURL(stream.Sources())
if rawURL == "" {
return errors.New("not homekit source")
}
@@ -123,15 +123,15 @@ func apiUnpair(id string) error {
streams.Delete(id)
return app.PatchConfig(id, nil, "streams")
return app.PatchConfig([]string{"streams", id}, nil)
}
func findHomeKitURLs() map[string]*url.URL {
urls := map[string]*url.URL{}
for id, stream := range streams.Streams() {
if rawURL := findHomeKitURL(stream); rawURL != "" {
for name, sources := range streams.GetAllSources() {
if rawURL := findHomeKitURL(sources); rawURL != "" {
if u, err := url.Parse(rawURL); err == nil {
urls[id] = u
urls[name] = u
}
}
}
+27 -24
View File
@@ -79,7 +79,7 @@ func Init() {
Handler: homekit.ServerHandler(srv),
}
if url := findHomeKitURL(stream); url != "" {
if url := findHomeKitURL(stream.Sources()); url != "" {
// 1. Act as transparent proxy for HomeKit camera
dial := func() (net.Conn, error) {
client, err := homekit.Dial(url, srtp.Server)
@@ -118,8 +118,8 @@ func Init() {
servers[host] = srv
}
api.HandleFunc(hap.PathPairSetup, hapPairSetup)
api.HandleFunc(hap.PathPairVerify, hapPairVerify)
api.HandleFunc(hap.PathPairSetup, hapHandler)
api.HandleFunc(hap.PathPairVerify, hapHandler)
log.Trace().Msgf("[homekit] mdns: %s", entries)
@@ -148,13 +148,19 @@ func streamHandler(rawURL string) (core.Producer, error) {
return client, err
}
func hapPairSetup(w http.ResponseWriter, r *http.Request) {
srv, ok := servers[r.Host]
if !ok {
log.Error().Msg("[homekit] unknown host: " + r.Host)
return
func resolve(host string) *server {
if len(servers) == 1 {
for _, srv := range servers {
return srv
}
}
if srv, ok := servers[host]; ok {
return srv
}
return nil
}
func hapHandler(w http.ResponseWriter, r *http.Request) {
conn, rw, err := w.(http.Hijacker).Hijack()
if err != nil {
return
@@ -162,32 +168,29 @@ func hapPairSetup(w http.ResponseWriter, r *http.Request) {
defer conn.Close()
if err = srv.hap.PairSetup(r, rw, conn); err != nil {
log.Error().Err(err).Caller().Send()
}
}
func hapPairVerify(w http.ResponseWriter, r *http.Request) {
srv, ok := servers[r.Host]
if !ok {
// Can support multiple HomeKit cameras on single port ONLY for Apple devices.
// Doesn't support Home Assistant and any other open source projects
// because they don't send the host header in requests.
srv := resolve(r.Host)
if srv == nil {
log.Error().Msg("[homekit] unknown host: " + r.Host)
_ = hap.WriteBackoff(rw)
return
}
conn, rw, err := w.(http.Hijacker).Hijack()
if err != nil {
return
switch r.RequestURI {
case hap.PathPairSetup:
err = srv.hap.PairSetup(r, rw, conn)
case hap.PathPairVerify:
err = srv.hap.PairVerify(r, rw, conn)
}
defer conn.Close()
if err = srv.hap.PairVerify(r, rw, conn); err != nil && err != io.EOF {
if err != nil && err != io.EOF {
log.Error().Err(err).Caller().Send()
}
}
func findHomeKitURL(stream *streams.Stream) string {
sources := stream.Sources()
func findHomeKitURL(sources []string) string {
if len(sources) == 0 {
return ""
}
+1 -1
View File
@@ -222,7 +222,7 @@ func (s *server) DelPair(conn net.Conn, id string) {
}
func (s *server) PatchConfig() {
if err := app.PatchConfig("pairings", s.pairings, "homekit", s.stream); err != nil {
if err := app.PatchConfig([]string{"homekit", s.stream, "pairings"}, s.pairings); err != nil {
log.Error().Err(err).Msgf(
"[homekit] can't save %s pairings=%v", s.stream, s.pairings,
)
+4
View File
@@ -14,6 +14,7 @@ import (
"github.com/AlexxIT/go2rtc/pkg/image"
"github.com/AlexxIT/go2rtc/pkg/magic"
"github.com/AlexxIT/go2rtc/pkg/mpjpeg"
"github.com/AlexxIT/go2rtc/pkg/pcm"
"github.com/AlexxIT/go2rtc/pkg/tcp"
)
@@ -87,6 +88,9 @@ func do(req *http.Request) (core.Producer, error) {
return image.Open(res)
case ct == "multipart/x-mixed-replace":
return mpjpeg.Open(res.Body)
//https://www.iana.org/assignments/media-types/audio/basic
case ct == "audio/basic":
return pcm.Open(res.Body)
}
return magic.Open(res.Body)
+5 -3
View File
@@ -2,6 +2,7 @@ package nest
import (
"net/http"
"strings"
"github.com/AlexxIT/go2rtc/internal/api"
"github.com/AlexxIT/go2rtc/internal/streams"
@@ -38,11 +39,12 @@ func apiNest(w http.ResponseWriter, r *http.Request) {
var items []*api.Source
for name, deviceID := range devices {
query.Set("device_id", deviceID)
for _, device := range devices {
query.Set("device_id", device.DeviceID)
query.Set("protocols", strings.Join(device.Protocols, ","))
items = append(items, &api.Source{
Name: name, URL: "nest:?" + query.Encode(),
Name: device.Name, URL: "nest:?" + query.Encode(),
})
}
+25
View File
@@ -0,0 +1,25 @@
# ONVIF
A regular camera has a single video source (`GetVideoSources`) and two profiles (`GetProfiles`).
Go2rtc has one video source and one profile per stream.
## Tested clients
Go2rtc works as ONVIF server:
- Happytime onvif client (windows)
- Home Assistant ONVIF integration (linux)
- Onvier (android)
- ONVIF Device Manager (windows)
PS. Support only TCP transport for RTSP protocol. UDP and HTTP transports - unsupported yet.
## Tested cameras
Go2rtc works as ONVIF client:
- Dahua IPC-K42
- OpenIPC
- Reolink RLC-520A
- TP-Link Tapo TC60
@@ -55,49 +55,73 @@ func onvifDeviceService(w http.ResponseWriter, r *http.Request) {
return
}
action := onvif.GetRequestAction(b)
if action == "" {
operation := onvif.GetRequestAction(b)
if operation == "" {
http.Error(w, "malformed request body", http.StatusBadRequest)
return
}
log.Trace().Msgf("[onvif] %s", action)
log.Trace().Msgf("[onvif] server request %s %s:\n%s", r.Method, r.RequestURI, b)
var res string
switch operation {
case onvif.DeviceGetNetworkInterfaces, // important for Hass
onvif.DeviceGetSystemDateAndTime, // important for Hass
onvif.DeviceGetDiscoveryMode,
onvif.DeviceGetDNS,
onvif.DeviceGetHostname,
onvif.DeviceGetNetworkDefaultGateway,
onvif.DeviceGetNetworkProtocols,
onvif.DeviceGetNTP,
onvif.DeviceGetScopes,
onvif.MediaGetVideoEncoderConfigurations,
onvif.MediaGetAudioEncoderConfigurations,
onvif.MediaGetAudioSources,
onvif.MediaGetAudioSourceConfigurations:
b = onvif.StaticResponse(operation)
switch action {
case onvif.ActionGetCapabilities:
case onvif.DeviceGetCapabilities:
// important for Hass: Media section
res = onvif.GetCapabilitiesResponse(r.Host)
b = onvif.GetCapabilitiesResponse(r.Host)
case onvif.ActionGetSystemDateAndTime:
// important for Hass
res = onvif.GetSystemDateAndTimeResponse()
case onvif.DeviceGetServices:
b = onvif.GetServicesResponse(r.Host)
case onvif.ActionGetNetworkInterfaces:
// important for Hass: none
res = onvif.GetNetworkInterfacesResponse()
case onvif.ActionGetDeviceInformation:
case onvif.DeviceGetDeviceInformation:
// important for Hass: SerialNumber (unique server ID)
res = onvif.GetDeviceInformationResponse("", "go2rtc", app.Version, r.Host)
b = onvif.GetDeviceInformationResponse("", "go2rtc", app.Version, r.Host)
case onvif.ActionGetServiceCapabilities:
case onvif.ServiceGetServiceCapabilities:
// important for Hass
res = onvif.GetServiceCapabilitiesResponse()
// TODO: check path links to media
b = onvif.GetMediaServiceCapabilitiesResponse()
case onvif.ActionSystemReboot:
res = onvif.SystemRebootResponse()
case onvif.DeviceSystemReboot:
b = onvif.StaticResponse(operation)
time.AfterFunc(time.Second, func() {
os.Exit(0)
})
case onvif.ActionGetProfiles:
// important for Hass: H264 codec, width, height
res = onvif.GetProfilesResponse(streams.GetAll())
case onvif.MediaGetVideoSources:
b = onvif.GetVideoSourcesResponse(streams.GetAllNames())
case onvif.ActionGetStreamUri:
case onvif.MediaGetProfiles:
// important for Hass: H264 codec, width, height
b = onvif.GetProfilesResponse(streams.GetAllNames())
case onvif.MediaGetProfile:
token := onvif.FindTagValue(b, "ProfileToken")
b = onvif.GetProfileResponse(token)
case onvif.MediaGetVideoSourceConfigurations:
// important for Happytime Onvif Client
b = onvif.GetVideoSourceConfigurationsResponse(streams.GetAllNames())
case onvif.MediaGetVideoSourceConfiguration:
token := onvif.FindTagValue(b, "ConfigurationToken")
b = onvif.GetVideoSourceConfigurationResponse(token)
case onvif.MediaGetStreamUri:
host, _, err := net.SplitHostPort(r.Host)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -105,16 +129,23 @@ func onvifDeviceService(w http.ResponseWriter, r *http.Request) {
}
uri := "rtsp://" + host + ":" + rtsp.Port + "/" + onvif.FindTagValue(b, "ProfileToken")
res = onvif.GetStreamUriResponse(uri)
b = onvif.GetStreamUriResponse(uri)
case onvif.MediaGetSnapshotUri:
uri := "http://" + r.Host + "/api/frame.jpeg?src=" + onvif.FindTagValue(b, "ProfileToken")
b = onvif.GetSnapshotUriResponse(uri)
default:
http.Error(w, "unsupported action", http.StatusBadRequest)
http.Error(w, "unsupported operation", http.StatusBadRequest)
log.Warn().Msgf("[onvif] unsupported operation: %s", operation)
log.Debug().Msgf("[onvif] unsupported request:\n%s", b)
return
}
log.Trace().Msgf("[onvif] server response:\n%s", b)
w.Header().Set("Content-Type", "application/soap+xml; charset=utf-8")
if _, err = w.Write([]byte(res)); err != nil {
if _, err = w.Write(b); err != nil {
log.Error().Err(err).Caller().Send()
}
}
@@ -160,7 +191,7 @@ func apiOnvif(w http.ResponseWriter, r *http.Request) {
}
if l := log.Trace(); l.Enabled() {
b, _ := client.GetProfiles()
b, _ := client.MediaRequest(onvif.MediaGetProfiles)
l.Msgf("[onvif] src=%s profiles:\n%s", src, b)
}
+102
View File
@@ -0,0 +1,102 @@
package ring
import (
"encoding/json"
"net/http"
"net/url"
"github.com/AlexxIT/go2rtc/internal/api"
"github.com/AlexxIT/go2rtc/internal/streams"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/ring"
)
func Init() {
streams.HandleFunc("ring", func(source string) (core.Producer, error) {
return ring.Dial(source)
})
api.HandleFunc("api/ring", apiRing)
}
func apiRing(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
var ringAPI *ring.RingRestClient
var err error
// Check auth method
if email := query.Get("email"); email != "" {
// Email/Password Flow
password := query.Get("password")
code := query.Get("code")
ringAPI, err = ring.NewRingRestClient(ring.EmailAuth{
Email: email,
Password: password,
}, nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Try authentication (this will trigger 2FA if needed)
if _, err = ringAPI.GetAuth(code); err != nil {
if ringAPI.Using2FA {
// Return 2FA prompt
json.NewEncoder(w).Encode(map[string]interface{}{
"needs_2fa": true,
"prompt": ringAPI.PromptFor2FA,
})
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
} else {
// Refresh Token Flow
refreshToken := query.Get("refresh_token")
if refreshToken == "" {
http.Error(w, "either email/password or refresh_token is required", http.StatusBadRequest)
return
}
ringAPI, err = ring.NewRingRestClient(ring.RefreshTokenAuth{
RefreshToken: refreshToken,
}, nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
// Fetch devices
devices, err := ringAPI.FetchRingDevices()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Create clean query with only required parameters
cleanQuery := url.Values{}
cleanQuery.Set("refresh_token", ringAPI.RefreshToken)
var items []*api.Source
for _, camera := range devices.AllCameras {
cleanQuery.Set("device_id", camera.DeviceID)
// Stream source
items = append(items, &api.Source{
Name: camera.Description,
URL: "ring:?" + cleanQuery.Encode(),
})
// Snapshot source
items = append(items, &api.Source{
Name: camera.Description + " Snapshot",
URL: "ring:?" + cleanQuery.Encode() + "&snapshot",
})
}
api.ResponseSources(w, items)
}
+60
View File
@@ -0,0 +1,60 @@
## Tested client
| From | To | Comment |
|--------|---------------------------------|---------|
| go2rtc | Reolink RLC-520A fw. v3.1.0.801 | OK |
**go2rtc.yaml**
```yaml
streams:
rtmp-reolink1: rtmp://192.168.10.92/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=password
rtmp-reolink2: rtmp://192.168.10.92/bcs/channel0_sub.bcs?channel=0&stream=1&user=admin&password=password
rtmp-reolink3: rtmp://192.168.10.92/bcs/channel0_ext.bcs?channel=0&stream=1&user=admin&password=password
```
## Tested server
| From | To | Comment |
|------------------------|--------|---------------------|
| OBS 31.0.2 | go2rtc | OK |
| OpenIPC 2.5.03.02-lite | go2rtc | OK |
| FFmpeg 6.1 | go2rtc | OK |
| GoPro Black 12 | go2rtc | OK, 1080p, 5000kbps |
**go2rtc.yaml**
```yaml
rtmp:
listen: :1935
streams:
tmp:
```
**OBS**
Settings > Stream:
- Service: Custom
- Server: rtmp://192.168.10.101/tmp
- Stream Key: <empty>
- Use auth: <disabled>
**OpenIPC**
WebUI > Majestic > Settings > Outgoing
- Enable
- Address: rtmp://192.168.10.101/tmp
- Save
- Restart
**FFmpeg**
```shell
ffmpeg -re -i bbb.mp4 -c copy -f flv rtmp://192.168.10.101/tmp
```
**GoPro**
GoPro Quik > Camera > Translation > Other
+1 -1
View File
@@ -133,7 +133,7 @@ func streamsHandle(url string) (core.Producer, error) {
func streamsConsumerHandle(url string) (core.Consumer, func(), error) {
cons := flv.NewConsumer()
run := func() {
wr, err := rtmp.DialPublish(url)
wr, err := rtmp.DialPublish(url, cons)
if err != nil {
return
}
+33 -3
View File
@@ -1,6 +1,7 @@
package rtsp
import (
"errors"
"io"
"net"
"net/url"
@@ -147,6 +148,7 @@ func tcpHandler(conn *rtsp.Conn) {
var closer func()
trace := log.Trace().Enabled()
level := zerolog.WarnLevel
conn.Listen(func(msg any) {
if trace {
@@ -184,12 +186,38 @@ func tcpHandler(conn *rtsp.Conn) {
}
}
if query.Get("backchannel") == "1" {
conn.Medias = append(conn.Medias, &core.Media{
Kind: core.KindAudio,
Direction: core.DirectionRecvonly,
Codecs: []*core.Codec{
{Name: core.CodecOpus, ClockRate: 48000, Channels: 2},
{Name: core.CodecPCM, ClockRate: 16000},
{Name: core.CodecPCMA, ClockRate: 16000},
{Name: core.CodecPCMU, ClockRate: 16000},
{Name: core.CodecPCM, ClockRate: 8000},
{Name: core.CodecPCMA, ClockRate: 8000},
{Name: core.CodecPCMU, ClockRate: 8000},
},
})
}
if s := query.Get("pkt_size"); s != "" {
conn.PacketSize = uint16(core.Atoi(s))
}
// param name like ffmpeg style https://ffmpeg.org/ffmpeg-protocols.html
if s := query.Get("log_level"); s != "" {
if lvl, err := zerolog.ParseLevel(s); err == nil {
level = lvl
}
}
// will help to protect looping requests to same source
conn.Connection.Source = query.Get("source")
if err := stream.AddConsumer(conn); err != nil {
log.Warn().Err(err).Str("stream", name).Msg("[rtsp]")
log.WithLevel(level).Err(err).Str("stream", name).Msg("[rtsp]")
return
}
@@ -226,8 +254,10 @@ func tcpHandler(conn *rtsp.Conn) {
})
if err := conn.Accept(); err != nil {
if err != io.EOF {
log.Warn().Err(err).Caller().Send()
if errors.Is(err, rtsp.FailedAuth) {
log.Warn().Str("remote_addr", conn.Connection.RemoteAddr).Msg("[rtsp] failed authentication")
} else if err != io.EOF {
log.WithLevel(level).Err(err).Caller().Send()
}
if closer != nil {
closer()
+51 -4
View File
@@ -1,8 +1,55 @@
## Testing notes
## Examples
```yaml
streams:
test1-basic: ffmpeg:virtual?video#video=h264
test2-reconnect: ffmpeg:virtual?video&duration=10#video=h264
test3-execkill: exec:./examples/rtsp_client/rtsp_client/rtsp_client {output}
# known RTSP sources
rtsp-dahua1: rtsp://admin:password@192.168.10.90/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
rtsp-dahua2: rtsp://admin:password@192.168.10.90/cam/realmonitor?channel=1&subtype=1
rtsp-tplink1: rtsp://admin:password@192.168.10.91/stream1
rtsp-tplink2: rtsp://admin:password@192.168.10.91/stream2
rtsp-reolink1: rtsp://admin:password@192.168.10.92/h264Preview_01_main
rtsp-reolink2: rtsp://admin:password@192.168.10.92/h264Preview_01_sub
rtsp-sonoff1: rtsp://admin:password@192.168.10.93/av_stream/ch0
rtsp-sonoff2: rtsp://admin:password@192.168.10.93/av_stream/ch1
# known RTMP sources
rtmp-reolink1: rtmp://192.168.10.92/bcs/channel0_main.bcs?channel=0&stream=0&user=admin&password=password
rtmp-reolink2: rtmp://192.168.10.92/bcs/channel0_sub.bcs?channel=0&stream=1&user=admin&password=password
rtmp-reolink3: rtmp://192.168.10.92/bcs/channel0_ext.bcs?channel=0&stream=1&user=admin&password=password
# known HTTP sources
http-reolink1: http://192.168.10.92/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password=password
http-reolink2: http://192.168.10.92/flv?port=1935&app=bcs&stream=channel0_sub.bcs&user=admin&password=password
http-reolink3: http://192.168.10.92/flv?port=1935&app=bcs&stream=channel0_ext.bcs&user=admin&password=password
# known ONVIF sources
onvif-dahua1: onvif://admin:password@192.168.10.90?subtype=MediaProfile00000
onvif-dahua2: onvif://admin:password@192.168.10.90?subtype=MediaProfile00001
onvif-dahua3: onvif://admin:password@192.168.10.90?subtype=MediaProfile00000&snapshot
onvif-tplink1: onvif://admin:password@192.168.10.91:2020?subtype=profile_1
onvif-tplink2: onvif://admin:password@192.168.10.91:2020?subtype=profile_2
onvif-reolink1: onvif://admin:password@192.168.10.92:8000?subtype=000
onvif-reolink2: onvif://admin:password@192.168.10.92:8000?subtype=001
onvif-reolink3: onvif://admin:password@192.168.10.92:8000?subtype=000&snapshot
onvif-openipc1: onvif://admin:password@192.168.10.95:80?subtype=PROFILE_000
onvif-openipc2: onvif://admin:password@192.168.10.95:80?subtype=PROFILE_001
# some EXEC examples
exec-h264-pipe: exec:ffmpeg -re -i bbb.mp4 -c copy -f h264 -
exec-flv-pipe: exec:ffmpeg -re -i bbb.mp4 -c copy -f flv -
exec-mpegts-pipe: exec:ffmpeg -re -i bbb.mp4 -c copy -f mpegts -
exec-adts-pipe: exec:ffmpeg -re -i bbb.mp4 -c copy -f adts -
exec-mjpeg-pipe: exec:ffmpeg -re -i bbb.mp4 -c mjpeg -f mjpeg -
exec-hevc-pipe: exec:ffmpeg -re -i bbb.mp4 -c libx265 -preset superfast -tune zerolatency -f hevc -
exec-wav-pipe: exec:ffmpeg -re -i bbb.mp4 -c pcm_alaw -ar 8000 -ac 1 -f wav -
exec-y4m-pipe: exec:ffmpeg -re -i bbb.mp4 -c rawvideo -f yuv4mpegpipe -
exec-pcma-pipe: exec:ffmpeg -re -i numb.mp3 -c:a pcm_alaw -ar:a 8000 -ac:a 1 -f wav -
exec-pcmu-pipe: exec:ffmpeg -re -i numb.mp3 -c:a pcm_mulaw -ar:a 8000 -ac:a 1 -f wav -
exec-s16le-pipe: exec:ffmpeg -re -i numb.mp3 -c:a pcm_s16le -ar:a 16000 -ac:a 1 -f wav -
# some FFmpeg examples
ffmpeg-video-h264: ffmpeg:virtual?video#video=h264
ffmpeg-video-4K: ffmpeg:virtual?video&size=4K#video=h264
ffmpeg-video-10s: ffmpeg:virtual?video&duration=10#video=h264
ffmpeg-video-src2: ffmpeg:virtual?video=testsrc2&size=2K#video=h264
```
+8 -2
View File
@@ -22,6 +22,12 @@ func (s *Stream) AddConsumer(cons core.Consumer) (err error) {
producers:
for prodN, prod := range s.producers {
// check for loop request, ex. `camera1: ffmpeg:camera1`
if info, ok := cons.(core.Info); ok && prod.url == info.GetSource() {
log.Trace().Msgf("[streams] skip cons=%d prod=%d", consN, prodN)
continue
}
if prodErrors[prodN] != nil {
log.Trace().Msgf("[streams] skip cons=%d prod=%d", consN, prodN)
continue
@@ -129,7 +135,7 @@ func formatError(consMedias, prodMedias []*core.Media, prodErrors []error) error
for _, media := range prodMedias {
if media.Direction == core.DirectionRecvonly {
for _, codec := range media.Codecs {
prod = appendString(prod, codec.PrintName())
prod = appendString(prod, media.Kind+":"+codec.PrintName())
}
}
}
@@ -137,7 +143,7 @@ func formatError(consMedias, prodMedias []*core.Media, prodErrors []error) error
for _, media := range consMedias {
if media.Direction == core.DirectionSendonly {
for _, codec := range media.Codecs {
cons = appendString(cons, codec.PrintName())
cons = appendString(cons, media.Kind+":"+codec.PrintName())
}
}
}
+3 -3
View File
@@ -48,12 +48,12 @@ func apiStreams(w http.ResponseWriter, r *http.Request) {
name = src
}
if New(name, src) == nil {
if New(name, query["src"]...) == nil {
http.Error(w, "", http.StatusBadRequest)
return
}
if err := app.PatchConfig(name, src, "streams"); err != nil {
if err := app.PatchConfig([]string{"streams", name}, query["src"]); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
@@ -96,7 +96,7 @@ func apiStreams(w http.ResponseWriter, r *http.Request) {
case "DELETE":
delete(streams, src)
if err := app.PatchConfig(src, nil, "streams"); err != nil {
if err := app.PatchConfig([]string{"streams", src}, nil); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
+2 -1
View File
@@ -171,5 +171,6 @@ func (c *conn) label() string {
if c.UserAgent != "" {
sb.WriteString("\nuser_agent=" + c.UserAgent)
}
return sb.String()
// escape quotes https://github.com/AlexxIT/go2rtc/issues/1603
return strings.ReplaceAll(sb.String(), `"`, `'`)
}
+1 -1
View File
@@ -103,7 +103,7 @@ func (s *Stream) Play(source string) error {
}
func (s *Stream) AddInternalProducer(conn core.Producer) {
producer := &Producer{conn: conn, state: stateInternal}
producer := &Producer{conn: conn, state: stateInternal, url: "internal"}
s.mu.Lock()
s.producers = append(s.producers, producer)
s.mu.Unlock()
+10 -3
View File
@@ -21,6 +21,12 @@ func NewStream(source any) *Stream {
return &Stream{
producers: []*Producer{NewProducer(source)},
}
case []string:
s := new(Stream)
for _, str := range source {
s.producers = append(s.producers, NewProducer(str))
}
return s
case []any:
s := new(Stream)
for _, src := range source {
@@ -41,11 +47,12 @@ func NewStream(source any) *Stream {
}
}
func (s *Stream) Sources() (sources []string) {
func (s *Stream) Sources() []string {
sources := make([]string, 0, len(s.producers))
for _, prod := range s.producers {
sources = append(sources, prod.url)
}
return
return sources
}
func (s *Stream) SetSource(source string) {
@@ -70,7 +77,7 @@ func (s *Stream) RemoveConsumer(cons core.Consumer) {
}
func (s *Stream) AddProducer(prod core.Producer) {
producer := &Producer{conn: prod, state: stateExternal}
producer := &Producer{conn: prod, state: stateExternal, url: "external"}
s.mu.Lock()
s.producers = append(s.producers, producer)
s.mu.Unlock()
+50 -22
View File
@@ -42,10 +42,6 @@ func Init() {
})
}
func Get(name string) *Stream {
return streams[name]
}
var sanitize = regexp.MustCompile(`\s`)
// Validate - not allow creating dynamic streams with spaces in the source
@@ -56,13 +52,19 @@ func Validate(source string) error {
return nil
}
func New(name string, source string) *Stream {
if Validate(source) != nil {
return nil
func New(name string, sources ...string) *Stream {
for _, source := range sources {
if Validate(source) != nil {
return nil
}
}
stream := NewStream(source)
stream := NewStream(sources)
streamsMu.Lock()
streams[name] = stream
streamsMu.Unlock()
return stream
}
@@ -95,6 +97,10 @@ func Patch(name string, source string) *Stream {
return nil
}
if Validate(source) != nil {
return nil
}
// check an existing stream with this name
if stream, ok := streams[name]; ok {
stream.SetSource(source)
@@ -102,7 +108,9 @@ func Patch(name string, source string) *Stream {
}
// create new stream with this name
return New(name, source)
stream := NewStream(source)
streams[name] = stream
return stream
}
func GetOrPatch(query url.Values) *Stream {
@@ -113,7 +121,7 @@ func GetOrPatch(query url.Values) *Stream {
}
// check if src is stream name
if stream, ok := streams[source]; ok {
if stream := Get(source); stream != nil {
return stream
}
@@ -128,21 +136,41 @@ func GetOrPatch(query url.Values) *Stream {
return Patch(source, source)
}
func GetAll() (names []string) {
var log zerolog.Logger
// streams map
var streams = map[string]*Stream{}
var streamsMu sync.Mutex
func Get(name string) *Stream {
streamsMu.Lock()
defer streamsMu.Unlock()
return streams[name]
}
func Delete(name string) {
streamsMu.Lock()
defer streamsMu.Unlock()
delete(streams, name)
}
func GetAllNames() []string {
streamsMu.Lock()
names := make([]string, 0, len(streams))
for name := range streams {
names = append(names, name)
}
return
streamsMu.Unlock()
return names
}
func Streams() map[string]*Stream {
return streams
func GetAllSources() map[string][]string {
streamsMu.Lock()
sources := make(map[string][]string, len(streams))
for name, stream := range streams {
sources[name] = stream.Sources()
}
streamsMu.Unlock()
return sources
}
func Delete(id string) {
delete(streams, id)
}
var log zerolog.Logger
var streams = map[string]*Stream{}
var streamsMu sync.Mutex
+4
View File
@@ -15,4 +15,8 @@ func Init() {
streams.HandleFunc("tapo", func(source string) (core.Producer, error) {
return tapo.Dial(source)
})
streams.HandleFunc("vigi", func(source string) (core.Producer, error) {
return tapo.Dial(source)
})
}
+39
View File
@@ -0,0 +1,39 @@
# V4L2
What you should to know about [V4L2](https://en.wikipedia.org/wiki/Video4Linux):
- V4L2 (Video for Linux API version 2) works only in Linux
- supports USB cameras and other similar devices
- one device can only be connected to one software simultaneously
- cameras support a fixed list of formats, resolutions and frame rates
- basic cameras supports only RAW (non-compressed) pixel formats
- regular cameras supports MJPEG format (series of JPEG frames)
- advances cameras support H264 format (MSE/MP4, WebRTC compatible)
- using MJPEG and H264 formats (if the camera supports them) won't cost you the CPU usage
- transcoding RAW format to MJPEG or H264 - will cost you a significant CPU usage
- H265 (HEVC) format is also supported (if the camera supports it)
Tests show that the basic Keenetic router with MIPS processor can broadcast three MJPEG cameras in the following resolutions: 1600х1200 + 640х480 + 640х480. The USB bus bandwidth is no more enough for larger resolutions. CPU consumption is no more than 5%.
Supported formats for your camera can be found here: **Go2rtc > WebUI > Add > V4L2**.
## RAW format
Example:
```yaml
streams:
camera1: v4l2:device?video=/dev/video0&input_format=yuyv422&video_size=1280x720&framerate=10
```
Go2rtc supports built-in transcoding of RAW to MJPEG format. This does not need to be additionally configured.
```
ffplay http://localhost:1984/api/stream.mjpeg?src=camera1
```
**Important.** You don't have to transcode the RAW format to transmit it over the network. You can stream it in `y4m` format, which is perfectly supported by ffmpeg. It won't cost you a CPU usage. But will require high network bandwidth.
```
ffplay http://localhost:1984/api/stream.y4m?src=camera1
```
+7
View File
@@ -0,0 +1,7 @@
//go:build !linux
package v4l2
func Init() {
// not supported
}
+89
View File
@@ -0,0 +1,89 @@
package v4l2
import (
"encoding/binary"
"fmt"
"net/http"
"os"
"strings"
"github.com/AlexxIT/go2rtc/internal/api"
"github.com/AlexxIT/go2rtc/internal/streams"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/v4l2"
"github.com/AlexxIT/go2rtc/pkg/v4l2/device"
)
func Init() {
streams.HandleFunc("v4l2", func(source string) (core.Producer, error) {
return v4l2.Open(source)
})
api.HandleFunc("api/v4l2", apiV4L2)
}
func apiV4L2(w http.ResponseWriter, r *http.Request) {
files, err := os.ReadDir("/dev")
if err != nil {
return
}
var sources []*api.Source
for _, file := range files {
if !strings.HasPrefix(file.Name(), core.KindVideo) {
continue
}
path := "/dev/" + file.Name()
dev, err := device.Open(path)
if err != nil {
continue
}
formats, _ := dev.ListFormats()
for _, fourCC := range formats {
name, ffmpeg := findFormat(fourCC)
source := &api.Source{Name: name}
sizes, _ := dev.ListSizes(fourCC)
for _, wh := range sizes {
if source.Info != "" {
source.Info += " "
}
source.Info += fmt.Sprintf("%dx%d", wh[0], wh[1])
frameRates, _ := dev.ListFrameRates(fourCC, wh[0], wh[1])
for _, fr := range frameRates {
source.Info += fmt.Sprintf("@%d", fr)
if source.URL == "" && ffmpeg != "" {
source.URL = fmt.Sprintf(
"v4l2:device?video=%s&input_format=%s&video_size=%dx%d&framerate=%d",
path, ffmpeg, wh[0], wh[1], fr,
)
}
}
}
if source.Info != "" {
sources = append(sources, source)
}
}
_ = dev.Close()
}
api.ResponseSources(w, sources)
}
func findFormat(fourCC uint32) (name, ffmpeg string) {
for _, format := range device.Formats {
if format.FourCC == fourCC {
return format.Name, format.FFmpeg
}
}
return string(binary.LittleEndian.AppendUint32(nil, fourCC)), ""
}
+14 -9
View File
@@ -11,13 +11,15 @@ If an external connection via STUN is used:
- Uses [UDP hole punching](https://en.wikipedia.org/wiki/UDP_hole_punching) technology to bypass NAT even if you not open your server to the World
- For about 20% of users, the techology will not work because of the [Symmetric NAT](https://tomchen.github.io/symmetric-nat-test/)
- UDP is not suitable for transmitting 2K and 4K high bitrate video over open networks because of the high loss rate
- UDP is not suitable for transmitting 2K and 4K high bitrate video over open networks because of the high loss rate:
- https://habr.com/ru/companies/flashphoner/articles/480006/
- https://www.youtube.com/watch?v=FXVg2ckuKfs
## Default config
```yaml
webrtc:
listen: ":8555/tcp"
listen: ":8555"
ice_servers:
- urls: [ "stun:stun.l.google.com:19302" ]
```
@@ -29,7 +31,7 @@ webrtc:
```yaml
webrtc:
# fix local TCP or UDP or both ports for WebRTC media
listen: ":8555/tcp" # address of your local server
listen: ":8555" # address of your local server
# add additional host candidates manually
# order is important, the first will have a higher priority
@@ -53,17 +55,20 @@ webrtc:
# including candidates from the `listen` option
# use `candidates: []` to remove all auto discovery candidates
candidates: [ 192.168.1.123 ]
# enable localhost candidates
loopback: true
# list of network types to be used for connection
# including candidates from the `listen` option
networks: [ udp4, udp6, tcp4, tcp6 ]
# list of interfaces to be used for connection
# not related to the `listen` option
# including interfaces from unspecified `listen` option (empty host)
interfaces: [ eno1 ]
# list of host IP-addresses to be used for connection
# not related to the `listen` option
# including IPs from unspecified `listen` option (empty host)
ips: [ 192.168.1.123 ]
# range for random UDP ports [min, max] to be used for connection
@@ -71,14 +76,16 @@ webrtc:
udp_ports: [ 50000, 50100 ]
```
By default go2rtc uses **fixed TCP** port and multiple **random UDP** ports for each WebRTC connection - `listen: ":8555/tcp"`.
By default go2rtc uses **fixed TCP** port and **fixed UDP** ports for each **direct** WebRTC connection - `listen: ":8555"`.
You can set **fixed TCP** and **fixed UDP** port for all connections - `listen: ":8555"`. This may has lower performance, but it's your choice.
You can set **fixed TCP** and **random UDP** port for all connections - `listen: ":8555/tcp"`.
Don't know why, but you can disable TCP port and leave only random UDP ports - `listen: ""`.
## Config filters
**Importan!** By default go2rtc exclude all Docker-like candidates (`172.16.0.0/12`). This can not be disabled.
Filters allow you to exclude unnecessary candidates. Extra candidates don't make your connection worse or better. But the wrong filter settings can break everything. Skip this setting if you don't understand it.
For example, go2rtc is installed on the host system. And there are unnecessary interfaces. You can keep only the relevant via `interfaces` or `ips` options. You can also exclude IPv6 candidates if your server supports them but your home network does not.
@@ -97,8 +104,6 @@ For example, go2rtc inside closed docker container (ex. [Frigate](https://frigat
webrtc:
listen: ":8555" # use fixed TCP and UDP ports
candidates: [ 192.168.1.2:8555 ] # add manual host candidate (use docker port forwarding)
filters:
candidates: [] # skip all internal docker candidates
```
## Userful links
+9 -3
View File
@@ -2,11 +2,12 @@ package webrtc
import (
"net"
"slices"
"strings"
"github.com/AlexxIT/go2rtc/internal/api/ws"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/webrtc"
"github.com/AlexxIT/go2rtc/pkg/xnet"
pion "github.com/pion/webrtc/v3"
)
@@ -73,16 +74,21 @@ func FilterCandidate(candidate *pion.ICECandidate) bool {
return false
}
// remove any Docker-like IP from candidates
if ip := net.ParseIP(candidate.Address); ip != nil && xnet.Docker.Contains(ip) {
return false
}
// host candidate should be in the hosts list
if candidate.Typ == pion.ICECandidateTypeHost && filters.Candidates != nil {
if !slices.Contains(filters.Candidates, candidate.Address) {
if !core.Contains(filters.Candidates, candidate.Address) {
return false
}
}
if filters.Networks != nil {
networkType := NetworkType(candidate.Protocol.String(), candidate.Address)
if !slices.Contains(filters.Networks, networkType) {
if !core.Contains(filters.Networks, networkType) {
return false
}
}
+5 -1
View File
@@ -41,9 +41,11 @@ func streamsHandler(rawURL string) (core.Producer, error) {
// https://aws.amazon.com/kinesis/video-streams/
// https://docs.aws.amazon.com/kinesisvideostreams-webrtc-dg/latest/devguide/what-is-kvswebrtc.html
// https://github.com/orgs/awslabs/repositories?q=kinesis+webrtc
return kinesisClient(rawURL, query, "webrtc/kinesis")
return kinesisClient(rawURL, query, "webrtc/kinesis", nil)
} else if format == "openipc" {
return openIPCClient(rawURL, query)
} else if format == "switchbot" {
return switchbotClient(rawURL, query)
} else {
return go2rtcClient(rawURL)
}
@@ -54,6 +56,8 @@ func streamsHandler(rawURL string) (core.Producer, error) {
} else if format == "wyze" {
// https://github.com/mrlt8/docker-wyze-bridge
return wyzeClient(rawURL)
} else if format == "creality" {
return crealityClient(rawURL)
} else {
return whepClient(rawURL)
}
+110
View File
@@ -0,0 +1,110 @@
package webrtc
import (
"encoding/base64"
"encoding/json"
"io"
"net/http"
"strings"
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/webrtc"
)
// https://github.com/AlexxIT/go2rtc/issues/1600
func crealityClient(url string) (core.Producer, error) {
pc, err := PeerConnection(true)
if err != nil {
return nil, err
}
prod := webrtc.NewConn(pc)
prod.FormatName = "webrtc/creality"
prod.Mode = core.ModeActiveProducer
prod.Protocol = "http"
prod.URL = url
medias := []*core.Media{
{Kind: core.KindVideo, Direction: core.DirectionRecvonly},
{Kind: core.KindAudio, Direction: core.DirectionRecvonly},
}
// TODO: return webrtc.SessionDescription
offer, err := prod.CreateCompleteOffer(medias)
if err != nil {
return nil, err
}
body, err := offerToB64(offer)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", url, body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "plain/text")
// TODO: change http.DefaultClient settings
client := http.Client{Timeout: time.Second * 5000}
defer client.CloseIdleConnections()
res, err := client.Do(req)
if err != nil {
return nil, err
}
answer, err := answerFromB64(res.Body)
if err != nil {
return nil, err
}
if err = prod.SetAnswer(answer); err != nil {
return nil, err
}
return prod, nil
}
func offerToB64(sdp string) (io.Reader, error) {
// JS object
v := map[string]string{
"type": "offer",
"sdp": sdp,
}
// bytes
b, err := json.Marshal(v)
if err != nil {
return nil, err
}
// base64, why? who knows...
s := base64.StdEncoding.EncodeToString(b)
return strings.NewReader(s), nil
}
func answerFromB64(r io.Reader) (string, error) {
// base64
b, err := io.ReadAll(r)
if err != nil {
return "", err
}
// bytes
if b, err = base64.StdEncoding.DecodeString(string(b)); err != nil {
return "", err
}
// JS object
var v map[string]string
if err = json.Unmarshal(b, &v); err != nil {
return "", err
}
// string "v=0..."
return v["sdp"], nil
}
+29 -16
View File
@@ -34,7 +34,10 @@ func (k kinesisResponse) String() string {
return fmt.Sprintf("type=%s, payload=%s", k.Type, k.Payload)
}
func kinesisClient(rawURL string, query url.Values, format string) (core.Producer, error) {
func kinesisClient(
rawURL string, query url.Values, format string,
sdpOffer func(prod *webrtc.Conn, query url.Values) (any, error),
) (core.Producer, error) {
// 1. Connect to signalign server
conn, _, err := websocket.DefaultDialer.Dial(rawURL, nil)
if err != nil {
@@ -108,23 +111,33 @@ func kinesisClient(rawURL string, query url.Values, format string) (core.Produce
}
})
medias := []*core.Media{
{Kind: core.KindVideo, Direction: core.DirectionRecvonly},
{Kind: core.KindAudio, Direction: core.DirectionRecvonly},
var payload any
if sdpOffer == nil {
medias := []*core.Media{
{Kind: core.KindVideo, Direction: core.DirectionRecvonly},
{Kind: core.KindAudio, Direction: core.DirectionRecvonly},
}
// 4. Create offer
var offer string
if offer, err = prod.CreateOffer(medias); err != nil {
return nil, err
}
// 5. Send offer
payload = pion.SessionDescription{
Type: pion.SDPTypeOffer,
SDP: offer,
}
} else {
if payload, err = sdpOffer(prod, query); err != nil {
return nil, err
}
}
// 4. Create offer
offer, err := prod.CreateOffer(medias)
if err != nil {
return nil, err
}
// 5. Send offer
req.Action = "SDP_OFFER"
req.Payload, _ = json.Marshal(pion.SessionDescription{
Type: pion.SDPTypeOffer,
SDP: offer,
})
req.Payload, _ = json.Marshal(payload)
if err = conn.WriteJSON(req); err != nil {
return nil, err
}
@@ -218,5 +231,5 @@ func wyzeClient(rawURL string) (core.Producer, error) {
"ice_servers": []string{string(kvs.Servers)},
}
return kinesisClient(kvs.URL, query, "webrtc/wyze")
return kinesisClient(kvs.URL, query, "webrtc/wyze", nil)
}
+23 -2
View File
@@ -1,6 +1,7 @@
package webrtc
import (
"encoding/base64"
"encoding/json"
"io"
"net/http"
@@ -62,8 +63,8 @@ func syncHandler(w http.ResponseWriter, r *http.Request) {
// 2. application/sdp - receive/response SDP via WebRTC-HTTP Egress Protocol (WHEP)
// 3. other - receive/response raw SDP
func outputWebRTC(w http.ResponseWriter, r *http.Request) {
url := r.URL.Query().Get("src")
stream := streams.Get(url)
u := r.URL.Query().Get("src")
stream := streams.Get(u)
if stream == nil {
http.Error(w, api.StreamNotFound, http.StatusNotFound)
return
@@ -87,6 +88,21 @@ func outputWebRTC(w http.ResponseWriter, r *http.Request) {
}
offer = desc.SDP
case "application/x-www-form-urlencoded":
if err := r.ParseForm(); err != nil {
log.Error().Err(err).Caller().Send()
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
offerB64 := r.Form.Get("data")
b, err := base64.StdEncoding.DecodeString(offerB64)
if err != nil {
log.Error().Err(err).Caller().Send()
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
offer = string(b)
default:
body, err := io.ReadAll(r.Body)
if err != nil {
@@ -124,6 +140,11 @@ func outputWebRTC(w http.ResponseWriter, r *http.Request) {
}
err = json.NewEncoder(w).Encode(v)
case "application/x-www-form-urlencoded":
w.Header().Set("Content-Type", mediaType)
answerB64 := base64.StdEncoding.EncodeToString([]byte(answer))
_, err = w.Write([]byte(answerB64))
case MimeSDP:
w.Header().Set("Content-Type", mediaType)
w.WriteHeader(http.StatusCreated)
+40
View File
@@ -0,0 +1,40 @@
package webrtc
import (
"net/url"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/webrtc"
)
func switchbotClient(rawURL string, query url.Values) (core.Producer, error) {
return kinesisClient(rawURL, query, "webrtc/switchbot", func(prod *webrtc.Conn, query url.Values) (any, error) {
medias := []*core.Media{
{Kind: core.KindVideo, Direction: core.DirectionRecvonly},
}
offer, err := prod.CreateOffer(medias)
if err != nil {
return nil, err
}
v := struct {
Type string `json:"type"`
SDP string `json:"sdp"`
Resolution int `json:"resolution"`
PlayType int `json:"play_type"`
}{
Type: "offer",
SDP: offer,
}
switch query.Get("resolution") {
case "hd":
v.Resolution = 0
case "sd":
v.Resolution = 1
}
return v, nil
})
}
+33 -17
View File
@@ -24,7 +24,7 @@ func Init() {
} `yaml:"webrtc"`
}
cfg.Mod.Listen = ":8555/tcp"
cfg.Mod.Listen = ":8555"
cfg.Mod.IceServers = []pion.ICEServer{
{URLs: []string{"stun:stun.l.google.com:19302"}},
}
@@ -40,15 +40,17 @@ func Init() {
AddCandidate(network, candidate)
}
var err error
// create pionAPI with custom codecs list and custom network settings
serverAPI, err := webrtc.NewServerAPI(network, address, &filters)
serverAPI, err = webrtc.NewServerAPI(network, address, &filters)
if err != nil {
log.Error().Err(err).Caller().Send()
return
}
// use same API for WebRTC server and client if no address
clientAPI := serverAPI
clientAPI = serverAPI
if address != "" {
log.Info().Str("addr", cfg.Mod.Listen).Msg("[webrtc] listen")
@@ -81,11 +83,13 @@ func Init() {
streams.HandleFunc("webrtc", streamsHandler)
}
var serverAPI, clientAPI *pion.API
var log zerolog.Logger
var PeerConnection func(active bool) (*pion.PeerConnection, error)
func asyncHandler(tr *ws.Transport, msg *ws.Message) error {
func asyncHandler(tr *ws.Transport, msg *ws.Message) (err error) {
var stream *streams.Stream
var mode core.Mode
@@ -104,8 +108,30 @@ func asyncHandler(tr *ws.Transport, msg *ws.Message) error {
return errors.New(api.StreamNotFound)
}
var offer struct {
Type string `json:"type"`
SDP string `json:"sdp"`
ICEServers []pion.ICEServer `json:"ice_servers"`
}
// V2 - json/object exchange, V1 - raw SDP exchange
apiV2 := msg.Type == "webrtc"
if apiV2 {
if err = msg.Unmarshal(&offer); err != nil {
return err
}
} else {
offer.SDP = msg.String()
}
// create new PeerConnection instance
pc, err := PeerConnection(false)
var pc *pion.PeerConnection
if offer.ICEServers == nil {
pc, err = PeerConnection(false)
} else {
pc, err = serverAPI.NewPeerConnection(pion.Configuration{ICEServers: offer.ICEServers})
}
if err != nil {
log.Error().Err(err).Caller().Send()
return err
@@ -145,20 +171,10 @@ func asyncHandler(tr *ws.Transport, msg *ws.Message) error {
}
})
// V2 - json/object exchange, V1 - raw SDP exchange
apiV2 := msg.Type == "webrtc"
log.Trace().Msgf("[webrtc] offer:\n%s", offer.SDP)
// 1. SetOffer, so we can get remote client codecs
var offer string
if apiV2 {
offer = msg.GetString("sdp")
} else {
offer = msg.String()
}
log.Trace().Msgf("[webrtc] offer:\n%s", offer)
if err = conn.SetOffer(offer); err != nil {
if err = conn.SetOffer(offer.SDP); err != nil {
log.Warn().Err(err).Caller().Send()
return err
}
+38
View File
@@ -0,0 +1,38 @@
package webrtc
import (
"encoding/json"
"testing"
"github.com/AlexxIT/go2rtc/internal/api/ws"
pion "github.com/pion/webrtc/v3"
"github.com/stretchr/testify/require"
)
func TestWebRTCAPIv1(t *testing.T) {
raw := `{"type":"webrtc/offer","value":"v=0\n..."}`
msg := new(ws.Message)
err := json.Unmarshal([]byte(raw), msg)
require.Nil(t, err)
require.Equal(t, "v=0\n...", msg.String())
}
func TestWebRTCAPIv2(t *testing.T) {
raw := `{"type":"webrtc","value":{"type":"offer","sdp":"v=0\n...","ice_servers":[{"urls":["stun:stun.l.google.com:19302"]}]}}`
msg := new(ws.Message)
err := json.Unmarshal([]byte(raw), msg)
require.Nil(t, err)
var offer struct {
Type string `json:"type"`
SDP string `json:"sdp"`
ICEServers []pion.ICEServer `json:"ice_servers"`
}
err = msg.Unmarshal(&offer)
require.Nil(t, err)
require.Equal(t, "offer", offer.Type)
require.Equal(t, "v=0\n...", offer.SDP)
require.Equal(t, "stun:stun.l.google.com:19302", offer.ICEServers[0].URLs[0])
}
+2 -1
View File
@@ -2,9 +2,10 @@ package webtorrent
import (
"fmt"
"net/http"
"github.com/AlexxIT/go2rtc/pkg/webtorrent"
"github.com/gorilla/websocket"
"net/http"
)
var upgrader *websocket.Upgrader
+7 -1
View File
@@ -6,6 +6,7 @@ import (
"github.com/AlexxIT/go2rtc/internal/app"
"github.com/AlexxIT/go2rtc/internal/bubble"
"github.com/AlexxIT/go2rtc/internal/debug"
"github.com/AlexxIT/go2rtc/internal/doorbird"
"github.com/AlexxIT/go2rtc/internal/dvrip"
"github.com/AlexxIT/go2rtc/internal/echo"
"github.com/AlexxIT/go2rtc/internal/exec"
@@ -24,19 +25,21 @@ import (
"github.com/AlexxIT/go2rtc/internal/nest"
"github.com/AlexxIT/go2rtc/internal/ngrok"
"github.com/AlexxIT/go2rtc/internal/onvif"
"github.com/AlexxIT/go2rtc/internal/ring"
"github.com/AlexxIT/go2rtc/internal/roborock"
"github.com/AlexxIT/go2rtc/internal/rtmp"
"github.com/AlexxIT/go2rtc/internal/rtsp"
"github.com/AlexxIT/go2rtc/internal/srtp"
"github.com/AlexxIT/go2rtc/internal/streams"
"github.com/AlexxIT/go2rtc/internal/tapo"
"github.com/AlexxIT/go2rtc/internal/v4l2"
"github.com/AlexxIT/go2rtc/internal/webrtc"
"github.com/AlexxIT/go2rtc/internal/webtorrent"
"github.com/AlexxIT/go2rtc/pkg/shell"
)
func main() {
app.Version = "1.9.4"
app.Version = "1.9.9"
// 1. Core modules: app, api/ws, streams
@@ -78,10 +81,13 @@ func main() {
mpegts.Init() // mpegts passive source
roborock.Init() // roborock source
homekit.Init() // homekit source
ring.Init() // ring source
nest.Init() // nest source
bubble.Init() // bubble source
expr.Init() // expr source
gopro.Init() // gopro source
doorbird.Init() // doorbird source
v4l2.Init() // v4l2 source
// 6. Helper modules
-1
View File
@@ -9,7 +9,6 @@ import (
)
func IsADTS(b []byte) bool {
_ = b[1]
return len(b) > 7 && b[0] == 0xFF && b[1]&0xF6 == 0xF0
}
+9
View File
@@ -22,6 +22,15 @@ func RTPDepay(handler core.HandlerFunc) core.HandlerFunc {
//log.Printf("[RTP/AAC] units: %d, size: %4d, ts: %10d, %t", headersSize/2, len(packet.Payload), packet.Timestamp, packet.Marker)
if len(packet.Payload) < int(2+headersSize) {
// In very rare cases noname cameras may send data not according to the standard
// https://github.com/AlexxIT/go2rtc/issues/1328
if IsADTS(packet.Payload) {
clone := *packet
clone.Version = RTPPacketVersionAAC
clone.Timestamp = timestamp
clone.Payload = clone.Payload[ADTSHeaderSize:]
handler(&clone)
}
return
}
+33
View File
@@ -0,0 +1,33 @@
package aac
import (
"encoding/hex"
"testing"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
"github.com/stretchr/testify/require"
)
func TestBuggy_RTSP_AAC(t *testing.T) {
// https: //github.com/AlexxIT/go2rtc/issues/1328
payload, _ := hex.DecodeString("fff16080431ffc211ad4458aa309a1c0a8761a230502b7c74b2b5499252a010555e32e460128303c8ace4fd3260d654a424f7e7c65eddc96735fc6f1ac0edf94fdefa0e0bd6370da1c07b9c0e77a9d6e86b196a1ac7439dcafadcffcf6d89f60ac67f8884868e931383ad3e40cf5495470d1f606ef6f7624d285b951ebfa0e42641ab98f1371182b237d14f1bd16ad714fa2f1c6a7d23ebde7a0e34a2eca156a608a4caec49d9dca4b6fe2a09e9cdbf762c5b4148a3914abb7959c991228b0837b5988334b9fc18b8fac689b5ca1e4661573bbb8b253a86cae7ec14ace49969a9a76fd571ab6e650764cb59114d61dcedf07ac61b39e4ac66adebfd0d0ab45d518dd3c161049823f150864d977cf0855172ac8482e4b25fe911325d19617558c5405af74aff5492e4599bee53f2dbdf0503730af37078550f84c956b7ee89aae83c154fa2fa6e6792c5ddd5cd5cf6bb96bf055fee7f93bed59ffb039daee5ea7e5593cb194e9091e417c67d8f73026a6a6ae056e808f7c65c03d1b9197d3709ceb63bc7b979f7ba71df5e7c6395d99d6ea229000a6bc16fb4346d6b27d32f5d8d1200736d9366d59c0c9547210813b602473da9c46f9015bbb37594c1dd90cd6a36e96bd5d6a1445ab93c9e65505ec2c722bb4cc27a10600139a48c83594dde145253c386f6627d8c6e5102fe3828a590c709bc87f55b37e97d1ae72b017b09c6bb2c13299817bb45cc67318e10b6822075b97c6a03ec1c0")
packet := &rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: true,
SequenceNumber: 36944,
Timestamp: 4217191328,
SSRC: 12892774,
},
Payload: payload,
}
var size int
RTPDepay(func(packet *core.Packet) {
size = len(packet.Payload)
})(packet)
require.Equal(t, len(payload), size+ADTSHeaderSize)
}
+1 -1
View File
@@ -231,7 +231,7 @@ func (c *Client) Handle() error {
Header: rtp.Header{
Timestamp: core.Now90000(),
},
Payload: annexb.EncodeToAVCC(b[6:], false),
Payload: annexb.EncodeToAVCC(b[6:]),
}
c.videoTrack.WriteRTP(pkt)
} else {
+6 -1
View File
@@ -157,7 +157,12 @@ func UnmarshalCodec(md *sdp.MediaDescription, payloadType string) *Codec {
}
}
if c.Name == "" {
switch c.Name {
case "PCM":
// https://www.reddit.com/r/Hikvision/comments/17elxex/comment/k642g2r/
// check pkg/rtsp/rtsp_test.go TestHikvisionPCM
c.Name = CodecPCML
case "":
// https://en.wikipedia.org/wiki/RTP_payload_formats
switch payloadType {
case "0":
+5
View File
@@ -25,6 +25,7 @@ type Info interface {
SetSource(string)
SetURL(string)
WithRequest(*http.Request)
GetSource() string
}
// Connection just like webrtc.PeerConnection
@@ -123,6 +124,10 @@ func (c *Connection) WithRequest(r *http.Request) {
c.UserAgent = r.UserAgent()
}
func (c *Connection) GetSource() string {
return c.Source
}
// Create like os.Create, init Consumer with existing Transport
func Create(w io.Writer) (*Connection, error) {
return &Connection{Transport: w}, nil
+10 -2
View File
@@ -124,9 +124,13 @@ func MarshalSDP(name string, medias []*Media) ([]byte, error) {
codec := media.Codecs[0]
name := codec.Name
if name == CodecELD {
switch codec.Name {
case CodecELD:
name = CodecAAC
case CodecPCML:
name = CodecPCM // beacuse we using pcm.LittleToBig for RTSP server
default:
name = codec.Name
}
md := &sdp.MediaDescription{
@@ -137,6 +141,10 @@ func MarshalSDP(name string, medias []*Media) ([]byte, error) {
}
md.WithCodec(codec.PayloadType, name, codec.ClockRate, codec.Channels, codec.FmtpLine)
if media.Direction != "" {
md.WithPropertyAttribute(media.Direction)
}
if media.ID != "" {
md.WithValueAttribute("control", media.ID)
}
+43
View File
@@ -0,0 +1,43 @@
package core
// This code copied from go1.21 for backward support in go1.20.
// We need to support go1.20 for Windows 7
// Index returns the index of the first occurrence of v in s,
// or -1 if not present.
func Index[S ~[]E, E comparable](s S, v E) int {
for i := range s {
if v == s[i] {
return i
}
}
return -1
}
// Contains reports whether v is present in s.
func Contains[S ~[]E, E comparable](s S, v E) bool {
return Index(s, v) >= 0
}
type Ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 |
~string
}
// Max returns the maximal value in x. It panics if x is empty.
// For floating-point E, Max propagates NaNs (any NaN value in x
// forces the output to be NaN).
func Max[S ~[]E, E Ordered](x S) E {
if len(x) < 1 {
panic("slices.Max: empty list")
}
m := x[0]
for i := 1; i < len(x); i++ {
if x[i] > m {
m = x[i]
}
}
return m
}
+7 -4
View File
@@ -140,6 +140,7 @@ func (s *Sender) Start() {
s.done = make(chan struct{})
go func() {
// for range on nil chan is OK
for packet := range s.buf {
s.Output(packet)
}
@@ -148,7 +149,7 @@ func (s *Sender) Start() {
}
func (s *Sender) Wait() {
if done := s.done; s.done != nil {
if done := s.done; done != nil {
<-done
}
}
@@ -165,10 +166,12 @@ func (s *Sender) State() string {
func (s *Sender) Close() {
// close buffer if exists
if buf := s.buf; buf != nil {
s.buf = nil
defer close(buf)
s.mu.Lock()
if s.buf != nil {
close(s.buf) // exit from for range loop
s.buf = nil // prevent writing to closed chan
}
s.mu.Unlock()
s.Node.Close()
}
+53
View File
@@ -0,0 +1,53 @@
package core
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestSenser(t *testing.T) {
recv := make(chan *Packet) // blocking receiver
sender := NewSender(nil, &Codec{})
sender.Output = func(packet *Packet) {
recv <- packet
}
require.Equal(t, "new", sender.State())
sender.Start()
require.Equal(t, "connected", sender.State())
sender.Input(&Packet{})
sender.Input(&Packet{})
require.Equal(t, 2, sender.Packets)
require.Equal(t, 0, sender.Drops)
// important to read one before close
// because goroutine in Start() can run with nil chan
// it's OK in real life, but bad for test
_, ok := <-recv
require.True(t, ok)
sender.Close()
require.Equal(t, "closed", sender.State())
sender.Input(&Packet{})
require.Equal(t, 2, sender.Packets)
require.Equal(t, 1, sender.Drops)
// read 2nd
_, ok = <-recv
require.True(t, ok)
// read 3rd
select {
case <-recv:
ok = true
default:
ok = false
}
require.False(t, ok)
}
+93
View File
@@ -0,0 +1,93 @@
package doorbird
import (
"fmt"
"net"
"net/url"
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
)
type Client struct {
core.Connection
conn net.Conn
}
func Dial(rawURL string) (*Client, error) {
u, err := url.Parse(rawURL)
if err != nil {
return nil, err
}
user := u.User.Username()
pass, _ := u.User.Password()
if u.Port() == "" {
u.Host += ":80"
}
conn, err := net.DialTimeout("tcp", u.Host, core.ConnDialTimeout)
if err != nil {
return nil, err
}
s := fmt.Sprintf("POST /bha-api/audio-transmit.cgi?http-user=%s&http-password=%s HTTP/1.0\r\n", user, pass) +
"Content-Type: audio/basic\r\n" +
"Content-Length: 9999999\r\n" +
"Connection: Keep-Alive\r\n" +
"Cache-Control: no-cache\r\n" +
"\r\n"
_ = conn.SetWriteDeadline(time.Now().Add(core.ConnDeadline))
if _, err = conn.Write([]byte(s)); err != nil {
return nil, err
}
medias := []*core.Media{
{
Kind: core.KindAudio,
Direction: core.DirectionSendonly,
Codecs: []*core.Codec{
{Name: core.CodecPCMU, ClockRate: 8000},
},
},
}
return &Client{
core.Connection{
ID: core.NewID(),
FormatName: "doorbird",
Protocol: "http",
URL: rawURL,
Medias: medias,
Transport: conn,
},
conn,
}, nil
}
func (c *Client) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
return nil, core.ErrCantGetTrack
}
func (c *Client) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {
sender := core.NewSender(media, track.Codec)
sender.Handler = func(pkt *rtp.Packet) {
_ = c.conn.SetWriteDeadline(time.Now().Add(core.ConnDeadline))
if n, err := c.conn.Write(pkt.Payload); err == nil {
c.Send += n
}
}
sender.HandleRTP(track)
c.Senders = append(c.Senders, sender)
return nil
}
func (c *Client) Start() (err error) {
_, err = c.conn.Read(nil)
return
}
+2 -2
View File
@@ -53,7 +53,7 @@ func (c *Producer) Start() error {
packet := &rtp.Packet{
Header: rtp.Header{Timestamp: c.videoTS},
Payload: annexb.EncodeToAVCC(payload, false),
Payload: annexb.EncodeToAVCC(payload),
}
//log.Printf("[AVC] %v, len: %d, ts: %10d", h265.Types(payload), len(payload), packet.Timestamp)
@@ -146,7 +146,7 @@ func (c *Producer) probe() error {
c.videoTS = binary.LittleEndian.Uint32(ts)
c.videoDT = 90000 / uint32(fps)
payload := annexb.EncodeToAVCC(b[16:], false)
payload := annexb.EncodeToAVCC(b[16:])
c.addVideoTrack(b[4], payload)
case 0xFA: // audio
+27 -15
View File
@@ -140,23 +140,29 @@ func (c *Producer) probe() error {
// 1. Empty video/audio flag
// 2. MedaData without stereo key for AAC
// 3. Audio header after Video keyframe tag
waitType := []byte{TagData}
timeout := time.Now().Add(core.ProbeTimeout)
for len(waitType) != 0 && time.Now().Before(timeout) {
// OpenIPC camera (on old firmwares) sends:
// 1. Empty video/audio flag
// 2. No MetaData packet
// 3. Sends a video packet in more than 3 seconds
waitVideo := true
waitAudio := true
timeout := time.Now().Add(time.Second * 5)
for (waitVideo || waitAudio) && time.Now().Before(timeout) {
pkt, err := c.readPacket()
if err != nil {
return err
}
if i := bytes.IndexByte(waitType, pkt.PayloadType); i < 0 {
continue
} else {
waitType = append(waitType[:i], waitType[i+1:]...)
}
//log.Printf("%d %0.20s", pkt.PayloadType, pkt.Payload)
switch pkt.PayloadType {
case TagAudio:
if !waitAudio {
continue
}
_ = pkt.Payload[1] // bounds
codecID := pkt.Payload[0] >> 4 // SoundFormat
@@ -179,8 +185,13 @@ func (c *Producer) probe() error {
Codecs: []*core.Codec{codec},
}
c.Medias = append(c.Medias, media)
waitAudio = false
case TagVideo:
if !waitVideo {
continue
}
var codec *core.Codec
if isExHeader(pkt.Payload) {
@@ -213,19 +224,20 @@ func (c *Producer) probe() error {
Codecs: []*core.Codec{codec},
}
c.Medias = append(c.Medias, media)
waitVideo = false
case TagData:
if !bytes.Contains(pkt.Payload, []byte("onMetaData")) {
waitType = append(waitType, TagData)
continue
}
// Dahua cameras doesn't send videocodecid
if bytes.Contains(pkt.Payload, []byte("videocodecid")) ||
bytes.Contains(pkt.Payload, []byte("width")) ||
bytes.Contains(pkt.Payload, []byte("framerate")) {
waitType = append(waitType, TagVideo)
if !bytes.Contains(pkt.Payload, []byte("videocodecid")) &&
!bytes.Contains(pkt.Payload, []byte("width")) &&
!bytes.Contains(pkt.Payload, []byte("framerate")) {
waitVideo = false
}
if bytes.Contains(pkt.Payload, []byte("audiocodecid")) {
waitType = append(waitType, TagAudio)
if !bytes.Contains(pkt.Payload, []byte("audiocodecid")) {
waitAudio = false
}
}
}
+40 -44
View File
@@ -11,64 +11,60 @@ const startAUD = StartCode + "\x09\xF0"
const startAUDstart = startAUD + StartCode
// EncodeToAVCC
// will change original slice data!
// safeAppend should be used if original slice has useful data after end (part of other slice)
//
// FFmpeg MPEG-TS: 00000001 AUD 00000001 SPS 00000001 PPS 000001 IFrame
// FFmpeg H264: 00000001 SPS 00000001 PPS 000001 IFrame 00000001 PFrame
func EncodeToAVCC(b []byte, safeAppend bool) []byte {
const minSize = len(StartCode) + 1
// 1. Check frist "start code"
if len(b) < len(startAUDstart) || string(b[:len(StartCode)]) != StartCode {
return nil
}
// 2. Skip Access unit delimiter (AUD) from FFmpeg
if string(b[:len(startAUDstart)]) == startAUDstart {
b = b[6:]
}
// Reolink: 000001 AUD 000001 VPS 00000001 SPS 00000001 PPS 00000001 IDR 00000001 IDR
func EncodeToAVCC(annexb []byte) (avc []byte) {
var start int
for i, n := minSize, len(b)-minSize; i < n; {
// 3. Check "start code" (first 2 bytes)
if b[i] != 0 || b[i+1] != 0 {
i++
continue
}
avc = make([]byte, 0, len(annexb)+4) // init memory with little overhead
// 4. Check "start code" (3 bytes size or 4 bytes size)
if b[i+2] == 1 {
if safeAppend {
// protect original slice from "damage"
b = bytes.Clone(b)
safeAppend = false
for i := 0; ; i++ {
var offset int
if i+3 < len(annexb) {
// search next separator
if annexb[i] == 0 && annexb[i+1] == 0 {
if annexb[i+2] == 1 {
offset = 3 // 00 00 01
} else if annexb[i+2] == 0 && annexb[i+3] == 1 {
offset = 4 // 00 00 00 01
} else {
continue
}
} else {
continue
}
// convert start code from 3 bytes to 4 bytes
b = append(b, 0)
copy(b[i+1:], b[i:])
n++
} else if b[i+2] != 0 || b[i+3] != 1 {
i++
continue
} else {
i = len(annexb) // move i to data end
}
// 5. Set size for previous AU
size := uint32(i - start - len(StartCode))
binary.BigEndian.PutUint32(b[start:], size)
if start != 0 {
size := uint32(i - start)
avc = binary.BigEndian.AppendUint32(avc, size)
avc = append(avc, annexb[start:i]...)
}
start = i
// sometimes FFmpeg put separator at the end
if i += offset; i == len(annexb) {
break
}
i += minSize
if isAUD(annexb[i]) {
start = 0 // skip this NALU
} else {
start = i // save this position
}
}
// 6. Set size for last AU
size := uint32(len(b) - start - len(StartCode))
binary.BigEndian.PutUint32(b[start:], size)
return
}
return b
func isAUD(b byte) bool {
const h264 = 9
const h265 = 35 << 1
return b&0b0001_1111 == h264 || b&0b0111_1110 == h265
}
func DecodeAVCC(b []byte, safeClone bool) []byte {
File diff suppressed because one or more lines are too long
+4 -1
View File
@@ -22,7 +22,7 @@ func RTPDepay(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
buf := make([]byte, 0, 512*1024) // 512K
return func(packet *rtp.Packet) {
//log.Printf("[RTP] codec: %s, nalu: %2d, size: %6d, ts: %10d, pt: %2d, ssrc: %d, seq: %d, %v", track.Codec.Name, packet.Payload[0]&0x1F, len(packet.Payload), packet.Timestamp, packet.PayloadType, packet.SSRC, packet.SequenceNumber, packet.Marker)
//log.Printf("[RTP] codec: %s, nalu: %2d, size: %6d, ts: %10d, pt: %2d, ssrc: %d, seq: %d, %v", codec.Name, packet.Payload[0]&0x1F, len(packet.Payload), packet.Timestamp, packet.PayloadType, packet.SSRC, packet.SequenceNumber, packet.Marker)
payload, err := depack.Unmarshal(packet.Payload)
if len(payload) == 0 || err != nil {
@@ -68,6 +68,9 @@ func RTPDepay(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
payload = payload[i:]
continue
case NALUTypePFrame, NALUTypeSPS, NALUTypePPS: // pass
default:
return // skip any unknown NAL unit type
}
break
}
+1
View File
@@ -3,6 +3,7 @@ package h265
import (
"encoding/base64"
"encoding/binary"
"github.com/AlexxIT/go2rtc/pkg/core"
)
+2 -1
View File
@@ -2,8 +2,9 @@ package h265
import (
"encoding/binary"
"github.com/AlexxIT/go2rtc/pkg/h264"
"math"
"github.com/AlexxIT/go2rtc/pkg/h264"
)
//
+9
View File
@@ -2,12 +2,21 @@ package camera
import (
"encoding/base64"
"strings"
"testing"
"github.com/AlexxIT/go2rtc/pkg/hap"
"github.com/stretchr/testify/require"
)
func TestNilCharacter(t *testing.T) {
var res SetupEndpoints
char := &hap.Character{}
err := char.ReadTLV8(&res)
require.NotNil(t, err)
require.NotNil(t, strings.Contains(err.Error(), "can't read value"))
}
type testTLV8 struct {
name string
value string
+10 -3
View File
@@ -3,6 +3,7 @@ package hap
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
@@ -126,11 +127,17 @@ func (c *Character) Write(v any) (err error) {
// ReadTLV8 value to right struct
func (c *Character) ReadTLV8(v any) (err error) {
return tlv8.UnmarshalBase64(c.Value.(string), v)
if s, ok := c.Value.(string); ok {
return tlv8.UnmarshalBase64(s, v)
}
return fmt.Errorf("hap: can't read value: %v", v)
}
func (c *Character) ReadBool() bool {
return c.Value.(bool)
func (c *Character) ReadBool() (bool, error) {
if v, ok := c.Value.(bool); ok {
return v, nil
}
return false, fmt.Errorf("hap: can't read value: %v", c.Value)
}
func (c *Character) String() string {
+15
View File
@@ -235,3 +235,18 @@ func WriteResponse(w *bufio.Writer, statusCode int, contentType string, body []b
}
return w.Flush()
}
func WriteBackoff(rw *bufio.ReadWriter) error {
plainM2 := struct {
State byte `tlv8:"6"`
Error byte `tlv8:"7"`
}{
State: StateM2,
Error: 3, // BackoffError
}
body, err := tlv8.Marshal(plainM2)
if err != nil {
return err
}
return WriteResponse(rw.Writer, http.StatusOK, MimeTLV8, body)
}
+2 -1
View File
@@ -2,8 +2,9 @@ package hass
import (
"errors"
"github.com/gorilla/websocket"
"os"
"github.com/gorilla/websocket"
)
type API struct {
+1 -1
View File
@@ -3,7 +3,7 @@ package homekit
import (
"fmt"
"io"
"math/rand/v2"
"math/rand"
"net"
"time"
+2 -3
View File
@@ -2,7 +2,6 @@ package homekit
import (
"encoding/hex"
"slices"
"github.com/AlexxIT/go2rtc/pkg/aac"
"github.com/AlexxIT/go2rtc/pkg/core"
@@ -22,8 +21,8 @@ func videoToMedia(codecs []camera.VideoCodec) *core.Media {
for _, codec := range codecs {
for _, param := range codec.CodecParams {
// get best profile and level
profileID := slices.Max(param.ProfileID)
level := slices.Max(param.Level)
profileID := core.Max(param.ProfileID)
level := core.Max(param.Level)
profile := videoProfiles[profileID] + videoLevels[level]
mediaCodec := &core.Codec{
Name: videoCodecs[codec.CodecType],
+2 -2
View File
@@ -113,7 +113,7 @@ func (c *Producer) Start() error {
Header: rtp.Header{
Timestamp: uint32(ts * 90000),
},
Payload: annexb.EncodeToAVCC(body, false),
Payload: annexb.EncodeToAVCC(body),
}
video.WriteRTP(pkt)
}
@@ -168,7 +168,7 @@ func (c *Producer) probe() error {
}
waitVideo = false
body = annexb.EncodeToAVCC(body, false)
body = annexb.EncodeToAVCC(body)
codec := h264.AVCCToCodec(body)
media = &core.Media{
Kind: core.KindVideo,
+2 -2
View File
@@ -25,7 +25,7 @@ func Open(r io.Reader) (*Producer, error) {
return nil, err
}
buf = annexb.EncodeToAVCC(buf, false) // won't break original buffer
buf = annexb.EncodeToAVCC(buf) // won't break original buffer
var codec *core.Codec
var format string
@@ -82,7 +82,7 @@ func (c *Producer) Start() error {
if len(c.Receivers) > 0 {
pkt := &rtp.Packet{
Header: rtp.Header{Timestamp: core.Now90000()},
Payload: annexb.EncodeToAVCC(buf[:i], true),
Payload: annexb.EncodeToAVCC(buf[:i]),
}
c.Receivers[0].WriteRTP(pkt)
+10
View File
@@ -24,6 +24,7 @@ func NewKeyframe() *Keyframe {
Direction: core.DirectionSendonly,
Codecs: []*core.Codec{
{Name: core.CodecJPEG},
{Name: core.CodecRAW},
{Name: core.CodecH264},
{Name: core.CodecH265},
},
@@ -87,6 +88,15 @@ func (k *Keyframe) AddTrack(media *core.Media, _ *core.Codec, track *core.Receiv
if track.Codec.IsRTP() {
sender.Handler = mjpeg.RTPDepay(sender.Handler)
}
case core.CodecRAW:
sender.Handler = func(packet *rtp.Packet) {
if n, err := k.wr.Write(packet.Payload); err == nil {
k.Send += n
}
}
sender.Handler = mjpeg.Encoder(track.Codec, 5, sender.Handler)
}
sender.HandleRTP(track)
+12 -37
View File
@@ -10,10 +10,14 @@ import (
"syscall"
"time"
"github.com/AlexxIT/go2rtc/pkg/xnet"
"github.com/miekg/dns" // awesome library for parsing mDNS records
)
const ServiceHAP = "_hap._tcp.local." // HomeKit Accessory Protocol
const (
ServiceDNSSD = "_services._dns-sd._udp.local."
ServiceHAP = "_hap._tcp.local." // HomeKit Accessory Protocol
)
type ServiceEntry struct {
Name string `json:"name,omitempty"`
@@ -153,6 +157,7 @@ type Browser struct {
Service string
Addr net.Addr
Nets []*net.IPNet
Recv net.PacketConn
Sends []net.PacketConn
@@ -165,7 +170,9 @@ type Browser struct {
// Receiver will get multicast responses on senders requests.
func (b *Browser) ListenMulticastUDP() error {
// 1. Collect IPv4 interfaces
ip4s, err := InterfacesIP4()
nets, err := xnet.IPNets(func(ip net.IP) bool {
return !xnet.Docker.Contains(ip)
})
if err != nil {
return err
}
@@ -182,11 +189,12 @@ func (b *Browser) ListenMulticastUDP() error {
ctx := context.Background()
for _, ip4 := range ip4s {
conn, err := lc1.ListenPacket(ctx, "udp4", ip4.String()+":5353") // same port important
for _, ipn := range nets {
conn, err := lc1.ListenPacket(ctx, "udp4", ipn.IP.String()+":5353") // same port important
if err != nil {
continue
}
b.Nets = append(b.Nets, ipn)
b.Sends = append(b.Sends, conn)
}
@@ -364,36 +372,3 @@ func NewServiceEntries(msg *dns.Msg, ip net.IP) (entries []*ServiceEntry) {
return
}
func InterfacesIP4() ([]net.IP, error) {
intfs, err := net.Interfaces()
if err != nil {
return nil, err
}
var ips []net.IP
loop:
for _, intf := range intfs {
if intf.Flags&net.FlagUp == 0 || intf.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := intf.Addrs()
if err != nil {
continue
}
for _, addr := range addrs {
switch v := addr.(type) {
case *net.IPNet:
if ip := v.IP.To4(); ip != nil {
ips = append(ips, ip)
continue loop
}
}
}
}
return ips, nil
}
+2 -1
View File
@@ -1,8 +1,9 @@
package mdns
import (
"github.com/stretchr/testify/require"
"testing"
"github.com/stretchr/testify/require"
)
func TestDiscovery(t *testing.T) {
+101 -96
View File
@@ -20,7 +20,11 @@ func Serve(service string, entries []*ServiceEntry) error {
}
func (b *Browser) Serve(entries []*ServiceEntry) error {
var msg dns.Msg
names := make(map[string]*ServiceEntry, len(entries))
for _, entry := range entries {
name := entry.name() + "." + b.Service
names[name] = entry
}
buf := make([]byte, 1500)
for {
@@ -29,129 +33,130 @@ func (b *Browser) Serve(entries []*ServiceEntry) error {
break
}
if err = msg.Unpack(buf[:n]); err != nil {
var req dns.Msg // request
if err = req.Unpack(buf[:n]); err != nil {
continue
}
if !HasQuestionPTP(&msg, b.Service) {
// skip messages without Questions
if req.Question == nil {
continue
}
remoteIP := addr.(*net.UDPAddr).IP
localIP := MatchLocalIP(remoteIP)
localIP := b.MatchLocalIP(remoteIP)
// skip messages from unknown networks (can be docker network)
if localIP == nil {
continue
}
answer, err := NewDNSAnswer(entries, b.Service, localIP).Pack()
var res dns.Msg // response
for _, q := range req.Question {
if q.Qtype != dns.TypePTR || q.Qclass != dns.ClassINET {
continue
}
if q.Name == ServiceDNSSD {
AppendDNSSD(&res, b.Service)
} else if q.Name == b.Service {
for _, entry := range entries {
AppendEntry(&res, entry, b.Service, localIP)
}
} else if entry, ok := names[q.Name]; ok {
AppendEntry(&res, entry, b.Service, localIP)
}
}
if res.Answer == nil {
continue
}
res.MsgHdr.Response = true
res.MsgHdr.Authoritative = true
data, err := res.Pack()
if err != nil {
continue
}
for _, send := range b.Sends {
_, _ = send.WriteTo(answer, MulticastAddr)
_, _ = send.WriteTo(data, MulticastAddr)
}
}
return nil
}
func HasQuestionPTP(msg *dns.Msg, name string) bool {
for _, q := range msg.Question {
if q.Qtype == dns.TypePTR && q.Name == name {
return true
func (b *Browser) MatchLocalIP(remote net.IP) net.IP {
for _, ipn := range b.Nets {
if ipn.Contains(remote) {
return ipn.IP
}
}
return false
return nil
}
func NewDNSAnswer(entries []*ServiceEntry, service string, ip net.IP) *dns.Msg {
msg := dns.Msg{
MsgHdr: dns.MsgHdr{
Response: true,
Authoritative: true,
func AppendDNSSD(msg *dns.Msg, service string) {
msg.Answer = append(
msg.Answer,
&dns.PTR{
Hdr: dns.RR_Header{
Name: ServiceDNSSD, // _services._dns-sd._udp.local.
Rrtype: dns.TypePTR, // 12
Class: dns.ClassINET, // 1
Ttl: 4500,
},
Ptr: service, // _home-assistant._tcp.local.
},
}
for _, entry := range entries {
ptrName := entry.name() + "." + service
srvName := entry.name() + ".local."
msg.Answer = append(
msg.Answer,
&dns.PTR{
Hdr: dns.RR_Header{
Name: service,
Rrtype: dns.TypePTR,
Class: dns.ClassINET,
Ttl: 4500,
},
Ptr: ptrName,
},
)
msg.Extra = append(
msg.Extra,
&dns.TXT{
Hdr: dns.RR_Header{
Name: ptrName,
Rrtype: dns.TypeTXT,
Class: ClassCacheFlush,
Ttl: 4500,
},
Txt: entry.TXT(),
},
&dns.SRV{
Hdr: dns.RR_Header{
Name: ptrName,
Rrtype: dns.TypeSRV,
Class: ClassCacheFlush,
Ttl: 120,
Rdlength: 0,
},
Port: entry.Port,
Target: srvName,
},
&dns.A{
Hdr: dns.RR_Header{
Name: srvName,
Rrtype: dns.TypeA,
Class: ClassCacheFlush,
Ttl: 120,
Rdlength: 0,
},
A: ip,
},
)
}
return &msg
)
}
func MatchLocalIP(remote net.IP) net.IP {
intfs, err := net.Interfaces()
if err != nil {
return nil
}
func AppendEntry(msg *dns.Msg, entry *ServiceEntry, service string, ip net.IP) {
ptrName := entry.name() + "." + service
srvName := entry.name() + ".local."
for _, intf := range intfs {
if intf.Flags&net.FlagUp == 0 || intf.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := intf.Addrs()
if err != nil {
continue
}
for _, addr := range addrs {
switch v := addr.(type) {
case *net.IPNet:
if local := v.IP.To4(); local != nil && v.Contains(remote) {
return local
}
}
}
}
return nil
msg.Answer = append(
msg.Answer,
&dns.PTR{
Hdr: dns.RR_Header{
Name: service, // _home-assistant._tcp.local.
Rrtype: dns.TypePTR, // 12
Class: dns.ClassINET, // 1
Ttl: 4500,
},
Ptr: ptrName, // Home\ Assistant._home-assistant._tcp.local.
},
)
msg.Extra = append(
msg.Extra,
&dns.TXT{
Hdr: dns.RR_Header{
Name: ptrName, // Home\ Assistant._home-assistant._tcp.local.
Rrtype: dns.TypeTXT, // 16
Class: ClassCacheFlush, // 32769
Ttl: 4500,
},
Txt: entry.TXT(),
},
&dns.SRV{
Hdr: dns.RR_Header{
Name: ptrName, // Home\ Assistant._home-assistant._tcp.local.
Rrtype: dns.TypeSRV, // 33
Class: ClassCacheFlush, // 32769
Ttl: 120,
},
Port: entry.Port, // 8123
Target: srvName, // 963f1fa82b7142809711cebe7c826322.local.
},
&dns.A{
Hdr: dns.RR_Header{
Name: srvName, // 963f1fa82b7142809711cebe7c826322.local.
Rrtype: dns.TypeA, // 1
Class: ClassCacheFlush, // 32769
Ttl: 120,
},
A: ip,
},
)
}
+1 -1
View File
@@ -46,7 +46,7 @@ func (c *Consumer) AddTrack(media *core.Media, _ *core.Codec, track *core.Receiv
if track.Codec.IsRTP() {
sender.Handler = RTPDepay(sender.Handler)
} else if track.Codec.Name == core.CodecRAW {
sender.Handler = Encoder(track.Codec, sender.Handler)
sender.Handler = Encoder(track.Codec, 0, sender.Handler)
}
sender.HandleRTP(track)
+58 -14
View File
@@ -9,24 +9,38 @@ import (
"github.com/pion/rtp"
)
// FixJPEG - reencode JPEG if it has wrong header
//
// for example, this app produce "bad" images:
// https://github.com/jacksonliam/mjpg-streamer
//
// and they can't be uploaded to the Telegram servers:
// {"ok":false,"error_code":400,"description":"Bad Request: IMAGE_PROCESS_FAILED"}
func FixJPEG(b []byte) []byte {
// skip non-JPEG
if len(b) < 10 || b[0] != 0xFF || b[1] != 0xD8 {
return b
}
// skip if header OK for imghdr library
// https://docs.python.org/3/library/imghdr.html
if string(b[2:4]) == "\xFF\xDB" || string(b[6:10]) == "JFIF" || string(b[6:10]) == "Exif" {
if len(b) < 10 || b[0] != 0xFF || b[1] != markerSOI {
return b
}
// skip JPEG without app marker
if b[2] == 0xFF && b[3] == markerDQT {
return b
}
switch string(b[6:10]) {
case "JFIF", "Exif":
// skip if header OK for imghdr library
// - https://docs.python.org/3/library/imghdr.html
return b
case "AVI1":
// adds DHT tables to JPEG file before SOS marker
// useful when you want to save a JPEG frame from an MJPEG stream
// - https://github.com/image-rs/jpeg-decoder/issues/76
// - https://github.com/pion/mediadevices/pull/493
// - https://bugzilla.mozilla.org/show_bug.cgi?id=963907#c18
return InjectDHT(b)
}
// reencode JPEG if it has wrong header
//
// for example, this app produce "bad" images:
// https://github.com/jacksonliam/mjpg-streamer
//
// and they can't be uploaded to the Telegram servers:
// {"ok":false,"error_code":400,"description":"Bad Request: IMAGE_PROCESS_FAILED"}
img, err := jpeg.Decode(bytes.NewReader(b))
if err != nil {
return b
@@ -38,12 +52,19 @@ func FixJPEG(b []byte) []byte {
return buf.Bytes()
}
func Encoder(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
// Encoder convert YUV frame to Img.
// Support skipping empty frames, for example if USB cam needs time to start.
func Encoder(codec *core.Codec, skipEmpty int, handler core.HandlerFunc) core.HandlerFunc {
newImage := y4m.NewImage(codec.FmtpLine)
return func(packet *rtp.Packet) {
img := newImage(packet.Payload)
if skipEmpty != 0 && y4m.HasSameColor(img) {
skipEmpty--
return
}
buf := bytes.NewBuffer(nil)
if err := jpeg.Encode(buf, img, nil); err != nil {
return
@@ -54,3 +75,26 @@ func Encoder(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
handler(&clone)
}
}
const dhtSize = 432 // known size for 4 default tables
func InjectDHT(b []byte) []byte {
if bytes.Index(b, []byte{0xFF, markerDHT}) > 0 {
return b // already exist
}
i := bytes.Index(b, []byte{0xFF, markerSOS})
if i < 0 {
return b
}
dht := make([]byte, 0, dhtSize)
dht = MakeHuffmanHeaders(dht)
tmp := make([]byte, len(b)+dhtSize)
copy(tmp, b[:i])
copy(tmp[i:], dht)
copy(tmp[i+dhtSize:], b[i:])
return tmp
}
+10
View File
@@ -0,0 +1,10 @@
package mjpeg
const (
markerSOF = 0xC0 // Start Of Frame (Baseline Sequential)
markerSOI = 0xD8 // Start Of Image
markerEOI = 0xD9 // End Of Image
markerSOS = 0xDA // Start Of Scan
markerDQT = 0xDB // Define Quantization Table
markerDHT = 0xC4 // Define Huffman Table
)
+13
View File
@@ -0,0 +1,13 @@
package mjpeg
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestRFC2435(t *testing.T) {
lqt, cqt := MakeTables(71)
require.Equal(t, byte(9), lqt[0])
require.Equal(t, byte(10), cqt[0])
}
+59 -30
View File
@@ -2,21 +2,24 @@ package mjpeg
// RFC 2435. Appendix A
var jpeg_luma_quantizer = []byte{
16, 11, 10, 16, 24, 40, 51, 61,
12, 12, 14, 19, 26, 58, 60, 55,
14, 13, 16, 24, 40, 57, 69, 56,
14, 17, 22, 29, 51, 87, 80, 62,
18, 22, 37, 56, 68, 109, 103, 77,
24, 35, 55, 64, 81, 104, 113, 92,
49, 64, 78, 87, 103, 121, 120, 101,
72, 92, 95, 98, 112, 100, 103, 99,
// don't know why two tables are not respect RFC
// https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/rtpdec_jpeg.c
var jpeg_luma_quantizer = [64]byte{
16, 11, 12, 14, 12, 10, 16, 14,
13, 14, 18, 17, 16, 19, 24, 40,
26, 24, 22, 22, 24, 49, 35, 37,
29, 40, 58, 51, 61, 60, 57, 51,
56, 55, 64, 72, 92, 78, 64, 68,
87, 69, 55, 56, 80, 109, 81, 87,
95, 98, 103, 104, 103, 62, 77, 113,
121, 112, 100, 120, 92, 101, 103, 99,
}
var jpeg_chroma_quantizer = []byte{
17, 18, 24, 47, 99, 99, 99, 99,
18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99,
47, 66, 99, 99, 99, 99, 99, 99,
var jpeg_chroma_quantizer = [64]byte{
17, 18, 18, 24, 21, 24, 47, 26,
26, 47, 99, 66, 56, 66, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
@@ -37,7 +40,7 @@ func MakeTables(q byte) (lqt, cqt []byte) {
if q < 50 {
factor = 5000 / factor
} else if q > 99 {
} else {
factor = 200 - factor*2
}
@@ -140,43 +143,69 @@ var chm_ac_symbols = []byte{
func MakeHeaders(p []byte, t byte, w, h uint16, lqt, cqt []byte) []byte {
// Appendix A from https://www.rfc-editor.org/rfc/rfc2435
p = append(p, 0xFF, 0xD8)
p = append(p, 0xFF, markerSOI)
p = MakeQuantHeader(p, lqt, 0)
p = MakeQuantHeader(p, cqt, 1)
if t == 0 {
t = 0x21
t = 0x21 // hsamp = 2, vsamp = 1
} else {
t = 0x22
t = 0x22 // hsamp = 2, vsamp = 2
}
p = append(p,
0xFF, 0xC0, 0, 17, 8,
p = append(p, 0xFF, markerSOF,
0, 17, // size
8, // bits per component
byte(h>>8), byte(h&0xFF),
byte(w>>8), byte(w&0xFF),
3, 0, t, 0, 1, 0x11, 1, 2, 0x11, 1,
3, // number of components
0, // comp 0
t,
0, // quant table 0
1, // comp 1
0x11, // hsamp = 1, vsamp = 1
1, // quant table 1
2, // comp 2
0x11, // hsamp = 1, vsamp = 1
1, // quant table 1
)
p = MakeHuffmanHeader(p, lum_dc_codelens, lum_dc_symbols, 0, 0)
p = MakeHuffmanHeader(p, lum_ac_codelens, lum_ac_symbols, 0, 1)
p = MakeHuffmanHeader(p, chm_dc_codelens, chm_dc_symbols, 1, 0)
p = MakeHuffmanHeader(p, chm_ac_codelens, chm_ac_symbols, 1, 1)
p = MakeHuffmanHeaders(p)
return append(p, 0xFF, 0xDA, 0, 12, 3, 0, 0, 1, 0x11, 2, 0x11, 0, 63, 0)
return append(p, 0xFF, markerSOS,
0, 12, // size
3, // 3 components
0, // comp 0
0, // huffman table 0
1, // comp 1
0x11, // huffman table 1
2, // comp 2
0x11, // huffman table 1
0, // first DCT coeff
63, // last DCT coeff
0, // sucessive approx
)
}
func MakeQuantHeader(p []byte, qt []byte, tableNo byte) []byte {
p = append(p, 0xFF, 0xDB, 0, 67, tableNo)
p = append(p, 0xFF, markerDQT, 0, 67, tableNo)
return append(p, qt...)
}
func MakeHuffmanHeader(p, codelens, symbols []byte, tableNo, tableClass byte) []byte {
p = append(p,
0xFF, 0xC4, 0,
byte(3+len(codelens)+len(symbols)),
p = append(p, 0xFF, markerDHT,
0, byte(3+len(codelens)+len(symbols)), // size
(tableClass<<4)|tableNo,
)
p = append(p, codelens...)
return append(p, symbols...)
}
func MakeHuffmanHeaders(p []byte) []byte {
p = MakeHuffmanHeader(p, lum_dc_codelens, lum_dc_symbols, 0, 0)
p = MakeHuffmanHeader(p, lum_ac_codelens, lum_ac_symbols, 0, 1)
p = MakeHuffmanHeader(p, chm_dc_codelens, chm_dc_symbols, 1, 0)
p = MakeHuffmanHeader(p, chm_ac_codelens, chm_ac_symbols, 1, 1)
return p
}
+3 -2
View File
@@ -3,10 +3,11 @@ package mjpeg
import (
"bytes"
"encoding/binary"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
"image"
"image/jpeg"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
)
func RTPDepay(handlerFunc core.HandlerFunc) core.HandlerFunc {
+1 -1
View File
@@ -364,7 +364,7 @@ func (p *PES) GetPacket() (pkt *rtp.Packet) {
Header: rtp.Header{
PayloadType: p.StreamType,
},
Payload: annexb.EncodeToAVCC(p.Payload, false),
Payload: annexb.EncodeToAVCC(p.Payload),
}
if p.DTS != 0 {
+11 -7
View File
@@ -18,15 +18,21 @@ func Next(rd *bufio.Reader) (http.Header, []byte, error) {
return nil, nil, err
}
if strings.HasPrefix(s, "--") {
break
}
if s == "\r\n" {
continue
}
return nil, nil, errors.New("multipart: wrong boundary: " + s)
if !strings.HasPrefix(s, "--") {
return nil, nil, errors.New("multipart: wrong boundary: " + s)
}
// Foscam G2 has a awful implementation of MJPEG
// https://github.com/AlexxIT/go2rtc/issues/1258
if b, _ := rd.Peek(2); string(b) == "--" {
continue
}
break
}
tp := textproto.NewReader(rd)
@@ -50,7 +56,5 @@ func Next(rd *bufio.Reader) (http.Header, []byte, error) {
return nil, nil, err
}
_, _ = rd.Discard(2) // skip "\r\n"
return http.Header(header), buf, nil
}
+167 -29
View File
@@ -17,9 +17,15 @@ type API struct {
StreamProjectID string
StreamDeviceID string
StreamSessionID string
StreamExpiresAt time.Time
// WebRTC
StreamSessionID string
// RTSP
StreamToken string
StreamExtensionToken string
extendTimer *time.Timer
}
@@ -27,6 +33,12 @@ type Auth struct {
AccessToken string
}
type DeviceInfo struct {
Name string
DeviceID string
Protocols []string
}
var cache = map[string]*API{}
var cacheMu sync.Mutex
@@ -53,6 +65,8 @@ func NewAPI(clientID, clientSecret, refreshToken string) (*API, error) {
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return nil, errors.New("nest: wrong status: " + res.Status)
}
@@ -78,7 +92,7 @@ func NewAPI(clientID, clientSecret, refreshToken string) (*API, error) {
return api, nil
}
func (a *API) GetDevices(projectID string) (map[string]string, error) {
func (a *API) GetDevices(projectID string) ([]DeviceInfo, error) {
uri := "https://smartdevicemanagement.googleapis.com/v1/enterprises/" + projectID + "/devices"
req, err := http.NewRequest("GET", uri, nil)
if err != nil {
@@ -92,6 +106,7 @@ func (a *API) GetDevices(projectID string) (map[string]string, error) {
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return nil, errors.New("nest: wrong status: " + res.Status)
@@ -105,24 +120,30 @@ func (a *API) GetDevices(projectID string) (map[string]string, error) {
return nil, err
}
devices := map[string]string{}
devices := make([]DeviceInfo, 0, len(resv.Devices))
for _, device := range resv.Devices {
// only RTSP and WEB_RTC available (both supported)
if len(device.Traits.SdmDevicesTraitsCameraLiveStream.SupportedProtocols) == 0 {
continue
}
if device.Traits.SdmDevicesTraitsCameraLiveStream.SupportedProtocols[0] != "WEB_RTC" {
continue
}
i := strings.LastIndexByte(device.Name, '/')
if i <= 0 {
continue
}
name := device.Traits.SdmDevicesTraitsInfo.CustomName
devices[name] = device.Name[i+1:]
// Devices configured through the Nest app use the container/room name as opposed to the customName trait
if name == "" && len(device.ParentRelations) > 0 {
name = device.ParentRelations[0].DisplayName
}
devices = append(devices, DeviceInfo{
Name: name,
DeviceID: device.Name[i+1:],
Protocols: device.Traits.SdmDevicesTraitsCameraLiveStream.SupportedProtocols,
})
}
return devices, nil
@@ -157,6 +178,7 @@ func (a *API) ExchangeSDP(projectID, deviceID, offer string) (string, error) {
if err != nil {
return "", err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return "", errors.New("nest: wrong status: " + res.Status)
@@ -186,11 +208,137 @@ func (a *API) ExtendStream() error {
var reqv struct {
Command string `json:"command"`
Params struct {
MediaSessionID string `json:"mediaSessionId"`
MediaSessionID string `json:"mediaSessionId,omitempty"`
StreamExtensionToken string `json:"streamExtensionToken,omitempty"`
} `json:"params"`
}
reqv.Command = "sdm.devices.commands.CameraLiveStream.ExtendWebRtcStream"
reqv.Params.MediaSessionID = a.StreamSessionID
if a.StreamToken != "" {
// RTSP
reqv.Command = "sdm.devices.commands.CameraLiveStream.ExtendRtspStream"
reqv.Params.StreamExtensionToken = a.StreamExtensionToken
} else {
// WebRTC
reqv.Command = "sdm.devices.commands.CameraLiveStream.ExtendWebRtcStream"
reqv.Params.MediaSessionID = a.StreamSessionID
}
b, err := json.Marshal(reqv)
if err != nil {
return err
}
uri := "https://smartdevicemanagement.googleapis.com/v1/enterprises/" +
a.StreamProjectID + "/devices/" + a.StreamDeviceID + ":executeCommand"
req, err := http.NewRequest("POST", uri, bytes.NewReader(b))
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+a.Token)
client := &http.Client{Timeout: time.Second * 5000}
res, err := client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return errors.New("nest: wrong status: " + res.Status)
}
var resv struct {
Results struct {
ExpiresAt time.Time `json:"expiresAt"`
MediaSessionID string `json:"mediaSessionId"`
StreamExtensionToken string `json:"streamExtensionToken"`
StreamToken string `json:"streamToken"`
} `json:"results"`
}
if err = json.NewDecoder(res.Body).Decode(&resv); err != nil {
return err
}
a.StreamSessionID = resv.Results.MediaSessionID
a.StreamExpiresAt = resv.Results.ExpiresAt
a.StreamExtensionToken = resv.Results.StreamExtensionToken
a.StreamToken = resv.Results.StreamToken
return nil
}
func (a *API) GenerateRtspStream(projectID, deviceID string) (string, error) {
var reqv struct {
Command string `json:"command"`
Params struct{} `json:"params"`
}
reqv.Command = "sdm.devices.commands.CameraLiveStream.GenerateRtspStream"
b, err := json.Marshal(reqv)
if err != nil {
return "", err
}
uri := "https://smartdevicemanagement.googleapis.com/v1/enterprises/" +
projectID + "/devices/" + deviceID + ":executeCommand"
req, err := http.NewRequest("POST", uri, bytes.NewReader(b))
if err != nil {
return "", err
}
req.Header.Set("Authorization", "Bearer "+a.Token)
client := &http.Client{Timeout: time.Second * 5000}
res, err := client.Do(req)
if err != nil {
return "", err
}
if res.StatusCode != 200 {
return "", errors.New("nest: wrong status: " + res.Status)
}
var resv struct {
Results struct {
StreamURLs map[string]string `json:"streamUrls"`
StreamExtensionToken string `json:"streamExtensionToken"`
StreamToken string `json:"streamToken"`
ExpiresAt time.Time `json:"expiresAt"`
} `json:"results"`
}
if err = json.NewDecoder(res.Body).Decode(&resv); err != nil {
return "", err
}
if _, ok := resv.Results.StreamURLs["rtspUrl"]; !ok {
return "", errors.New("nest: failed to generate rtsp url")
}
a.StreamProjectID = projectID
a.StreamDeviceID = deviceID
a.StreamToken = resv.Results.StreamToken
a.StreamExtensionToken = resv.Results.StreamExtensionToken
a.StreamExpiresAt = resv.Results.ExpiresAt
return resv.Results.StreamURLs["rtspUrl"], nil
}
func (a *API) StopRTSPStream() error {
if a.StreamProjectID == "" || a.StreamDeviceID == "" {
return errors.New("nest: tried to stop rtsp stream without a project or device ID")
}
var reqv struct {
Command string `json:"command"`
Params struct {
StreamExtensionToken string `json:"streamExtensionToken"`
} `json:"params"`
}
reqv.Command = "sdm.devices.commands.CameraLiveStream.StopRtspStream"
reqv.Params.StreamExtensionToken = a.StreamExtensionToken
b, err := json.Marshal(reqv)
if err != nil {
@@ -216,19 +364,10 @@ func (a *API) ExtendStream() error {
return errors.New("nest: wrong status: " + res.Status)
}
var resv struct {
Results struct {
ExpiresAt time.Time `json:"expiresAt"`
MediaSessionID string `json:"mediaSessionId"`
} `json:"results"`
}
if err = json.NewDecoder(res.Body).Decode(&resv); err != nil {
return err
}
a.StreamSessionID = resv.Results.MediaSessionID
a.StreamExpiresAt = resv.Results.ExpiresAt
a.StreamProjectID = ""
a.StreamDeviceID = ""
a.StreamExtensionToken = ""
a.StreamToken = ""
return nil
}
@@ -261,10 +400,10 @@ type Device struct {
//SdmDevicesTraitsCameraClipPreview struct {
//} `json:"sdm.devices.traits.CameraClipPreview"`
} `json:"traits"`
//ParentRelations []struct {
// Parent string `json:"parent"`
// DisplayName string `json:"displayName"`
//} `json:"parentRelations"`
ParentRelations []struct {
Parent string `json:"parent"`
DisplayName string `json:"displayName"`
} `json:"parentRelations"`
}
func (a *API) StartExtendStreamTimer() {
@@ -277,7 +416,6 @@ func (a *API) StartExtendStreamTimer() {
duration = time.Until(a.StreamExpiresAt.Add(-30 * time.Second))
a.extendTimer.Reset(duration)
})
}
func (a *API) StopExtendStreamTimer() {
+71 -13
View File
@@ -3,18 +3,25 @@ package nest
import (
"errors"
"net/url"
"strings"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/rtsp"
"github.com/AlexxIT/go2rtc/pkg/webrtc"
pion "github.com/pion/webrtc/v3"
)
type Client struct {
type WebRTCClient struct {
conn *webrtc.Conn
api *API
}
func Dial(rawURL string) (*Client, error) {
type RTSPClient struct {
conn *rtsp.Conn
api *API
}
func Dial(rawURL string) (core.Producer, error) {
u, err := url.Parse(rawURL)
if err != nil {
return nil, err
@@ -36,6 +43,42 @@ func Dial(rawURL string) (*Client, error) {
return nil, err
}
protocols := strings.Split(query.Get("protocols"), ",")
if len(protocols) > 0 && protocols[0] == "RTSP" {
return rtspConn(nestAPI, rawURL, projectID, deviceID)
}
// Default to WEB_RTC for backwards compataiility
return rtcConn(nestAPI, rawURL, projectID, deviceID)
}
func (c *WebRTCClient) GetMedias() []*core.Media {
return c.conn.GetMedias()
}
func (c *WebRTCClient) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
return c.conn.GetTrack(media, codec)
}
func (c *WebRTCClient) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {
return c.conn.AddTrack(media, codec, track)
}
func (c *WebRTCClient) Start() error {
c.api.StartExtendStreamTimer()
return c.conn.Start()
}
func (c *WebRTCClient) Stop() error {
c.api.StopExtendStreamTimer()
return c.conn.Stop()
}
func (c *WebRTCClient) MarshalJSON() ([]byte, error) {
return c.conn.MarshalJSON()
}
func rtcConn(nestAPI *API, rawURL, projectID, deviceID string) (*WebRTCClient, error) {
rtcAPI, err := webrtc.NewAPI()
if err != nil {
return nil, err
@@ -77,31 +120,46 @@ func Dial(rawURL string) (*Client, error) {
return nil, err
}
return &Client{conn: conn, api: nestAPI}, nil
return &WebRTCClient{conn: conn, api: nestAPI}, nil
}
func (c *Client) GetMedias() []*core.Media {
return c.conn.GetMedias()
func rtspConn(nestAPI *API, rawURL, projectID, deviceID string) (*RTSPClient, error) {
rtspURL, err := nestAPI.GenerateRtspStream(projectID, deviceID)
if err != nil {
return nil, err
}
rtspClient := rtsp.NewClient(rtspURL)
if err := rtspClient.Dial(); err != nil {
return nil, err
}
if err := rtspClient.Describe(); err != nil {
return nil, err
}
return &RTSPClient{conn: rtspClient, api: nestAPI}, nil
}
func (c *Client) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
func (c *RTSPClient) GetMedias() []*core.Media {
result := c.conn.GetMedias()
return result
}
func (c *RTSPClient) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
return c.conn.GetTrack(media, codec)
}
func (c *Client) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {
return c.conn.AddTrack(media, codec, track)
}
func (c *Client) Start() error {
func (c *RTSPClient) Start() error {
c.api.StartExtendStreamTimer()
return c.conn.Start()
}
func (c *Client) Stop() error {
func (c *RTSPClient) Stop() error {
c.api.StopRTSPStream()
c.api.StopExtendStreamTimer()
return c.conn.Stop()
}
func (c *Client) MarshalJSON() ([]byte, error) {
func (c *RTSPClient) MarshalJSON() ([]byte, error) {
return c.conn.MarshalJSON()
}
+2 -1
View File
@@ -3,10 +3,11 @@ package ngrok
import (
"bufio"
"encoding/json"
"github.com/AlexxIT/go2rtc/pkg/core"
"io"
"os/exec"
"strings"
"github.com/AlexxIT/go2rtc/pkg/core"
)
type Ngrok struct {
+38
View File
@@ -0,0 +1,38 @@
## Profiles
- Profile A - For access control configuration
- Profile C - For door control and event management
- Profile S - For basic video streaming
- Video streaming and configuration
- Profile T - For advanced video streaming
- H.264 / H.265 video compression
- Imaging settings
- Motion alarm and tampering events
- Metadata streaming
- Bi-directional audio
## Services
https://www.onvif.org/profiles/specifications/
- https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl
- https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl
- https://www.onvif.org/ver10/media/wsdl/media.wsdl
## TMP
| | Dahua | Reolink | TP-Link |
|------------------------|---------|---------|---------|
| GetCapabilities | no auth | no auth | no auth |
| GetServices | no auth | no auth | no auth |
| GetServiceCapabilities | no auth | no auth | auth |
| GetSystemDateAndTime | no auth | no auth | no auth |
| GetNetworkInterfaces | auth | auth | auth |
| GetDeviceInformation | auth | auth | auth |
| GetProfiles | auth | auth | auth |
| GetScopes | auth | auth | auth |
- Dahua - onvif://192.168.10.90:80
- Reolink - onvif://192.168.10.92:8000
- TP-Link - onvif://192.168.10.91:2020/onvif/device_service
-
+29 -87
View File
@@ -2,8 +2,6 @@ package onvif
import (
"bytes"
"crypto/sha1"
"encoding/base64"
"errors"
"html"
"io"
@@ -12,8 +10,6 @@ import (
"regexp"
"strings"
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
)
const PathDevice = "/onvif/device_service"
@@ -41,7 +37,7 @@ func NewClient(rawURL string) (*Client, error) {
client.deviceURL = baseURL + u.Path
}
b, err := client.GetCapabilities()
b, err := client.DeviceRequest(DeviceGetCapabilities)
if err != nil {
return nil, err
}
@@ -95,7 +91,7 @@ func (c *Client) GetURI() (string, error) {
}
func (c *Client) GetName() (string, error) {
b, err := c.GetDeviceInformation()
b, err := c.DeviceRequest(DeviceGetDeviceInformation)
if err != nil {
return "", err
}
@@ -104,7 +100,7 @@ func (c *Client) GetName() (string, error) {
}
func (c *Client) GetProfilesTokens() ([]string, error) {
b, err := c.GetProfiles()
b, err := c.MediaRequest(MediaGetProfiles)
if err != nil {
return nil, err
}
@@ -127,86 +123,56 @@ func (c *Client) HasSnapshots() bool {
return strings.Contains(string(b), `SnapshotUri="true"`)
}
func (c *Client) GetCapabilities() ([]byte, error) {
func (c *Client) GetProfile(token string) ([]byte, error) {
return c.Request(
c.deviceURL,
`<tds:GetCapabilities xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:Category>All</tds:Category>
</tds:GetCapabilities>`,
c.mediaURL, `<trt:GetProfile><trt:ProfileToken>`+token+`</trt:ProfileToken></trt:GetProfile>`,
)
}
func (c *Client) GetNetworkInterfaces() ([]byte, error) {
return c.Request(
c.deviceURL, `<tds:GetNetworkInterfaces xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>`,
)
}
func (c *Client) GetDeviceInformation() ([]byte, error) {
return c.Request(
c.deviceURL, `<tds:GetDeviceInformation xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>`,
)
}
func (c *Client) GetProfiles() ([]byte, error) {
return c.Request(
c.mediaURL, `<trt:GetProfiles xmlns:trt="http://www.onvif.org/ver10/media/wsdl"/>`,
)
func (c *Client) GetVideoSourceConfiguration(token string) ([]byte, error) {
return c.Request(c.mediaURL, `<trt:GetVideoSourceConfiguration>
<trt:ConfigurationToken>`+token+`</trt:ConfigurationToken>
</trt:GetVideoSourceConfiguration>`)
}
func (c *Client) GetStreamUri(token string) ([]byte, error) {
return c.Request(
c.mediaURL,
`<trt:GetStreamUri xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema">
return c.Request(c.mediaURL, `<trt:GetStreamUri>
<trt:StreamSetup>
<tt:Stream>RTP-Unicast</tt:Stream>
<tt:Transport><tt:Protocol>RTSP</tt:Protocol></tt:Transport>
</trt:StreamSetup>
<trt:ProfileToken>`+token+`</trt:ProfileToken>
</trt:GetStreamUri>`,
)
</trt:GetStreamUri>`)
}
func (c *Client) GetSnapshotUri(token string) ([]byte, error) {
return c.Request(
c.imaginURL,
`<trt:GetSnapshotUri xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
<trt:ProfileToken>`+token+`</trt:ProfileToken>
</trt:GetSnapshotUri>`,
)
}
func (c *Client) GetSystemDateAndTime() ([]byte, error) {
return c.Request(
c.deviceURL, `<tds:GetSystemDateAndTime xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>`,
c.imaginURL, `<trt:GetSnapshotUri><trt:ProfileToken>`+token+`</trt:ProfileToken></trt:GetSnapshotUri>`,
)
}
func (c *Client) GetServiceCapabilities() ([]byte, error) {
// some cameras answer GetServiceCapabilities for media only for path = "/onvif/media"
return c.Request(
c.mediaURL, `<trt:GetServiceCapabilities xmlns:trt="http://www.onvif.org/ver10/media/wsdl"/>`,
c.mediaURL, `<trt:GetServiceCapabilities />`,
)
}
func (c *Client) SystemReboot() ([]byte, error) {
return c.Request(
c.deviceURL, `<tds:SystemReboot xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>`,
)
func (c *Client) DeviceRequest(operation string) ([]byte, error) {
switch operation {
case DeviceGetServices:
operation = `<tds:GetServices><tds:IncludeCapability>true</tds:IncludeCapability></tds:GetServices>`
case DeviceGetCapabilities:
operation = `<tds:GetCapabilities><tds:Category>All</tds:Category></tds:GetCapabilities>`
default:
operation = `<tds:` + operation + `/>`
}
return c.Request(c.deviceURL, operation)
}
func (c *Client) GetServices() ([]byte, error) {
return c.Request(
c.deviceURL, `<tds:GetServices xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:IncludeCapability>true</tds:IncludeCapability>
</tds:GetServices>`,
)
}
func (c *Client) GetScopes() ([]byte, error) {
return c.Request(
c.deviceURL, `<tds:GetScopes xmlns:tds="http://www.onvif.org/ver10/device/wsdl" />`,
)
func (c *Client) MediaRequest(operation string) ([]byte, error) {
operation = `<trt:` + operation + `/>`
return c.Request(c.mediaURL, operation)
}
func (c *Client) Request(url, body string) ([]byte, error) {
@@ -214,35 +180,11 @@ func (c *Client) Request(url, body string) ([]byte, error) {
return nil, errors.New("onvif: unsupported service")
}
buf := bytes.NewBuffer(nil)
buf.WriteString(
`<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">`,
)
if user := c.url.User; user != nil {
nonce := core.RandString(16, 36)
created := time.Now().UTC().Format(time.RFC3339Nano)
pass, _ := user.Password()
h := sha1.New()
h.Write([]byte(nonce + created + pass))
buf.WriteString(`<s:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>` + user.Username() + `</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">` + base64.StdEncoding.EncodeToString(h.Sum(nil)) + `</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">` + base64.StdEncoding.EncodeToString([]byte(nonce)) + `</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">` + created + `</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</s:Header>`)
}
buf.WriteString(`<s:Body>` + body + `</s:Body></s:Envelope>`)
e := NewEnvelopeWithUser(c.url.User)
e.Append(body)
client := &http.Client{Timeout: time.Second * 5000}
res, err := client.Post(url, `application/soap+xml;charset=utf-8`, buf)
res, err := client.Post(url, `application/soap+xml;charset=utf-8`, bytes.NewReader(e.Bytes()))
if err != nil {
return nil, err
}
+79
View File
@@ -0,0 +1,79 @@
package onvif
import (
"crypto/sha1"
"encoding/base64"
"fmt"
"net/url"
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
)
type Envelope struct {
buf []byte
}
const (
prefix1 = `<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
`
prefix2 = `<s:Body>
`
suffix = `
</s:Body>
</s:Envelope>`
)
func NewEnvelope() *Envelope {
e := &Envelope{buf: make([]byte, 0, 1024)}
e.Append(prefix1, prefix2)
return e
}
func NewEnvelopeWithUser(user *url.Userinfo) *Envelope {
if user == nil {
return NewEnvelope()
}
nonce := core.RandString(16, 36)
created := time.Now().UTC().Format(time.RFC3339Nano)
pass, _ := user.Password()
h := sha1.New()
h.Write([]byte(nonce + created + pass))
e := &Envelope{buf: make([]byte, 0, 1024)}
e.Append(prefix1)
e.Appendf(`<s:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>%s</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%s</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%s</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%s</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</s:Header>
`,
user.Username(),
base64.StdEncoding.EncodeToString(h.Sum(nil)),
base64.StdEncoding.EncodeToString([]byte(nonce)),
created)
e.Append(prefix2)
return e
}
func (e *Envelope) Append(args ...string) {
for _, s := range args {
e.buf = append(e.buf, s...)
}
}
func (e *Envelope) Appendf(format string, args ...any) {
e.buf = fmt.Appendf(e.buf, format, args...)
}
func (e *Envelope) Bytes() []byte {
return append(e.buf, suffix...)
}
+24 -1
View File
@@ -1,6 +1,7 @@
package onvif
import (
"fmt"
"net"
"regexp"
"strconv"
@@ -11,7 +12,7 @@ import (
)
func FindTagValue(b []byte, tag string) string {
re := regexp.MustCompile(`(?s)[:<]` + tag + `>([^<]+)`)
re := regexp.MustCompile(`(?s)<(?:\w+:)?` + tag + `\b[^>]*>([^<]+)`)
m := re.FindSubmatch(b)
if len(m) != 2 {
return ""
@@ -106,3 +107,25 @@ func atoi(s string) int {
}
return i
}
func GetPosixTZ(current time.Time) string {
// Thanks to https://github.com/Path-Variable/go-posix-time
_, offset := current.Zone()
if current.IsDST() {
_, end := current.ZoneBounds()
endPlus1 := end.Add(time.Hour * 25)
_, offset = endPlus1.Zone()
}
var prefix string
if offset < 0 {
prefix = "GMT+"
offset = -offset / 60
} else {
prefix = "GMT-"
offset = offset / 60
}
return prefix + fmt.Sprintf("%02d:%02d", offset/60, offset%60)
}

Some files were not shown because too many files have changed in this diff Show More