diff --git a/README.md b/README.md index 1790603..e470aac 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ srt://127.0.0.1:6001?streamid=#!::h=test110,m=request (5)支持datachannel,只支持对接jessibuca播放器 +(6)WHIP支持对接OBS 30.2 beta HEVC + datachannel播放地址:webrtc://127.0.0.1:1290/webrtc/play/live/test110 ``` diff --git a/rtc/unpacker.go b/rtc/unpacker.go index 3cdcbeb..8ad6d02 100644 --- a/rtc/unpacker.go +++ b/rtc/unpacker.go @@ -7,6 +7,7 @@ import ( "github.com/bluenviron/gortsplib/v4/pkg/format" "github.com/bluenviron/gortsplib/v4/pkg/format/rtph264" + "github.com/bluenviron/gortsplib/v4/pkg/format/rtph265" "github.com/bluenviron/gortsplib/v4/pkg/format/rtplpcm" "github.com/bluenviron/gortsplib/v4/pkg/format/rtpsimpleaudio" "github.com/bluenviron/gortsplib/v4/pkg/rtpreorderer" @@ -53,10 +54,16 @@ func NewUnPacker(mimeType string, clockRate uint32, pktChan chan<- base.AvPacket un.payloadType = base.AvPacketPtOpus un.format = &format.Opus{} un.dec = NewOpusRtpDecoder(un.format) + case webrtc.MimeTypeH265: + un.payloadType = base.AvPacketPtHevc + un.format = &format.H265{} + un.dec = NewH265RtpDecoder(un.format) default: nazalog.Error("unsupport mineType:", mimeType) } + nazalog.Info("create rtp unpacker, mimeType:", mimeType) + return un } @@ -174,3 +181,35 @@ func (r *OpusRtpDecoder) Decode(pkt *rtp.Packet) ([]byte, error) { return frame, nil } + +type H265RtpDecoder struct { + IRtpDecoder + dec *rtph265.Decoder +} + +func NewH265RtpDecoder(f format.Format) *H265RtpDecoder { + dec, _ := f.(*format.H265).CreateDecoder() + return &H265RtpDecoder{ + dec: dec, + } +} + +func (r *H265RtpDecoder) Decode(pkt *rtp.Packet) ([]byte, error) { + nalus, err := r.dec.Decode(pkt) + if err != nil { + return nil, ErrNeedMoreFrames + } + + if len(nalus) == 0 { + err = fmt.Errorf("invalid frame") + return nil, err + } + + var frame []byte + for _, nalu := range nalus { + frame = append(frame, avc.NaluStartCode4...) + frame = append(frame, nalu...) + } + + return frame, nil +}