Le 15/06/2011 08:27, David Baelde a écrit :
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<[email protected]>  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).
I know this is not a constructive comment but it looks more natural at first for the regular user :)

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).
Do I have to understand that mono_or_stereo() here returns a new source ?
So In my context:

def create_playlist(uri) =

# not sure where to put the following function, but if it should exists for create_playlist() I do not see other place.

   def mono_or_stereo(format,source) =

       output.icecast(format,mount="foo",source)
       end
       mono_or_stereo : (format('a),source('a))->source('a)


        s = input.alsa(device="#{source_device}")
        s = server.insert_metadata(id="#{stream_id}-meta", s)
        #here we go
        s = mono_or_stereo(%mp3(channels="#{channel_nb}"),source)
        # wooot ?
        # What if I want the bitrate to be set as argument too ?


(...)
end

Hope this helps,

Of course it helps.
Thanks !
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users

Reply via email to