/*
* Copyright (C) 2005-2008 by Pieter Palmers
*
* This file is part of FFADO
* FFADO = Free Firewire (pro-)audio drivers for linux
*
* FFADO is based upon FreeBoB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#ifndef DICEDEVICE_H
#define DICEDEVICE_H
#include "ffadodevice.h"
#include "debugmodule/debugmodule.h"
#include "libavc/avc_definitions.h"
#include "libstreaming/amdtp/AmdtpReceiveStreamProcessor.h"
#include "libstreaming/amdtp/AmdtpTransmitStreamProcessor.h"
#include "libstreaming/amdtp/AmdtpPort.h"
#include "libieee1394/ieee1394service.h"
#include "libcontrol/Element.h"
#include "libcontrol/MatrixMixer.h"
#include "libcontrol/CrossbarRouter.h"
#include "dice_eap.h"
#include
#include
class ConfigRom;
class Ieee1394Service;
namespace Util {
class Configuration;
}
namespace Dice {
class Notifier;
class Device : public FFADODevice {
// private:
typedef std::vector< std::string > diceNameVector;
typedef std::vector< std::string >::iterator diceNameVectorIterator;
public:
class Notifier;
class EAP;
/**
* this class represents the EAP interface
* available on some devices
*/
class EAP : public Control::Container
{
public:
enum eWaitReturn {
eWR_Error,
eWR_Timeout,
eWR_Busy,
eWR_Done,
};
enum eRegBase {
eRT_Base,
eRT_Capability,
eRT_Command,
eRT_Mixer,
eRT_Peak,
eRT_NewRouting,
eRT_NewStreamCfg,
eRT_CurrentCfg,
eRT_Standalone,
eRT_Application,
eRT_None,
};
enum eRouteSource {
eRS_AES = 0,
eRS_ADAT = 1,
eRS_Mixer = 2,
eRS_InS0 = 4,
eRS_InS1 = 5,
eRS_ARM = 10,
eRS_ARX0 = 11,
eRS_ARX1 = 12,
eRS_Muted = 15,
eRS_Invalid = 16,
};
enum eRouteDestination {
eRD_AES = 0,
eRD_ADAT = 1,
eRD_Mixer0 = 2,
eRD_Mixer1 = 3,
eRD_InS0 = 4,
eRD_InS1 = 5,
eRD_ARM = 10,
eRD_ATX0 = 11,
eRD_ATX1 = 12,
eRD_Muted = 15,
eRD_Invalid = 16,
};
public:
// ----------
class RouterConfig {
public:
struct Route
{
enum eRouteSource src;
int srcChannel;
enum eRouteDestination dst;
int dstChannel;
int peak;
};
typedef std::vector RouteVector;
typedef std::vector::iterator RouteVectorIterator;
RouterConfig(EAP &);
RouterConfig(EAP &, enum eRegBase, unsigned int offset);
virtual ~RouterConfig();
virtual bool read() {return read(m_base, m_offset);};
virtual bool write() {return write(m_base, m_offset);};
virtual bool read(enum eRegBase b, unsigned offset);
virtual bool write(enum eRegBase b, unsigned offset);
virtual void show();
bool insertRoute(struct Route r)
{return insertRoute(r, m_routes.size());};
bool insertRoute(struct Route r, unsigned int index);
bool replaceRoute(unsigned int old_index, struct Route new_route);
bool replaceRoute(struct Route old_route, struct Route new_route);
bool removeRoute(struct Route r);
bool removeRoute(unsigned int index);
int getRouteIndex(struct Route r);
struct Route getRoute(unsigned int index);
unsigned int getNbRoutes() {return m_routes.size();};
struct Route getRouteForDestination(enum eRouteDestination dst, int channel);
RouteVector getRoutesForSource(enum eRouteSource src, int channel);
struct Route decodeRoute(uint32_t val);
uint32_t encodeRoute(struct Route r);
public:
static enum eRouteDestination intToRouteDestination(int);
static enum eRouteSource intToRouteSource(int);
protected:
EAP &m_eap;
enum eRegBase m_base;
unsigned int m_offset;
RouteVector m_routes;
protected:
DECLARE_DEBUG_MODULE_REFERENCE;
};
// ----------
// the peak space is a special version of a router config
class PeakSpace : public RouterConfig {
public:
PeakSpace(EAP &p) : RouterConfig(p, eRT_Peak, 0) {};
virtual ~PeakSpace() {};
virtual bool read() {return read(m_base, m_offset);};
virtual bool write() {return write(m_base, m_offset);};
virtual bool read(enum eRegBase b, unsigned offset);
virtual bool write(enum eRegBase b, unsigned offset);
virtual void show();
};
// ----------
class StreamConfig {
public:
struct ConfigBlock { // FIXME: somewhere in the DICE avdevice this is present too
uint32_t nb_audio;
uint32_t nb_midi;
uint32_t names[DICE_EAP_CHANNEL_CONFIG_NAMESTR_LEN_QUADS];
uint32_t ac3_map;
};
void showConfigBlock(struct ConfigBlock &);
diceNameVector getNamesForBlock(struct ConfigBlock &b);
public:
StreamConfig(EAP &, enum eRegBase, unsigned int offset);
~StreamConfig();
bool read() {return read(m_base, m_offset);};
bool write() {return write(m_base, m_offset);};
bool read(enum eRegBase b, unsigned offset);
bool write(enum eRegBase b, unsigned offset);
void show();
private:
EAP &m_eap;
enum eRegBase m_base;
unsigned int m_offset;
uint32_t m_nb_tx;
uint32_t m_nb_rx;
struct ConfigBlock *m_tx_configs;
struct ConfigBlock *m_rx_configs;
DECLARE_DEBUG_MODULE_REFERENCE;
};
public: // mixer control subclass
class Mixer : public Control::MatrixMixer {
public:
Mixer(EAP &);
~Mixer();
bool init();
void show();
void updateNameCache();
/**
* load the coefficients from the device into the local cache
* @return
*/
bool loadCoefficients();
/**
* Stores the coefficients from the cache to the device
* @return
*/
bool storeCoefficients();
virtual std::string getRowName( const int );
virtual std::string getColName( const int );
virtual int canWrite( const int, const int );
virtual double setValue( const int, const int, const double );
virtual double getValue( const int, const int );
virtual int getRowCount( );
virtual int getColCount( );
// full map updates are unsupported
virtual bool getCoefficientMap(int &);
virtual bool storeCoefficientMap(int &);
private:
EAP & m_eap;
fb_quadlet_t *m_coeff;
std::map m_input_route_map;
std::map m_output_route_map;
DECLARE_DEBUG_MODULE_REFERENCE;
};
// ----------
class Router : public Control::CrossbarRouter {
private:
struct Source {
std::string name;
enum eRouteSource src;
int srcChannel;
};
typedef std::vector