Fix incoming FLV source

This commit is contained in:
Alexey Khit
2023-08-14 06:48:52 +03:00
parent f412852d50
commit 5d533338d0
2 changed files with 13 additions and 8 deletions
+8 -8
View File
@@ -19,6 +19,8 @@ type Client struct {
medias []*core.Media medias []*core.Media
receivers []*core.Receiver receivers []*core.Receiver
video, audio *core.Receiver
recv int recv int
} }
@@ -120,8 +122,6 @@ func (c *Client) Describe() error {
} }
func (c *Client) Play() error { func (c *Client) Play() error {
video, audio := core.VA(c.receivers)
for { for {
tagType, timeMS, b, err := c.Transport.ReadTag() tagType, timeMS, b, err := c.Transport.ReadTag()
if err != nil { if err != nil {
@@ -132,31 +132,31 @@ func (c *Client) Play() error {
switch tagType { switch tagType {
case TagAudio: case TagAudio:
if audio == nil || b[1] == 0 { if c.audio == nil || b[1] == 0 {
continue continue
} }
pkt := &rtp.Packet{ pkt := &rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Timestamp: TimeToRTP(timeMS, audio.Codec.ClockRate), Timestamp: TimeToRTP(timeMS, c.audio.Codec.ClockRate),
}, },
Payload: b[2:], Payload: b[2:],
} }
audio.WriteRTP(pkt) c.audio.WriteRTP(pkt)
case TagVideo: case TagVideo:
// frame type 4b, codecID 4b, avc packet type 8b, composition time 24b // frame type 4b, codecID 4b, avc packet type 8b, composition time 24b
if video == nil || b[1] == 0 { if c.video == nil || b[1] == 0 {
continue continue
} }
pkt := &rtp.Packet{ pkt := &rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Timestamp: TimeToRTP(timeMS, video.Codec.ClockRate), Timestamp: TimeToRTP(timeMS, c.video.Codec.ClockRate),
}, },
Payload: b[5:], Payload: b[5:],
} }
video.WriteRTP(pkt) c.video.WriteRTP(pkt)
} }
} }
} }
+5
View File
@@ -18,6 +18,11 @@ func (c *Client) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver,
} }
} }
track := core.NewReceiver(media, codec) track := core.NewReceiver(media, codec)
if media.Kind == core.KindVideo {
c.video = track
} else {
c.audio = track
}
c.receivers = append(c.receivers, track) c.receivers = append(c.receivers, track)
return track, nil return track, nil
} }