mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 23:02:45 +08:00
update examples to support H264 tracks without SPS/PPS
This commit is contained in:
@@ -63,15 +63,15 @@ func main() {
|
||||
}
|
||||
|
||||
// find the H264 track
|
||||
h264tr, h264trID := func() (*gortsplib.TrackH264, int) {
|
||||
h264TrackID, h264track := func() (int, *gortsplib.TrackH264) {
|
||||
for i, track := range tracks {
|
||||
if h264tr, ok := track.(*gortsplib.TrackH264); ok {
|
||||
return h264tr, i
|
||||
if h264track, ok := track.(*gortsplib.TrackH264); ok {
|
||||
return i, h264track
|
||||
}
|
||||
}
|
||||
return nil, -1
|
||||
return -1, nil
|
||||
}()
|
||||
if h264trID < 0 {
|
||||
if h264TrackID < 0 {
|
||||
panic("H264 track not found")
|
||||
}
|
||||
|
||||
@@ -86,17 +86,18 @@ func main() {
|
||||
}
|
||||
defer h264dec.close()
|
||||
|
||||
// send SPS and PPS to the decoder
|
||||
if h264tr.SPS() == nil || h264tr.PPS() == nil {
|
||||
panic("SPS or PPS not present into the SDP")
|
||||
// if present, send SPS and PPS from the SDP to the decoder
|
||||
if h264track.SPS() != nil {
|
||||
h264dec.decode(h264track.SPS())
|
||||
}
|
||||
if h264track.PPS() != nil {
|
||||
h264dec.decode(h264track.PPS())
|
||||
}
|
||||
h264dec.decode(h264tr.SPS())
|
||||
h264dec.decode(h264tr.PPS())
|
||||
|
||||
// called when a RTP packet arrives
|
||||
saveCount := 0
|
||||
c.OnPacketRTP = func(trackID int, pkt *rtp.Packet) {
|
||||
if trackID != h264trID {
|
||||
if trackID != h264TrackID {
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user