deps/patches/2.17/
==================

Rebased patch series for pjsip 2.17.  Selected at build time:

    ./get_dependencies.sh --version 2.17

The default (no --version flag) is 2.12 and applies the series at
deps/patches/[0-9][0-9]_*.patch.  The 2.17 path uses this folder.


Numbering convention
--------------------
Same NN_ prefixes as the 2.12 series so each patch is recognisable
across versions.  A patch dropped from the 2.17 path simply doesn't
exist here; do not renumber.  New 2.17-only patches use NN >= 40 to
avoid colliding with the 2.12 series.


Current status (June 2026)
==========================

Present in this folder
----------------------

Foundation / build:
  02_zsrtp_link.patch                  2.17-only - tweak ZSRTP linker flags
                                       so the GnuTLS / OpenSSL split in
                                       2.17 doesn't dead-strip cryptopp.

Core SIP / dialog / signalling:
  03_pjsip_signaling.patch             ported - INVITE / dialog rework
                                       around 2.14 + RFC 6026 timing.
  04_pjnath_ice_strans.patch           ported - early-candidate wiring,
                                       offset-tracker hunk split fix.
  11_transport_ice.patch               ported - drops on_ice_complete2
                                       (upstream); pjmedia_ice_cb hunk
                                       verified.
  27_pjmedia_rebind_remote_peer.patch  ported - depends on 20.
  28_pjsip_tls_route_sni_selector.patch
                                       ported - was renamed from
                                       28_pjsip_tls_lis_create_*; same
                                       feature, simplified hook point.
  33_pjsip_inv_cause_text_bound.patch  ported - rebased for the 2.17
                                       sip_inv.c whitespace sweep and
                                       the (int)inv->cause cast; bounds
                                       inv->cause_text into inv->pool
                                       so a transaction-pool reason
                                       phrase can't outlive its source.
  34_conf_get_frame_port_ref.patch     2.17-only - closes the get-frame
                                       half of the conference-port UAF
                                       that patch 30 only fixed on the
                                       removal side.  Wraps the two
                                       pjmedia_port_get_frame() calls
                                       in conf.c::read_port() with
                                       pj_grp_lock_add_ref/dec_ref so
                                       the audio I/O thread can't
                                       dispatch through a freed
                                       function-pointer table during
                                       hangup.
  30_conf_port_grp_lock_uaf.patch      ported - 2.17-only re-derivation
                                       of the conference-port UAF fix.
  31_stream_transport_grp_lock_uaf.patch
                                       ported - 2.17-only re-derivation
                                       of the stream-transport UAF fix.

Media / SDP / codecs:
  07_codecs.patch                      ported - opus mono advertisement,
                                       x264 preset/tune retune for lower
                                       latency, and PROFILE_H264_HIGH
                                       support in the SDP fmtp switch.
                                       (Only AVCODEC_HAS_ENCODE and
                                       avcodec_get_frame_defaults hunks
                                       stay out - both subsumed by
                                       2.17's FFmpeg 5+ migration.)
  08_media_core.patch                  ported - vid_tee mutex wrap, RTCP
                                       PLI, mixer_port, KEYFRAME_REQUESTED
                                       event, real EC reset, TIAS disable,
                                       MIXER signature.  Skipped:
                                       converter.c debug logging.
  15_vpx.patch                         ported - verified, no-op guard,
                                       preserves 2.12 behaviour.
  20_sylk_aead_transport.patch         ported - Makefile hunk re-targeted
                                       against vanilla 2.17.
  24_video_sdp_rtcp_fb.patch           ported - 4-space indent, clean.
  22_srtp_transport_get_info_uaf.patch ported - 2.17 already NULLs the
                                       libsrtp ctx pointers; this port
                                       adds the SSRC-zero on stop and
                                       the session_inited guards in
                                       get_info as defense-in-depth.
  25_libswscale_converter_uaf.patch    ported - clean 4-space.

Devices:
  05_audio_device.patch                ported - the ~1100 line audio
                                       device patch rebased after the 2.13
                                       whitespace sweep.
  06_video_device.patch                ported - includes the real
                                       pjmedia_vid_dev_fb_set_callback
                                       and fb_dev.c.  Was a heavy lift
                                       (~1800 lines) because the 2.15
                                       Metal renderer landed upstream.
                                       June 2026: folds in the
                                       avf_factory_refresh() crash fix
                                       (heap overflow + nil-name deref)
                                       and the AVCaptureDevice retain/
                                       release UAF fix - both were bugs
                                       in the avf_dev.m this patch
                                       introduces, so they are fixed at
                                       source rather than layered on top.
                                       Supersedes the interim 50/51.
  (16_mac_audio_vpio_disable,          FOLDED into 05 (June 2026) - these
   21_alsa_dev_pjsip217_log,           only adapted to the coreaudio_dev.m /
   35_alsa_dev_add_dev_custom_call)    alsa_dev.c API changes that patch 05
                                       itself makes, so they are now baked
                                       into patch 05 and the standalone
                                       patches were removed.  Patch 05's
                                       audio file sections were regenerated
                                       from pristine 2.17 to the final state.
                                       See patch 05's header for details.

ZRTP (copy-as-is from 2.12 - the ZRTPCPP source is version-independent):
  13_zsrtp.patch                       copy-as-is - ZRTPCPP wrapper.
  18_fix_uint_zrtp.patch               copy-as-is - ZRTPCPP source,
                                       pinned commit.
  19_fix_zrtp_cstdint_include.patch    copy-as-is - ZRTPCPP source.
  29_zsrtp_hmac_ctx_lifetime.patch     copy-as-is - OpenSSL 3 HMAC_CTX
                                       lifetime fix + -DZRTP_OPENSSL on
                                       the Makefile.  Source files
                                       byte-identical to 2.12 so the
                                       same patch applies; Makefile
                                       lands with line offset from 13.

ZRTP / SRTP (2.17 needed surgery):
  12_transport_zrtp.patch              ported - the ~2100 line transport
                                       glue, intertwined with 2.17's
                                       SRTP / ZRTP changes.
                                       June 2026: the transport_zrtp.c
                                       crash/locking fixes formerly carried
                                       as separate patches 46/47/49 are now
                                       folded into the file this patch
                                       creates (all were bugs in our own
                                       module).  Net result is byte-identical
                                       to 12 -> 46 -> 47 -> 49.
  12a_zrtp_pjmedia_h_makefile.patch    ported - companion to 12, exposes
                                       transport_zrtp.h via pjmedia.h
                                       and adds the .o to the Makefile.
                                       (.obsolete sibling is dead weight
                                       and can be deleted.)

VP9 / VPX (4 patches working together):
  23_vpx_packetizer_libwebrtc_interop.patch
                                       PARKED no-op - vanilla 2.17's
                                       1-byte VP9 descriptor (B / E only)
                                       is what libwebrtc actually wants.
                                       Adding RFC-9628 fields broke Sylk
                                       Mobile decode.  Kept as a slot
                                       holder + rationale log.
  44_vpx_encoder_rate_control.patch    2.17-only - 1.5 Mbps target, VBR,
                                       dropframe_thresh=0.  Without this
                                       the encoder produced ~0.8 fps to
                                       Sylk Mobile.
  45_vpx_encoder_quality_preset.patch  2.17-only - cpu_used 9->4,
                                       rc_max_quantizer 56->48.  Removes
                                       the pixelated / blocky picture
                                       once 44 fixed framerate.

New 2.17-only support:
  40_videodev_extra_objs.patch         Makefile add-ons for the AVF /
                                       fb_dev objects landed by patch 06.
  42_pjmedia_argb_format.patch         Adds PJMEDIA_FORMAT_ARGB to the
                                       format registry + libyuv I420
                                       conversion path used by the
                                       FrameBufferVideoRenderer.
  (46_zrtp_detach_race_null_deref,     FOLDED into 12 (June 2026) - these
   47_zrtp_cb_lock_sync,               three transport_zrtp.c crash/locking
   49_zrtp_cb2_lock_body)              fixes were bugs in our own module and
                                       are now baked into the file patch 12
                                       creates; the standalone patches were
                                       removed.  See patch 12's header for
                                       what each one did.
  48_h264_sylk_mobile_interop.patch    2.17-only - H.264 SDP fmtp:
                                       profile-level-id 42e01e -> 42e01f
                                       (Constrained Baseline Level 3.0
                                       -> 3.1), strips the leading space
                                       from " packetization-mode".
                                       Matches Sylk Mobile / libwebrtc
                                       / standard WebRTC, unlocking
                                       720p negotiation on Mac -> Sylk
                                       Mobile H.264 calls.


Dropped permanently
-------------------
  10_ffmpeg_util.patch                 FFmpeg 5+ migration is upstreamed.
  17_fix_ffmpeg.patch                  Same.
  30_diag_log_stream_info_from_sdp     Diagnostic-only ("do NOT ship").
  pending/02_pjlib_darwin.patch        GCD semaphores are upstream now.
  31_zrtp_detach_race_null_deref.old   Was .old in 2.12 too.


Still TODO
----------

Tier 4 (medium risk):
  pending/14_pjsip_tls_log_fix.patch   TLS cert info logging.  The
                                       update_certs_info(cert_info*)
                                       signature changed in 2.17.

Tier 5+ (heavy):
  01_build_system.patch                Makefile / config_auto rebase
                                       against the 2.17 object list.
                                       The 2.17 build works without it
                                       (individual patches touch their
                                       own Makefile fragments) so this
                                       is cleanup, not a blocker.
  09_aec.patch                         AEC2 / AEC3 are split into
                                       echo_webrtc.c (AEC2) and
                                       echo_webrtc_aec3.c (AEC3) in
                                       2.17.  The 2.12 patch was a
                                       single-file drop; needs splitting.
                                       Audio quality regression vs 2.12
                                       until done.


Cython / sipsimple-side work pending
------------------------------------
Patch 08 added two C symbols that nothing in Python calls yet:

  * pjmedia_rtcp_build_rtcp_pli() - needs a cdef extern in
    _core.pxd plus a wrapper on whatever owns the RTCP session, so
    sipsimple can actually request keyframes from peers when its
    decoder loses sync.

  * pjmedia_snd_port_reset_ec_state() is now real (was a no-op stub)
    but the existing Python wrapper - if any - may still bail early
    because it predates a working impl.


Rebase / verification order
---------------------------
Patches apply in numeric order.  No special sequencing is needed for
the currently-present set; just run:

    ./get_dependencies.sh --version 2.17

and every "Applying patch ..." line should be followed by zero
"FAILED" or "rejects" lines.  Hunks landing with offset / fuzz are
fine; rejections need a manual look.


Notes for future ports
----------------------
gpatch's offset-tracker carries across hunks within a single file
section.  If a hunk further down a patch silently misapplies after
an earlier hunk added a large block, split the second hunk into its
own  --- pjsip_orig/...  / +++ pjsip/...  section so the tracker
resets.  See patch 04 for the pattern.

Blank context lines in a unified diff must start with a single space.
Most editors (including the tooling that generated some of these
patches) strip trailing whitespace, which turns blank context lines
into bare newlines and corrupts the patch.  When in doubt, run:

    awk '/^@@/{h=1;print;next} /^(---|\+\+\+) /{h=0;print;next} \
         h && /^$/{print " ";next} {print}' patch.patch > patch.fixed
