Browse Source

rtmp: always send decoder config before IDR frames

pull/923/head
aler9 4 years ago
parent
commit
f620484757
  1. 25
      internal/core/rtmp_conn.go

25
internal/core/rtmp_conn.go

@ -337,8 +337,6 @@ func (c *rtmpConn) runRead(ctx context.Context) error {
continue continue
} }
// TODO: send H264DecoderConfig instead of NALUs?
// wait until we receive an IDR // wait until we receive an IDR
if !videoFirstIDRFound { if !videoFirstIDRFound {
if !h264.IDRPresent(data.h264NALUs) { if !h264.IDRPresent(data.h264NALUs) {
@ -350,6 +348,29 @@ func (c *rtmpConn) runRead(ctx context.Context) error {
videoDTSEst = h264.NewDTSEstimator() 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) avcc, err := h264.EncodeAVCC(data.h264NALUs)
if err != nil { if err != nil {
return err return err

Loading…
Cancel
Save