mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-26 00:22:16 +00:00
rtmp: read or write tracks only after interacting with the path
This commit is contained in:
parent
86c5fa9ba4
commit
bbfea63539
@ -302,12 +302,6 @@ func (c *rtmpConn) runRead(ctx context.Context, u *url.URL) error {
|
||||
c.path.Name(),
|
||||
sourceTrackInfo(res.stream.tracks()))
|
||||
|
||||
c.nconn.SetWriteDeadline(time.Now().Add(time.Duration(c.writeTimeout)))
|
||||
err := c.conn.WriteTracks(videoTrack, audioTrack)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.path.Conf().RunOnRead != "" {
|
||||
c.log(logger.Info, "runOnRead command started")
|
||||
onReadCmd := externalcmd.NewCmd(
|
||||
@ -324,6 +318,11 @@ func (c *rtmpConn) runRead(ctx context.Context, u *url.URL) error {
|
||||
}()
|
||||
}
|
||||
|
||||
err := c.conn.WriteTracks(videoTrack, audioTrack)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// disable read deadline
|
||||
c.nconn.SetReadDeadline(time.Time{})
|
||||
|
||||
@ -461,26 +460,6 @@ func (c *rtmpConn) runRead(ctx context.Context, u *url.URL) error {
|
||||
}
|
||||
|
||||
func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
|
||||
c.nconn.SetReadDeadline(time.Now().Add(time.Duration(c.readTimeout)))
|
||||
videoTrack, audioTrack, err := c.conn.ReadTracks()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var tracks gortsplib.Tracks
|
||||
videoTrackID := -1
|
||||
audioTrackID := -1
|
||||
|
||||
if videoTrack != nil {
|
||||
videoTrackID = len(tracks)
|
||||
tracks = append(tracks, videoTrack)
|
||||
}
|
||||
|
||||
if audioTrack != nil {
|
||||
audioTrackID = len(tracks)
|
||||
tracks = append(tracks, audioTrack)
|
||||
}
|
||||
|
||||
pathName, query, rawQuery := pathNameAndQuery(u)
|
||||
|
||||
res := c.pathManager.publisherAdd(pathPublisherAddReq{
|
||||
@ -514,6 +493,25 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
|
||||
c.state = rtmpConnStatePublish
|
||||
c.stateMutex.Unlock()
|
||||
|
||||
videoTrack, audioTrack, err := c.conn.ReadTracks()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var tracks gortsplib.Tracks
|
||||
videoTrackID := -1
|
||||
audioTrackID := -1
|
||||
|
||||
if videoTrack != nil {
|
||||
videoTrackID = len(tracks)
|
||||
tracks = append(tracks, videoTrack)
|
||||
}
|
||||
|
||||
if audioTrack != nil {
|
||||
audioTrackID = len(tracks)
|
||||
tracks = append(tracks, audioTrack)
|
||||
}
|
||||
|
||||
rres := c.path.publisherStart(pathPublisherStartReq{
|
||||
author: c,
|
||||
tracks: tracks,
|
||||
|
Loading…
Reference in New Issue
Block a user