update gortsplib, gohlslib (#1637)

This commit is contained in:
Alessandro Ros 2023-04-01 18:39:12 +02:00 committed by GitHub
parent 41ce925be5
commit 2dffccf9c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 662 additions and 531 deletions

View file

@ -4,7 +4,7 @@ import (
"fmt"
"time"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/pion/rtp"
)
@ -30,7 +30,7 @@ type formatProcessorGeneric struct {
func newGeneric(
udpMaxPayloadSize int,
forma format.Format,
forma formats.Format,
generateRTPPackets bool,
) (*formatProcessorGeneric, error) {
if generateRTPPackets {

View file

@ -3,13 +3,13 @@ package formatprocessor
import (
"testing"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/pion/rtp"
"github.com/stretchr/testify/require"
)
func TestGenericRemovePadding(t *testing.T) {
forma := &format.Generic{
forma := &formats.Generic{
PayloadTyp: 96,
RTPMap: "private/90000",
}

View file

@ -4,9 +4,9 @@ import (
"bytes"
"time"
"github.com/aler9/gortsplib/v2/pkg/codecs/h264"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/aler9/gortsplib/v2/pkg/formatdecenc/rtph264"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtph264"
"github.com/bluenviron/mediacommon/pkg/codecs/h264"
"github.com/pion/rtp"
)
@ -87,7 +87,7 @@ func (d *UnitH264) GetNTP() time.Time {
type formatProcessorH264 struct {
udpMaxPayloadSize int
format *format.H264
format *formats.H264
encoder *rtph264.Encoder
decoder *rtph264.Decoder
@ -95,7 +95,7 @@ type formatProcessorH264 struct {
func newH264(
udpMaxPayloadSize int,
forma *format.H264,
forma *formats.H264,
allocateEncoder bool,
) (*formatProcessorH264, error) {
t := &formatProcessorH264{
@ -112,37 +112,56 @@ func newH264(
func (t *formatProcessorH264) updateTrackParametersFromRTPPacket(pkt *rtp.Packet) {
sps, pps := rtpH264ExtractSPSPPS(pkt)
update := false
if sps != nil && !bytes.Equal(sps, t.format.SafeSPS()) {
t.format.SafeSetSPS(sps)
if sps != nil && !bytes.Equal(sps, t.format.SPS) {
update = true
}
if pps != nil && !bytes.Equal(pps, t.format.SafePPS()) {
t.format.SafeSetPPS(pps)
if pps != nil && !bytes.Equal(pps, t.format.PPS) {
update = true
}
if update {
if sps == nil {
sps = t.format.SPS
}
if pps == nil {
pps = t.format.PPS
}
t.format.SafeSetParams(sps, pps)
}
}
func (t *formatProcessorH264) updateTrackParametersFromNALUs(nalus [][]byte) {
sps := t.format.SPS
pps := t.format.PPS
update := false
for _, nalu := range nalus {
typ := h264.NALUType(nalu[0] & 0x1F)
switch typ {
case h264.NALUTypeSPS:
if !bytes.Equal(nalu, t.format.SafeSPS()) {
t.format.SafeSetSPS(nalu)
if !bytes.Equal(nalu, sps) {
sps = nalu
update = true
}
case h264.NALUTypePPS:
if !bytes.Equal(nalu, t.format.SafePPS()) {
t.format.SafeSetPPS(nalu)
if !bytes.Equal(nalu, pps) {
pps = nalu
update = true
}
}
}
if update {
t.format.SafeSetParams(sps, pps)
}
}
func (t *formatProcessorH264) remuxAccessUnit(nalus [][]byte) [][]byte {
var sps []byte
var pps []byte
addParameters := false
n := 0
@ -159,10 +178,8 @@ func (t *formatProcessorH264) remuxAccessUnit(nalus [][]byte) [][]byte {
case h264.NALUTypeIDR: // prepend parameters if there's at least an IDR
if !addParameters {
addParameters = true
sps = t.format.SafeSPS()
pps = t.format.SafePPS()
if sps != nil && pps != nil {
if t.format.SPS != nil && t.format.PPS != nil {
n += 2
}
}
@ -177,9 +194,9 @@ func (t *formatProcessorH264) remuxAccessUnit(nalus [][]byte) [][]byte {
filteredNALUs := make([][]byte, n)
i := 0
if addParameters && sps != nil && pps != nil {
filteredNALUs[0] = sps
filteredNALUs[1] = pps
if addParameters && t.format.SPS != nil && t.format.PPS != nil {
filteredNALUs[0] = t.format.SPS
filteredNALUs[1] = t.format.PPS
i = 2
}

View file

@ -4,14 +4,14 @@ import (
"bytes"
"testing"
"github.com/aler9/gortsplib/v2/pkg/codecs/h264"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/bluenviron/mediacommon/pkg/codecs/h264"
"github.com/pion/rtp"
"github.com/stretchr/testify/require"
)
func TestH264DynamicParams(t *testing.T) {
forma := &format.H264{
forma := &formats.H264{
PayloadTyp: 96,
PacketizationMode: 1,
}
@ -54,7 +54,7 @@ func TestH264DynamicParams(t *testing.T) {
}
func TestH264OversizedPackets(t *testing.T) {
forma := &format.H264{
forma := &formats.H264{
PayloadTyp: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
@ -153,7 +153,7 @@ func TestH264OversizedPackets(t *testing.T) {
}
func TestH264EmptyPacket(t *testing.T) {
forma := &format.H264{
forma := &formats.H264{
PayloadTyp: 96,
PacketizationMode: 1,
}

View file

@ -4,9 +4,9 @@ import (
"bytes"
"time"
"github.com/aler9/gortsplib/v2/pkg/codecs/h265"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/aler9/gortsplib/v2/pkg/formatdecenc/rtph265"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtph265"
"github.com/bluenviron/mediacommon/pkg/codecs/h265"
"github.com/pion/rtp"
)
@ -94,7 +94,7 @@ func (d *UnitH265) GetNTP() time.Time {
type formatProcessorH265 struct {
udpMaxPayloadSize int
format *format.H265
format *formats.H265
encoder *rtph265.Encoder
decoder *rtph265.Decoder
@ -102,7 +102,7 @@ type formatProcessorH265 struct {
func newH265(
udpMaxPayloadSize int,
forma *format.H265,
forma *formats.H265,
allocateEncoder bool,
) (*formatProcessorH265, error) {
t := &formatProcessorH265{
@ -119,47 +119,70 @@ func newH265(
func (t *formatProcessorH265) updateTrackParametersFromRTPPacket(pkt *rtp.Packet) {
vps, sps, pps := rtpH265ExtractVPSSPSPPS(pkt)
update := false
if vps != nil && !bytes.Equal(vps, t.format.SafeVPS()) {
t.format.SafeSetVPS(vps)
if vps != nil && !bytes.Equal(vps, t.format.VPS) {
update = true
}
if sps != nil && !bytes.Equal(sps, t.format.SafeSPS()) {
t.format.SafeSetSPS(sps)
if sps != nil && !bytes.Equal(sps, t.format.SPS) {
update = true
}
if pps != nil && !bytes.Equal(pps, t.format.SafePPS()) {
t.format.SafeSetPPS(pps)
if pps != nil && !bytes.Equal(pps, t.format.PPS) {
update = true
}
if update {
if vps == nil {
vps = t.format.VPS
}
if sps == nil {
sps = t.format.SPS
}
if pps == nil {
pps = t.format.PPS
}
t.format.SafeSetParams(vps, sps, pps)
}
}
func (t *formatProcessorH265) updateTrackParametersFromNALUs(nalus [][]byte) {
vps := t.format.VPS
sps := t.format.SPS
pps := t.format.PPS
update := false
for _, nalu := range nalus {
typ := h265.NALUType((nalu[0] >> 1) & 0b111111)
switch typ {
case h265.NALUType_VPS_NUT:
if !bytes.Equal(nalu, t.format.SafeVPS()) {
t.format.SafeSetVPS(nalu)
if !bytes.Equal(nalu, t.format.VPS) {
vps = nalu
update = true
}
case h265.NALUType_SPS_NUT:
if !bytes.Equal(nalu, t.format.SafePPS()) {
t.format.SafeSetSPS(nalu)
if !bytes.Equal(nalu, t.format.SPS) {
sps = nalu
update = true
}
case h265.NALUType_PPS_NUT:
if !bytes.Equal(nalu, t.format.SafePPS()) {
t.format.SafeSetPPS(nalu)
if !bytes.Equal(nalu, t.format.PPS) {
pps = nalu
update = true
}
}
}
if update {
t.format.SafeSetParams(vps, sps, pps)
}
}
func (t *formatProcessorH265) remuxAccessUnit(nalus [][]byte) [][]byte {
var vps []byte
var sps []byte
var pps []byte
addParameters := false
n := 0
@ -178,11 +201,7 @@ func (t *formatProcessorH265) remuxAccessUnit(nalus [][]byte) [][]byte {
if !addParameters {
addParameters = true
vps = t.format.SafeVPS()
sps = t.format.SafeSPS()
pps = t.format.SafePPS()
if vps != nil && sps != nil && pps != nil {
if t.format.VPS != nil && t.format.SPS != nil && t.format.PPS != nil {
n += 3
}
}
@ -197,10 +216,10 @@ func (t *formatProcessorH265) remuxAccessUnit(nalus [][]byte) [][]byte {
filteredNALUs := make([][]byte, n)
i := 0
if addParameters && vps != nil && sps != nil && pps != nil {
filteredNALUs[0] = vps
filteredNALUs[1] = sps
filteredNALUs[2] = pps
if addParameters && t.format.VPS != nil && t.format.SPS != nil && t.format.PPS != nil {
filteredNALUs[0] = t.format.VPS
filteredNALUs[1] = t.format.SPS
filteredNALUs[2] = t.format.PPS
i = 3
}

View file

@ -4,14 +4,14 @@ import (
"bytes"
"testing"
"github.com/aler9/gortsplib/v2/pkg/codecs/h265"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/bluenviron/mediacommon/pkg/codecs/h265"
"github.com/pion/rtp"
"github.com/stretchr/testify/require"
)
func TestH265DynamicParams(t *testing.T) {
forma := &format.H265{
forma := &formats.H265{
PayloadTyp: 96,
}
@ -59,7 +59,7 @@ func TestH265DynamicParams(t *testing.T) {
}
func TestH265OversizedPackets(t *testing.T) {
forma := &format.H265{
forma := &formats.H265{
PayloadTyp: 96,
VPS: []byte{byte(h265.NALUType_VPS_NUT) << 1, 10, 11, 12},
SPS: []byte{byte(h265.NALUType_SPS_NUT) << 1, 13, 14, 15},
@ -146,7 +146,7 @@ func TestH265OversizedPackets(t *testing.T) {
}
func TestH265EmptyPacket(t *testing.T) {
forma := &format.H265{
forma := &formats.H265{
PayloadTyp: 96,
}

View file

@ -4,8 +4,8 @@ import (
"fmt"
"time"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/aler9/gortsplib/v2/pkg/formatdecenc/rtpmpeg4audio"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpmpeg4audio"
"github.com/pion/rtp"
)
@ -29,14 +29,14 @@ func (d *UnitMPEG4Audio) GetNTP() time.Time {
type formatProcessorMPEG4Audio struct {
udpMaxPayloadSize int
format *format.MPEG4Audio
format *formats.MPEG4Audio
encoder *rtpmpeg4audio.Encoder
decoder *rtpmpeg4audio.Decoder
}
func newMPEG4Audio(
udpMaxPayloadSize int,
forma *format.MPEG4Audio,
forma *formats.MPEG4Audio,
allocateEncoder bool,
) (*formatProcessorMPEG4Audio, error) {
t := &formatProcessorMPEG4Audio{

View file

@ -4,8 +4,8 @@ import (
"fmt"
"time"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/aler9/gortsplib/v2/pkg/formatdecenc/rtpsimpleaudio"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpsimpleaudio"
"github.com/pion/rtp"
)
@ -29,14 +29,14 @@ func (d *UnitOpus) GetNTP() time.Time {
type formatProcessorOpus struct {
udpMaxPayloadSize int
format *format.Opus
format *formats.Opus
encoder *rtpsimpleaudio.Encoder
decoder *rtpsimpleaudio.Decoder
}
func newOpus(
udpMaxPayloadSize int,
forma *format.Opus,
forma *formats.Opus,
allocateEncoder bool,
) (*formatProcessorOpus, error) {
t := &formatProcessorOpus{

View file

@ -2,7 +2,7 @@
package formatprocessor
import (
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
)
// Processor allows to cleanup and normalize streams.
@ -14,26 +14,26 @@ type Processor interface {
// New allocates a Processor.
func New(
udpMaxPayloadSize int,
forma format.Format,
forma formats.Format,
generateRTPPackets bool,
) (Processor, error) {
switch forma := forma.(type) {
case *format.H264:
case *formats.H264:
return newH264(udpMaxPayloadSize, forma, generateRTPPackets)
case *format.H265:
case *formats.H265:
return newH265(udpMaxPayloadSize, forma, generateRTPPackets)
case *format.VP8:
case *formats.VP8:
return newVP8(udpMaxPayloadSize, forma, generateRTPPackets)
case *format.VP9:
case *formats.VP9:
return newVP9(udpMaxPayloadSize, forma, generateRTPPackets)
case *format.MPEG4Audio:
case *formats.MPEG4Audio:
return newMPEG4Audio(udpMaxPayloadSize, forma, generateRTPPackets)
case *format.Opus:
case *formats.Opus:
return newOpus(udpMaxPayloadSize, forma, generateRTPPackets)
default:

View file

@ -4,8 +4,8 @@ import (
"fmt"
"time"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/aler9/gortsplib/v2/pkg/formatdecenc/rtpvp8"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpvp8"
"github.com/pion/rtp"
)
@ -29,14 +29,14 @@ func (d *UnitVP8) GetNTP() time.Time {
type formatProcessorVP8 struct {
udpMaxPayloadSize int
format *format.VP8
format *formats.VP8
encoder *rtpvp8.Encoder
decoder *rtpvp8.Decoder
}
func newVP8(
udpMaxPayloadSize int,
forma *format.VP8,
forma *formats.VP8,
allocateEncoder bool,
) (*formatProcessorVP8, error) {
t := &formatProcessorVP8{

View file

@ -4,8 +4,8 @@ import (
"fmt"
"time"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/aler9/gortsplib/v2/pkg/formatdecenc/rtpvp9"
"github.com/bluenviron/gortsplib/v3/pkg/formats"
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpvp9"
"github.com/pion/rtp"
)
@ -29,14 +29,14 @@ func (d *UnitVP9) GetNTP() time.Time {
type formatProcessorVP9 struct {
udpMaxPayloadSize int
format *format.VP9
format *formats.VP9
encoder *rtpvp9.Encoder
decoder *rtpvp9.Decoder
}
func newVP9(
udpMaxPayloadSize int,
forma *format.VP9,
forma *formats.VP9,
allocateEncoder bool,
) (*formatProcessorVP9, error) {
t := &formatProcessorVP9{