Browse Source

rtmp: invert flag of InitializeServer() and InitializeClient()

pull/1128/head
aler9 3 years ago
parent
commit
176f2f0729
  1. 4
      internal/core/rtmp_conn.go
  2. 4
      internal/core/rtmp_server_test.go
  3. 2
      internal/core/rtmp_source.go
  4. 8
      internal/rtmp/conn.go
  5. 6
      internal/rtmp/conn_test.go

4
internal/core/rtmp_conn.go

@ -206,12 +206,12 @@ func (c *rtmpConn) runInner(ctx context.Context) error { @@ -206,12 +206,12 @@ func (c *rtmpConn) runInner(ctx context.Context) error {
c.nconn.SetReadDeadline(time.Now().Add(time.Duration(c.readTimeout)))
c.nconn.SetWriteDeadline(time.Now().Add(time.Duration(c.writeTimeout)))
u, isReading, err := c.conn.InitializeServer()
u, isPublishing, err := c.conn.InitializeServer()
if err != nil {
return err
}
if isReading {
if !isPublishing {
return c.runRead(ctx, u)
}
return c.runPublish(ctx, u)

4
internal/core/rtmp_server_test.go

@ -143,7 +143,7 @@ func TestRTMPServerAuth(t *testing.T) { @@ -143,7 +143,7 @@ func TestRTMPServerAuth(t *testing.T) {
defer nconn.Close()
conn := rtmp.NewConn(nconn)
err = conn.InitializeClient(u, true)
err = conn.InitializeClient(u, false)
require.NoError(t, err)
_, _, err = conn.ReadTracks()
@ -231,7 +231,7 @@ func TestRTMPServerAuthFail(t *testing.T) { @@ -231,7 +231,7 @@ func TestRTMPServerAuthFail(t *testing.T) {
defer nconn.Close()
conn := rtmp.NewConn(nconn)
err = conn.InitializeClient(u, true)
err = conn.InitializeClient(u, false)
require.NoError(t, err)
for i := 0; i < 3; i++ {

2
internal/core/rtmp_source.go

@ -79,7 +79,7 @@ func (s *rtmpSource) run(ctx context.Context) error { @@ -79,7 +79,7 @@ func (s *rtmpSource) run(ctx context.Context) error {
readDone <- func() error {
nconn.SetReadDeadline(time.Now().Add(time.Duration(s.readTimeout)))
nconn.SetWriteDeadline(time.Now().Add(time.Duration(s.writeTimeout)))
err = conn.InitializeClient(u, true)
err = conn.InitializeClient(u, false)
if err != nil {
return err
}

8
internal/rtmp/conn.go

@ -152,7 +152,7 @@ func (c *Conn) readCommandResult(commandName string, isValid func(*message.MsgCo @@ -152,7 +152,7 @@ func (c *Conn) readCommandResult(commandName string, isValid func(*message.MsgCo
}
// InitializeClient performs the initialization of a client-side connection.
func (c *Conn) InitializeClient(u *url.URL, isPlaying bool) error {
func (c *Conn) InitializeClient(u *url.URL, isPublishing bool) error {
connectpath, actionpath := splitPath(u)
err := handshake.DoClient(c.bc, false)
@ -208,7 +208,7 @@ func (c *Conn) InitializeClient(u *url.URL, isPlaying bool) error { @@ -208,7 +208,7 @@ func (c *Conn) InitializeClient(u *url.URL, isPlaying bool) error {
return err
}
if isPlaying {
if !isPublishing {
err = c.mrw.Write(&message.MsgCommandAMF0{
ChunkStreamID: 3,
Name: "createStream",
@ -524,7 +524,7 @@ func (c *Conn) InitializeServer() (*url.URL, bool, error) { @@ -524,7 +524,7 @@ func (c *Conn) InitializeServer() (*url.URL, bool, error) {
return nil, false, err
}
return u, true, nil
return u, false, nil
case "publish":
if len(cmd.Arguments) < 2 {
@ -559,7 +559,7 @@ func (c *Conn) InitializeServer() (*url.URL, bool, error) { @@ -559,7 +559,7 @@ func (c *Conn) InitializeServer() (*url.URL, bool, error) {
return nil, false, err
}
return u, false, nil
return u, true, nil
}
}
}

6
internal/rtmp/conn_test.go

@ -257,7 +257,7 @@ func TestInitializeClient(t *testing.T) { @@ -257,7 +257,7 @@ func TestInitializeClient(t *testing.T) {
defer nconn.Close()
conn := NewConn(nconn)
err = conn.InitializeClient(u, ca == "read")
err = conn.InitializeClient(u, ca == "publish")
require.NoError(t, err)
<-done
@ -280,14 +280,14 @@ func TestInitializeServer(t *testing.T) { @@ -280,14 +280,14 @@ func TestInitializeServer(t *testing.T) {
defer nconn.Close()
conn := NewConn(nconn)
u, isReading, err := conn.InitializeServer()
u, isPublishing, err := conn.InitializeServer()
require.NoError(t, err)
require.Equal(t, &url.URL{
Scheme: "rtmp",
Host: "127.0.0.1:9121",
Path: "//stream/",
}, u)
require.Equal(t, ca == "read", isReading)
require.Equal(t, ca == "publish", isPublishing)
close(done)
}()

Loading…
Cancel
Save