April 2024 - This site, and Kamaelia are being updated. There is significant work needed, and PRs are welcome.

Kamaelia.Util.RateChunker

Breaks data into chunks matching a required chunk rate

Send data, such as binary strings to this component and it will break it down to roughly constant sized chunks, to match a required 'rate' of chunk emission.

This is not about 'real time' chunking of a live data source, but is instead about precisely chunking data that you know has been generated, or will be consumed, at a particular rate.

You specify the 'rate' of the incoming data and the rate you want chunks sent out at. RateChunker will determine what size the chunks need to be, applying dynamic rounding to precisely match the rate without drift over time.

Example Usage

Chunking a stream of 48KHz 16bit stereo audio into 25 chunks per second of audio data (one chunk for each frame of a corresponding piece of 25fps video):

bps = bytesPerSample = 2*2

Pipeline( AudioSource(),
          RateChunker(datarate=48000*bps, quantasize=bps, chunkrate=25),
          ...
        )

The quanta size ensures that the chunks RateChunker sends out always contain a whole number of samples (4 bytes per sample).

Behaviour

At initialisation, specify:

  • the rate of the incoming data (eg. bytes/second)
  • the required rate of outgoing chunks of data
  • the minimum quanta size (see below)

Send slicable data items, such as strings containing binary data to the "inbox" inbox. The same data is sent out of the "outbox" outbox, rechunked to meet the required chunk rate.

The outgoing chunk sizes are dynamically varied to match the required chunk rate as accurately as possible. The quantasize parameter dictates the minimum unit by which the chunksize will be varied.

For example, for 16bit stereo audio data, there are 4 bytes per sample, so a quantasize of 4 should be specified, to make sure samples remain whole.

If a producerFinished or shutdownMicroprocess message is received on the "control" inbox. It is immediately sent on out of the "signal" outbox and the component then immediately terminates.


Kamaelia.Util.RateChunker.RateChunker

class RateChunker(Axon.Component.component)

RateChunker(datarate,quantasize,chunkrate) -> new Chunk component.

Alters the chunksize of incoming data to match a desired chunkrate.

Keyword arguments:

  • datarate -- rate of the incoming data
  • quantasize -- minimum granularity with which the data can be split
  • chunkrate -- desired chunk rate

Inboxes

  • control : Shutdown signalling
  • inbox : Data items

Outboxes

  • outbox : Rechunked data items
  • signal : Shutdown signalling

Methods defined here

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self, datarate, quantasize, chunkrate)

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

checkShutdown(self)

main(self)

Main loop

Feedback

Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT