@@ -213,8 +213,9 @@ func TestMediaPort(t *testing.T) {
213213 codecs := msdk .NewCodecSet ()
214214 codecs .SetEnabled (info .SDPName , true )
215215
216- sub := strings .SplitN (info .SDPName , "/" , 2 )
216+ sub := strings .SplitN (info .SDPName , "/" , 3 )
217217 codecName := sub [0 ]
218+ encName := strings .ToUpper (codecName )
218219 nativeRateSDP , err := strconv .Atoi (sub [1 ])
219220 nativeRate := nativeRateSDP
220221 require .NoError (t , err )
@@ -342,30 +343,34 @@ func TestMediaPort(t *testing.T) {
342343 aliceToBobWrites := 1
343344 bobToAliceWrites := 1
344345 if tconf .Rate == nativeRate {
345- expChainBase := fmt .Sprintf ("Switch(%d) -> LatencyEntry -> %s(encode) -> ByteEncoder(%d) -> StatsWriter(%s/%d) -> LatencyExit" ,
346- nativeRate , codecName , nativeRate , codecName , nativeRateSDP )
347- require .Equal (t , fmt .Sprintf ("%s -> RTPWriteStream(%s:%d)" , expChainBase , ip2 , port2 ), aliceToBobWriteChain )
348- require .Equal (t , fmt .Sprintf ("%s -> RTPWriteStream(%s:%d)" , expChainBase , ip1 , port1 ), bobToAliceWriteChain )
346+ expChainBase := fmt .Sprintf ("Switch(%d) -> LatencyEntry -> %s(encode) -> ByteEncoder(%d) -> StatsWriter(%s) -> LatencyExit" ,
347+ nativeRate , encName , nativeRate , info .SDPName )
348+ if tconf .Encrypted != sdp .EncryptionNone {
349+ require .Equal (t , fmt .Sprintf ("%s -> SRTPWriteStream" , expChainBase ), aliceToBobWriteChain )
350+ require .Equal (t , fmt .Sprintf ("%s -> SRTPWriteStream" , expChainBase ), bobToAliceWriteChain )
351+ } else {
352+ require .Equal (t , fmt .Sprintf ("%s -> RTPWriteStream(%s:%d)" , expChainBase , ip2 , port2 ), aliceToBobWriteChain )
353+ require .Equal (t , fmt .Sprintf ("%s -> RTPWriteStream(%s:%d)" , expChainBase , ip1 , port1 ), bobToAliceWriteChain )
354+ }
349355
350- expChainBase = fmt .Sprintf ("SilenceFiller(25) -> RTP(%%d) -> ByteDecoder -> %s(decode) -> LatencyExit -> Switch(%d) -> Buffer(%d)" , codecName , nativeRate , nativeRate )
356+ expChainBase = fmt .Sprintf ("SilenceFiller(25) -> RTP(%%d) -> ByteDecoder -> %s(decode) -> LatencyExit -> Switch(%d) -> Buffer(%d)" , encName , nativeRate , nativeRate )
351357 require .Equal (t , fmt .Sprintf (expChainBase , aliceAudio .Type ), bobToAliceHandleChain )
352358 require .Equal (t , fmt .Sprintf (expChainBase , bobAudio .Type ), aliceToBobHandleChain )
353359 } else {
354- expChain := fmt .Sprintf ("Switch(48000) -> Resample(48000->%d) -> LatencyEntry -> %s(encode) -> ByteEncoder(%d) -> StatsWriter(%s/%d ) -> LatencyExit -> SRTPWriteStream" ,
355- nativeRate , codecName , nativeRate , codecName , nativeRateSDP )
360+ expChain := fmt .Sprintf ("Switch(48000) -> Resample(48000->%d) -> LatencyEntry -> %s(encode) -> ByteEncoder(%d) -> StatsWriter(%s) -> LatencyExit -> SRTPWriteStream" ,
361+ nativeRate , encName , nativeRate , info . SDPName )
356362 require .Equal (t , expChain , aliceToBobWriteChain )
357363 require .Equal (t , expChain , bobToAliceWriteChain )
358364
359365 // This side does not resample the received audio, it uses sample rate of the RTP source.
360366 var expChainAlice string
361367 if bobToAliceNoResample {
362- expChainAlice = fmt .Sprintf ("SilenceFiller(25) -> RTP(%d) -> ByteDecoder -> %s(decode) -> LatencyExit -> Switch(%d) -> Buffer(%d)" , aliceAudio .Type , codecName , nativeRate , nativeRate )
368+ expChainAlice = fmt .Sprintf ("SilenceFiller(25) -> RTP(%d) -> ByteDecoder -> %s(decode) -> LatencyExit -> Switch(%d) -> Buffer(%d)" , aliceAudio .Type , encName , nativeRate , nativeRate )
363369 } else {
364- expChainAlice = fmt .Sprintf ("SilenceFiller(25) -> RTP(%d) -> ByteDecoder -> %s(decode) -> Resample(%d->48000) -> LatencyExit -> Switch(48000) -> Buffer(48000)" , aliceAudio .Type , codecName , nativeRate )
370+ expChainAlice = fmt .Sprintf ("SilenceFiller(25) -> RTP(%d) -> ByteDecoder -> %s(decode) -> Resample(%d->48000) -> LatencyExit -> Switch(48000) -> Buffer(48000)" , aliceAudio .Type , encName , nativeRate )
365371 }
366-
367372 // This side resamples the received audio to the expected sample rate.
368- expChainBob := fmt .Sprintf ("SilenceFiller(25) -> RTP(%d) -> ByteDecoder -> %s(decode) -> Resample(%d->48000) -> LatencyExit -> Switch(48000) -> Buffer(48000)" , bobAudio .Type , codecName , nativeRate )
373+ expChainBob := fmt .Sprintf ("SilenceFiller(25) -> RTP(%d) -> ByteDecoder -> %s(decode) -> Resample(%d->48000) -> LatencyExit -> Switch(48000) -> Buffer(48000)" , bobAudio .Type , encName , nativeRate )
369374
370375 require .Equal (t , expChainAlice , bobToAliceHandleChain )
371376 require .Equal (t , expChainBob , aliceToBobHandleChain )
@@ -387,6 +392,9 @@ func TestMediaPort(t *testing.T) {
387392 case "AMR-WB" :
388393 rampUpFrames += 1
389394 offsetSamples += 14 + 16
395+ case "opus" :
396+ rampUpFrames += 2
397+ offsetSamples += 24
390398 }
391399 aliceToBobWrites += rampUpFrames
392400 bobToAliceWrites += rampUpFrames
0 commit comments