diff --git a/pkg/flv/amf/amf_test.go b/pkg/flv/amf/amf_test.go index f22308e6..81e506d8 100644 --- a/pkg/flv/amf/amf_test.go +++ b/pkg/flv/amf/amf_test.go @@ -137,6 +137,70 @@ func TestNewReader(t *testing.T) { }, }, }, + { + name: "mediamtx", + actual: "0200075f726573756c74003ff0000000000000030006666d7356657202000d4c4e5820392c302c3132342c32000c6361706162696c697469657300403f0000000000000000090300056c6576656c0200067374617475730004636f646502001d4e6574436f6e6e656374696f6e2e436f6e6e6563742e53756363657373000b6465736372697074696f6e020015436f6e6e656374696f6e207375636365656465642e000e6f626a656374456e636f64696e67000000000000000000000009", + expect: []any{ + "_result", float64(1), map[string]any{ + "capabilities": float64(31), + "fmsVer": "LNX 9,0,124,2", + }, map[string]any{ + "code": "NetConnection.Connect.Success", + "description": "Connection succeeded.", + "level": "status", + "objectEncoding": float64(0), + }, + }, + }, + { + name: "mediamtx", + actual: "0200075f726573756c7400401000000000000005003ff0000000000000", + expect: []any{"_result", float64(4), any(nil), float64(1)}, + }, + { + name: "mediamtx", + actual: "0200086f6e537461747573004014000000000000050300056c6576656c0200067374617475730004636f64650200144e657453747265616d2e506c61792e5265736574000b6465736372697074696f6e02000a706c6179207265736574000009", + expect: []any{ + "onStatus", float64(5), any(nil), map[string]any{ + "code": "NetStream.Play.Reset", + "description": "play reset", + "level": "status", + }, + }, + }, + { + name: "mediamtx", + actual: "0200086f6e537461747573004014000000000000050300056c6576656c0200067374617475730004636f64650200144e657453747265616d2e506c61792e5374617274000b6465736372697074696f6e02000a706c6179207374617274000009", + expect: []any{ + "onStatus", float64(5), any(nil), map[string]any{ + "code": "NetStream.Play.Start", + "description": "play start", + "level": "status", + }, + }, + }, + { + name: "mediamtx", + actual: "0200086f6e537461747573004014000000000000050300056c6576656c0200067374617475730004636f64650200144e657453747265616d2e446174612e5374617274000b6465736372697074696f6e02000a64617461207374617274000009", + expect: []any{ + "onStatus", float64(5), any(nil), map[string]any{ + "code": "NetStream.Data.Start", + "description": "data start", + "level": "status", + }, + }, + }, + { + name: "mediamtx", + actual: "0200086f6e537461747573004014000000000000050300056c6576656c0200067374617475730004636f646502001c4e657453747265616d2e506c61792e5075626c6973684e6f74696679000b6465736372697074696f6e02000e7075626c697368206e6f74696679000009", + expect: []any{ + "onStatus", float64(5), any(nil), map[string]any{ + "code": "NetStream.Play.PublishNotify", + "description": "publish notify", + "level": "status", + }, + }, + }, { name: "obs-connect", actual: "020007636f6e6e656374003ff000000000000003000361707002000c617070312f73747265616d3100047479706502000a6e6f6e70726976617465000e737570706f727473476f4177617901010008666c61736856657202001f464d4c452f332e302028636f6d70617469626c653b20464d53632f312e3029000673776655726c02002272746d703a2f2f3139322e3136382e31302e3130312f617070312f73747265616d310005746355726c02002272746d703a2f2f3139322e3136382e31302e3130312f617070312f73747265616d31000009", diff --git a/pkg/rtmp/conn.go b/pkg/rtmp/conn.go index f81b1dec..2c7c3dda 100644 --- a/pkg/rtmp/conn.go +++ b/pkg/rtmp/conn.go @@ -52,13 +52,14 @@ func (c *Conn) readResponse(transID float64) ([]any, error) { if err != nil { return nil, err } + //log.Printf("[rtmp] type=%d data=%s", msgType, b) switch msgType { case TypeSetPacketSize: c.rdPacketSize = binary.BigEndian.Uint32(b) case TypeCommand: items, _ := amf.NewReader(b).ReadItems() - if len(items) >= 3 && items[1] == transID { + if len(items) >= 3 && (items[1] == transID || items[1] == float64(0)) { return items, nil } } @@ -288,7 +289,7 @@ func (c *Conn) writePublish() error { return err } - v, err := c.readResponse(0) + v, err := c.readResponse(5) if err != nil { return nil } @@ -307,7 +308,8 @@ func (c *Conn) writePlay() error { return err } - v, err := c.readResponse(0) + // Reolink response with ID=0, other software respose with ID=5 + v, err := c.readResponse(5) if err != nil { return nil }