signalwire / freeswitch

FreeSWITCH is a Software Defined Telecom Stack enabling the digital transformation from proprietary telecom switches to a versatile software implementation that runs on any commodity hardware. From a Raspberry PI to a multi-core server, FreeSWITCH can unlock the telecommunications potential of any device.
https://freeswitch.com/#getting-started
Other
3.54k stars 1.41k forks source link

Distorted early media in call recording when mod_dptools:wait_for_answer is used. #2454

Open evgeniibuchnev opened 5 months ago

evgeniibuchnev commented 5 months ago

Describe the bug

When native mod_dptools:wait_for_answer application is used - the call recording appears distorted in early media part of the overall call. When call is answered - clean and quality recording presented.

With a workaround in Lua both parts of the call(early media and answered media) recording appear OK.

This issue is easily reproducible with below. When real calls are made the issue persists.

To Reproduce

Dialplan snippet:

<include>
    <context name="testing">

        <extension name="leg_1">
            <condition field="destination_number" expression="^(leg_1)$">
                <action application="pre_answer" />
                <action application="playback" data="tone_stream://%(800,200,300);loops=2" />
                <action application="answer" />
                <action application="playback" data="tone_stream://%(800,200,300);loops=2" />
                <action application="hangup" data="busy" />
            </condition>
        </extension>

        <extension name="leg_21">
            <condition field="destination_number" expression="^(leg_21)$">
                <action application="answer" />
                <action application="record_session" data="/usr/local/freeswitch/recordings/distorted.wav" />
                <action application="wait_for_answer" />
                <action application="sleep" data="10000" />
                <action application="hangup" data="busy" />
            </condition>
        </extension>

        <extension name="leg_22">
            <condition field="destination_number" expression="^(leg_22)$">
                <action application="answer" />
                <action application="record_session" data="/usr/local/freeswitch/recordings/clean.wav" />
                <action application="lua" data="wait_for_answer.lua" />
                <action application="sleep" data="10000" />
                <action application="hangup" data="busy" />
            </condition>
        </extension>

    </context>
</include>

Workaround solution via wait_for_answer.lua:

function wait_for_answer(ses, sleep_interval_ms)
    local sleep_interval_ms = sleep_interval_ms or 20
    while not ses:answered() do
        ses:sleep(sleep_interval_ms)
    end
    ses:consoleLog("INFO", 'Session is in ANSWERED state.')
end

if session:ready() then
    wait_for_answer(session)
end

You can trigger these by:

bgapi originate {}loopback/leg_1/testing leg_21 XML testing
bgapi originate {}loopback/leg_1/testing leg_22 XML testing

Have a look into recordings:

image

Expected behavior

A clean recording (without distortion) is expected.

Package version or git hash

evgeniibuchnev commented 5 months ago

413 looks related, although this ticket has clean and easy instruction for reproduction. Workaround included.

suiyuemanbu commented 4 weeks ago

ses:sleep(sleep_interval_ms) 和 switch_ivr_sleep() 有什么区别?