Disable video and force ulaw over SIP trunk

Hello, we use Asterisk 19.4.0 on Debian 11 using PJSIP. Our SIP devices use Opus full band codec internally and have h.264 video support. Our SIP trunk does not support video, and supports ulaw.

When we dial an outside number over the trunk, Asterisk transcodes from opus to ulaw. This is an undesired behavior - for outgoing calls, we’d like to force ulaw while still maintaining wideband opus capability internally. Additionally, our devices show a black screen for the video feed, also undesirable - we’d like to disable video for outgoing SIP trunk calls.

Our endpoints are configured as follows, allowing all codecs used in our configuration.

disallow=all
allow=opus
allow=g722
allow=ulaw
allow=h264

I was able to get this sort of working by editing the dial plan entry for my sip trunk, and re-inviting the media session after it has been established with a different set of codecs (ulaw) and disabling video, as follows:

[sip-trunk]
exten => _X.,1,NoOp()
exten => _X.,2,Answer()
exten => _X.,3,Set(PJSIP_MEDIA_OFFER(audio)=!all,ulaw)
exten => _X.,4,Set(PJSIP_MEDIA_OFFER(video)=!all)
exten => _X.,5,Set(PJSIP_SEND_SESSION_REFRESH()=invite) ;send invite with variable

exten => _1NXXNXXXXXX,6,NoOp()
exten => _1NXXNXXXXXX,n,Dial(PJSIP/${EXTEN}@voipms)
exten => _1NXXNXXXXXX,n,Hangup()

exten => _NXXNXXXXXX,6,NoOp()
exten => _NXXNXXXXXX,n,Dial(PJSIP/1${EXTEN}@voipms)
exten => _NXXNXXXXXX,n,Hangup()

This works and the outgoing codec is switched from opus to ulaw, and the video feed is disabled. However, when an outgoing call is made, the video feed starts and then once asterisk answers, it flickers and is disabled. I am guessing this is because asterisk answers (Answer()) and then changes the media session parameters, turning the feed off. This is annoying to our users and seems to slow down the initial contact.

Is there a way to fix this, perhaps to disable the video feed and set the codec before the media stream is first established?

Thank you

Hi might be a stupid question
what happens if you disable your Answer in line 2 and use UPDATE

exten => _X.,1,NoOp()
same => n,Set(PJSIP_MEDIA_OFFER(audio)=!all,ulaw)
same => n,Set(PJSIP_MEDIA_OFFER(video)=!all)
same => n,Set(PJSIP_SEND_SESSION_REFRESH()= update)

I tried that. It gives me an error that the session must be answered before it can be updated.

[May 16 12:31:42] WARNING[38718][C-00000023]: pjsip/dialplan_functions.c:1700 pjsip_acf_session_refresh_write: 'PJSIP_SEND_SESSION_REFRESH' not allowed on unanswered channel 'PJSIP/user-00000040'.

The updated config:

exten => _X.,1,Set(PJSIP_MEDIA_OFFER(audio)=!all,ulaw)
exten => _X.,2,Set(PJSIP_MEDIA_OFFER(video)=!all)
exten => _X.,3,Set(PJSIP_SEND_SESSION_REFRESH()=update) ;send invite with variable

can you try changing audio/video before the answer, and see if that works
also not sure where the PJSIP_SEND_SESSION_REFRESH is needed in this example or not
also try change to use same and n in your code instead of exten => _X.,2 as it make coding much simpler

exten => _X.,1,Set(PJSIP_MEDIA_OFFER(audio)=!all,ulaw)
same => n,Set(PJSIP_MEDIA_OFFER(video)=!all)
same => n,Answer()
same => n,Set(PJSIP_SEND_SESSION_REFRESH()=update) ;send invite with variable

Hi - Thanks for the coding tip, asterisk neophyte over here!

Your suggested change makes sense to me, but has no effect.

exten => _X.,3,NoOp()
 same => n,Set(PJSIP_MEDIA_OFFER(audio)=!all,ulaw)
 same => n,Set(PJSIP_MEDIA_OFFER(video)=!all)
 same => n,Answer()
 same => n,Set(PJSIP_SEND_SESSION_REFRESH()=update) ;send invite with variable

This connects to the trunk with a black video screen.

The only configuration that successfully removes the video is:

exten => _X.,3,NoOp()
 same => n,Answer()
 same => n,Set(PJSIP_MEDIA_OFFER(audio)=!all,ulaw)
 same => n,Set(PJSIP_MEDIA_OFFER(video)=!all)
 same => n,Set(PJSIP_SEND_SESSION_REFRESH()=update) ;send invite with variable

but the video screen flashes briefly, very annoying!

1 Like

hmm, I’m out of ideas
only option left as I know is to patch asterisk

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.