@@ -363,3 +363,51 @@ func encryptSRTP(context *Context, pkt *rtp.Packet) ([]byte, error) {
363363
364364 return encrypted , nil
365365}
366+
367+ func TestSessionSRTPPacketWithPadding (t * testing.T ) {
368+ lim := test .TimeOut (time .Second * 5 )
369+ defer lim .Stop ()
370+
371+ report := test .CheckRoutines (t )
372+ defer report ()
373+
374+ const (
375+ testSSRC = 5000
376+ rtpHeaderSize = 12
377+ paddingSize = 5
378+ authTagLen = 10 // For AES_CM_128_HMAC_SHA1_80, the auth tag length is 10 bytes.
379+ )
380+ testPayload := []byte {0x00 , 0x01 , 0x03 , 0x04 }
381+ readBuffer := make ([]byte , rtpHeaderSize + paddingSize + len (testPayload ))
382+ aSession , bSession := buildSessionSRTPPair (t )
383+
384+ aWriteStream , err := aSession .OpenWriteStream ()
385+ assert .NoError (t , err )
386+
387+ writeBytes , err := aWriteStream .WriteRTP (& rtp.Header {SSRC : testSSRC , Padding : true , PaddingSize : paddingSize },
388+ append ([]byte {}, testPayload ... ))
389+ assert .NoError (t , err )
390+ assert .Equalf (t , rtpHeaderSize + paddingSize + len (testPayload )+ authTagLen , writeBytes ,
391+ "WriteRTP should return the size of the packet including padding, exp(%v) actual(%v)" ,
392+ rtpHeaderSize + paddingSize + len (testPayload )+ authTagLen , writeBytes )
393+
394+ bReadStream , ssrc , err := bSession .AcceptStream ()
395+ assert .NoError (t , err )
396+ assert .Equalf (t , uint32 (testSSRC ), ssrc , "SSRC mismatch during accept exp(%v) actual(%v)" , testSSRC , ssrc )
397+
398+ readBytes , err := bReadStream .Read (readBuffer )
399+ assert .NoError (t , err )
400+ assert .Equal (t , rtpHeaderSize + paddingSize + len (testPayload ), readBytes ,
401+ "Read should return the size of the packet including padding, exp(%v) actual(%v)" ,
402+ rtpHeaderSize + paddingSize + len (testPayload ), readBytes )
403+
404+ var rtpPacket rtp.Packet
405+ err = rtpPacket .Unmarshal (readBuffer [:readBytes ])
406+ assert .NoError (t , err )
407+ assert .Equal (t , rtpPacket .Padding , true )
408+ assert .Equal (t , rtpPacket .PaddingSize , byte (paddingSize ))
409+ assert .Equal (t , rtpPacket .Payload , testPayload )
410+
411+ assert .NoError (t , aSession .Close ())
412+ assert .NoError (t , bSession .Close ())
413+ }
0 commit comments