Hi,

I think a little more detail could be useful, we haven't covered this
advanced issue very much yet.

On Tue, Jun 14, 2011 at 8:40 PM, Romain Beauxis <to...@rastageeks.org> wrote:
> We use format values to find out the content type of the streams
> (audio/video tracks, mono/stereo etc..). Thus, for some technical
> reasons, format values cannot use variables.

The technical reason is static typing: liquidsoap needs to know the
type of your function without executing it.

Suppose we were able to write the following:
def mono_or_stereo(~mono=true,source)
  n = if mono then 1 else 2 end
  output.icecast(%mp3(channels=n),mount="foo",source)
end
The type of our function would have to be something like:
(?mono:bool,source)->(if mono then 1 else 2 end,0,0)source
In other words the type of the resulting source depends on the value
that is passed. This is called a dependent type system, but it is far
too complex for liquidsoap (we would loose type inference and error
messages would be terrible).

Encoding formats are a trick to avoid dependent types: that's why they
cannot be computed, they are just constants disguised as functions.
When you write %mp3(channels=2) you're not calling a function you're
just referring to another constant.

Thanks to those, we can have almost what we tried to write:
def mono_or_stereo(format,source)
  output.icecast(format,mount="foo",source)
end
mono_or_stereo : (format('a),source('a))->source('a)

The 'a is sort of a dependency, but of a much simpler kind: we take
the parameters of the format and use them for the source. We can't
choose between mp3 and ogg, or the bitrate parameters inside
mono_or_stereo, though: it has to be called directly with a
fully-formed format constant, such as
mono_or_stereo(%mp3(channels=2),source).

Hope this helps,
-- 
David

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Savonet-users mailing list
Savonet-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/savonet-users

Reply via email to