Skip to content

Add callback to notify succesfull completion of conf/vid_conf operation#4446

Merged
trengginas merged 8 commits intomasterfrom
conf-callback
Jun 5, 2025
Merged

Add callback to notify succesfull completion of conf/vid_conf operation#4446
trengginas merged 8 commits intomasterfrom
conf-callback

Conversation

@trengginas
Copy link
Copy Markdown
Member

@trengginas trengginas commented May 30, 2025

Since #3928, conference/video conference is done asynchronously.
The changes introduce other implications, consider the scenario:

  • App connect the port1 and port2 (pjsua_conf_connect())
  • App immediately checks the port information after the above API returns (pjsua_conf_get_port_info()).

After the patch, the information from (pjsua_conf_get_port_info()) might not be the latest, since the operation is not
completed.

This PR will add a callback to notify when the operation is completed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces asynchronous callbacks to notify the completion of audio and video conference operations, addressing potential staleness in port information due to asynchronous execution. Key changes include:

  • Adding callback methods (on_conf_op_completed and on_vid_conf_op_completed) in Endpoint.
  • Setting up the corresponding callback functions in both audio and video conference subsystems.
  • Updating documentation and API comments to indicate that operations now execute asynchronously.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pjsip/src/pjsua2/endpoint.cpp Added conversion methods and callback handlers for conf operations.
pjsip/include/pjsua2/endpoint.hpp Introduced callback parameter structures and virtual callbacks.
pjsip/src/pjsua-lib/pjsua_vid.c Added setter for video conference operation callback.
pjsip/src/pjsua-lib/pjsua_aud.c Added setter for audio conference operation callback.
pjsip/include/pjsua-lib/pjsua.h Updated documentation to indicate asynchronous behavior.
pjmedia/src/pjmedia/vid_conf.c Updated operation dispatch and callback invocation in video conf.
pjmedia/src/pjmedia/conference.c Updated operation dispatch and callback invocation in audio conf.
pjmedia/include/pjmedia/vid_conf.h Defined types and documentation for video conference operations.
pjmedia/include/pjmedia/conference.h Defined types and documentation for audio conference operations.
pjsip-apps/src/pjsua/pjsua_app.c Added commented examples of using the new callbacks.
Comments suppressed due to low confidence (1)

pjsip/include/pjsua-lib/pjsua.h:8093

  • The term 'succesfull' is misspelled; consider correcting it to 'successful'.
* This operation executes asynchronously, use the callback set from \a on_conf_op_completed to receive notification upon succesfull

pjmedia_vid_conf_op_info info = { 0 };

pj_log_push_indent();
info.op_type = PJMEDIA_VID_CONF_OP_DISCONNECT_PORTS;
Copy link

Copilot AI May 30, 2025

Choose a reason for hiding this comment

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

In the op_update_port function, the callback is reporting a disconnect operation type instead of an update; change it to PJMEDIA_VID_CONF_OP_UPDATE_PORT to correctly indicate an 'update port' operation.

Suggested change
info.op_type = PJMEDIA_VID_CONF_OP_DISCONNECT_PORTS;
info.op_type = PJMEDIA_VID_CONF_OP_UPDATE_PORT;

Copilot uses AI. Check for mistakes.
pj_mutex_unlock(conf->mutex);

/* Process op */
switch(type) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not invoke the callbacks from this function instead? E.g: after the switch and just copy the op type & op param to info, and as mentioned before, adding status/result into the info may be better.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Some operations are called from other method. e.g.: op_disconnect_ports() are called from op_remove_port() or op_remove_port() from pjmedia_conf_destroy().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If I understand this correctly, then this callback is called for operations that are explicitly invoked by users.
Operation that is not explicitly called will not get notified by this callback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, no callback there. Or just add some callback invocations in conf_destroy(). Either way sounds okay to me, also better to mention this in the docs.

* (e.g., startTransmit/stopTransmit), the first AudioMedia serves
* as the source.
*/
AudioMediaVector2 opData;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not very sure about a couple things here:

  • using vector, perhaps simply leave it as port ids? Note: app can use AudioMediaHelper to cast it to AudioMedia (better also mention this in this docs perhaps) and there may be also port number -1.
  • using term Conf in the naming (perhaps this is the first in pjsua2?), what about using Media instead? In pjsua2, the focus tends to shift from Conf to Media/port (see adjustRx/TxLevel vs pjmedia_conf_adjust_rx_level docs).

Copy link
Copy Markdown
Member

@nanangizz nanangizz Jun 3, 2025

Choose a reason for hiding this comment

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

It is no longer AudioMediaVector but still a vector, unsigned vector :)
The param is not an array of a specific type, what if in the future there is a new field that is not an int/unsigned.
If union is a problem (in SWIG perhaps), IMO, using a flat struct/class is better than a vector, e.g:

struct OpParam {
  unsigned mediaId;
  unsigned targetMediaId; /* Only applicable for op: ... */
  int adjustLevel; /* Only applicable for op: ... */
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When using union is chosen, please make sure it works with SWIG (java, python, C#).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

actually MediaEventData is using union (ref). Tested here using java, and it works

@trengginas trengginas merged commit 4d1b0f8 into master Jun 5, 2025
42 checks passed
@trengginas trengginas deleted the conf-callback branch June 5, 2025 09:47
BarryYin pushed a commit to BarryYin/pjproject that referenced this pull request Feb 3, 2026
…on (pjsip#4446)

* Add callback to notify succesfull completion of conf/vid_conf operation

* Fix incorrect op_type

* Modification based on comments

* Missed to set status

* modification based on comments

* modification based on comments

* Modification based on comments

* Add comments and call the callback from conf_destroy()
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.

4 participants