mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 15:46:51 +08:00
rtph264: return error in decoder if packetization-mode is 2 (#153)
This commit is contained in:
@@ -234,6 +234,7 @@ func TestClientPublishSerial(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
err = c.StartPublishing(scheme+"://localhost:8554/teststream",
|
||||
@@ -386,6 +387,7 @@ func TestClientPublishParallel(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
writerDone := make(chan struct{})
|
||||
@@ -545,6 +547,7 @@ func TestClientPublishPauseSerial(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
err = c.StartPublishing("rtsp://localhost:8554/teststream",
|
||||
@@ -679,6 +682,7 @@ func TestClientPublishPauseParallel(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
err = c.StartPublishing("rtsp://localhost:8554/teststream",
|
||||
@@ -820,6 +824,7 @@ func TestClientPublishAutomaticProtocol(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
c := Client{}
|
||||
@@ -984,6 +989,7 @@ func TestClientPublishRTCPReport(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}})
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
@@ -1120,6 +1126,7 @@ func TestClientPublishIgnoreTCPRTPPackets(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
err = c.StartPublishing("rtsp://localhost:8554/teststream",
|
||||
|
@@ -54,6 +54,7 @@ func TestClientReadTracks(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
track2 := &TrackMPEG4Audio{
|
||||
@@ -501,12 +502,14 @@ func TestClientReadPartial(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
track2 := &TrackH264{
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track1, track2}
|
||||
@@ -654,6 +657,7 @@ func TestClientReadContentBase(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -790,6 +794,7 @@ func TestClientReadAnyPort(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -948,6 +953,7 @@ func TestClientReadAutomaticProtocol(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -1041,6 +1047,7 @@ func TestClientReadAutomaticProtocol(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}}
|
||||
tracks.setControls()
|
||||
|
||||
@@ -1305,6 +1312,7 @@ func TestClientReadDifferentInterleavedIDs(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track1}
|
||||
@@ -1515,6 +1523,7 @@ func TestClientReadRedirect(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -1675,6 +1684,7 @@ func TestClientReadPause(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -1849,6 +1859,7 @@ func TestClientReadRTCPReport(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -2030,6 +2041,7 @@ func TestClientReadErrorTimeout(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -2182,6 +2194,7 @@ func TestClientReadIgnoreTCPInvalidTrack(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -2311,6 +2324,7 @@ func TestClientReadSeek(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -2483,6 +2497,7 @@ func TestClientReadKeepaliveFromSession(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -2612,6 +2627,7 @@ func TestClientReadDifferentSource(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
|
@@ -109,6 +109,7 @@ func TestClientSession(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -192,6 +193,7 @@ func TestClientAuth(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -258,6 +260,7 @@ func TestClientDescribeCharset(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
err = conn.WriteResponse(&base.Response{
|
||||
|
@@ -37,6 +37,7 @@ func main() {
|
||||
// create an H264 track
|
||||
track := &gortsplib.TrackH264{
|
||||
PayloadType: 96,
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
// connect to the server and start publishing the track
|
||||
|
@@ -38,6 +38,7 @@ func main() {
|
||||
// create an H264 track
|
||||
track := &gortsplib.TrackH264{
|
||||
PayloadType: 96,
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
// Client allows to set additional client options
|
||||
|
@@ -39,6 +39,7 @@ func main() {
|
||||
// create an H264 track
|
||||
track := &gortsplib.TrackH264{
|
||||
PayloadType: 96,
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
// connect to the server and start publishing the track
|
||||
|
@@ -62,20 +62,22 @@ func main() {
|
||||
}
|
||||
|
||||
// find the H264 track
|
||||
h264track := func() *gortsplib.TrackH264 {
|
||||
track := func() *gortsplib.TrackH264 {
|
||||
for _, track := range tracks {
|
||||
if h264track, ok := track.(*gortsplib.TrackH264); ok {
|
||||
return h264track
|
||||
if track, ok := track.(*gortsplib.TrackH264); ok {
|
||||
return track
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if h264track == nil {
|
||||
if track == nil {
|
||||
panic("H264 track not found")
|
||||
}
|
||||
|
||||
// setup RTP/H264->H264 decoder
|
||||
rtpDec := &rtph264.Decoder{}
|
||||
rtpDec := &rtph264.Decoder{
|
||||
PacketizationMode: track.PacketizationMode,
|
||||
}
|
||||
rtpDec.Init()
|
||||
|
||||
// setup H264->raw frames decoder
|
||||
@@ -86,11 +88,11 @@ func main() {
|
||||
defer h264RawDec.close()
|
||||
|
||||
// if SPS and PPS are present into the SDP, send them to the decoder
|
||||
sps := h264track.SafeSPS()
|
||||
sps := track.SafeSPS()
|
||||
if sps != nil {
|
||||
h264RawDec.decode(sps)
|
||||
}
|
||||
pps := h264track.SafePPS()
|
||||
pps := track.SafePPS()
|
||||
if pps != nil {
|
||||
h264RawDec.decode(pps)
|
||||
}
|
||||
@@ -131,7 +133,7 @@ func main() {
|
||||
}
|
||||
|
||||
// setup and read the H264 track only
|
||||
err = c.SetupAndPlay(gortsplib.Tracks{h264track}, baseURL)
|
||||
err = c.SetupAndPlay(gortsplib.Tracks{track}, baseURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -47,7 +47,9 @@ func main() {
|
||||
}
|
||||
|
||||
// setup RTP/H264->H264 decoder
|
||||
rtpDec := &rtph264.Decoder{}
|
||||
rtpDec := &rtph264.Decoder{
|
||||
PacketizationMode: track.PacketizationMode,
|
||||
}
|
||||
rtpDec.Init()
|
||||
|
||||
// setup H264->MPEGTS muxer
|
||||
|
@@ -52,7 +52,9 @@ func main() {
|
||||
}
|
||||
|
||||
// setup RTP/H264->H264 decoder
|
||||
rtpDec := &rtph264.Decoder{}
|
||||
rtpDec := &rtph264.Decoder{
|
||||
PacketizationMode: track.PacketizationMode,
|
||||
}
|
||||
rtpDec.Init()
|
||||
|
||||
// setup H264->raw frames decoder
|
||||
|
@@ -79,7 +79,9 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
||||
}
|
||||
|
||||
// setup RTP/H264->H264 decoder
|
||||
rtpDec := &rtph264.Decoder{}
|
||||
rtpDec := &rtph264.Decoder{
|
||||
PacketizationMode: h264track.PacketizationMode,
|
||||
}
|
||||
rtpDec.Init()
|
||||
|
||||
// setup H264->MPEGTS muxer
|
||||
|
@@ -24,6 +24,9 @@ var ErrNonStartingPacketAndNoPrevious = errors.New(
|
||||
|
||||
// Decoder is a RTP/H264 decoder.
|
||||
type Decoder struct {
|
||||
// indicates the packetization mode.
|
||||
PacketizationMode int
|
||||
|
||||
timeDecoder *rtptimedec.Decoder
|
||||
firstPacketReceived bool
|
||||
fragmentedSize int
|
||||
@@ -42,6 +45,10 @@ func (d *Decoder) Init() {
|
||||
|
||||
// Decode decodes NALUs from a RTP/H264 packet.
|
||||
func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
|
||||
if d.PacketizationMode >= 2 {
|
||||
return nil, 0, fmt.Errorf("PacketizationMode >= 2 is not supported")
|
||||
}
|
||||
|
||||
if len(pkt.Payload) < 1 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragmented packets
|
||||
return nil, 0, fmt.Errorf("payload is too short")
|
||||
@@ -154,7 +161,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return nalus, d.timeDecoder.Decode(pkt.Timestamp), err
|
||||
return nalus, d.timeDecoder.Decode(pkt.Timestamp), nil
|
||||
}
|
||||
|
||||
// DecodeUntilMarker decodes NALUs from a RTP/H264 packet and puts them in a buffer.
|
||||
|
@@ -2,5 +2,5 @@
|
||||
package rtph264
|
||||
|
||||
const (
|
||||
rtpClockRate = 90000 // h264 always uses 90khz
|
||||
rtpClockRate = 90000 // H264 always uses 90khz
|
||||
)
|
||||
|
@@ -30,6 +30,7 @@ func invalidURLAnnounceReq(t *testing.T, control string) base.Request {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
track.SetControl(control)
|
||||
|
||||
@@ -235,6 +236,7 @@ func TestServerPublishSetupPath(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
track.SetControl(ca.control)
|
||||
|
||||
@@ -330,6 +332,7 @@ func TestServerPublishErrorSetupDifferentPaths(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -410,6 +413,7 @@ func TestServerPublishErrorSetupTrackTwice(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -511,12 +515,14 @@ func TestServerPublishErrorRecordPartialTracks(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
track2 := &TrackH264{
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track1, track2}
|
||||
@@ -668,6 +674,7 @@ func TestServerPublish(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -864,6 +871,7 @@ func TestServerPublishErrorInvalidProtocol(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -969,6 +977,7 @@ func TestServerPublishRTCPReport(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -1146,6 +1155,7 @@ func TestServerPublishTimeout(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -1275,6 +1285,7 @@ func TestServerPublishWithoutTeardown(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
@@ -1394,6 +1405,7 @@ func TestServerPublishUDPChangeConn(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
tracks := Tracks{track}
|
||||
|
@@ -96,6 +96,7 @@ func TestServerReadSetupPath(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track, track, track, track, track})
|
||||
@@ -163,6 +164,7 @@ func TestServerReadSetupErrors(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -285,6 +287,7 @@ func TestServerReadSetupErrorSameUDPPortsAndIP(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -378,6 +381,7 @@ func TestServerRead(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -719,6 +723,7 @@ func TestServerReadRTCPReport(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}})
|
||||
defer stream.Close()
|
||||
|
||||
@@ -867,6 +872,7 @@ func TestServerReadVLCMulticast(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -922,6 +928,7 @@ func TestServerReadTCPResponseBeforeFrames(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -1022,6 +1029,7 @@ func TestServerReadPlayPlay(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -1112,6 +1120,7 @@ func TestServerReadPlayPausePlay(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -1238,6 +1247,7 @@ func TestServerReadPlayPausePause(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -1372,6 +1382,7 @@ func TestServerReadTimeout(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -1487,6 +1498,7 @@ func TestServerReadWithoutTeardown(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -1593,6 +1605,7 @@ func TestServerReadUDPChangeConn(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -1699,12 +1712,14 @@ func TestServerReadPartialTracks(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
track2 := &TrackH264{
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track1, track2})
|
||||
|
@@ -343,6 +343,7 @@ func TestServerErrorMethodNotImplemented(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -428,6 +429,7 @@ func TestServerErrorTCPTwoConnOneSession(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -534,6 +536,7 @@ func TestServerErrorTCPOneConnTwoSessions(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -634,6 +637,7 @@ func TestServerSetupMultipleTransports(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}})
|
||||
defer stream.Close()
|
||||
|
||||
@@ -715,6 +719,7 @@ func TestServerGetSetParameter(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -888,6 +893,7 @@ func TestServerSessionClose(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}})
|
||||
defer stream.Close()
|
||||
|
||||
@@ -962,6 +968,7 @@ func TestServerSessionAutoClose(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}})
|
||||
defer stream.Close()
|
||||
|
||||
@@ -1026,6 +1033,7 @@ func TestServerSessionTeardown(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}})
|
||||
defer stream.Close()
|
||||
|
||||
@@ -1106,6 +1114,7 @@ func TestServerErrorInvalidPath(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
stream := NewServerStream(Tracks{track})
|
||||
@@ -1226,6 +1235,7 @@ func TestServerAuth(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PPS: []byte{0x01, 0x02, 0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
req := base.Request{
|
||||
|
@@ -16,6 +16,7 @@ type TrackH264 struct {
|
||||
PayloadType uint8
|
||||
SPS []byte
|
||||
PPS []byte
|
||||
PacketizationMode int
|
||||
|
||||
trackBase
|
||||
mutex sync.RWMutex
|
||||
@@ -61,7 +62,8 @@ func (t *TrackH264) fillParamsFromMediaDescription(md *psdp.MediaDescription) er
|
||||
return fmt.Errorf("invalid fmtp attribute (%v)", v)
|
||||
}
|
||||
|
||||
if tmp[0] == "sprop-parameter-sets" {
|
||||
switch tmp[0] {
|
||||
case "sprop-parameter-sets":
|
||||
tmp := strings.Split(tmp[1], ",")
|
||||
if len(tmp) < 2 {
|
||||
return fmt.Errorf("invalid sprop-parameter-sets (%v)", v)
|
||||
@@ -79,7 +81,14 @@ func (t *TrackH264) fillParamsFromMediaDescription(md *psdp.MediaDescription) er
|
||||
|
||||
t.SPS = sps
|
||||
t.PPS = pps
|
||||
return nil
|
||||
|
||||
case "packetization-mode":
|
||||
tmp, err := strconv.ParseInt(tmp[1], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid packetization-mode (%v)", v)
|
||||
}
|
||||
|
||||
t.PacketizationMode = int(tmp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +105,7 @@ func (t *TrackH264) clone() Track {
|
||||
PayloadType: t.PayloadType,
|
||||
SPS: t.SPS,
|
||||
PPS: t.PPS,
|
||||
PacketizationMode: t.PacketizationMode,
|
||||
trackBase: t.trackBase,
|
||||
}
|
||||
}
|
||||
@@ -135,21 +145,27 @@ func (t *TrackH264) MediaDescription() *psdp.MediaDescription {
|
||||
|
||||
typ := strconv.FormatInt(int64(t.PayloadType), 10)
|
||||
|
||||
fmtp := typ + " packetization-mode=1"
|
||||
fmtp := typ
|
||||
|
||||
var tmp []string
|
||||
if t.PacketizationMode != 0 {
|
||||
tmp = append(tmp, "packetization-mode="+strconv.FormatInt(int64(t.PacketizationMode), 10))
|
||||
}
|
||||
var tmp2 []string
|
||||
if t.SPS != nil {
|
||||
tmp = append(tmp, base64.StdEncoding.EncodeToString(t.SPS))
|
||||
tmp2 = append(tmp2, base64.StdEncoding.EncodeToString(t.SPS))
|
||||
}
|
||||
if t.PPS != nil {
|
||||
tmp = append(tmp, base64.StdEncoding.EncodeToString(t.PPS))
|
||||
tmp2 = append(tmp2, base64.StdEncoding.EncodeToString(t.PPS))
|
||||
}
|
||||
if len(tmp) > 0 {
|
||||
fmtp += "; sprop-parameter-sets=" + strings.Join(tmp, ",")
|
||||
if tmp2 != nil {
|
||||
tmp = append(tmp, "sprop-parameter-sets="+strings.Join(tmp2, ","))
|
||||
}
|
||||
|
||||
if len(t.SPS) >= 4 {
|
||||
fmtp += "; profile-level-id=" + strings.ToUpper(hex.EncodeToString(t.SPS[1:4]))
|
||||
tmp = append(tmp, "profile-level-id="+strings.ToUpper(hex.EncodeToString(t.SPS[1:4])))
|
||||
}
|
||||
if tmp != nil {
|
||||
fmtp += " " + strings.Join(tmp, "; ")
|
||||
}
|
||||
|
||||
return &psdp.MediaDescription{
|
||||
|
@@ -12,6 +12,7 @@ func TestTrackH264Attributes(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02},
|
||||
PPS: []byte{0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
require.Equal(t, 90000, track.ClockRate())
|
||||
require.Equal(t, "", track.GetControl())
|
||||
@@ -175,7 +176,7 @@ func TestTrackH264GetSPSPPSErrors(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
tr := &TrackH264{}
|
||||
var tr TrackH264
|
||||
err := tr.fillParamsFromMediaDescription(ca.md)
|
||||
require.EqualError(t, err, ca.err)
|
||||
})
|
||||
@@ -187,6 +188,7 @@ func TestTrackH264Clone(t *testing.T) {
|
||||
PayloadType: 96,
|
||||
SPS: []byte{0x01, 0x02},
|
||||
PPS: []byte{0x03, 0x04},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
clone := track.clone()
|
||||
@@ -206,6 +208,7 @@ func TestTrackH264MediaDescription(t *testing.T) {
|
||||
PPS: []byte{
|
||||
0x68, 0xee, 0x3c, 0x80,
|
||||
},
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
require.Equal(t, &psdp.MediaDescription{
|
||||
@@ -235,6 +238,7 @@ func TestTrackH264MediaDescription(t *testing.T) {
|
||||
t.Run("no sps/pps", func(t *testing.T) {
|
||||
track := &TrackH264{
|
||||
PayloadType: 96,
|
||||
PacketizationMode: 1,
|
||||
}
|
||||
|
||||
require.Equal(t, &psdp.MediaDescription{
|
||||
|
@@ -258,6 +258,7 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
||||
PPS: []byte{
|
||||
0x68, 0xee, 0x3c, 0x80,
|
||||
},
|
||||
PacketizationMode: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -310,6 +311,7 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
||||
PPS: []byte{
|
||||
0x68, 0xeb, 0xe3, 0xcb, 0x22, 0xc0,
|
||||
},
|
||||
PacketizationMode: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -343,6 +345,7 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
||||
PPS: []byte{
|
||||
0x68, 0xfa, 0x8f, 0x2c,
|
||||
},
|
||||
PacketizationMode: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@@ -79,6 +79,7 @@ func TestTracksReadSkipGenericTracksWithoutClockRate(t *testing.T) {
|
||||
PayloadType: 97,
|
||||
SPS: []byte{0x67, 0x64, 0x00, 0x28, 0xac, 0xb4, 0x03, 0xc0, 0x11, 0x3f, 0x2a},
|
||||
PPS: []byte{0x68, 0xee, 0x01, 0x9e, 0x2c},
|
||||
PacketizationMode: 1,
|
||||
},
|
||||
&TrackPCMU{
|
||||
trackBase: trackBase{
|
||||
|
Reference in New Issue
Block a user