Discussion:
[asterisk-dev] Manipulate re-INVITE response in user written Asterisk module
Andreas Wehrmann
2018-10-30 21:50:31 UTC
Permalink
Hello folks,

I'm currently writing a module for Asterisk
to make it divert a video stream to an external videoserver.
The scenario is this:

- some external participant is calling into Asterisk (offering audio+video)

- using SIP session supplements: in the incoming (INVITE) message callback,
a video session is set up on the videoserver (actually: this happens always, regardless of what is offered)

- using the dialplan, the call is routed to another PBX supporting audio only
(but video codecs are enabled on our side, so video will be offered by Asterisk)

- when the other PBX answers, I'm using SIP session supplements to determine whether the call answered by the other PBX supports video
-- if video is supported, my module does nothing
-- if video is rejected, I manipulate the SDP inside to make it seem to Asterisk
as if video actually was supported by inserting connection info pointing to the video server

What I've just described does work.
The SIP supplement is registered with a response priority of AST_SIP_SESSION_BEFORE_MEDIA
and handles the INVITE method only.

However, what doesn't work is if the external participant initially calls in
with audio only and enables video later by sending a reINVITE.

I do not get a callback from my already registered SIP supplement when the other PBX
responds to the reINVITE in order to give me a chance to manipulate the SDP.
I guess this is because the session was already active and thus "AFTER_MEDIA".

When I register a SIP supplement with "AST_SIP_SESSION_AFTER_MEDIA",
I do indeed get a callback for the reINVITE response,
but that happens too late, since SDP negotiation inside Asterisk has already happened.

I then tried to register an SDP handler (just to see what callbacks I get and whether they might be useful).
The only callback I receive is defer_incoming_sdp_stream() for the reINVITE that my Asterisk receives
which doesn't seem too useful for what I'm trying to do.

Since I had no more ideas left, I then tried to hook into PJSIP directly
by providing a pjsip_module that implements the on_rx_response() callback.

That doesn't really work either, because the callback never fired.
After I played around with module priority the callback eventually fired but I was unable to get the TSX and dialog references from PJ
(probably because the module got called too early?).
However I need those to get the corresponding ast_sip_session.

At this point, I don't know how to proceed.
Is there a way to hook into reINVITE responses to achieve what I'm trying to do?


Best regards,

Andreas
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Astricon is coming up October 9-11! Signup is available at: https://www.asterisk.org/community/astricon-user-conference

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk
Matt Fredrickson
2018-11-02 20:29:19 UTC
Permalink
Post by Andreas Wehrmann
Hello folks,
I'm currently writing a module for Asterisk
to make it divert a video stream to an external videoserver.
- some external participant is calling into Asterisk (offering audio+video)
- using SIP session supplements: in the incoming (INVITE) message callback,
a video session is set up on the videoserver (actually: this happens always, regardless of what is offered)
- using the dialplan, the call is routed to another PBX supporting audio only
(but video codecs are enabled on our side, so video will be offered by Asterisk)
- when the other PBX answers, I'm using SIP session supplements to determine whether the call answered by the other PBX supports video
-- if video is supported, my module does nothing
-- if video is rejected, I manipulate the SDP inside to make it seem to Asterisk
as if video actually was supported by inserting connection info pointing to the video server
What I've just described does work.
The SIP supplement is registered with a response priority of AST_SIP_SESSION_BEFORE_MEDIA
and handles the INVITE method only.
However, what doesn't work is if the external participant initially calls in
with audio only and enables video later by sending a reINVITE.
I do not get a callback from my already registered SIP supplement when the other PBX
responds to the reINVITE in order to give me a chance to manipulate the SDP.
I guess this is because the session was already active and thus "AFTER_MEDIA".
When I register a SIP supplement with "AST_SIP_SESSION_AFTER_MEDIA",
I do indeed get a callback for the reINVITE response,
but that happens too late, since SDP negotiation inside Asterisk has already happened.
I then tried to register an SDP handler (just to see what callbacks I get and whether they might be useful).
The only callback I receive is defer_incoming_sdp_stream() for the reINVITE that my Asterisk receives
which doesn't seem too useful for what I'm trying to do.
Since I had no more ideas left, I then tried to hook into PJSIP directly
by providing a pjsip_module that implements the on_rx_response() callback.
That doesn't really work either, because the callback never fired.
After I played around with module priority the callback eventually fired but I was unable to get the TSX and dialog references from PJ
(probably because the module got called too early?).
However I need those to get the corresponding ast_sip_session.
At this point, I don't know how to proceed.
Is there a way to hook into reINVITE responses to achieve what I'm trying to do?
Good question! Sounds like an interesting project. For the purpose
of pure curiosity, do you mind if I ask why you're trying to send the
video to a separate server?

With regards to your specific questions, I'm guessing this is
something that George Joseph or Josh Colp might have a few more
opinions about.
--
Matthew Fredrickson
Digium - A Sangoma Company | Asterisk Project Lead
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Astricon is coming up October 9-11! Signup is available at: https://www.asterisk.org/community/astricon-user-conference

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo
Andreas Wehrmann
2018-11-05 07:53:53 UTC
Permalink
This post might be inappropriate. Click to display it.
Joshua C. Colp
2018-11-05 11:07:32 UTC
Permalink
Post by Andreas Wehrmann
Hello folks,
I'm currently writing a module for Asterisk
to make it divert a video stream to an external videoserver.
- some external participant is calling into Asterisk (offering audio+video)
- using SIP session supplements: in the incoming (INVITE) message callback,
a video session is set up on the videoserver (actually: this happens always, regardless of what is offered)
- using the dialplan, the call is routed to another PBX supporting audio only
(but video codecs are enabled on our side, so video will be offered by Asterisk)
- when the other PBX answers, I'm using SIP session supplements to determine whether the call answered by the other PBX supports video
-- if video is supported, my module does nothing
-- if video is rejected, I manipulate the SDP inside to make it seem to Asterisk
as if video actually was supported by inserting connection info pointing to the video server
What I've just described does work.
The SIP supplement is registered with a response priority of AST_SIP_SESSION_BEFORE_MEDIA
and handles the INVITE method only.
However, what doesn't work is if the external participant initially calls in
with audio only and enables video later by sending a reINVITE.
I do not get a callback from my already registered SIP supplement when the other PBX
responds to the reINVITE in order to give me a chance to manipulate the SDP.
I guess this is because the session was already active and thus "AFTER_MEDIA".
When I register a SIP supplement with "AST_SIP_SESSION_AFTER_MEDIA",
I do indeed get a callback for the reINVITE response,
but that happens too late, since SDP negotiation inside Asterisk has already happened.
I then tried to register an SDP handler (just to see what callbacks I get and whether they might be useful).
The only callback I receive is defer_incoming_sdp_stream() for the reINVITE that my Asterisk receives
which doesn't seem too useful for what I'm trying to do.
I think this occurs as you're essentially fighting the SDP negotiation inside of the PJSIP INVITE session code itself to try to insert yourself at the right point, and it doesn't provide a location to do that.
Post by Andreas Wehrmann
Since I had no more ideas left, I then tried to hook into PJSIP directly
by providing a pjsip_module that implements the on_rx_response() callback.
That doesn't really work either, because the callback never fired.
This is because once a dialog is established only the modules attached to that dialog are executed, except for those executed before the transaction and dialog is found. You have to add your module to the dialog in some way to continue getting called. Some of the modules already do this, such as res_pjsip_nat. It uses "pjsip_dlg_add_usage" to add itself to the dialog so it continues to get called in the future.
Post by Andreas Wehrmann
After I played around with module priority the callback eventually fired but I was unable to get the TSX and dialog references from PJ
(probably because the module got called too early?).
However I need those to get the corresponding ast_sip_session.
At this point, I don't know how to proceed.
Is there a way to hook into reINVITE responses to achieve what I'm trying to do?
The above dialog comment should allow you to continue to get callbacks and is the easiest way to make it work.
--
Joshua C. Colp
Digium - A Sangoma Company | Senior Software Developer
445 Jan Davis Drive NW - Huntsville, AL 35806 - US
Check us out at: www.digium.com & www.asterisk.org
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Astricon is coming up October 9-11! Signup is available at: https://www.asterisk.org/community/astricon-user-conference

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-d
Andreas Wehrmann
2018-11-06 11:01:01 UTC
Permalink
Post by Joshua C. Colp
Post by Andreas Wehrmann
Since I had no more ideas left, I then tried to hook into PJSIP directly
by providing a pjsip_module that implements the on_rx_response() callback.
That doesn't really work either, because the callback never fired.
This is because once a dialog is established only the modules attached to that dialog are executed, except for those executed before the transaction and dialog is found. You have to add your module to the dialog in some way to continue getting called. Some of the modules already do this, such as res_pjsip_nat. It uses "pjsip_dlg_add_usage" to add itself to the dialog so it continues to get called in the future.
Post by Andreas Wehrmann
After I played around with module priority the callback eventually fired but I was unable to get the TSX and dialog references from PJ
(probably because the module got called too early?).
However I need those to get the corresponding ast_sip_session.
At this point, I don't know how to proceed.
Is there a way to hook into reINVITE responses to achieve what I'm trying to do?
The above dialog comment should allow you to continue to get callbacks and is the easiest way to make it work.
That was it!
Attaching the module to the dialog worked.
Thank you for the hint, I do appreciate it!

Best regards
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Astricon is coming up October 9-11! Signup is available at: https://www.asterisk.org/community/astricon-user-conference

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listi
Hans-Peter Jansen
2018-11-14 16:08:59 UTC
Permalink
Post by Andreas Wehrmann
Post by Joshua C. Colp
The above dialog comment should allow you to continue to get callbacks and
is the easiest way to make it work.
That was it!
Attaching the module to the dialog worked.
Thank you for the hint, I do appreciate it!
Is that module available somewhere in public? Sounds like fun to play with...

Cheers,
Pete
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Astricon is coming up October 9-11! Signup is available at: https://www.asterisk.org/community/astricon-user-conference

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listi
Andreas Wehrmann
2018-11-15 07:42:24 UTC
Permalink
Post by Hans-Peter Jansen
Is that module available somewhere in public? Sounds like fun to play with...
Cheers,
Pete
The work is actually based on what was done at the Emynos project:
https://www.emynos.eu/


The code has some serious problems though and only covers a very
specific call-flow.
It was okay for us, since we consider this thing as a proof-of-concept only.


Best regards,
Andreas
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Astricon is coming up October 9-11! Signup is available at: https://www.asterisk.org/community/astricon-user-conference

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/list
Andreas Wehrmann
2018-11-15 13:59:00 UTC
Permalink
Post by Andreas Wehrmann
https://www.emynos.eu/
The code has some serious problems though and only covers a very
specific call-flow.
It was okay for us, since we consider this thing as a proof-of-concept only.
Best regards,
Andreas
Alright, so the GIT repos are not available anymore.
I wrote to one of the project members and asked about that.

He did indeed reply and told me that they are
supposedly in the process of finding another hoster.


Best regards,
Andreas
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Astricon is coming up October 9-11! Signup is available at: https://www.asterisk.org/community/astricon-user-conference

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/aste
Hans-Peter Jansen
2018-11-15 15:42:23 UTC
Permalink
Post by Andreas Wehrmann
Post by Andreas Wehrmann
https://www.emynos.eu/
The code has some serious problems though and only covers a very
specific call-flow.
It was okay for us, since we consider this thing as a proof-of-concept only.
Best regards,
Andreas
Alright, so the GIT repos are not available anymore.
I wrote to one of the project members and asked about that.
He did indeed reply and told me that they are
supposedly in the process of finding another hoster.
Thanks for the infos, Andreas.

Would be nice to get a notice, when they succeed...

Cheers,
Pete
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Astricon is coming up October 9-11! Signup is available at: https://www.asterisk.org/community/astricon-user-conference

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo
Loading...