org.mmbase.module.builders.vwms
Class EncodeHandler

java.lang.Object
  |
  +--org.mmbase.module.builders.vwms.EncodeHandler
All Implemented Interfaces:
java.lang.Runnable

public class EncodeHandler
extends java.lang.Object
implements java.lang.Runnable

When an audiopart has to be ripped or when ripped audio has to be encoded, an EncodeHandler is created to control this process. Each EncodeHandler has a task describing what it must do. The node field contains a reference to nodes (audiopart or rawaudio) used when controlling the services. After initializing the service, the EncodeHandler starts the service by putting it in a certain state, and then waits for it to finish. When the service finishes the EncodeHandler checks the result value stored in info field which is equal to the proces exitvalue. If this is equal to 0, the RawAudio representing the data created by service (eg. wav or realaudio) is set in a state ready for usage and the service will be reset. Otherwise the EncodeHandler quits and removes itself from list of running EncodeHandlers and leaves the service in current state. Also there are EncodeHandlers used to recover for when the mmbase is reset when service is still busy or just finished.

Version:
$Revision: 1.22 $ $Date: 2001/05/11 07:57:49 $
Author:
Rico Jansen?, Daniel?, David van Zeventer

Field Summary
 MMObjectNode node
           
static java.lang.String RAWAUDIO_URL_HOST1
           
 
Constructor Summary
EncodeHandler(EncodeCop parent, java.lang.String task, MMObjectNode node)
          Constructor initializes EncodeHandler task and related node.
 
Method Summary
 MMObjectNode addRawAudio(int id, int status, int format, int speed, int channels)
          Creates a RawAudio node for an audiopart.
 void doCDRip()
          Handles the audio file cdripping.
 void doG2Encode()
          Handles the Real G2 Encoding of an audiopart.
 void doRecoverBusyCDRip(int cdplayernumber)
          When mmbase has been reset during cd ripping we wait again for the cdplayer to finish.
 void doRecoverBusyG2Encoder(int g2encnumber)
          When mmbase has been reset during encoding we wait again for the encoder to finish.
 void doRecoverFinishedCDRip(int cdplayernumber)
          This is for the case when mmbase was reset just when an cdplayer finishes.
 void doRecoverFinishedG2Encoder(int g2encnumber)
          This is for the case when mmbase was reset just when an encoder finishes.
 void init()
           
 void run()
          Checks EncoderHandlers task variable to decide what to do.
 void start()
          Starts the admin Thread.
 void stop()
          Stops the admin Thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

node

public MMObjectNode node

RAWAUDIO_URL_HOST1

public static final java.lang.String RAWAUDIO_URL_HOST1
Constructor Detail

EncodeHandler

public EncodeHandler(EncodeCop parent,
                     java.lang.String task,
                     MMObjectNode node)
Constructor initializes EncodeHandler task and related node.
Parameters:
parent - EncodeCop reference.
task - name of the task.
node - is a reference to either a audioparts or rawaudio node (type is encoded audio eg. g2).
Method Detail

init

public void init()

start

public void start()
Starts the admin Thread.

stop

public void stop()
Stops the admin Thread.

run

public void run()
Checks EncoderHandlers task variable to decide what to do. Currently there are two type of tasks: service tasks and 'recover for service' tasks. The servicetasks are tasks for CDRipping 'cdrip' and Encoding 'g2encode'. The recovertasks perform recovery for when the mmbaseserver is being reset when service is busy or when service just finished.
Specified by:
run in interface java.lang.Runnable

doCDRip

public void doCDRip()
Handles the audio file cdripping. First we search the ripping cdplayer by checking which owner claimed it. This is the same as the owner of the audiopart for which this EncodeHandler is created. Ripping is signalled by changing cdplayers' state to 'record'. The ripped audio is represented by a rawaudio of type wav, which gets a 'done' state when ripping is done. When ripping is done and all went ok, we finish the ripped rawaudio and reset the cdplayer and create a rawaudio that represents the encoded audio, its creating will trigger the encode process. If something goes wrong during all this, we stop and remove the EncodeHandler from list.

doG2Encode

public void doG2Encode()
Handles the Real G2 Encoding of an audiopart. First we wait for a free g2encoder, and when we found one initialize the g2encoder and start it by setting the state to 'encode'. The rawaudio representing the encoded audio is set to a state indicating that its being encoded. We wait until encoding finishes and if everything went ok, we finish the rawaudio and reset the encoder and finally remote the encodehandler from list. If something goes wrong during all this, we stop and remove the EncodeHandler from list.

addRawAudio

public MMObjectNode addRawAudio(int id,
                                int status,
                                int format,
                                int speed,
                                int channels)
Creates a RawAudio node for an audiopart.
Parameters:
id - the idnumber = audiopartobjectnumber
status - current state
format - file format
speed - bitrate
channels - amount of audio channels
Returns:
RawAudio node

doRecoverBusyG2Encoder

public void doRecoverBusyG2Encoder(int g2encnumber)
When mmbase has been reset during encoding we wait again for the encoder to finish. After the encoder finishes, we check the process exitvalue and when all is ok, we finish the RawAudio representing the encoded audio (this will make audiopart available to usage). After that we reset the service and remove the EncodeHandler from list. If something went wrong during all this, the RawAudio and g2encoder service will be left in current state and we remove the EncodeHandler from list.
Parameters:
g2encnumber - object number of the g2encoder we're recovering for.

doRecoverBusyCDRip

public void doRecoverBusyCDRip(int cdplayernumber)
When mmbase has been reset during cd ripping we wait again for the cdplayer to finish. After the cdplayer finishes, we check the process exitvalue and when all is ok, we finish the RawAudio representing the ripped audio. After that we reset the service and we create a RawAudio representing the to be encoded audio. (Creation will eventually start encoder via EncodeCop that inturn start the EncodeHandler.) When the RawAudio is created we remove the EncodeHandler from list. If something went wrong during all this, the RawAudio and cdplayer service will be left in current state and we remove the EncodeHandler from list.
Parameters:
cdplayernumber - object number of the cdplayer we're recovering for.

doRecoverFinishedG2Encoder

public void doRecoverFinishedG2Encoder(int g2encnumber)
This is for the case when mmbase was reset just when an encoder finishes. After bootup the EncodeCop detects that there's an encoder that just finished, so recovery is needed. First we check the process exitvalue and when all is ok, we finish the RawAudio representing the encoded audio (this will make audiopart available to usage). After that we reset the service and remove the EncodeHandler from list. If something went wrong during all this, the RawAudio and g2encoder service will be left in current state and we remove the EncodeHandler from list.
Parameters:
g2encnumber - object number of the g2encoder we're recovering for.

doRecoverFinishedCDRip

public void doRecoverFinishedCDRip(int cdplayernumber)
This is for the case when mmbase was reset just when an cdplayer finishes. After bootup the EncodeCop detects that there's an cdplayer that just finished, so recovery is needed. First we check the process exitvalue and when all is ok, we finish the RawAudio representing the ripped audio. After that we reset the service and we create a RawAudio representing the to be encoded audio. (Creation will eventually start encoder via EncodeCop that inturn start the EncodeHandler.) When the RawAudio is created we remove the EncodeHandler from list. If something went wrong during all this, the RawAudio and cdplayer service will be left in current state and we remove the EncodeHandler from list.
Parameters:
cdplayernumber - object number of the cdplayer we're recovering for.


MMBase 2001