HAVi

Common issues for distributed systems


HAVi

HAVi (Home Audio Visual Interoperability Architecture) is concerned with the following home devices

It is extensible to other Consumer Electronics (CE) devices


Firewire


HAVi devices


Full AV devices (FAV)


Intermediate AV devices (IAV)


Base AV device (BAV)


HAVi control


Components of HAVi devices


HAVi transport mechanisms


Device and Function control modules


HAVi device and component indentifiers


HAVi registry


HAVi object booting


HAVi service advertisement


HAVi service discovery


HAVi clients


DCMCLient methods

Methods applicable to an entire device


FCMClient methods

Methods applicable to functional modules in a device


VCRClient methods


TunerClient methods


HAVi service invocation


HAVi messaging


HAVi streams


HAVi user interface


HAVi remote control


Naive PVR


PVR communications


PVR class diagram


Naive PVR code



import org.havi.constants.*;
import org.havi.types.*;
import org.havi.system.*;
import org.havi.fcm.constants.*;
import org.havi.fcm.types.*;
import org.havi.fcm.avdisc.*;
import org.havi.fcm.vcr.*;

public class NaivePVR {
    static final int TIMEOUT    = 10000;   // in milliseconds

    SoftwareElement             se = new SoftwareElement();
    RegistryLocalClient         registryClient; =  = new RegistryLocalClient(se);

    SEID                        vcrSeid;
    SEID                        avDiscSeid;

    StreamManagerLocalClient    streamManagerClient;
    FcmClient                   vcrFcmClient;
    FcmClient                   avDiscFcmClient;

    VcrClient                   vcrClient;
    AvDiscClient                avDiscClient;

    Connection                  recordingConnection;

    FcmPlug                     avDiscFcmInputPlug;
    FcmPlug                     avDiscFcmOutputPlug;


    public NaivePVR() {

	vcrSeid = findSeid(ConstSoftwareElementType.VCR_FCM);
	acDisvSewid = findSeid(ConstSoftwareElementType.AVDISC_FCM);

        // create necessary clients
        try {

            streamManagerClient = new StreamManagerLocalClient(se);

            vcrFcmClient        = new FcmClient (se, vcrSeid);
            avDiscFcmClient     = new FcmClient (se, avDiscSeid);
 
            vcrClient       = new VcrClient (se, vcrSeid);
            avDiscClient    = new AvDiscClient (se, avDiscSeid);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    public SEID findSeid(int seType) {
	try {
	    SEID[] seids = findAllSEs(seType);
	    if (seids.length >= 1)
		return seids[0];
	    else
		return 0;
	} catch(Exception e) {
	    // ??
	}
	return 0;
    }

    /***********************************************************************
     * Locates all SEs of a specified type on the home network.
     */
    public SEID[] findAllSEs(int seType) throws HaviException,
                                                HaviInvalidValueException {
        SimpleQuery sq;
        HaviByteArrayOutputStream hbaos = new HaviByteArrayOutputStream();

        sq = new SimpleQuery();
        sq.setAttributeName(ConstAttributeName.ATT_SE_TYPE);

        hbaos.reset();
        hbaos.writeInt(seType);

        sq.setCompareValue(hbaos);
        sq.setCompareOperation(ConstComparisonOperator.EQU);

        // This will hold the return value from the registry after
        // getElementSync is called
        SEIDSeqHolder seidSequence = new SEIDSeqHolder();

        registryClient.getElementSync(TIMEOUT, sq, seidSequence);
        SEID[] seidList = seidSequence.getValue();

        return seidList;
    } // findAllSEs

 
    /**************************************************************************/
    /* This should be the first method to be called after creating the PVR
     * object.  At this point all the necessary stream connections will be
     * created and after successful connections are established the 'live
     * program will be under 'PVR' mode.
     *
     * A 'live stream' connection will first be established between the VCR
     * and the AvDisc.  The AvDisc will be recording the content from the VCR.
     */

    public void start() throws Exception {

        // set up a connection to record to the intermediate storage device from the input source
        recordingConnection = makeConnection (vcrFcmClient,
                                               avDiscFcmClient);
        if (recordingConnection == null) {
            throw new Exception("Unable to establish connection between Vcr and AvDisc ! :-(");
        }

        // get the FcmPlug information from the connection
        avDiscFcmInputPlug  = recordingConnection.getSink();
        vcrFcmOutputPlug    = recordingConnection.getSource();

        // start recording on avdisc
        avDiscClient.recordSync(TIMEOUT,
                                ConstAvDiscRecordingMode.NORMAL,
                                avDiscFcmInputPlug.getPlugNum(),
                                (short)0,       // listNumber
                                (short)0,       // indexNumber
                                null,       // recordingTime
                                (long)0);   // recordingSize

        // start playing the input source (vcr)
        vcrClient.playSync(TIMEOUT);
    }


    /***********************************************************************/

    public Connection makeConnection(FcmClient srcFcm,
                                     FcmClient destFcm) {
        Connection connection = null;
        try {
            ConnectionHint          connectionHint;
            ConnectionIdHolder      connectionHolder;

            FcmPlug srcFcmOutputPlug = getFcmPlug(srcFcm,
                                                  ConstDirection.OUT);

            FcmPlug destFcmInputPlug = getFcmPlug(destFcm,
                                                  ConstDirection.IN);

            connectionHint = new ConnectionHint (false, // anyTransport,
                                                 true, // anyStreamType,
                                                 true, // anyTransmissionFormat,
                                                 true, // anyChannel,
                                                 ConstTransportType.IEC61883,    // specific transport type ,
                                                 null, // specific StreamType stype,
                                                 null, // TransmissionFormat tformat,
                                                 null);  // Channel channel

            ConnectionIdHolder ch = new ConnectionIdHolder();

            streamManagerClient.flowToSync(TIMEOUT, false, srcFcmOutputPlug, 
					    destFcmInputPlug, connectionHint, ch);

            ConnectionId connectionId = ch.getValue();
            connection = new Connection();
            streamManagerClient.getConnectionSync(TIMEOUT,connectionId, connection);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return(connection);
    }

    /***********************************************************************/
    public FcmPlug getFcmPlug(FcmClient fcmClient, int direction)
    {
        FcmPlug fcmPlug = null;
        try {
            // first get the Huid of the fcm
            HUIDHolder fcmHuidHolder = new HUIDHolder();
            fcmClient.getHuidSync (TIMEOUT, fcmHuidHolder);
            HUID fcmHuid = fcmHuidHolder.getValue();

            // get the TargetId from the HUID
            TargetId targetId = fcmHuid.getTargetId();

            // take the first plug, we should be able to
            // use this since we have the FCM reserved
            fcmPlug = new FcmPlug (targetId, direction, (short)0);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return(fcmPlug);
    }
}

 

Jan Newmarch <jan@newmarch.name>
Last modified: Tue Apr 15 06:32:53 EST 2003
Copyright © Jan Newmarch, Monash University, 2007
Creative Commons License This work is licensed under a Creative Commons License
The moral right of Jan Newmarch to be identified as the author of this page has been asserted.