audio Package

audio Package

class hanyuu.streamer.audio.FileInformation(filename, metadata=None)[source]

Bases: object

A class that should be returned from the function passed to Manager for file discovery.

This is to make switching functions easier since the Manager doesn’t need to know what format the function returns but only know that it returns a FileInformation instance instead.

class hanyuu.streamer.audio.Manager(source, processors=None, **options)[source]

Bases: object

A class that manages the audio pipeline. Each component gets a reference to the processor before it.

Note

This is a very cruel pipeline and has specifics to our needs and is in no way a generic implementation.

Nor does it have proper definitions of what should go out or into a processor.

The Manager expects that all registered processors have at least the following characteristics:

start(): Called when Manager.start() is called. This should
initialize required components. The Manager expects that a call to close and start is close to equal of recreating the whole instance.
close(): Called when Manager.close() is called. This should
close down the processor cleanly and if potential long running cleanups are to be done should use the garbage sub package shipped with the audio package.
__init__(): Called when the Manager instance is created.

This should not start any state dependant parts, these should be done in the start method instead.

Gets passed one positional argument that is the previous processor in the chain. Or if the first processor read below.

Gets passed extra keyword arguments if specified in the class attribute options. Read more about this attribute below.

The current version expects the first specified processor to take a function as source argument. That can be called for the filepath of an audiofile. This first processor is responsible for opening it.

Note

This means the processor doesn’t actually need to decode the file but that it is just expected to accept the function as source. What it does with the function is not important to the Manager.

The current version expects the last specified processor to have several methods available to be used by the Manager. These are:

status(): A method that is called when status() is called.
This should return something of significants to the user.
metadata(): A method that accepts a single unicode argument.
This is called whenever new metadata is found at the start of the processor chain.
close()[source]

Calls the close method on all registered processor instances.

Warning

Exceptions are propagated.

get_source()[source]
Returns unicode:
 A full file path to an audio file.

The value returned from Manager.source() is expected to be an FileInformation object. But there is one exception to this rule.

When Manager.source() returns a different type it will be used as the positional arguments to the FileInformation constructor by using the FileInformation(*returntype) syntax.

processors = [<class 'hanyuu.streamer.audio.files.FileSource'>, <class 'hanyuu.streamer.audio.encoder.Encoder'>, <class 'hanyuu.streamer.audio.icecast.Icecast'>]

A list of processors that are instanced in order and are passed their previous friend as first argument.

start()[source]

Calls the start method on all registered processor instances.

This method does nothing if a previous call to start() was successful but close() was not called in between the two calls.

Warning

Exceptions are propagated.

status()[source]

Calls the status method on the last processor in the chain.

If no method was found returns False instead.

hanyuu.streamer.audio.test_config(password=None)[source]
hanyuu.streamer.audio.test_dir(directory=u'/media/F/Music', files=None)[source]

encoder Module

class hanyuu.streamer.audio.encoder.Encoder(source, lame_settings)[source]

Bases: object

An Encoder class that handles the encoder subprocess underneath.

This expects various things from the source given.

The source should have the following characteristics:

read(): A function that accepts a single integer argument that is
the amount of bytes to return. It should return PCM audio data in a supported format.
sample_rate: The sample rate of the audio data. This should be
the full integer of the sample rate (44100 instead of 44.1)
bits_per_sample: The bits per sample of the audio data. This
can be 16, 24 and 32 bits.
close()[source]

This calls the EncoderInstance.close() method on the EncoderInstance.

encoding_settings = None

The settings for encoding to pass to lame as a list.

options = [(u'lame_settings', [u'--cbr', u'-b', u'192', u'--resample', u'44.1'])]
report_close()[source]

This method is called by the EncoderInstance class when it gets closed or an error occurs in the instance. This should handle the case gracefully and even restart the instance if the close was unintentional by the user.

The method registers the EncoderInstance instance for garbage collection by the garbage module.

restart()[source]

This method rather then restart, destroys and then recreates the underlying EncoderInstance instance.

start()[source]

This clears our alive flag and starts a new EncoderInstance instance by calling start_instance().

start_instance()[source]

This method is responsible for creating and starting the EncoderInstance class instances.

This creates a new EncoderInstance instance and calls the EncoderInstance.start() method on it.

After the call to ‘start’ returns the new instance is assigned to instance.

class hanyuu.streamer.audio.encoder.EncoderInstance(encoder_manager)[source]

Bases: object

Class that represents a subprocessed encoder.

close()[source]
read(size=4096, timeout=10.0)[source]
run()[source]
start()[source]
switch_source(new_source)[source]
write(data)[source]
class hanyuu.streamer.audio.encoder.GarbageInstance(item=None)[source]

Bases: hanyuu.streamer.audio.garbage.Garbage

collect()[source]
hanyuu.streamer.audio.encoder.LAME_BIN = u'lame'

The path to the LAME binary. This can be just ‘lame’ on bash environments.

files Module

Module that handles file access and decoding to PCM.

It uses python-audiotools for the majority of the work done.

exception hanyuu.streamer.audio.files.AudioError[source]

Bases: exceptions.Exception

Exception raised when an error occurs in this module.

class hanyuu.streamer.audio.files.AudioFile(filename)[source]

Bases: object

A Simple wrapper around the audiotools library.

This opens the filename given wraps the file in a PCMConverter that turns it into PCM of format 44.1kHz, Stereo, 24-bit depth.

close()[source]

Registers self for garbage collection. This method does not close anything and only registers itself for colleciton.

progress(current, total)[source]

Dummy progress function

read(size=4096, timeout=0.0)[source]

Returns at most a string of size size.

The timeout argument is unused. But kept in for compatibility with other read methods in the audio module.

class hanyuu.streamer.audio.files.FileSource(source_function)[source]

Bases: object

change_source()[source]

Calls the source function and returns the result if not None.

close()[source]
initialize()[source]

Sets the initial source from the source function.

read(size=4096, timeout=10.0)[source]
skip()[source]
start()[source]

Starts the source

class hanyuu.streamer.audio.files.GarbageAudioFile(item=None)[source]

Bases: hanyuu.streamer.audio.garbage.Garbage

Garbage class of the AudioFile class

collect()[source]

Tries to close the AudioFile resources when called.

icecast Module

class hanyuu.streamer.audio.icecast.Icecast(source, config)[source]

Bases: object

close()[source]

Closes the libshout object and tries to join the thread if we are not calling this from our own thread.

connect()[source]

Connect the libshout object to the configured server.

connected()[source]

Returns True if the libshout object is currently connected to an icecast server.

connecting_timeout = 5.0

The time to wait when we lose connection by cause of external behaviour.

metadata(metadata)[source]
nonblocking(state)[source]
options = [('icecast_config', {})]

Options that __init__() should get passed from the pipeline manager when being created. (See hanyuu.streamer.audio.Manager for more information.)

read(size, timeout=None)[source]
reboot_libshout()[source]

Internal method

Tries to recreate the libshout object.

run()[source]
setup_libshout()[source]

Internal method

Creates a libshout object and puts the configuration to use.

start()[source]

Starts the thread that reads from source and feeds it to icecast.

switch_source(new_source)[source]

Tries to change the source without disconnect from icecast.

class hanyuu.streamer.audio.icecast.IcecastConfig(attributes=None)[source]

Bases: dict

Simple dict subclass that knows how to apply the keys to a libshout object.

setup(shout)[source]

Setup ‘shout’ configuration by setting attributes on the object.

‘shout’ is a pylibshout.Shout object.

exception hanyuu.streamer.audio.icecast.IcecastError[source]

Bases: exceptions.Exception

Project Versions

Table Of Contents

Previous topic

streamer Package

Next topic

garbage Package

This Page