/* config.h.in. */
#ifndef CONFIG_H
#define CONFIG_H

#define BINDIR "$BINDIR"
#define LIBDIR "$LIBDIR"
#define SHAREDIR "$SHAREDIR"

/* configuration file locations */
#define USER_CONFIG_FILE    "$USER_CONFIG_FILE"
#define SYSTEM_CONFIG_FILE  "$SYSTEM_CONFIG_FILE"

/* Define indicating availability of lrint() */
#define HAVE_LRINT $HAVE_LRINT

/* Define indicatin availability of lrintf() */
#define HAVE_LRINTF $HAVE_LRINTF

// serialization
#define SERIALIZE_USE_EXPAT $SERIALIZE_USE_EXPAT

#define CACHEDIR "$CACHEDIR"

// discovery
#define ENABLE_DISCOVERY_CACHE               1

// watchdog
#define WATCHDOG_DEFAULT_CHECK_INTERVAL_USECS   (1000*1000*4)
#define WATCHDOG_DEFAULT_RUN_REALTIME           1
#define WATCHDOG_DEFAULT_PRIORITY               98

// threading
#define THREAD_MAX_RTPRIO                   98
#define THREAD_MIN_RTPRIO                   1

// time

// we should be using absolute clock_nanosleep
// but on my system it causes a problem on shutdown.
#define USE_ABSOLUTE_NANOSLEEP              1

// 1394 service constants 
#define IEEE1394SERVICE_USE_CYCLETIMER_DLL                         1
#define IEEE1394SERVICE_CYCLETIMER_DLL_UPDATE_INTERVAL_USEC   200000
#define IEEE1394SERVICE_CYCLETIMER_DLL_BANDWIDTH_HZ              0.5
#define IEEE1394SERVICE_MAX_FIREWIRE_PORTS                         4
#define IEEE1394SERVICE_MIN_SPLIT_TIMEOUT_USECS              1000000

#define IEEE1394SERVICE_CYCLETIMER_HELPER_RUN_REALTIME       1
#define IEEE1394SERVICE_CYCLETIMER_HELPER_PRIO               1

// config rom read wait interval
#define IEEE1394SERVICE_CONFIGROM_READ_WAIT_USECS         1000

// FCP defines
#define IEEE1394SERVICE_FCP_MAX_TRIES                        2
#define IEEE1394SERVICE_FCP_SLEEP_BETWEEN_FAILURES_USECS  1000
#define IEEE1394SERVICE_FCP_POLL_TIMEOUT_MSEC              200
#define IEEE1394SERVICE_FCP_RESPONSE_TIMEOUT_USEC       200000

// The current version of libiec61883 doesn't seem to calculate
// the bandwidth correctly. Defining this to non-zero skips
// bandwidth allocation when doing CMP connections.
#define IEEE1394SERVICE_SKIP_IEC61883_BANDWIDTH_ALLOCATION   1

#define MINIMUM_INTERRUPTS_PER_PERIOD                       2U

// These are the result of a lot of trial and error
// due to weirdness in the kernel layer
#define MAX_XMIT_PACKET_SIZE                         (2048-16)
#define MIN_XMIT_PACKET_SIZE                                72
#define MAX_XMIT_NB_BUFFERS                                128
#define MAX_RECV_NB_BUFFERS                                128
#define MIN_RECV_PACKET_SIZE                                72

// the default ISO receive mode. 
// 0 = auto, 1 = packet-per-buffer, 2 = bufferfill. 
// 'auto' will automatically choose the mode that is expected 
// to perform best for the given situation. For large periods 
// this is 'bufferfill' mode, for small periods this is 
// 'packet-per-buffer' mode. The 'BUFFERFILL_MODE_THRESHOLD' 
// defines what a 'large period' is.
#define DEFAULT_ISO_RECEIVE_MODE                             0

// the number of packets required to fill one period from which
// the bufferfill mode is to be used
#define BUFFERFILL_MODE_THRESHOLD                           64


#define ISOHANDLER_FLUSH_BEFORE_ITERATE                      0

#define ISOHANDLER_DEATH_DETECT_TIMEOUT_USECS        1000000LL

#define ISOHANDLER_CHECK_CTR_RECONSTRUCTION                  1

#define ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT         16
#define ISOHANDLERMANAGER_MAX_STREAMS_PER_ISOTHREAD         16

// The best setup is if the receive handlers have lower priority
// than the client thread since that ensures that as soon as we
// received sufficient frames, the client thread runs.
// The transmit thread should have higher priority to ensure that
// all available data is flushed to the ISO kernel buffers as
// soon as possible
// At this moment, the jack backend uses base+5 to init ffado
// prio
#define ISOHANDLERMANAGER_ISO_PRIO_INCREASE                  0
#define ISOHANDLERMANAGER_ISO_PRIO_INCREASE_RECV            -1
#define ISOHANDLERMANAGER_ISO_PRIO_INCREASE_XMIT             1

// the timeout for ISO activity on any thread
// NOTE: don't make this 0
#define ISOHANDLERMANAGER_ISO_TASK_WAIT_TIMEOUT_USECS        1000000LL

// allows to add some processing margin. This shifts the time
// at which the buffer is transfer()'ed, making things somewhat
// more robust. It should be noted though that shifting the transfer
// time to a later time instant also causes the xmit buffer fill to be
// lower on average. This can be counteracted by increasing the
// STREAMPROCESSORMANAGER_XMIT_PREBUFFER_FRAMES option
#define STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS           (3072*0)

// the number of frames that we prebuffer in the 1394 ISO layer
// this adds directly to the roundtrip latency
#define STREAMPROCESSORMANAGER_XMIT_PREBUFFER_FRAMES         100

// causes the waitForPeriod() call to wait until sufficient
// data is present in the buffer such that a transfer() will
// succeed. Normally we wait for the period of time that theoretically
// would mean that his is true. However sometimes the kernel hasn't
// flushed everything to userspace (or the card hasn't IRQ'd).
// the side-effect of this is some jitter in the return timing
// whenever this occurs.
#define STREAMPROCESSORMANAGER_ALLOW_DELAYED_PERIOD_SIGNAL         1

// startup control
#define STREAMPROCESSORMANAGER_CYCLES_FOR_DRYRUN            40000
#define STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP           200
#define STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_XMIT     20
#define STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_RECV     0
#define STREAMPROCESSORMANAGER_SYNCSTART_TRIES              10
#define STREAMPROCESSORMANAGER_SYNC_WAIT_TIME_MSEC          200
#define STREAMPROCESSORMANAGER_NB_ALIGN_TRIES               40
#define STREAMPROCESSORMANAGER_ALIGN_AVERAGE_TIME_MSEC      400

#define STREAMPROCESSORMANAGER_DYNAMIC_SYNC_DELAY           0

// the default bandwidth of the stream processor timestamp DLL when synchronizing (should be fast)
#define STREAMPROCESSOR_DLL_FAST_BW_HZ                      5.0
// the default bandwidth of the stream processor timestamp DLL when streaming
#define STREAMPROCESSOR_DLL_BW_HZ                           0.1

// -- AMDTP options -- //

// in ticks
// as per AMDTP2.1: 354.17us + 125us, but FFADO measures from the
// packet transmission time, so subtract 125 us:
// 354.17us @ 24.576ticks/usec = 8704 ticks
#define AMDTP_TRANSMIT_TRANSFER_DELAY   (8704U)

// the absolute minimum number of cycles we want to transmit
// a packet ahead of the presentation time. The nominal time
// the packet is transmitted ahead of the presentation time is
// given by AMDTP_TRANSMIT_TRANSFER_DELAY (in ticks), but in case we
// are too late for that, this constant defines how late we can
// be.
#define AMDTP_MIN_CYCLES_BEFORE_PRESENTATION                1

// the absolute maximum number of cycles we want to transmit
// a packet ahead of the ideal transmit time. The nominal time
// the packet is transmitted ahead of the presentation time is
// given by AMDTP_TRANSMIT_TRANSFER_DELAY (in ticks), but we can send
// packets early if we want to. (not completely according to spec)
// (for spec compliance you need to specify a value of 0)
#define AMDTP_MAX_CYCLES_TO_TRANSMIT_EARLY                  1

// ensure that the AMDTP SP clips all float values to [-1.0..1.0]
#define AMDTP_CLIP_FLOATS                                   1

// Allow that devices request that the AMDTP transmit SP adds
// payload to the NO-DATA packets.
#define AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT                  1

// Default setting for the payload setting if
// AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT is enabled. Devices can
// explicity override this
#define AMDTP_SEND_PAYLOAD_IN_NODATA_XMIT_BY_DEFAULT     true

// -- MOTU options -- //

// the transfer delay is substracted from the ideal presentation
// time to obtain a corrected presentation time. This values is
// then used to stamp the packet and determine the transmission
// time instant.
#define MOTU_TRANSMIT_TRANSFER_DELAY    (0U)

// the absolute minimum number of cycles we want to transmit
// a packet ahead of the presentation time. The nominal time
// the packet is transmitted ahead of the presentation time is
// given by MOTU_TRANSMIT_TRANSFER_DELAY (in ticks), but in case we
// are too late for that, this constant defines how late we can
// be.
#define MOTU_MIN_CYCLES_BEFORE_PRESENTATION                0

// the absolute maximum number of cycles we want to transmit
// a packet ahead of the ideal transmit time. The nominal time
// the packet is transmitted ahead of the presentation time is
// given by MOTU_TRANSMIT_TRANSFER_DELAY (in ticks), but we can send
// packets early if we want to.
#define MOTU_MAX_CYCLES_TO_TRANSMIT_EARLY                  2

// ensure that the MOTU tx SP clips all float values to [-1.0..1.0]
#define MOTU_CLIP_FLOATS                                   1

// -- RME options -- //

// the transfer delay is substracted from the ideal presentation
// time to obtain a corrected presentation time. This value is
// then used to stamp the packet and determine the transmission
// time instant.  This is in ticks, and has been determined 
// experimentally to provide the most stability.
#define RME_TRANSMIT_TRANSFER_DELAY    (3U*TICKS_PER_CYCLE)

// the absolute minimum number of cycles we want to transmit
// a packet ahead of the presentation time. The nominal time
// the packet is transmitted ahead of the presentation time is
// given by RME_TRANSMIT_TRANSFER_DELAY (in ticks), but in case we
// are too late for that, this constant defines how late we can
// be.
#define RME_MIN_CYCLES_BEFORE_PRESENTATION                1

// the absolute maximum number of cycles we want to transmit
// a packet ahead of the ideal transmit time. The nominal time
// the packet is transmitted ahead of the presentation time is
// given by RME_TRANSMIT_TRANSFER_DELAY (in ticks), but we can send
// packets early if we want to.
#define RME_MAX_CYCLES_TO_TRANSMIT_EARLY                  5

// The transfer delay assumed for incoming packets from an RME. 
// Normally this would be the same as the transmit transfer delay.
// This value is in ticks.
#define RME_RECEIVE_TRANSFER_DELAY     RME_TRANSMIT_TRANSFER_DELAY

// ensure that the RME tx SP clips all float values to [-1.0..1.0]
#define RME_CLIP_FLOATS                                   1

// -- Digidesign options -- //
//
// Currently these are just verbatim copies of the values which
// seem to work for MOTU devices.  Some tweaks may well be 
// necessary once testing begins with real devices.

// the transfer delay is substracted from the ideal presentation
// time to obtain a corrected presentation time. This values is
// then used to stamp the packet and determine the transmission
// time instant.
#define DIGIDESIGN_TRANSMIT_TRANSFER_DELAY    (0U)

// the absolute minimum number of cycles we want to transmit
// a packet ahead of the presentation time. The nominal time
// the packet is transmitted ahead of the presentation time is
// given by DIGIDESIGN_TRANSMIT_TRANSFER_DELAY (in ticks), but 
// in case we are too late for that, this constant defines how 
// late we can be.
#define DIGIDESIGN_MIN_CYCLES_BEFORE_PRESENTATION                0

// the absolute maximum number of cycles we want to transmit
// a packet ahead of the ideal transmit time. The nominal time
// the packet is transmitted ahead of the presentation time is
// given by DIGIDESIGN_TRANSMIT_TRANSFER_DELAY (in ticks), but 
// we can send packets early if we want to.
#define DIGIDESIGN_MAX_CYCLES_TO_TRANSMIT_EARLY                  2

// ensure that the DIGIDESIGN tx SP clips all float values to [-1.0..1.0]
#define DIGIDESIGN_CLIP_FLOATS                                   1

/// The unavoidable device specific hacks

// Use the information in the music plug instead of that in the
// cluster info block for the stream configuration. Should not
// be necessary
#define AVC_STREAMCONFIG_USE_MUSICPLUG                     0

#endif // CONFIG_H
