@@ -252,3 +252,64 @@ func BenchmarkTrackLocalWrite(b *testing.B) {
252
252
assert .NoError (b , err )
253
253
}
254
254
}
255
+
256
+ func Test_TrackLocalStatic_Padding (t * testing.T ) {
257
+ mediaEngineOne := & MediaEngine {}
258
+ assert .NoError (t , mediaEngineOne .RegisterCodec (RTPCodecParameters {
259
+ RTPCodecCapability : RTPCodecCapability {MimeType : "video/VP8" , ClockRate : 90000 , Channels : 0 , SDPFmtpLine : "" , RTCPFeedback : nil },
260
+ PayloadType : 100 ,
261
+ }, RTPCodecTypeVideo ))
262
+
263
+ mediaEngineTwo := & MediaEngine {}
264
+ assert .NoError (t , mediaEngineTwo .RegisterCodec (RTPCodecParameters {
265
+ RTPCodecCapability : RTPCodecCapability {MimeType : "video/VP8" , ClockRate : 90000 , Channels : 0 , SDPFmtpLine : "" , RTCPFeedback : nil },
266
+ PayloadType : 200 ,
267
+ }, RTPCodecTypeVideo ))
268
+
269
+ offerer , err := NewAPI (WithMediaEngine (mediaEngineOne )).NewPeerConnection (Configuration {})
270
+ assert .NoError (t , err )
271
+
272
+ answerer , err := NewAPI (WithMediaEngine (mediaEngineTwo )).NewPeerConnection (Configuration {})
273
+ assert .NoError (t , err )
274
+
275
+ track , err := NewTrackLocalStaticSample (RTPCodecCapability {MimeType : MimeTypeVP8 }, "video" , "pion" )
276
+ assert .NoError (t , err )
277
+
278
+ _ , err = offerer .AddTransceiverFromKind (RTPCodecTypeVideo )
279
+ assert .NoError (t , err )
280
+
281
+ _ , err = answerer .AddTrack (track )
282
+ assert .NoError (t , err )
283
+
284
+ onTrackFired , onTrackFiredFunc := context .WithCancel (context .Background ())
285
+
286
+ offerer .OnTrack (func (track * TrackRemote , _ * RTPReceiver ) {
287
+ assert .Equal (t , track .PayloadType (), PayloadType (100 ))
288
+ assert .Equal (t , track .Codec ().RTPCodecCapability .MimeType , "video/VP8" )
289
+
290
+ for i := 0 ; i < 20 ; i ++ {
291
+ // Padding payload
292
+ p , _ , e := track .ReadRTP ()
293
+ assert .NoError (t , e )
294
+ assert .True (t , p .Padding )
295
+ assert .Equal (t , p .PaddingSize , byte (255 ))
296
+ }
297
+
298
+ onTrackFiredFunc ()
299
+ })
300
+
301
+ assert .NoError (t , signalPair (offerer , answerer ))
302
+
303
+ exit := false
304
+
305
+ for ! exit {
306
+ select {
307
+ case <- time .After (1 * time .Millisecond ):
308
+ assert .NoError (t , track .GeneratePadding (1 ))
309
+ case <- onTrackFired .Done ():
310
+ exit = true
311
+ }
312
+ }
313
+
314
+ closePairNow (t , offerer , answerer )
315
+ }
0 commit comments