rtmp: always send decoder config before IDR frames

This commit is contained in:
aler9 2022-04-10 17:07:42 +02:00
parent 2a0dc3b63d
commit f620484757

View file

@ -337,8 +337,6 @@ func (c *rtmpConn) runRead(ctx context.Context) error {
continue
}
// TODO: send H264DecoderConfig instead of NALUs?
// wait until we receive an IDR
if !videoFirstIDRFound {
if !h264.IDRPresent(data.h264NALUs) {
@ -350,6 +348,29 @@ func (c *rtmpConn) runRead(ctx context.Context) error {
videoDTSEst = h264.NewDTSEstimator()
}
if h264.IDRPresent(data.h264NALUs) {
codec := nh264.Codec{
SPS: map[int][]byte{
0: videoTrack.SPS(),
},
PPS: map[int][]byte{
0: videoTrack.PPS(),
},
}
b := make([]byte, 128)
var n int
codec.ToConfig(b, &n)
b = b[:n]
err = c.conn.WritePacket(av.Packet{
Type: av.H264DecoderConfig,
Data: b,
})
if err != nil {
return err
}
}
avcc, err := h264.EncodeAVCC(data.h264NALUs)
if err != nil {
return err