[Freeswitch-users] question on media bugs: add / remove /add sequence leading to crash when session ends

Piotr Gregor piotr at dataandsignal.com
Thu Oct 10 15:22:59 UTC 2019


Hi David,

As Dragos mentioned, there are examples in FS source tree how to do this,
mod_avmd in particular.
Others are mod_cv, mod_stress, mod_soundtouch, mod_oreka, mod_vmd, mod_vmd,
mod_ladspa, mod_snapshot, mod_fsk, mod_video_filter, mod_spandsp.

You may need to switch_channel_set_private/switch_channel_remove_private.

Instead of removing/re-adding the bug you can add it just once with
switch_core_media_bug_add, and remove it when FS session ends.
You can then supply the state describing your app's session as the 5th
argument to a call:

my_session_t *my_session =
alloc_my_session_dynamically_or_use_global_variable_just_about_anything_but_local_stack(not_active)
__cannot_fail__;
switch_core_media_bug_add(session, "my-function", NULL, my_callback,
my_session, 0, my_flags, &my_bug)

In that state you can put whatever you need, including whether your app on
given FS session is active at the moment,
and based on that you can drive your code inside my_callback.

 static switch_bool_t my_callback(switch_media_bug_t * bug, void
*user_data, switch_abc_type_t type)
 {
     my_session = (my_session_t *) user_data;
     //
     switch (type) {
         case SWITCH_ABC_TYPE_INIT:
             // if it has just been started
             my_session->active = 1;
             // maybe do something more if needed when your session is
started (when you would (re)add bug otherwise)
             break;
         case SWITCH_ABC_TYPE_CLOSE:
             my_session->active = 0;
             // maybe do something more if needed when your session is
closed (when you would remove bug otherwise)
             break;
         case SWITCH_ABC_TYPE_READ_REPLACE:
             // processing frame of data if session is active
             break;
         case SWITCH_ABC_TYPE_WRITE_REPLACE:
             // processing frame of data if session is active
             break;
         default:
             // other types
             why();
     }
     // ...
 }

Callback will be called every time there is a reason to call it
(considering also the flags you've supplied).
Good luck!



Piotr Gregor
Software Engineer

M: (+44) 07483 866 525     www: dataandsignal.com






On Mon, Sep 9, 2019 at 1:19 PM Dragos Oancea <dragos at freeswitch.org> wrote:

> It looks to me like it should have worked.
>
> Maybe you do something wrong in the callback ?
>
> Refer to other code that uses media bug, like mod_avmd .
>
>
> On Fri, Sep 6, 2019 at 7:03 PM David Horton <daveh at drachtio.org> wrote:
>
>> (Resending, as original email has not appeared in the mailing list)
>>
>> I’m trying to understand the semantics of removing and re-adding a media
>> bug to a channel.
>>
>> My scenario is that I need to add a bug to a session, and after some
>> period of processing audio then want to remove it.
>> Based on other factors, some time later in the call, I may want to re-add
>> it again.
>>
>> I am on Freeswitch v1.8.5
>>
>> How I am doing this now is:
>>
>> - switch_core_media_bug_add(session, “my-function”, NULL, callback, …)
>>
>> some time later
>>
>> - switch_core_media_bug_remove(session, &bug);
>>
>> some time later
>>
>> - switch_core_media_bug_add(session, “my-function”, NULL, callback, …)
>>
>> That all works fine, but when the session ends I get a segfault.  See the
>> stack trace below.
>>
>> (Note: I also tried using ‘switch_core_media_bug_close’ for the second
>> step, and I don’t get a stack trace in that scenario, but neither does my
>> callback get invoked after I re-add the bug in step #3).
>>
>> So, two questions:
>>
>> 1) What is the recommended way to accomplish what I am doing?
>> 2) Is this a bug in freeswitch that I should report via Confluence?
>>
>> Thread 40 "freeswitch" received signal SIGSEGV, Segmentation fault.
>> [Switching to Thread 0x7fffee766700 (LWP 31704)]
>> __GI___pthread_rwlock_unlock (rwlock=0x7fffc801acf0) at
>> pthread_rwlock_unlock.c:38
>> 38      pthread_rwlock_unlock.c: No such file or directory.
>> (gdb) bt
>> #0  __GI___pthread_rwlock_unlock (rwlock=0x7fffc801acf0) at
>> pthread_rwlock_unlock.c:38
>> #1  0x00007ffff7658b6e in apr_thread_rwlock_unlock () from
>> /usr/local/freeswitch/lib/libfreeswitch.so.1
>> #2  0x00007ffff6fc2cf3 in switch_thread_rwlock_unlock
>> (rwlock=0x7fffc801ace8) at src/switch_apr.c:279
>> #3  0x00007ffff6fe3272 in switch_core_media_bug_remove_all_function
>> (session=0x7fffc801c158, function=0x0)
>>    at src/switch_core_media_bug.c:1231
>> #4  0x00007ffff700a6f3 in switch_core_session_hangup_state
>> (session=0x7fffc801c158, force=SWITCH_TRUE)
>>    at src/switch_core_state_machine.c:838
>> #5  0x00007ffff7007178 in switch_core_session_run (session=0x7fffc801c158)
>>    at src/switch_core_state_machine.c:615
>> #6  0x00007ffff700069e in switch_core_session_thread
>> (thread=0x7fffc8041410, obj=0x7fffc801c158)
>>    at src/switch_core_session.c:1698
>> #7  0x00007ffff7000a8d in switch_core_session_thread_pool_worker
>> (thread=0x7fffc8041410, obj=0x7fffc80412a0)
>>    at src/switch_core_session.c:1761
>> #8  0x00007ffff7660e1f in dummy_worker () from
>> /usr/local/freeswitch/lib/libfreeswitch.so.1
>> #9  0x00007ffff63554a4 in start_thread (arg=0x7fffee766700) at
>> pthread_create.c:456
>> #10 0x00007ffff5992d0f in clone () at
>> ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
>> _________________________________________________________________________
>>
>> The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
>> Enhance your FreeSWITCH install with disruptive priced SMS and PSTN
>> services.
>> Build your next product on our scalable cloud platform.
>>
>> Join our online community to chat in real time
>> https://signalwire.community
>>
>> Professional FreeSWITCH Services
>> sales at freeswitch.com
>> https://freeswitch.com
>>
>> Official FreeSWITCH Sites
>> https://freeswitch.com/oss
>> https://freeswitch.org/confluence
>> https://cluecon.com
>>
>> FreeSWITCH-users mailing list
>> FreeSWITCH-users at lists.freeswitch.org
>> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
>> https://freeswitch.com
>
> _________________________________________________________________________
>
> The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
> Enhance your FreeSWITCH install with disruptive priced SMS and PSTN
> services.
> Build your next product on our scalable cloud platform.
>
> Join our online community to chat in real time
> https://signalwire.community
>
> Professional FreeSWITCH Services
> sales at freeswitch.com
> https://freeswitch.com
>
> Official FreeSWITCH Sites
> https://freeswitch.com/oss
> https://freeswitch.org/confluence
> https://cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> https://freeswitch.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20191010/5e2e9bf5/attachment-0001.html>


More information about the FreeSWITCH-users mailing list