Gracefully returning back to channel after using Audiosocket

Hi there!

First of all, sorry if I posted this into wrong thread. I know that Audiosocket is community supported. And to be honest, this is a great addition! I spend a lot of time, trying to find solution which would suit my needs. And before I discovered Audiosocket I was looking into External media via ARI, which is much more complicated than using Audiosocket. So having AudioSocket shipped with asterisk just great :pray: !

I am sure that issue is not in module itself, but in my code / setup.

When I use audiosocket, I am able to retrieve audio stream, as well as send it back (which would play it without any issue) But then, when audio is played fully, I send termination message, in asterisk logs I have:

[Dec 07 22:12:18.509] ERROR[2468][C-00000059]: app_audiosocket.c:206 audiosocket_run: Failed to receive frame from AudioSocket message forchannel SIP/dev-00000058

Which impacts call flow.

I use this example: github com/CyCoreSystems/audiosocket/blob/master/examples/playfile/main.go

So then, I added a bit of logs to debug this, also trying different things to see if that helps.

In documentation ( AudioSocket - Asterisk Documentation ) it says that simply socket closure should be sufficient.

So I tried just close socket.
For example, when I modify code to something like this:

// Listen listens for and responds to AudioSocket connections
func Listen(ctx context.Context) error {
	l, err := net.Listen("tcp", listenAddr)
	if err != nil {
		return errors.Wrapf(err, "failed to bind listener to socket %s", listenAddr)
	}

	for {
		conn, err := l.Accept()
		if err != nil {
			log.Println("failed to accept new connection:", err)
			continue
		}

		ctx, cancel := context.WithTimeout(ctx, MaxCallDuration)
		go processDataFromAsterisk(ctx, cancel, conn)

		if _, err := conn.Write(audiosocket.HangupMessage()); err != nil {
			log.Println("failed to send hangup message:", err)
		}

	        conn.Close()
		// go Handle(ctx, conn)
	}
}

Basically close connection straight after starting it - same result.

I tried to send silence (something available in code, but not documentation), before sending termination message. I also tried to send termination message before sending audio stream - socket closed by asterisk, but still having an issue in the asterisk logs.

I also looked into audiosocket/asterisk/apps/app_audiosocket.c at master · CyCoreSystems/audiosocket · GitHub

But nothing that I could stop which would help me in troubleshooting :frowning:

PS: I use Asterisk 18.15.1.
PS: Sorry, I can post only two links in a post, so I had to remove valid links…/
I ran out of ideas and not shure where is that issue is coming from :frowning:

Thanks in advance!

So I have had another, fresh, look at this, but from asterisk module side: audiosocket/asterisk at master · CyCoreSystems/audiosocket · GitHub

When socket message is processing: it comes to the ast_audiosocket_receive_frame function (res/res_audiosocket.c#L227)

On the line 255 happens processing of termination message:

   if (kind == 0x00) {
		/* AudioSocket ended by remote */
		return NULL;
	}

When handling of frame is calling outside:
apps/app_audiosocket.c#L200

            f = ast_audiosocket_receive_frame(svc);
			if (!f) {
				ast_log(LOG_ERROR, "Failed to receive frame from AudioSocket message for"
					"channel %s\n", chanName);
				return -1;
			}

(remember, it returns NULL if we send termination message) we will always have this error in the logs.

Also, it reports the error back to dialplan.

When socket is closed, I think it will return &ast_null_frame,
I tried to find where it’s defined, but could find only something like this:

Which probably should not trigger that (!f) condition. But I tried to close socket - with the same result. I will try test that again.

I still not sure where hangup is coming from, I still think because App finished with error (more testiung and investagation is coming)
Also, I think this might be related to github com/CyCoreSystems/audiosocket/issues/16

To be honest, this looks like a bug to me.

What would be the best way to report this, so community can pick it up and fix ?

Did you find out, I have recently started understanding the usage of audio socket and external media.

Can you share your understanding of the scalability of both audio socket and external media

Hi!

No, I didn’t test it on scale, as I have an issue using it.