<commit_before>//
// Copyright (C) 2005-2007 SIPez LLC.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// Copyright (C) 2004-2007 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////


// SYSTEM INCLUDES

#include <stdio.h> 
#include <assert.h> 
#include <string.h>
#ifdef _VXWORKS /* [ */
#include <unistd.h>

#include <msgQLib.h>
#include <taskLib.h>
#include <vmLib.h>
#include <intLib.h>
#include <tickLib.h>
#endif /* _VXWORKS ] */

// APPLICATION INCLUDES
#ifdef _VXWORKS /* [ */
#if CPU == ARMSA110 || (CPU == ARMARCH4) || (CPU == STRONGARM) /* [ [ */
#include "mp/sa1100.h"
#elif (CPU == XSCALE) /* ] [ */
#include "mp/pxa255.h"
#else /* ] [ */
#error Unexpected CPU value
#endif /* ] ] */
#endif /* _VXWORKS ] */

#include "os/OsDefs.h" // for min macro
#include "os/OsMsgQ.h"
#include "os/OsConfigDb.h"
#include "mp/MpTypes.h"
#include "mp/MpCodec.h"
#include "mp/dmaTask.h"
#include "mp/MpBuf.h"
#include "mp/MpAudioBuf.h"
#include "mp/MpRtpBuf.h"
#include "mp/MpUdpBuf.h"
#include "mp/MpBufferMsg.h"
#include "mp/MpMisc.h"
#include "mp/NetInTask.h"
#include "mp/MprFromMic.h"
#include "mp/MprToSpkr.h"
#include "mp/MpMediaTask.h"
#include "mp/MpCodecFactory.h"

// EXTERNAL FUNCTIONS

// EXTERNAL VARIABLES

// CONSTANTS

#define MIC_BUFFER_Q_LEN 10
#define SPK_BUFFER_Q_LEN 14
#define ECHO_BUFFER_Q_LEN MIC_BUFFER_Q_LEN+SPK_BUFFER_Q_LEN

#ifdef _VXWORKS /* [ */
#define LOG_MSGQ_MAX_MSGS 8000
#define LOG_MSGQ_ITEM_LEN 60
#define ABSOLUTE_MAX_LOG_MSG_LEN 2048
#endif /* _VXWORKS ] */

#define RTP_BUFS 250
#define RTCP_BUFS 16
#define UDP_BUFS 10

// STATIC VARIABLE INITIALIZATIONS

    struct __MpGlobals MpMisc;

#ifdef _VXWORKS /* [ */
/************************************************************************/

static int logTaskPrio = 250;
int setLogTaskPrio(int p) {
   int save = logTaskPrio;
   logTaskPrio = 0xff & p;
   return save;
}

static int logging = 1;

static int printingLog = 0;
static int numDiscarded = 0;

int drain_log(int level /* how many to leave */)
{
        char msg[1];
        int l, n;

        if (level < 0) level = 50;
        n = msgQNumMsgs(MpMisc.LogQ);
        while(level < msgQNumMsgs(MpMisc.LogQ)) {
            l = msgQReceive(MpMisc.LogQ, msg, 1, VX_NO_WAIT);
            numDiscarded++;
        }
        return n;
}

int StartLogging()
{
        int i;
        i = logging;
        logging = 1;
        return i;
}

int StopLogging(int opt)
{
        int i;

        logging = 0;
        i = msgQNumMsgs(MpMisc.LogQ);
        if (opt) drain_log(50);
        return i;
}

int Zprintf0(int force, char *buf)
{
        int l;
        int n;
        int ret;
        int msgret;
        char *str;
        char junk;

        str = buf;
        l = sipx_min(ABSOLUTE_MAX_LOG_MSG_LEN, strlen(buf));
        ret = l;
        if (0 == MpMisc.LogQ) {
            ret = force ? fwrite(str, 1, ret, stderr) : 0;
            return ret;
        }
        if (force || logging) {
            if ((ret > MpMisc.logMsgSize) && !intContext()) {
                taskLock();
            }
            while (l > 0) {
                n = sipx_min(l, MpMisc.logMsgSize);
                msgret = msgQSend(MpMisc.LogQ, buf, n,
                                       VX_NO_WAIT, MSG_PRI_NORMAL);
                if (ERROR == msgret) {
                    // int r2 =
                    msgQReceive(MpMisc.LogQ, &junk, 1, VX_NO_WAIT);
                    // osPrintf("discard message; r1=%d, r2=%d, q=0x%X: '%s'\n",
                        // msgret, r2, MpMisc.LogQ, buf);
                    numDiscarded++;
                    msgret = msgQSend(MpMisc.LogQ, buf, n,
                                       VX_NO_WAIT, MSG_PRI_NORMAL);
                }
                if ((ERROR == msgret) && force) {
                    fwrite(str, 1, ret, stderr);
                    l = 0;
                } else {
                    l -= n;
                    buf += n;
                }
            }
            if ((ret > MpMisc.logMsgSize) && !intContext()) {
                taskUnlock();
            }
        } else {
            ret = 0;
        }
        return ret;
}

int Zprintfx(int force, char *fmt, int a, int b, int c, int d, int e, int f)
{
        int l, ret;
        char buf[256];

        if (force || logging) {
            sprintf(buf, fmt, a, b, c, d, e, f);
            l = Zprintf0(force, buf);
        } else {
            l = 0;
        }
        return l;
}

int NoPrintLog()
{
    int save = printingLog;
    if (printingLog) {
        numDiscarded = 0;
    }
    osPrintf("\n");
    printingLog = 0;
    return save;
}
int PrintLog(int num)
{
    int save = printingLog;
    if (!printingLog) {
        if (num > 0) drain_log(num);
        fprintf(stderr, "%d messages discarded\n", numDiscarded);
        numDiscarded = 0;
    }
    printingLog = 1;
    return save;
}

extern "C" int NPL(){return NoPrintLog();}
extern "C" int PL(int n){return PrintLog(n);}

static int printTask(int t1, int t2, int t3, int t4, int t5,
                int t6, int t7, int t8, int t9, int t10)
{
        char msg[LOG_MSGQ_ITEM_LEN+1];
        int l;
        int lastTick;
        int thisTick;
        int Hz;
        int qHz;

        Hz = sysClkRateGet();
        qHz = Hz / 4;
#define LOG_ANNOUNCE_MINUTES 5

        lastTick = (int) tickGet() - (LOG_ANNOUNCE_MINUTES * 61 * Hz);

        while (1) {
            while (!printingLog) taskDelay(qHz);
            l = msgQReceive(MpMisc.LogQ, msg, LOG_MSGQ_ITEM_LEN, VX_WAIT_FOREVER);
            thisTick = (int) tickGet();
            if ((LOG_ANNOUNCE_MINUTES * 60 * Hz) < (thisTick - lastTick)) {
                lastTick = thisTick;
                fprintf(stderr, "MsgLogger: %d.%03d seconds since boot\n",
                    thisTick/Hz, ((thisTick % Hz) * 1000) / Hz);
            }
            if (l > 0) {
                msg[l] = 0;
                fwrite(msg, 1, l, stderr);
            } else {
                osPrintf("\n\nLogger: quitting!\n\n");
                return 0;
            }
        }
}

MSG_Q_ID startLogging(int nmsgs, int maxlen)
{
        MpMisc.LogQ = msgQCreate(nmsgs, maxlen, MSG_Q_FIFO);
        if (NULL == MpMisc.LogQ) {
                osPrintf("cannot create LogQ!  Quitting\n");
        } else {
            Zprintf("logQ is 0x%X\n", (int) MpMisc.LogQ, 0,0,0,0,0);
            taskSpawn("Logger", logTaskPrio, 0, 8192, (FUNCPTR) printTask,
                           0, 0, 0,0,0,0,0,0,0,0);
        }
        return MpMisc.LogQ;
}

#ifdef DEBUG /* [ */
int jamLog(char *fmt, int count, int a, int b, int c, int d, int e)
{
    int i;

    for (i=0; i<count; i++) {
        Zprintfx(1, fmt, i, a, b, c, d, e);
    }
    return msgQNumMsgs(MpMisc.LogQ);
}
#endif /* DEBUG ] */

OsStatus startLogTask()
{
#ifdef _VXWORKS /* [ */
        MpMisc.logMsgLimit = LOG_MSGQ_MAX_MSGS;
        MpMisc.logMsgSize = LOG_MSGQ_ITEM_LEN;
        if (NULL == startLogging(MpMisc.logMsgLimit, MpMisc.logMsgSize)) {
            return OS_UNSPECIFIED;
        }
#endif /* _VXWORKS ] */
        return OS_SUCCESS;
}

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

/* Work around for GDB crash... */
static int dontStepInThis()
{
        int ps;

        ps = vmPageSizeGet();
        return ps;
}

static int goGetThePageSize()
{
        return dontStepInThis(); /*!!!*/
}
#endif /* _VXWORKS ] */

/************************************************************************/
extern "C" {
extern int showMpMisc(int justAddress);
extern int setMaxMic(int v);
extern int setMaxSpkr(int v);
extern int mpSetLatency(int maxMic, int maxSpkr, int minRtp);
#ifdef _VXWORKS /* [ */
extern int LoopBack(int on);
extern int LBon();
extern int LBoff();
extern int Spkr1On();
extern int Spkr1Off();
extern int Spkr2On();
extern int Spkr2Off();
#endif /* _VXWORKS ] */
}
/************************************************************************/

#ifdef _VXWORKS /* [ */
#if CPU == ARMSA110 || (CPU == ARMARCH4) || (CPU == STRONGARM) /* [ */

int LoopBack(int on) {
   MpBufferMsg*    pMsg;
   int save = MpMisc.doLoopBack;

   MpMisc.doLoopBack = on;
   while (0 < MpMisc.pLoopBackQ->numMsgs()) {
      if (OS_SUCCESS == MpMisc.pLoopBackQ->receive((OsMsg*&) pMsg,
                                                    OsTime::NO_WAIT_TIME)) {
         pMsg->releaseMsg();
      }
   }
   return save;
}
int LBon()  {return LoopBack(1);}
int LBoff() {return LoopBack(0);}

static int* gpsr = (int*) SA1100_GPSR;
static int* gpcr = (int*) SA1100_GPCR;
int Spkr1On()  {*gpcr = (1<<25); return 0;}
int Spkr1Off() {*gpsr = (1<<25); return 0;}
int Spkr2On()  {*gpcr = (1<<26); return 0;}
int Spkr2Off() {*gpsr = (1<<26); return 0;}

#endif /* StrongARM ] */
#endif /* _VXWORKS ] */

int showMpMisc(int justAddress)
{
   Zprintf("&MpMisc = 0x%X\n", (int) &MpMisc, 0,0,0,0,0);
   if (!justAddress) {
      Zprintf(" MicQ=0x%X, SpkQ=0x%X, EchoQ=0x%X, silence=0x%X\n"
         (int) MpMisc.pMicQ, (int) MpMisc.pSpkQ, (int) MpMisc.pEchoQ,
         (int) MpMisc.mpFgSilence, 0, 0, 0);
      Zprintf(" \n frameSamples=%d, frameBytes=%d, sampleBytes=%d,",
         MpMisc.frameSamples, MpMisc.frameBytes, MpMisc.sampleBytes, 0,0,0);
      Zprintf(" rtpMaxBytes=%d\n RawAudioPool=0x%X, RtpPool=0x%X, RtcpPool=0x%X\n",
         MpMisc.rtpMaxBytes, (int) MpMisc.RawAudioPool, (int) MpMisc.RtpPool,
         (int) MpMisc.RtcpPool, 0,0);
#ifdef _VXWORKS /* [ */
      Zprintf(" mem_page_size=%d, mem_page_mask=0x%08X\n"
         "LogQ=0x%X, logMsgLimit=%d, logMsgSize=%d\n",
         MpMisc.mem_page_size, MpMisc.mem_page_mask,
         (int) MpMisc.LogQ, MpMisc.logMsgLimit, MpMisc.logMsgSize, 0);
#endif /* _VXWORKS ] */
      Zprintf(" Latency: maxMic=%d, maxSpkr=%d"
         MpMisc.max_mic_buffers, MpMisc.max_spkr_buffers,
         0,0,0,0,0);
   }
   return (int) &MpMisc;
}

int setMaxMic(int v)
{
    int save = MpMisc.max_mic_buffers;

    if (v >= MIC_BUFFER_Q_LEN) {
        int vWas = v;
        v = MIC_BUFFER_Q_LEN - 1;
        osPrintf("\nmax_mic_buffers MUST BE less than %d... setting to"
            " %d instead of %d\n",
            MIC_BUFFER_Q_LEN, v, vWas);
    }
    if (v > 0) MpMisc.max_mic_buffers = v;
    return save;
}

int setMaxSpkr(int v)
{
    int save = MpMisc.max_spkr_buffers;

    if (v >= SPK_BUFFER_Q_LEN) {
        int vWas = v;
        v = SPK_BUFFER_Q_LEN - 1;
        osPrintf("\nmax_spkr_buffers MUST BE less than %d... setting to"
            " %d instead of %d\n",
            SPK_BUFFER_Q_LEN, v, vWas);
    }
    if (v > 0) MpMisc.max_spkr_buffers = v;
    return save;
}


int mpSetLatency(int maxMic, int maxSpkr, int minRtp)
{
    setMaxMic(maxMic);
    setMaxSpkr(maxSpkr);
    return 0;
}

int mpSetHighLatency()
{
    return mpSetLatency(2, 2, 3);
}

int mpSetMedLatency()
{
    return mpSetLatency(1, 1, 2);
}

int mpSetLowLatency()
{
    return mpSetLatency(1, 1, 1);
}

extern void doFrameLoop(int sampleRate, int frame_samples);
extern STATUS netStartup();

#ifndef CODEC_PLUGIN_PATH
// Windows compilers do not allow definition of preprocessor macros with 
// quotes in them within project files, so we need to stringify it here.
// All platforms do this now.
// Two levels of indirection are necessary to properly stringify a value in a macro.
#  define STRINGIFY(s) #s
#  define SSTRINGIFY(s) STRINGIFY(s)
#  ifndef DEFAULT_CODECS_PATH
#     define CODEC_PLUGIN_PATH  "."
#  else
#     define CODEC_PLUGIN_PATH  SSTRINGIFY(DEFAULT_CODECS_PATH)
#  endif
#endif

#ifdef __pingtel_on_posix__ // [
#  define PLUGIN_FILTER "libcodec_.*\\.so"
#elif defined(WIN32) // __pingtel_on_posix__ ] [
#  define PLUGIN_FILTER "codec_.*\\.dll"
#elif // WIN32 ] [<commit_msg>Remove some unused functions from MpMisc.cpp<commit_after>//
// Copyright (C) 2005-2007 SIPez LLC.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// Copyright (C) 2004-2007 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////


// SYSTEM INCLUDES

#include <stdio.h> 
#include <assert.h> 
#include <string.h>
#ifdef _VXWORKS /* [ */
#include <unistd.h>

#include <msgQLib.h>
#include <taskLib.h>
#include <vmLib.h>
#include <intLib.h>
#include <tickLib.h>
#endif /* _VXWORKS ] */

// APPLICATION INCLUDES
#ifdef _VXWORKS /* [ */
#if CPU == ARMSA110 || (CPU == ARMARCH4) || (CPU == STRONGARM) /* [ [ */
#include "mp/sa1100.h"
#elif (CPU == XSCALE) /* ] [ */
#include "mp/pxa255.h"
#else /* ] [ */
#error Unexpected CPU value
#endif /* ] ] */
#endif /* _VXWORKS ] */

#include "os/OsDefs.h" // for min macro
#include "os/OsMsgQ.h"
#include "os/OsConfigDb.h"
#include "mp/MpTypes.h"
#include "mp/MpCodec.h"
#include "mp/dmaTask.h"
#include "mp/MpBuf.h"
#include "mp/MpAudioBuf.h"
#include "mp/MpRtpBuf.h"
#include "mp/MpUdpBuf.h"
#include "mp/MpBufferMsg.h"
#include "mp/MpMisc.h"
#include "mp/NetInTask.h"
#include "mp/MprFromMic.h"
#include "mp/MprToSpkr.h"
#include "mp/MpMediaTask.h"
#include "mp/MpCodecFactory.h"

// EXTERNAL FUNCTIONS

// EXTERNAL VARIABLES

// CONSTANTS

#define MIC_BUFFER_Q_LEN 10
#define SPK_BUFFER_Q_LEN 14
#define ECHO_BUFFER_Q_LEN MIC_BUFFER_Q_LEN+SPK_BUFFER_Q_LEN

#ifdef _VXWORKS /* [ */
#define LOG_MSGQ_MAX_MSGS 8000
#define LOG_MSGQ_ITEM_LEN 60
#define ABSOLUTE_MAX_LOG_MSG_LEN 2048
#endif /* _VXWORKS ] */

#define RTP_BUFS 250
#define RTCP_BUFS 16
#define UDP_BUFS 10

// STATIC VARIABLE INITIALIZATIONS

    struct __MpGlobals MpMisc;

#ifdef _VXWORKS /* [ */
/************************************************************************/

static int logTaskPrio = 250;
int setLogTaskPrio(int p) {
   int save = logTaskPrio;
   logTaskPrio = 0xff & p;
   return save;
}

static int logging = 1;

static int printingLog = 0;
static int numDiscarded = 0;

int drain_log(int level /* how many to leave */)
{
        char msg[1];
        int l, n;

        if (level < 0) level = 50;
        n = msgQNumMsgs(MpMisc.LogQ);
        while(level < msgQNumMsgs(MpMisc.LogQ)) {
            l = msgQReceive(MpMisc.LogQ, msg, 1, VX_NO_WAIT);
            numDiscarded++;
        }
        return n;
}

int StartLogging()
{
        int i;
        i = logging;
        logging = 1;
        return i;
}

int StopLogging(int opt)
{
        int i;

        logging = 0;
        i = msgQNumMsgs(MpMisc.LogQ);
        if (opt) drain_log(50);
        return i;
}

int Zprintf0(int force, char *buf)
{
        int l;
        int n;
        int ret;
        int msgret;
        char *str;
        char junk;

        str = buf;
        l = sipx_min(ABSOLUTE_MAX_LOG_MSG_LEN, strlen(buf));
        ret = l;
        if (0 == MpMisc.LogQ) {
            ret = force ? fwrite(str, 1, ret, stderr) : 0;
            return ret;
        }
        if (force || logging) {
            if ((ret > MpMisc.logMsgSize) && !intContext()) {
                taskLock();
            }
            while (l > 0) {
                n = sipx_min(l, MpMisc.logMsgSize);
                msgret = msgQSend(MpMisc.LogQ, buf, n,
                                       VX_NO_WAIT, MSG_PRI_NORMAL);
                if (ERROR == msgret) {
                    // int r2 =
                    msgQReceive(MpMisc.LogQ, &junk, 1, VX_NO_WAIT);
                    // osPrintf("discard message; r1=%d, r2=%d, q=0x%X: '%s'\n",
                        // msgret, r2, MpMisc.LogQ, buf);
                    numDiscarded++;
                    msgret = msgQSend(MpMisc.LogQ, buf, n,
                                       VX_NO_WAIT, MSG_PRI_NORMAL);
                }
                if ((ERROR == msgret) && force) {
                    fwrite(str, 1, ret, stderr);
                    l = 0;
                } else {
                    l -= n;
                    buf += n;
                }
            }
            if ((ret > MpMisc.logMsgSize) && !intContext()) {
                taskUnlock();
            }
        } else {
            ret = 0;
        }
        return ret;
}

int Zprintfx(int force, char *fmt, int a, int b, int c, int d, int e, int f)
{
        int l, ret;
        char buf[256];

        if (force || logging) {
            sprintf(buf, fmt, a, b, c, d, e, f);
            l = Zprintf0(force, buf);
        } else {
            l = 0;
        }
        return l;
}

int NoPrintLog()
{
    int save = printingLog;
    if (printingLog) {
        numDiscarded = 0;
    }
    osPrintf("\n");
    printingLog = 0;
    return save;
}
int PrintLog(int num)
{
    int save = printingLog;
    if (!printingLog) {
        if (num > 0) drain_log(num);
        fprintf(stderr, "%d messages discarded\n", numDiscarded);
        numDiscarded = 0;
    }
    printingLog = 1;
    return save;
}

extern "C" int NPL(){return NoPrintLog();}
extern "C" int PL(int n){return PrintLog(n);}

static int printTask(int t1, int t2, int t3, int t4, int t5,
                int t6, int t7, int t8, int t9, int t10)
{
        char msg[LOG_MSGQ_ITEM_LEN+1];
        int l;
        int lastTick;
        int thisTick;
        int Hz;
        int qHz;

        Hz = sysClkRateGet();
        qHz = Hz / 4;
#define LOG_ANNOUNCE_MINUTES 5

        lastTick = (int) tickGet() - (LOG_ANNOUNCE_MINUTES * 61 * Hz);

        while (1) {
            while (!printingLog) taskDelay(qHz);
            l = msgQReceive(MpMisc.LogQ, msg, LOG_MSGQ_ITEM_LEN, VX_WAIT_FOREVER);
            thisTick = (int) tickGet();
            if ((LOG_ANNOUNCE_MINUTES * 60 * Hz) < (thisTick - lastTick)) {
                lastTick = thisTick;
                fprintf(stderr, "MsgLogger: %d.%03d seconds since boot\n",
                    thisTick/Hz, ((thisTick % Hz) * 1000) / Hz);
            }
            if (l > 0) {
                msg[l] = 0;
                fwrite(msg, 1, l, stderr);
            } else {
                osPrintf("\n\nLogger: quitting!\n\n");
                return 0;
            }
        }
}

MSG_Q_ID startLogging(int nmsgs, int maxlen)
{
        MpMisc.LogQ = msgQCreate(nmsgs, maxlen, MSG_Q_FIFO);
        if (NULL == MpMisc.LogQ) {
                osPrintf("cannot create LogQ!  Quitting\n");
        } else {
            Zprintf("logQ is 0x%X\n", (int) MpMisc.LogQ, 0,0,0,0,0);
            taskSpawn("Logger", logTaskPrio, 0, 8192, (FUNCPTR) printTask,
                           0, 0, 0,0,0,0,0,0,0,0);
        }
        return MpMisc.LogQ;
}

#ifdef DEBUG /* [ */
int jamLog(char *fmt, int count, int a, int b, int c, int d, int e)
{
    int i;

    for (i=0; i<count; i++) {
        Zprintfx(1, fmt, i, a, b, c, d, e);
    }
    return msgQNumMsgs(MpMisc.LogQ);
}
#endif /* DEBUG ] */

OsStatus startLogTask()
{
#ifdef _VXWORKS /* [ */
        MpMisc.logMsgLimit = LOG_MSGQ_MAX_MSGS;
        MpMisc.logMsgSize = LOG_MSGQ_ITEM_LEN;
        if (NULL == startLogging(MpMisc.logMsgLimit, MpMisc.logMsgSize)) {
            return OS_UNSPECIFIED;
        }
#endif /* _VXWORKS ] */
        return OS_SUCCESS;
}

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

/* Work around for GDB crash... */
static int dontStepInThis()
{
        int ps;

        ps = vmPageSizeGet();
        return ps;
}

static int goGetThePageSize()
{
        return dontStepInThis(); /*!!!*/
}
#endif /* _VXWORKS ] */

/************************************************************************/
extern "C" {
extern int showMpMisc(int justAddress);
extern int setMaxMic(int v);
extern int setMaxSpkr(int v);
extern int mpSetLatency(int maxMic, int maxSpkr, int minRtp);
#ifdef _VXWORKS /* [ */
extern int LoopBack(int on);
extern int LBon();
extern int LBoff();
extern int Spkr1On();
extern int Spkr1Off();
extern int Spkr2On();
extern int Spkr2Off();
#endif /* _VXWORKS ] */
}
/************************************************************************/

#ifdef _VXWORKS /* [ */
#if CPU == ARMSA110 || (CPU == ARMARCH4) || (CPU == STRONGARM) /* [ */

int LoopBack(int on) {
   MpBufferMsg*    pMsg;
   int save = MpMisc.doLoopBack;

   MpMisc.doLoopBack = on;
   while (0 < MpMisc.pLoopBackQ->numMsgs()) {
      if (OS_SUCCESS == MpMisc.pLoopBackQ->receive((OsMsg*&) pMsg,
                                                    OsTime::NO_WAIT_TIME)) {
         pMsg->releaseMsg();
      }
   }
   return save;
}
int LBon()  {return LoopBack(1);}
int LBoff() {return LoopBack(0);}

static int* gpsr = (int*) SA1100_GPSR;
static int* gpcr = (int*) SA1100_GPCR;
int Spkr1On()  {*gpcr = (1<<25); return 0;}
int Spkr1Off() {*gpsr = (1<<25); return 0;}
int Spkr2On()  {*gpcr = (1<<26); return 0;}
int Spkr2Off() {*gpsr = (1<<26); return 0;}

#endif /* StrongARM ] */
#endif /* _VXWORKS ] */

int showMpMisc(int justAddress)
{
   Zprintf("&MpMisc = 0x%X\n", (int) &MpMisc, 0,0,0,0,0);
   if (!justAddress) {
      Zprintf(" MicQ=0x%X, SpkQ=0x%X, EchoQ=0x%X, silence=0x%X\n"
         (int) MpMisc.pMicQ, (int) MpMisc.pSpkQ, (int) MpMisc.pEchoQ,
         (int) MpMisc.mpFgSilence, 0, 0, 0);
      Zprintf(" \n frameSamples=%d, frameBytes=%d, sampleBytes=%d,",
         MpMisc.frameSamples, MpMisc.frameBytes, MpMisc.sampleBytes, 0,0,0);
      Zprintf(" rtpMaxBytes=%d\n RawAudioPool=0x%X, RtpPool=0x%X, RtcpPool=0x%X\n",
         MpMisc.rtpMaxBytes, (int) MpMisc.RawAudioPool, (int) MpMisc.RtpPool,
         (int) MpMisc.RtcpPool, 0,0);
#ifdef _VXWORKS /* [ */
      Zprintf(" mem_page_size=%d, mem_page_mask=0x%08X\n"
         "LogQ=0x%X, logMsgLimit=%d, logMsgSize=%d\n",
         MpMisc.mem_page_size, MpMisc.mem_page_mask,
         (int) MpMisc.LogQ, MpMisc.logMsgLimit, MpMisc.logMsgSize, 0);
#endif /* _VXWORKS ] */
      Zprintf(" Latency: maxMic=%d, maxSpkr=%d"
         MpMisc.max_mic_buffers, MpMisc.max_spkr_buffers,
         0,0,0,0,0);
   }
   return (int) &MpMisc;
}

int setMaxMic(int v)
{
    int save = MpMisc.max_mic_buffers;

    if (v >= MIC_BUFFER_Q_LEN) {
        int vWas = v;
        v = MIC_BUFFER_Q_LEN - 1;
        osPrintf("\nmax_mic_buffers MUST BE less than %d... setting to"
            " %d instead of %d\n",
            MIC_BUFFER_Q_LEN, v, vWas);
    }
    if (v > 0) MpMisc.max_mic_buffers = v;
    return save;
}

int setMaxSpkr(int v)
{
    int save = MpMisc.max_spkr_buffers;

    if (v >= SPK_BUFFER_Q_LEN) {
        int vWas = v;
        v = SPK_BUFFER_Q_LEN - 1;
        osPrintf("\nmax_spkr_buffers MUST BE less than %d... setting to"
            " %d instead of %d\n",
            SPK_BUFFER_Q_LEN, v, vWas);
    }
    if (v > 0) MpMisc.max_spkr_buffers = v;
    return save;
}

#ifndef CODEC_PLUGIN_PATH
// Windows compilers do not allow definition of preprocessor macros with 
// quotes in them within project files, so we need to stringify it here.
// All platforms do this now.
// Two levels of indirection are necessary to properly stringify a value in a macro.
#  define STRINGIFY(s) #s
#  define SSTRINGIFY(s) STRINGIFY(s)
#  ifndef DEFAULT_CODECS_PATH
#     define CODEC_PLUGIN_PATH  "."
#  else
#     define CODEC_PLUGIN_PATH  SSTRINGIFY(DEFAULT_CODECS_PATH)
#  endif
#endif

#ifdef __pingtel_on_posix__ // [
#  define PLUGIN_FILTER "libcodec_.*\\.so"
#elif defined(WIN32) // __pingtel_on_posix__ ] [
#  define PLUGIN_FILTER "codec_.*\\.dll"
#elif // WIN32 ] [
{'fraction_non_alphanumeric': 0.1660393498716852, 'fraction_numerical': 0.01976047904191617, 'mean_word_length': 2.1797905616755067, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4015615', 'n_tokens_mistral': 9202, 'n_tokens_neox': 8694, 'n_words': 2033}