ladendirekt / pjsip4net

A wrapper library exposing the pjsip library to the .NET world in a OO-friendly way.
71 stars 42 forks source link

Ringback sound #91

Open Lanista12 opened 6 years ago

Lanista12 commented 6 years ago

Hello, Siniypin. I have the same problem as in issue #39. I used pjsip4net in my c# project and it works just fine. Quality is good, no interference or noise(other libraries had some problems with that), but there is one major problem: if someone calls me, the one does not hear any ringback sounds. In issue #39 you gave an example how to solve this problem using conference bridge and WavPlayer. https://gist.github.com/siniypin/47326a9fd78af95a3ff7 I tried to do that and I worked well, the caller heard every sound it played, but it worked only after I answered the call, and I need it to be played before I pick up the phone. If I execute this code on CallManager_Ring event _ua.CallManager.Calls.First().ConferenceSlotId return -1(I assume it is because I din't aswer the call yet, so connection is not established and ther is no media stream and sound port binded to it). If I execute the code anythere after _call.Answer() it return 1 and it works properly.

P.S: Sorry for bad grammar. English is not my native language.

siniypin commented 6 years ago

Hi, if I get you right, you want to stream a sound to a speaker device on a calling side before the call has been answered. For that you just have to create a sound player that will stream your audiofile to the speaker device and interconnect them via a ConferenceBridge. I'll stress that once again, you have to interconnect player and a speaker device, a call has nothing to do with the ringtone playback. A CallManager provides necessary callbacks for you to properly start and stop the playback at the right moments.

siniypin commented 6 years ago

@Lanista12 did it help? Did you figure this stuff out?

Lanista12 commented 6 years ago

@siniypin, no. Still trying figure that out.

siniypin commented 6 years ago

So what's the problem? Did you understand the suggestion?

Lanista12 commented 6 years ago

Yeah, I understood, but I realised that my approach was wrong from the begining. I found out that you don't need to send ringback tone at all. I used Wireshark to analyse traffic and I found that when you have incoming call, you have these packets if you use another sip-library(ozeki in my case): --> Request :INVITE sip:qwerty@1.2.3.4:32001;transport=TCP;rinstance=9887998e21ce5942 SIP/2.0 <-- Status: SIP/2.0 100 Trying <-- Status: SIP/2.0 180 Ringing And caller hear pingback sounds. But then I used pjsip4net, it had not got last packet with status code 180: --> Request :INVITE sip:qwerty@1.2.3.4:32001;transport=TCP;rinstance=9887998e21ce5942 SIP/2.0 <-- Status: SIP/2.0 100 Trying

it seems like this is the issue.

siniypin commented 6 years ago

Check out this comment: https://github.com/siniypin/pjsip4net/issues/62#issuecomment-253450472

Lanista12 commented 6 years ago

It didn't help. I did as it said in #62: var cfg = Configure.Pjsip4Net().With(x => x.Config.Require100Rel = true); But I have the same problem.

siniypin commented 6 years ago

Can you post your code here?

Lanista12 commented 6 years ago

This is how I initialize UserAgent:

                var cfg = Configure.Pjsip4Net().With(x => x.Config.Require100Rel = true);
                _ua = cfg.Build().Start();//build and start
                _ua.ImManager.IncomingMessage += IncomingMessage;
                _ua.CallManager.CallRedirected += CallRedirected;
                _ua.CallManager.IncomingDtmfDigit += IncomingDtmfDigit;
                _ua.ImManager.NatDetected += OnNatDetected;
                _ua.CallManager.IncomingCall += CallManager_IncomingCall;
                _ua.CallManager.Ring += CallManager_Ring;
                _ua.CallManager.CallStateChanged += CallManager_CallStateChanged;
siniypin commented 6 years ago

I assume a CallManager_Ring callback is never executed, correct?

siniypin commented 6 years ago

Can you post a CallManager_Ring implementation here as well?

Lanista12 commented 6 years ago

Here is my implementation of CallManager_Ring


        private void CallManager_Ring(object sender, RingEventArgs e)
        {
            // start ringtones
            if (e.RingOn)
            {
                if (e.IsRingback)
                {
                    MediaHandlers.StartRingback();
                }
                else
                {
                    MediaHandlers.StartRingtone();
                }
            }
            else
            {
                MediaHandlers.DetachAudio();

                RechangeCurrentSpeaker();
            }
        }

StartRingBack and StartRingTone is methods to play ringtones localy.

siniypin commented 6 years ago

So it is never executed, am I right?

siniypin commented 6 years ago

OK, I think I understand your problem a bit better now. Whenever you call a pjsip4net based app, the callee (basically any SIP-client) doesn't hear any ringback, because the app just never replies with 180.
That is a missing feature in pjsip4net. I'd need some time to add it and publish a new version of pjsip4net. Alternatively, you can fork the project, fix it and send me a pull request. Then I could quickly include it and publish to the nuget.

Lanista12 commented 6 years ago

Ok. Roughly speaking, how long will it take for you to add this changes?

siniypin commented 6 years ago

I won't promise you anything. You have to understand that I voluntarily maintain this library and support you guys in my spare time.

Lanista12 commented 6 years ago

Ok. Not trying to compel you or something like that. Just trying to understand if you find it an easy task, so you can fix it super fast, or should I try to do that. Nothing else.

siniypin commented 6 years ago

@Lanista12 please do a favor, fix it and send me a pull request back. I'm currently overloaded. My idea was to track if the ring event has been handled by the app code and call a downstream API with proper params (http://www.pjsip.org/docs/latest-1/pjsip/docs/html/group__PJSUA__LIB__CALL.htm#ga6dd4a80bd96c319398e218bbffda5153) to tell pjsip to send 180 back .

Lanista12 commented 6 years ago

Ok. I'll do my best.