Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

megre #6

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
39 changes: 39 additions & 0 deletions rtc/unpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}