diff --git a/README.md b/README.md index f69425ec..22f4a052 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,20 @@ Ultimate camera streaming application with support for RTSP, WebRTC, HomeKit, FF - [two-way audio](#two-way-audio) for some cameras - can be [integrated to](#module-api) any smart home platform or be used as [standalone app](#go2rtc-binary) +**Supported Formats** - describes the communication API: authorization, encryption, command set, structure of media packets + +- devices: `alsa` (Linux audio), `v4l2` (Linux video) +- files: `adts`, `flv`, `h264`, `hevc`, `hls`, `mjpeg`, `mpegts`, `mp4`, `wav` +- network (public and well known): `mpjpeg`, `onvif`, `rtmp`, `rtp`, `rtsp`, `webrtc`, `y2m` (yuv4mpegpipe) +- network (private and exclusive): `bubble`, `doorbird`, `dvrip`, `eseecloud`, `gopro`, `hass` (Home Assistant), `homekit` (Apple), `isapi` (Hikvision), `kasa` (TP-Link), `nest` (Google), `ring`, `roborock`, `tapo` and `vigi` (TP-Link), `tuya`, `webtorrent`, `xiaomi` (Mi Home) +- webrtc related: `creality`, `kinesis` (Amazon), `openipc`, `switchbot`, `whep`, `whip`, `wyze` +- other: `ascii`, `echo`, `exec`, `expr`, `ffmpeg` + +**Supported Protocols** - describes the transport for data transmission + +- public: `http`, `pipe`, `rtmp`, `rtsp`, `tcp`, `udp`, `webrtc`, `ws` (WebSocket) +- private: `cs2` (PPPP), `hap` and `hds` (HomeKit), `tutk` (P2P) + **Inspired by:** - series of streaming projects from [@deepch](https://github.com/deepch) @@ -138,6 +152,8 @@ Download binary for your OS from [latest release](https://github.com/AlexxIT/go2 Don't forget to fix the rights `chmod +x go2rtc_xxx_xxx` on Linux and Mac. +PS. The application is compiled with the latest versions of the Go language for maximum speed and security. Therefore, the [minimum OS versions](https://go.dev/wiki/MinimumRequirements) depend on the Go language. + ### go2rtc: Docker The Docker container [`alexxit/go2rtc`](https://hub.docker.com/r/alexxit/go2rtc) supports multiple architectures including `amd64`, `386`, `arm64`, and `arm`. This container offers the same functionality as the [Home Assistant Add-on](#go2rtc-home-assistant-add-on) but is designed to operate independently of Home Assistant. It comes preinstalled with [FFmpeg](#source-ffmpeg) and [Python](#source-echo). diff --git a/pkg/README.md b/pkg/README.md index e2759638..479dcce3 100644 --- a/pkg/README.md +++ b/pkg/README.md @@ -10,35 +10,49 @@ Some formats and protocols go2rtc supports exclusively. They have no equivalent - Codecs can be incoming - **Recevers codecs** - Codecs can be outgoing (two way audio) - **Senders codecs** -| Format | Source protocols | Ingress protocols | Recevers codecs | Senders codecs | Example | -|--------------|------------------|-------------------|------------------------------|--------------------|---------------| -| adts | http,tcp,pipe | http | aac | | `http:` | -| alsa | pipe | | | pcm | `alsa:` | -| bubble | http | | h264,hevc,pcm_alaw | | `bubble:` | -| dvrip | tcp | | h264,hevc,pcm_alaw,pcm_mulaw | pcm_alaw | `dvrip:` | -| flv | http,tcp,pipe | http | h264,aac | | `http:` | -| gopro | http+udp | | TODO | | `gopro:` | -| hass/webrtc | ws+udp,tcp | | TODO | | `hass:` | -| hls/mpegts | http | | h264,h265,aac,opus | | `http:` | -| homekit | homekit+udp | | h264,eld* | | `homekit:` | -| isapi | http | | | pcm_alaw,pcm_mulaw | `isapi:` | -| ivideon | ws | | h264 | | `ivideon:` | -| kasa | http | | h264,pcm_mulaw | | `kasa:` | -| h264 | http,tcp,pipe | http | h264 | | `http:` | -| hevc | http,tcp,pipe | http | hevc | | `http:` | -| mjpeg | http,tcp,pipe | http | mjpeg | | `http:` | -| mpjpeg | http,tcp,pipe | http | mjpeg | | `http:` | -| mpegts | http,tcp,pipe | http | h264,hevc,aac,opus | | `http:` | -| nest/webrtc | http+udp | | TODO | | `nest:` | -| roborock | mqtt+udp | | h264,opus | opus | `roborock:` | -| rtmp | rtmp | rtmp | h264,aac | | `rtmp:` | -| rtsp | rtsp+tcp,ws | rtsp+tcp | h264,hevc,aac,pcm*,opus | pcm*,opus | `rtsp:` | -| stdin | pipe | | | pcm_alaw,pcm_mulaw | `stdin:` | -| tapo | http | | h264,pcma | pcm_alaw | `tapo:` | -| wav | http,tcp,pipe | http | pcm_alaw,pcm_mulaw | | `http:` | -| webrtc* | TODO | TODO | h264,pcm_alaw,pcm_mulaw,opus | pcm_alaw,pcm_mulaw | `webrtc:` | -| webtorrent | TODO | TODO | TODO | TODO | `webtorrent:` | -| yuv4mpegpipe | http,tcp,pipe | http | rawvideo | | `http:` | +| Group | Format | Protocols | Ingress | Recevers codecs | Senders codecs | Example | +|------------|--------------|-----------------|---------|---------------------------------|---------------------|---------------| +| Devices | alsa | pipe | | | pcm | `alsa:` | +| Devices | v4l2 | pipe | | | | `v4l2:` | +| Files | adts | http, tcp, pipe | http | aac | | `http:` | +| Files | flv | http, tcp, pipe | http | h264, aac | | `http:` | +| Files | h264 | http, tcp, pipe | http | h264 | | `http:` | +| Files | hevc | http, tcp, pipe | http | hevc | | `http:` | +| Files | hls | http | | h264, h265, aac, opus | | `http:` | +| Files | mjpeg | http, tcp, pipe | http | mjpeg | | `http:` | +| Files | mpegts | http, tcp, pipe | http | h264, hevc, aac, opus | | `http:` | +| Files | wav | http, tcp, pipe | http | pcm_alaw, pcm_mulaw | | `http:` | +| Net (pub) | mpjpeg | http, tcp, pipe | http | mjpeg | | `http:` | +| Net (pub) | onvif | rtsp | | | | `onvif:` | +| Net (pub) | rtmp | rtmp | rtmp | h264, aac | | `rtmp:` | +| Net (pub) | rtsp | rtsp, ws | rtsp | h264, hevc, aac, pcm*, opus | pcm*, opus | `rtsp:` | +| Net (pub) | webrtc* | webrtc | webrtc | h264, pcm_alaw, pcm_mulaw, opus | pcm_alaw, pcm_mulaw | `webrtc:` | +| Net (pub) | yuv4mpegpipe | http, tcp, pipe | http | rawvideo | | `http:` | +| Net (priv) | bubble | http | | h264, hevc, pcm_alaw | | `bubble:` | +| Net (priv) | doorbird | http | | | | `doorbird:` | +| Net (priv) | dvrip | tcp | | h264, hevc, pcm_alaw, pcm_mulaw | pcm_alaw | `dvrip:` | +| Net (priv) | eseecloud | http | | | | `eseecloud:` | +| Net (priv) | gopro | udp | | TODO | | `gopro:` | +| Net (priv) | hass | webrtc | | TODO | | `hass:` | +| Net (priv) | homekit | hap | | h264, eld* | | `homekit:` | +| Net (priv) | isapi | http | | | pcm_alaw, pcm_mulaw | `isapi:` | +| Net (priv) | kasa | http | | h264, pcm_mulaw | | `kasa:` | +| Net (priv) | nest | rtsp, webrtc | | TODO | | `nest:` | +| Net (priv) | ring | webrtc | | | | `ring:` | +| Net (priv) | roborock | webrtc | | h264, opus | opus | `roborock:` | +| Net (priv) | tapo | http | | h264, pcma | pcm_alaw | `tapo:` | +| Net (priv) | tuya | webrtc | | | | `tuya:` | +| Net (priv) | vigi | http | | | | `vigi:` | +| Net (priv) | webtorrent | webrtc | TODO | TODO | TODO | `webtorrent:` | +| Net (priv) | xiaomi* | cs2, tutk | | | | `xiaomi:` | +| Services | flussonic | ws | | | | `flussonic:` | +| Services | ivideon | ws | | h264 | | `ivideon:` | +| Services | yandex | webrtc | | | | `yandex:` | +| Other | echo | * | | | | `echo:` | +| Other | exec | pipe, rtsp | | | | `exec:` | +| Other | expr | * | | | | `expr:` | +| Other | ffmpeg | pipe, rtsp | | | | `ffmpeg:` | +| Other | stdin | pipe | | | pcm_alaw, pcm_mulaw | `stdin:` | - **eld** - rare variant of aac codec - **pcm** - pcm_alaw pcm_mulaw pcm_s16be pcm_s16le @@ -46,23 +60,23 @@ Some formats and protocols go2rtc supports exclusively. They have no equivalent ## Consumers (output) -| Format | Protocol | Send codecs | Recv codecs | Example | -|--------------|-------------|------------------------------|-------------------------|---------------------------------------| -| adts | http | aac | | `GET /api/stream.adts` | -| ascii | http | mjpeg | | `GET /api/stream.ascii` | -| flv | http | h264,aac | | `GET /api/stream.flv` | -| hls/mpegts | http | h264,hevc,aac | | `GET /api/stream.m3u8` | -| hls/fmp4 | http | h264,hevc,aac,pcm*,opus | | `GET /api/stream.m3u8?mp4` | -| homekit | homekit+udp | h264,opus | | Apple HomeKit app | -| mjpeg | ws | mjpeg | | `{"type":"mjpeg"}` -> `/api/ws` | -| mpjpeg | http | mjpeg | | `GET /api/stream.mjpeg` | -| mp4 | http | h264,hevc,aac,pcm*,opus | | `GET /api/stream.mp4` | -| mse/fmp4 | ws | h264,hevc,aac,pcm*,opus | | `{"type":"mse"}` -> `/api/ws` | -| mpegts | http | h264,hevc,aac | | `GET /api/stream.ts` | -| rtmp | rtmp | h264,aac | | `rtmp://localhost:1935/{stream_name}` | -| rtsp | rtsp+tcp | h264,hevc,aac,pcm*,opus | | `rtsp://localhost:8554/{stream_name}` | -| webrtc | TODO | h264,pcm_alaw,pcm_mulaw,opus | pcm_alaw,pcm_mulaw,opus | `{"type":"webrtc"}` -> `/api/ws` | -| yuv4mpegpipe | http | rawvideo | | `GET /api/stream.y4m` | +| Format | Protocol | Send codecs | Recv codecs | Example | +|--------------|----------|---------------------------------|---------------------------|---------------------------------------| +| adts | http | aac | | `GET /api/stream.adts` | +| ascii | http | mjpeg | | `GET /api/stream.ascii` | +| flv | http | h264, aac | | `GET /api/stream.flv` | +| hls/mpegts | http | h264, hevc, aac | | `GET /api/stream.m3u8` | +| hls/fmp4 | http | h264, hevc, aac, pcm*, opus | | `GET /api/stream.m3u8?mp4` | +| homekit | hap | h264, opus | | Apple HomeKit app | +| mjpeg | ws | mjpeg | | `{"type":"mjpeg"}` -> `/api/ws` | +| mpjpeg | http | mjpeg | | `GET /api/stream.mjpeg` | +| mp4 | http | h264, hevc, aac, pcm*, opus | | `GET /api/stream.mp4` | +| mse/fmp4 | ws | h264, hevc, aac, pcm*, opus | | `{"type":"mse"}` -> `/api/ws` | +| mpegts | http | h264, hevc, aac | | `GET /api/stream.ts` | +| rtmp | rtmp | h264, aac | | `rtmp://localhost:1935/{stream_name}` | +| rtsp | rtsp | h264, hevc, aac, pcm*, opus | | `rtsp://localhost:8554/{stream_name}` | +| webrtc | webrtc | h264, pcm_alaw, pcm_mulaw, opus | pcm_alaw, pcm_mulaw, opus | `{"type":"webrtc"}` -> `/api/ws` | +| yuv4mpegpipe | http | rawvideo | | `GET /api/stream.y4m` | - **pcm** - pcm_alaw pcm_mulaw pcm_s16be pcm_s16le diff --git a/pkg/xiaomi/cloud.go b/pkg/xiaomi/cloud.go index 5e1e73cc..0dcfd241 100644 --- a/pkg/xiaomi/cloud.go +++ b/pkg/xiaomi/cloud.go @@ -78,12 +78,9 @@ func (c *Cloud) Login(username, password string) error { } req := Request{ - Method: "POST", - URL: "https://account.xiaomi.com/pass/serviceLoginAuth2", - RawBody: form.Encode(), - Headers: url.Values{ - "Content-Type": {"application/x-www-form-urlencoded"}, - }, + Method: "POST", + URL: "https://account.xiaomi.com/pass/serviceLoginAuth2", + Body: form, RawCookies: cookies, }.Encode() @@ -105,7 +102,7 @@ func (c *Cloud) Login(username, password string) error { return err } - // save auth for two step verification + // save auth for two-step verification c.auth = map[string]string{ "username": username, "password": password, @@ -265,11 +262,17 @@ func (c *Cloud) sendTicket() error { cookies += "; ick=" + c.auth["ick"] } + form := url.Values{ + "_json": {"true"}, + "icode": {captCode}, + "retry": {"0"}, + } + req = Request{ Method: "POST", URL: "https://account.xiaomi.com/identity/auth/send" + name + "Ticket", + Body: form, RawCookies: cookies, - RawBody: `{"retry":0,"icode":"` + captCode + `","_json":"true"}`, }.Encode() res, err = c.client.Do(req) @@ -531,7 +534,7 @@ type Request struct { Method string URL string RawParams string - RawBody string + Body url.Values Headers url.Values RawCookies string } @@ -542,8 +545,8 @@ func (r Request) Encode() *http.Request { } var body io.Reader - if r.RawBody != "" { - body = strings.NewReader(r.RawBody) + if r.Body != nil { + body = strings.NewReader(r.Body.Encode()) } req, err := http.NewRequest(r.Method, r.URL, body) @@ -554,7 +557,9 @@ func (r Request) Encode() *http.Request { if r.Headers != nil { req.Header = http.Header(r.Headers) } - + if r.Body != nil { + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + } if r.RawCookies != "" { req.Header.Set("Cookie", r.RawCookies) } diff --git a/pkg/xiaomi/cs2/conn.go b/pkg/xiaomi/cs2/conn.go index 198b3beb..cde09ab5 100644 --- a/pkg/xiaomi/cs2/conn.go +++ b/pkg/xiaomi/cs2/conn.go @@ -126,10 +126,11 @@ func (c *Conn) worker() { ch := buf[5] if c.isTCP { - // For TCP we should using ping/pong. + // For TCP we should send ping every second to keep connection alive. + // Based on PCAP analysis: official Mi Home app sends PING every ~1s. if now := time.Now(); now.After(keepaliveTS) { _, _ = c.conn.Write([]byte{magic, msgPing, 0, 0}) - keepaliveTS = now.Add(5 * time.Second) + keepaliveTS = now.Add(time.Second) } } else { // For UDP we should using ack.