Cookbook Example

How can I...?

Example 12 : Simple TCP based streamer that repeatedly streams (3 times) the same audio file. The reason it's the same file is because it's configured with a playlist that is created: [ shortfile, shortfile, shortfile ]. If this was [ song_one, song_two, song_three ], then this would be a simple streamer that had a playlist of 3 songs played repeatedly. Something that does this is often referred to as a carousel. Components used: SimpleServer, JoinChooserToCarousel, FixedRateControlledReusableFileReader, ForwardIteratingChooser, pipeline

    #!/usr/bin/python

    from Kamaelia.Chassis.ConnectedServer import SimpleServer
    from Kamaelia.Chassis.Prefab import JoinChooserToCarousel
    from Kamaelia.File.Reading import FixedRateControlledReusableFileReader
    from Kamaelia.Util.PipelineComponent import pipeline
    from Kamaelia.Util.Graphline import Graphline
    from Kamaelia.Util.Chooser import ForwardIteratingChooser

    shortfile = "/opt/kde3/share/sounds/KDE_Startup_2.ogg"

    FILES_TO_STREAM = [ shortfile, shortfile, shortfile ]# [ file_to_stream, file_to_stream2 ]
    BITRATE = 800000 # 38000
    CHUNKSIZEBYTES = 512
    SERVERPORT = 1500

    def MultiFileReaderProtocol(filenames, bitrate, chunksizebytes):
    def protocolFactory(*argv, **argd):
    return JoinChooserToCarousel(
    ForwardIteratingChooser(filenames),
    FixedRateControlledReusableFileReader(readmode="bytes",
    rate=bitrate/8,
    chunksize=chunksizebytes)
    )
    return protocolFactory

    if __name__ == '__main__':
    filereader = MultiFileReaderProtocol( FILES_TO_STREAM, BITRATE, CHUNKSIZEBYTES)
    server = SimpleServer( protocol = filereader, port = SERVERPORT ).run()
    Source: Examples/example12/SimpleMultiFileStreamer.py

 

Kamaelia is an open source project originated from and guided by BBC Research. For more information browse the site or get in contact.

This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)

(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved

This web site is powered by the same code created for the bicker manor project. For more details, contact Michael Sparks at BBC Research directly (cf contact)