[Freeswitch-dev] Fwd: [Freeswitch-users] codecs initialization flags in endpoint modules
Hello, I'm forwarding the message from my friend since is better suited for -dev ML. In addition, we changed the codec_init to ask only for DECODE on read and for ENCODE on write in sofia and skypiax and everything seems to work... there's a reason for that? are we going to break up things? regards, Matteo. ----- Messaggio inoltrato ----- Da: "Lele Forzani" <lele@windmill.it> A: freeswitch-users@lists.freeswitch.org Inviato: Venerdì, 3 aprile 2009 15:20:13 GMT +01:00 Amsterdam/Berlino/Berna/Roma/Stoccolma/Vienna Oggetto: [Freeswitch-users] codecs initialization flags in endpoint modules Hello, I've been experimenting with the use of mod_dahdi_codec and other ways to perform external transcoding for codecs, and came up with noticing that transcoding resources seemed to be used up twice what I expected. That is and 2x the number of call legs, ending up to two encoder and two decoder instances per leg. So, I looked at the code and noticed almost every endpoint module does something like this (excerpt from mod_sofia, sofia_glue.c:~1800): if (switch_core_codec_init(&tech_pvt->read_codec, tech_pvt->iananame, tech_pvt->rm_fmtp, tech_pvt->rm_rate, tech_pvt->codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags, NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); switch_goto_status(SWITCH_STATUS_FALSE, end); } if (switch_core_codec_init(&tech_pvt->write_codec, tech_pvt->iananame, tech_pvt->rm_fmtp, tech_pvt->rm_rate, tech_pvt->codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags, NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); switch_goto_status(SWITCH_STATUS_FALSE, end); } The flags being SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE seems to be causing the apparent 'double' allocation of transcoding resources, and I fail to understand the need for both, in both cases. Could someone please spend a minute to explain? thanks lele _______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
did you test it in scenarios where the ptime is mismatched, every combination of sample rate transcoding, eavesdroping on a channel in all the above situations? It would require a full suite of testing to confirm. switch_core_io.c:432 does use read_codec for encode i think cases arise where it does need both but we could change the code to delay when it inits until the first time it needs it instead so it would only take place when necessary. it would require changing all the codec modules in the if (encoding) if (decoding) so instead they were functions we would call the first time encode or decode was actually called. On Mon, Apr 6, 2009 at 10:26 AM, Matteo <mbrancaleoni@voismart.it> wrote:
Hello,
I'm forwarding the message from my friend since is better suited for -dev ML.
In addition, we changed the codec_init to ask only for DECODE on read and for ENCODE on write in sofia and skypiax and everything seems to work...
there's a reason for that?
are we going to break up things?
regards, Matteo.
----- Messaggio inoltrato ----- Da: "Lele Forzani" <lele@windmill.it> A: freeswitch-users@lists.freeswitch.org Inviato: Venerdì, 3 aprile 2009 15:20:13 GMT +01:00 Amsterdam/Berlino/Berna/Roma/Stoccolma/Vienna Oggetto: [Freeswitch-users] codecs initialization flags in endpoint modules
Hello, I've been experimenting with the use of mod_dahdi_codec and other ways to perform external transcoding for codecs, and came up with noticing that transcoding resources seemed to be used up twice what I expected. That is and 2x the number of call legs, ending up to two encoder and two decoder instances per leg.
So, I looked at the code and noticed almost every endpoint module does something like this (excerpt from mod_sofia, sofia_glue.c:~1800):
if (switch_core_codec_init(&tech_pvt->read_codec, tech_pvt->iananame, tech_pvt->rm_fmtp, tech_pvt->rm_rate, tech_pvt->codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags, NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); switch_goto_status(SWITCH_STATUS_FALSE, end); }
if (switch_core_codec_init(&tech_pvt->write_codec, tech_pvt->iananame, tech_pvt->rm_fmtp, tech_pvt->rm_rate, tech_pvt->codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags, NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); switch_goto_status(SWITCH_STATUS_FALSE, end); }
The flags being SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE seems to be causing the apparent 'double' allocation of transcoding resources, and I fail to understand the need for both, in both cases.
Could someone please spend a minute to explain?
thanks lele
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ Freeswitch-dev mailing list Freeswitch-dev@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
Hi, ----- "Anthony Minessale" <anthony.minessale@gmail.com> ha scritto:
did you test it in scenarios where the ptime is mismatched, every combination of sample rate transcoding, eavesdroping on a channel in all the above situations?
no, not at all
It would require a full suite of testing to confirm.
I agree.
switch_core_io.c:432 does use read_codec for encode
i think cases arise where it does need both but we could change the code to delay when it inits until the first time it needs it instead so it would only take place when necessary.
the question arose investigating the wrong resource usage of dadhi codec, since it allocs 2 resources for every call. maybe the issue is somewhere else? regards, matteo
yes it's a valid concern. We should work towards a patch like the one i proposed to init the resources only when they are first called upon so if a paticular call never needs the read codec to do encode and decode then it would only allocate them the first time they actually tried it. then most calls would only use one of each until some of the more crazy scenarios kicked in On Mon, Apr 6, 2009 at 1:20 PM, Matteo <mbrancaleoni@voismart.it> wrote:
Hi,
----- "Anthony Minessale" <anthony.minessale@gmail.com> ha scritto:
did you test it in scenarios where the ptime is mismatched, every combination of sample rate transcoding, eavesdroping on a channel in all the above situations?
no, not at all
It would require a full suite of testing to confirm.
I agree.
switch_core_io.c:432 does use read_codec for encode
i think cases arise where it does need both but we could change the code to delay when it inits until the first time it needs it instead so it would only take place when necessary.
the question arose investigating the wrong resource usage of dadhi codec, since it allocs 2 resources for every call.
maybe the issue is somewhere else?
regards, matteo
_______________________________________________ Freeswitch-dev mailing list Freeswitch-dev@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
please try now with latest code that should delay the init of the resources until they are in use so cases where they are not used both ways will not cost a hw resource. On Mon, Apr 6, 2009 at 1:43 PM, Anthony Minessale < anthony.minessale@gmail.com> wrote:
yes it's a valid concern.
We should work towards a patch like the one i proposed to init the resources only when they are first called upon so if a paticular call never needs the read codec to do encode and decode then it would only allocate them the first time they actually tried it. then most calls would only use one of each until some of the more crazy scenarios kicked in
On Mon, Apr 6, 2009 at 1:20 PM, Matteo <mbrancaleoni@voismart.it> wrote:
Hi,
----- "Anthony Minessale" <anthony.minessale@gmail.com> ha scritto:
did you test it in scenarios where the ptime is mismatched, every combination of sample rate transcoding, eavesdroping on a channel in all the above situations?
no, not at all
It would require a full suite of testing to confirm.
I agree.
switch_core_io.c:432 does use read_codec for encode
i think cases arise where it does need both but we could change the code to delay when it inits until the first time it needs it instead so it would only take place when necessary.
the question arose investigating the wrong resource usage of dadhi codec, since it allocs 2 resources for every call.
maybe the issue is somewhere else?
regards, matteo
_______________________________________________ Freeswitch-dev mailing list Freeswitch-dev@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org
-- Anthony Minessale II
FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/
AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch
FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
On Thu, 2009-04-09 at 12:41 -0500, Anthony Minessale wrote:
please try now with latest code that should delay the init of the resources until they are in use so cases where they are not used both ways will not cost a hw resource.
Thanks a lot Anthony, there is still a minor typo in mod_dahdi_codec, that was already there, but not causing as much harm as now, since encoders and decoders were always initialized in pairs. I'm pasting the diff in the mail body since it's a two letters change. --- src/mod/codecs/mod_dahdi_codec/mod_dahdi_codec.c- 2009-04-11 18:24:04.000000000 +0200 +++ src/mod/codecs/mod_dahdi_codec/mod_dahdi_codec.c 2009-04-11 18:24:11.000000000 +0200 @@ -126,7 +126,7 @@ fmts.dstfmt = (codec->implementation->ianacode == CODEC_G729_IANA_CODE) ? DAHDI_FORMAT_G729A : DAHDI_FORMAT_G723_1; context->encoding_fd = switch_dahdi_get_transcoder(&fmts); - if (context->decoding_fd < 0) { + if (context->encoding_fd < 0) { #ifdef DEBUG_DAHDI_CODEC switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "encoding requested and denied with %d/%d.\n", fmts.srcfmt, fmts.dstfmt); Other than that, it seems working, and the resource usage is what it was expected. Thanks, l.
fixed, thx On Fri, Apr 10, 2009 at 9:53 AM, Lele Forzani <lele@windmill.it> wrote:
On Thu, 2009-04-09 at 12:41 -0500, Anthony Minessale wrote:
please try now with latest code that should delay the init of the resources until they are in use so cases where they are not used both ways will not cost a hw resource.
Thanks a lot Anthony,
there is still a minor typo in mod_dahdi_codec, that was already there, but not causing as much harm as now, since encoders and decoders were always initialized in pairs.
I'm pasting the diff in the mail body since it's a two letters change.
--- src/mod/codecs/mod_dahdi_codec/mod_dahdi_codec.c- 2009-04-11 18:24:04.000000000 +0200 +++ src/mod/codecs/mod_dahdi_codec/mod_dahdi_codec.c 2009-04-11 18:24:11.000000000 +0200 @@ -126,7 +126,7 @@ fmts.dstfmt = (codec->implementation->ianacode == CODEC_G729_IANA_CODE) ? DAHDI_FORMAT_G729A : DAHDI_FORMAT_G723_1; context->encoding_fd = switch_dahdi_get_transcoder(&fmts); - if (context->decoding_fd < 0) { + if (context->encoding_fd < 0) { #ifdef DEBUG_DAHDI_CODEC switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "encoding requested and denied with %d/%d.\n", fmts.srcfmt, fmts.dstfmt);
Other than that, it seems working, and the resource usage is what it was expected.
Thanks, l.
_______________________________________________ Freeswitch-dev mailing list Freeswitch-dev@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
done On Fri, Apr 10, 2009 at 2:21 PM, Lele Forzani <lele@windmill.it> wrote:
On Fri, 2009-04-10 at 12:40 -0500, Anthony Minessale wrote:
fixed, thx
Sorry, I missed this earlier: context->codec_r is used in the decode path also.
patch attached (hope it's ok)
thanks l.
_______________________________________________ Freeswitch-dev mailing list Freeswitch-dev@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
participants (3)
-
Anthony Minessale
-
Lele Forzani
-
Matteo