Ari External Media Code Issue

Hi @gjoseph i checked and it workedddd wonders

but i still getting this error on asterisk debug but it comes only initally then it does not come all time

but the audio is coming perfectly

[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 22:28:19] ERROR[900751]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
– Remote UNIX connection
– Remote UNIX connection disconnected
== Connect attempt from ‘127.0.0.1’ unable to authenticate
– Remote UNIX connection

can you help me in this and can you tell me if i write opus what will the default configuration of opus ??

That error means that whatever you’re sending to Asterisk can’t be decoded. Where is the audio coming from? Are there empty frames in it? What does a pcap of the data stream show?

Defaults:

default max rate:    48000
default bitrate:      auto
default max bw:       full
default signal:       auto
default application:  voip
default complexity:     10
default packet loss:     0
default cbr:            no
default fec:           yes
default dtx:            no

You can change these by creating an entry in codecs.conf.

You can see the parameters by typing config show help codec_opus opus from the asterisk CLI but here’s an example:

[opus]
type=opus
max_bandwidth=full
max_playback_rate=48000
bitrate=64000
fec=no

You can also create aliases with different settings:

[opus_websocket]
type=opus
cbr=1
max_bandwidth=wide
max_playback_rate=48000
bitrate=64000
fec=no

Then you can use c(opus_websocket)or specify format: “opus_websocket”.

Okay greatttt , i have a node js script that is sending back to the asterisk , which is sending back to the socket in every 20ms

and i also want to ask doe it necessary to send packets back to audio socket in interval?? like 20 ms or can i send that in any time ?? like in real time not in 20 ms ??

and if yes then i have to do for all codes format
and if no then there must be the acurate bytes format or i can send as much bytes of data ?

Node js.txt (7.1 KB)

anything better that you can share me to check this

I also got one catch here i just made a script that will log what ever coming from asterisk nothing sending back

still it getting me this error

0.1’ unable to authenticate
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:03:53] ERROR[905003]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream

and my socket script received

:package: Binary packet (59 bytes)
7807c979c8c957c0a21223faef67f367 …
:package: Binary packet (59 bytes)
7807c979c8c957c0a21223faef67f367 …

:package: Binary packet (59 bytes)
7807c979c8c957c0a21223faef67f367 …
:package: Binary packet (59 bytes)
7807c979c8c957c0a21223faef67f367 …
:package: Binary packet (59 bytes)
7807c979c8c957c0a21223faef67f367 …
:package: Binary packet (59 bytes)
7807c979c8c957c0a21223faef67f367 …

and this is the sample code

// media-ws-dump.js
import { WebSocketServer } from “ws”;

const PORT = 6667;

const wss = new WebSocketServer({ port: PORT }, () =>
console.log(WS listening on ws://0.0.0.0:${PORT})
);

wss.on(“connection”, (ws) => {
console.log(“:link: client connected”);

ws.on(“message”, (data, isBinary) => {
if (isBinary) {
console.log(📦 Binary packet (${data.length} bytes));
// optional: hexdump first 16 bytes
console.log(data.subarray(0, 16).toString(“hex”), “…”);
} else {
console.log(💬 Text: ${data.toString()});
}
});

ws.on(“close”, () => console.log(“:electric_plug: client disconnected”));
ws.on(“error”, (e) => console.error(“WS error:”, e?.message || e));
});

dont you think i might create asterisk to crash?? becuase the error keeps on coming continiusly why this is try to decode if nothing is pased to this the same is working fine in slin16 and ualw format

there was no error if we do not pass anyhing back to asterisk we dont get any error like this

@gjoseph

In passthrough mode, you have to feed Asterisk with correctly framed data at the rate the codec expects (the “ptime”) even if it’s silence. If you don’t the opus decoder will complain because it can’t decode anything. The default rate for opus is 20ms. So yes, you need to continually send at that rate. In your test script, write the binary messages back to asterisk as you receive them. This will create an echo test and you shouldn’t get the error messages.

If you need to, you can do this for any codec. For the codecs that aren’t forced to passthrough mode, as long as you send Asterisk frames with a length that equals “optimal_frame_size” every 20ms, you’re fine.

so you are saying the opus that you have done changes runs in pass through mode that why it is getting me error rest other code are without passthrough mode so they dont need to send in every 20 ms?? right

and if that then why opus doesn’t run without passthrough mode like rest of the code @gjoseph

OK so I may have just misspoken. I forgot that I will create silence frames if I don’t get any frames from the remote app, even in passthrough mode. :slight_smile: Sorry about that. It does mean though that the data you’re sending isn’t formatted correctly. You’ll need to use Wireshark to get a packet capture to see what’s going on.

So for opus, you DO have to send data every 20ms if you have data to send. If you don’t send any data, chan_websocket will automatically create a silence frame and send it to the Asterisk core. The reason you have to send every 20ms is that opus data has packet headers, the packets can contain multiple frames and the packet lengths are variable so there’s no way for chan_websocket to buffer them and create proper frames at the proper interval. For the other codecs, their sample sizes and rates are fixed and well known so you can send chan_websocket arbitrary amounts of data and it can figure out how to break the data up into frames and feed them at a constant rate to the Asterisk core.

I did just make one change and pushed up a new version of the PR. I added a “ptime” parameter to the MEDIA_START message:

MEDIA_START connection_id:media_connection1 channel:WebSocket/media_connection1/0x7f8c0c0047d0 format:opus optimal_frame_size:0 ptime:20

This way you’ll know how often you need to send frames.

Hi @gjoseph on the node js script i am sending back the audio as soon as i receive it

:speech_balloon: Text: MEDIA_START connection_id:ace_media_ws channel:WebSocket/ace_media_ws/0x746ac8004b10 format:opus optimal_frame_size:0 ptime:20

but still its give me the error

ep 19 23:55:29] WARNING[927540]: chan_websocket.c:632 process_text_message: WebSocket/ace_media_ws/0x746ac8004b10: WebSocket MEDIA_START connection_id:ace_media_ws channel:WebSocket/ace_media_ws/0x746ac8004b10 format:opus optimal_frame_size:0 ptime:20 command unknown
– Channel WebSocket/ace_media_ws/0x746ac8004b10 joined ‘simple_bridge’ stasis-bridge
[Sep 19 23:55:29] ERROR[927541]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream
[Sep 19 23:55:29] ERROR[927541]: codec_opus.c:386 opus_dec_decode: Opus: decoding: corrupted stream

and i also tested this if i dont send back to asterisk it keeps giving me error continously so i gues that is also not working right now ???

I’m sorry but I can’t help you further based on the information you’ve given me.

  • What’s the source of the media you’re sending to your app?
  • Is it being transcoded from some other format?
  • If you examine the websocket connection with wireshark, do you see the same packets flowing in both directions?
  • Did you make any changes in codecs.conf?

Hi @gjoseph i understand your concern but you mentioned above that even if i had

// media-ws-echo.js
import { WebSocketServer } from “ws”;

const PORT = 6667;

const wss = new WebSocketServer({ port: PORT }, () =>
console.log(WS echo listening on ws://0.0.0.0:${PORT})
);

wss.on(“connection”, (ws) => {
console.log(" ^=^t^w client connected");

ws.on(“message”, (data, isBinary) => {
if (isBinary) {
console.log( ^=^s Binary packet (${data.length} bytes));
// ws.send(data, { binary: true, compress: false }); // echo back
} else {
const text = data.toString();
console.log( ^=^r Text: ${text});
// ws.send(text); // echo back
}
});

ws.on(“close”, () => console.log(" ^=^t^l client disconnected"));
ws.on(“error”, (e) => console.error(“WS error:”, e?.message || e));
});

not sending anythibg back to asterisk still asteirsk is giving me this error which you said earlier that websocket automatically send the silence to the asterisk

and i used opus format that is sending to the webscoket and that websocket is just sending back the data which i mention in the above code

still i am getting 2-3 error initially in that case also why??

and if i dont send the back asterisk is giving me the error that screenshot i have attached above

I can’t tell you why you’re seeing errors until I see the data from the wireshark capture.

Capture and save the packets from the websocket connection into a pcap file, then zip the pcap file and attach it here.

okay sure will share the pcap file

Well, it does look like you’re echoing the binary data back correctly but you should NEVER echo back the TEXT data. That’s why you’re getting WARNING[927540]: chan_websocket.c:632 process_text_message: WebSocket/ace_media_ws/0x746ac8004b10: WebSocket MEDIA_START connection_id:ace_media_ws channel:WebSocket/ace_media_ws/0x746ac8004b10 format:opus optimal_frame_size:0 ptime:20 command unknown

If you’re getting the “corrupted stream” errors then the data you’re sending out to your app is invalid. So now the question remains… Where exactly is the data you’re sending out coming from and in what format is it in originally? While the call is up, do a core show channel on both the incoming channel and the outgoing websocket channel and paste the result. Also you never answered my question about changes to codec.conf? Did you make any?

Hi @gjoseph any update on this ?

Well, IT’S SATURDAY so no there’s no update. I’ll take a look when I’m back at work on Monday.

okay @gjoseph Thanks a lottt !!!

@gauravs456 This is an open source project with a community, it is not a product with paid support. There’s no SLA, or even guarantee of when George will get to things. I also ask you to stop tagging him, there’s no need.

1 Like

okay i will remember that

You only get a short bust of corrupted stream errors at the beginning of the call and maybe at the end of the call but not in the middle of the call correct?

If you set transcode_via_sln = no in asterisk.conf, do you still see the errors?

Please the latest version of PR #1466. It should fix the error messages.