[asterisk-dev] A thread for format work

Matthew Jordan mjordan at digium.com
Wed Apr 30 07:50:05 CDT 2014

On Wed, Apr 30, 2014 at 5:59 AM, Joshua Colp <jcolp at digium.com> wrote:

> Matthew Jordan wrote:

>  :: Setting Attributes ::
>> The biggest sticky point is clearly #1. I don't think we should lose the
>> immutability convention - that feels bad, since there's a lot of benefit
>> to treating a format as a read-only object (no locking!) - and a format
>> shouldn't change very often. In order to maintain mutability, I'd remove
>> the public format attribute setting function and instead do the following:
> I disagree with this. Having the ability to set via name/value attributes
> could be extremely useful in the future. For example it would easily allow
> a module to exist which allows you to add to the cached formats of the
> system, with attributes. This is something that wasn't possible before. For
> simple things it would even take care of SDP.

If we allow attributes to be set after format creation, we have two options:

(1) We make formats mutable, and all the badness that entails.

(2) Setting a format implicitly dupes the existing format, adds the new
attribute, then returns a new format.

Going with option #2 (mutable == bad), I'm not sure how useful this is as a
public operation. When you get an SDP, the attributes will be presented to
you as a big ol' blob of text. You don't want to parse those outside of
something that is creating the format - otherwise you'll end up with this
incredibly bad code:

format1 = ast_format_attribute_set(format, "foo", "bar");
format2 = ast_format_attribute_set(format1, "yackity", "schmackity");
format3 = ast_format_attribute_set(format2, "oh_nos", "the_pain");
format = format3;


This, on the other hand, is slightly cleaner:

new_format = ast_format_sdp_parse(format, my_sdp_with_attributes);
format = new_format;

And is how both chan_sip and res_pjsip_sdp_rtp operate.

While we may some day want to add a public function that adds attributes...

>  :: Getting Attributes ::
>> Since the format is read-only, it's safe to get the format attributes
>> from a format object. There is one place where this is done using
>> ast_format_isset. ast_format_get_value is never used. As the object is
>> immutable, a public accessor for an attribute key could be used that
>> returns a const char *, which would fulfil both functions.
> The design currently gets away from the whole attribute key thing.
> Attributes are stored in whatever way the format interface has decided via
> an AO2 structure associated with the format itself. It needs a way to
> set/get that.
How so? The current design calls for a public function that accepts a const
char *key and a const char *value. The key and value are always going to be
presented to the core as text (inbound SDP), and typically will be
generated as text (outgoing SDP). Yes, sometimes we may need to interpret
the values as integers, or floats, or something - but that will typically
be the domain of the resource modules. I'm not sure storing them as
heterogeneous types is all that advantageous.

Matthew Jordan
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20140430/3b5965df/attachment-0001.html>

More information about the asterisk-dev mailing list