Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

Description

Audio device play/record failures were not consistently signaled across implementations. Only WMME and Oboe published PJMEDIA_EVENT_AUD_DEV_ERROR events, and pjsua_ext_snd_dev did not subscribe to these events.

Changes

Added event publishing to audio device backends:

  • ALSA (alsa_dev.c): Publish events in playback/capture thread error paths
  • PortAudio (pa_dev.c): Publish events in recorder/playback callbacks before returning paAbort
  • OpenSL ES (opensl_dev.c): Publish events on callback failures and buffer enqueue errors
  • Android JNI (android_jni_dev.c): Publish events in recorder/track callback error paths
  • CoreAudio (coreaudio_dev.m): Publish events in input/output renderer callbacks

Made pjsua_ext_snd_dev subscribe to events:

  • Subscribe in pjsua_ext_snd_dev_create() after sound device connection
  • Unsubscribe in pjsua_ext_snd_dev_destroy() before sound port destruction

All implementations follow the existing pattern from WMME/Oboe:

pjmedia_event_init(&e, PJMEDIA_EVENT_AUD_DEV_ERROR, &timestamp, &stream->base);
e.data.aud_dev_err.dir = PJMEDIA_DIR_PLAYBACK; // or PJMEDIA_DIR_CAPTURE
e.data.aud_dev_err.status = status;
e.data.aud_dev_err.id = device_id;
pjmedia_event_publish(NULL, &stream->base, &e, PJMEDIA_EVENT_PUBLISH_DEFAULT);

Events are only published on actual errors, not during normal shutdown (quit_flag check).

Motivation and Context

Applications using on_media_event() callback receive audio device errors inconsistently depending on which backend is active. This makes error handling unreliable across platforms.

How Has This Been Tested?

  • Built successfully on Linux with null audio device
  • Verified PJSUA starts without errors: ./pjsua-x86_64-pc-linux-gnu --null-audio --no-cli-console
  • Code follows existing WMME/Oboe implementation patterns

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the CODING STYLE of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
Original prompt

This section details on the original issue you should resolve

<issue_title>Signal PJMEDIA_EVENT_AUD_DEV_ERROR upon sound device play/record failure in any audio device</issue_title>
<issue_description>### Describe the feature

Currently WMME (pjmedia/src/pjmedia-audiodev/wmme_dev.c) and Oboe (pjmedia/src/pjmedia-audiodev/oboe_dev.cpp) publish media event PJMEDIA_EVENT_AUD_DEV_ERROR when sound device play/record failures occur. The pjsua-lib then receives the event and forwards it to app via the on_media_event() callback.

However, there are two issues:

  1. Not all audio device implementations in pjmedia/src/pjmedia-audiodev publish this event.
  2. The extra sound device (pjsua_ext_snd_dev) does not subscribe to the event so it cannot forward it via on_media_event() callback.

Describe alternatives you've considered

No response

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 23, 2026 02:06
…_ext_snd_dev

Co-authored-by: nanangizz <24786011+nanangizz@users.noreply.github.com>
…d CoreAudio

Co-authored-by: nanangizz <24786011+nanangizz@users.noreply.github.com>
Co-authored-by: nanangizz <24786011+nanangizz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix PJMEDIA_EVENT_AUD_DEV_ERROR handling for all audio devices Signal PJMEDIA_EVENT_AUD_DEV_ERROR on audio device failures Jan 23, 2026
Copilot AI requested a review from nanangizz January 23, 2026 02:15
@nanangizz nanangizz added this to the release-2.17 milestone Jan 23, 2026
@nanangizz nanangizz marked this pull request as ready for review January 23, 2026 02:29
@nanangizz nanangizz merged commit 913d7c4 into master Jan 23, 2026
74 of 76 checks passed
@nanangizz nanangizz deleted the copilot/fix-sound-device-error-event branch January 23, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signal PJMEDIA_EVENT_AUD_DEV_ERROR upon sound device play/record failure in any audio device

3 participants