Skip to content

Test 3rd-party media support#4923

Open
wosrediinanatour wants to merge 2 commits intopjsip:masterfrom
wosrediinanatour:test-third-party-media
Open

Test 3rd-party media support#4923
wosrediinanatour wants to merge 2 commits intopjsip:masterfrom
wosrediinanatour:test-third-party-media

Conversation

@wosrediinanatour
Copy link
Copy Markdown
Contributor

@wosrediinanatour wosrediinanatour commented Apr 15, 2026

The alt_pjsua demo lacked a way to supply application-defined SDP, making it impossible to verify that third-party media stacks can inject arbitrary session descriptions into outgoing INVITEs and 200 OK answers.

This PR adds tests for UAS and UAC that are using 3rd-party media.

The alt_pjsua demo uses alt_pjsua_aud.c and alt_pjsua_vid.c to replace
the standard PJMEDIA audio/video backend, demonstrating how a third-party
media stack integrates with pjsua-lib. Without a way to inject arbitrary
SDP, there was no automated way to verify that the custom media layer
correctly produces well-formed session descriptions in outgoing INVITEs
and 200 OK answers.

A --custom-sdp command-line option is added to pjsua_app (compiled with
PJSUA_MEDIA_HAS_PJMEDIA=0) and wired to an on_call_sdp_created callback
so the application can supply its own SDP. Two SIPp-based test pairs
exercise this in both call directions:

- UAC test: alt_pjsua sends an INVITE with custom audio SDP (PCMU);
  SIPp verifies the codec appears and answers with a matching 200 OK.
  Audio-only is used here because pjsua provisions only one media
  channel by default for outgoing calls, so a two-section custom SDP
  would trigger an assertion in pjsua_media_channel_update.

- UAS test: SIPp sends an INVITE with audio+video (PCMU + H263-1998/96);
  alt_pjsua auto-answers with the custom SDP and logs the incoming SDP.
  The UAS direction naturally supports two media sections because
  med_prov_cnt is derived from the remote INVITE's media count.

alt_pjsua_vid.c gains stub mocks for AVI player/recorder functions and
pjsua_call_get_vid_conf_port. These symbols are normally compiled in
pjsua_vid.c behind PJSUA_MEDIA_HAS_PJMEDIA guards; without the stubs
the linker cannot resolve them when the whole project is built with
PJSUA_MEDIA_HAS_PJMEDIA=0.

A dedicated alt-pjsua CI job copies
pjsip-apps/src/3rdparty_media_sample/config_site.h (which sets
PJSUA_MEDIA_HAS_PJMEDIA=0, PJMEDIA_HAS_VIDEO=1, and disables all
standard codecs) into pjlib/include/pj/, builds only the libraries
(make lib), then compiles alt_pjsua and runs the SIPp tests. A
dedicated job is used rather than appending to an existing one so the
test environment exactly matches the third-party media configuration
without inheriting unrelated defines.
@wosrediinanatour
Copy link
Copy Markdown
Contributor Author

Still UAC has to be fixed (Video does not work).

@wosrediinanatour wosrediinanatour changed the title Test 3rd-party media Test 3rd-party media support Apr 17, 2026
The UAC test was audio-only because on_call_sdp_created_cb replaces the
generated SDP after pjsua_media_channel_init has already provisioned
call->med_prov_cnt from call->opt (aud_cnt + vid_cnt + txt_cnt).  The
provisioned count may be larger than the two-section custom SDP, but it
can also be smaller when fewer transports were actually allocated; e.g.
only one RTP socket appears in the log (port 4000) even when vid_cnt=1.

In that situation pjsua_media_channel_update's assertion
    call->med_prov_cnt >= local_sdp->media_count
fires: med_prov_cnt=1 < custom_sdp->media_count=2.

For UAS the assertion never fires because med_prov_cnt is set directly
from rem_sdp->media_count (the incoming INVITE already carries 2 media
sections), which is always >= the local answer.

Fix: after the on_call_sdp_created callback in pjsua_media_channel_create_sdp,
sync med_prov_cnt upward to match sdp->media_count if the callback added media
sections.  This mirrors the existing pattern for the rem_sdp (UAS) path
(lines 2539-2541: "this media count must never decrease").

The other SDP callbacks (on_call_rx_offer, on_call_tx_offer) are invoked
*before* pjsua_media_channel_create_sdp and let apply_call_setting() re-
provision transports, so med_prov_cnt is already correct when they return.
on_call_sdp_created is unique in being invoked at the end of SDP creation,
bypassing re-provisioning, so an explicit sync is needed there.

The fix lives in pjsua_media.c (not in the application callback) so that any
on_call_sdp_created implementation that adds media sections automatically
gets correct behaviour, without reaching into pjsua_internal.h.

The UAC and UAS XML/PY test scripts are updated to carry both
m=audio (PCMU/0) and m=video (H263-1998/96) in every SDP, and to
verify via ereg/CLI-expect that both codec lines appear.

/* Sync med_prov_cnt with the final SDP media count in case the callback
* added or replaced media sections (e.g. custom SDP with more m= lines).
* Mirrors the same invariant maintained for the rem_sdp (UAS) path above:
Copy link
Copy Markdown
Contributor Author

@wosrediinanatour wosrediinanatour Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my proposed fix to fix alt-pjsua-uac-custom-sdp.

Now the test cases should be green.

@wosrediinanatour
Copy link
Copy Markdown
Contributor Author

wosrediinanatour commented Apr 17, 2026

PTAL @sauwming, @nanangizz

How I would approach this PR:

  1. check the two new tests
  2. check if the ci-linux integration is OK
  3. check the code changes:
    a. pjsua app has been updated to be able to use custom SDP
    b. alt_pjsua_vid.c has been updated to resolve linkage problems
    c. The only real fix of PJSUA is done in Test 3rd-party media support #4923 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant