VoIP.info Guide

Asterisk PJSIP_MEDIA_OFFER: change one outbound codec offer safely

Apply an audio or video offer to the intended outbound PJSIP channel while keeping endpoint policy, pre-dial timing, SDP, answers, translation and later session refreshes independently observable.

Reviewed 2026-10-14Asterisk Latest API branch 23 PJSIP_MEDIA_OFFER, PJSIP_SEND_SESSION_REFRESH, Dial and res_pjsip documentation plus current pre-dial, codec-negotiation and codec-module references reviewed October 13, 2026; no Asterisk host, endpoint, channel, dialplan, codec module, offer, answer, refresh, translator, packet, media stream or live call was inspected or testedAdvancedDocumentation based · not lab tested

Choose the exact PJSIP channel and offer phase

PJSIP_MEDIA_OFFER() reads or writes the codec list for one media type on a PJSIP channel. Asterisk documents the write path for an outbound SIP channel before dialing, or for a later refresh on an established media session. Those are different timelines and channel states.

Name the caller, every created callee and the intended SIP leg before changing a list. A value written on the inbound or caller channel is not evidence that the outbound INVITE used it.

Run an initial-offer change on each intended callee

A lowercase b pre-dial handler runs on each callee after its channel is created and before the call is placed. Uppercase B runs on the caller before callee channels exist. Use the callee path when the requirement is to alter the offer emitted by the outbound PJSIP channel.

Every pre-dial handler is a Gosub and must return. Keep it short, preserve the surrounding application state and do not enter another call-control application from the handler. In a managed PBX, use a supported hook rather than editing generated dialplan.

Keep media types and codec lists explicit

The function accepts audio or video as the media choice. Record the list before and after the write and preserve the exact outbound SDP. Removing video, preferring one audio codec and leaving the endpoint policy unchanged are three different changes.

The documented session-refresh example uses !all,g722; treat list-clearing and ordered additions as an intentional policy expression, not a string to copy into every endpoint. A codec name alone does not establish clock rate, format parameters, RTP profile, protection or peer acceptance.

Reconcile the override with endpoint negotiation

The outbound channel still participates in Asterisk PJSIP codec negotiation. Endpoint allow and the incoming-offer, outgoing-offer, incoming-answer and outgoing-answer preference fields supply configured inputs at different control points. The pending and resolved stream topologies can therefore differ from both the endpoint order and the dialplan value.

Capture the two SIP legs separately. Asterisk is a back-to-back user agent; the caller-facing answer and callee-facing offer are not one end-to-end codec list.

Treat an established-session refresh as a new exchange

After setup, PJSIP_SEND_SESSION_REFRESH() can send a re-INVITE or UPDATE and is documented for use with PJSIP_MEDIA_OFFER(). It does not check or enforce what the endpoint supports, and Asterisk warns that an unsupported offer can cause loss of media.

Use refresh only for an explicit mid-call requirement on the intended answered channel. Record the method, offer, response, resulting channel formats and packet path; do not add a refresh merely because an initial pre-dial write ran on the wrong channel.

Verify negotiation, translation and usable media separately

A successful SIP answer proves a narrower result than decoded audio or video. Confirm the selected payload and attributes, media in both directions, channel read and write formats, installed codec modules and an available translation path when the two legs differ.

Correct the earliest proven mismatch and preserve rollback. Retest a supported offer and a negative or rejected case without weakening security or enabling broad codec lists. This guide is documentation-derived; no host, endpoint, channel, codec, translator, packet or call was tested.

Send a controlled post-answer offer with an explicit refresh

The PJSIP_SEND_SESSION_REFRESH guide covers the documented handoff from a staged audio or video offer to re-INVITE or UPDATE and warns that endpoint format support is not enforced by the refresh function.

Sources & applicability

Primary references for the technical details above. Operational examples and planning checklists are VoIP.info editorial guidance.

Examples require adaptation to your topology. No live PBX or hardware testing is claimed.