drachtio / drachtio-freeswitch-modules

A collection of open-sourced freeswitch modules that I use in various drachtio applications
MIT License
171 stars 119 forks source link

mod_audio_fork silent sound to client when play message from lws #106

Open TechGuyVN opened 1 year ago

TechGuyVN commented 1 year ago

Dear Friend,

I made an callbot using freeswitch & my backend. Use flow:

Our problem is: if test 1/2 call is okay no problem if increase concurrent call with long audio ( base64 test bigger about 0.6Mb) sound become silent when playback to client I see those log:

1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:06.881613 99.80% [DEBUG] switch_ivr_play_say.c:1566 Codec Activated L16@8000hz 1 channels 20ms 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:11.381619 99.67% [DEBUG] switch_ivr_play_say.c:2015 done playing file /tmp/1e4abe06-e9af-4090-9ecd-92b424d192b7_49.tmp.r8 2023-03-07 00:38:16.501604 99.57% [DEBUG] lws_glue.cpp:54 (27) processIncomingMessage - received playAudio message and final = 1 and audioDuration = 5.070000 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:16.521622 99.57% [DEBUG] mod_audio_fork.c:21 responseHandler: sending event payload: {"audioContentType":"raw","sampleRate":8000,"audioDuration":4.07,"textContent":"sorry i call from hotline of company xxx please give me some minutes to introduce our services","file":"/tmp/1e4abe06-e9af-4090-9ecd-92b424d192b7_50.tmp.r8"}. 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:16.621606 99.57% [DEBUG] switch_ivr.c:632 sofia/external/0765992824 Command Execute [depth=1] playback(/tmp/1e4abe06-e9af-4090-9ecd-92b424d192b7_50.tmp.r8) 1e4abe06-e9af-4090-9ecd-92b424d192b7 EXECUTE [depth=1] sofia/external/0765992824 playback(/tmp/1e4abe06-e9af-4090-9ecd-92b424d192b7_50.tmp.r8) 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:16.621606 99.57% [DEBUG] switch_ivr_play_say.c:1566 Codec Activated L16@8000hz 1 channels 20ms 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:18.501607 99.57% [ERR] lws_glue.cpp:620 (26) dropping packets! 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:18.501607 99.57% [ERR] lws_glue.cpp:620 (27) dropping packets! 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:20.501649 99.53% [ERR] lws_glue.cpp:620 (26) dropping packets! 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:20.501649 99.53% [ERR] lws_glue.cpp:620 (27) dropping packets! 1e4abe06-e9af-4090-9ecd-92b424d192b7 2023-03-07 00:38:20.701655 99.53% [DEBUG] switch_ivr_play_say.c:2015 done playing file /tmp/1e4abe06-e9af-4090-9ecd-92b424d192b7_50.tmp.r8

in 620 core of lws_glue.cpp it like that: ` uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE]; switch_frame_t frame = { 0 }; frame.data = data; frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { if (frame.datalen) { spx_uint32_t out_len = available >> 1; // space for samples which are 2 bytes spx_uint32_t in_len = frame.samples;

        speex_resampler_process_interleaved_int(tech_pvt->resampler,
          (const spx_int16_t *) frame.data,
          (spx_uint32_t *) &in_len,
          (spx_int16_t *) ((char *) pAudioPipe->binaryWritePtr()),
          &out_len);

        if (out_len > 0) {
          // bytes written = num samples * 2 * num channels
          size_t bytes_written = out_len << tech_pvt->channels;
          pAudioPipe->binaryWritePtrAdd(bytes_written);
          available = pAudioPipe->binarySpaceAvailable();
          dirty = true;
        }
        if (available < pAudioPipe->binaryMinSpace()) {
          if (!tech_pvt->buffer_overrun_notified) {
            tech_pvt->buffer_overrun_notified = 1;
            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "(%u) dropping packets!\n",
              tech_pvt->id);
            tech_pvt->responseHandler(session, EVENT_BUFFER_OVERRUN, NULL);
          }
          break;
        }
      }
    }

`

I guess buffer limit read text too short so i increase it to 5Mb but not working: `/ discard incoming text messages over the socket that are longer than this /

define MAX_RECV_BUF_SIZE (5065600)

define RECV_BUF_REALLOC_SIZE (16 * 1024)

`

can you help me this case