Exemple #1
0
// Handles the SET_FOCUS message.
// Returns TRUE if the message was handled, otherwise FALSE.
UtlBoolean MpMediaTask::handleSetFocus(MpFlowGraphBase* pFlowGraph)
{
   if (pFlowGraph != NULL)
   {
      if (!isManagedFlowGraph(pFlowGraph) ||
          !pFlowGraph->isStarted())
      {
         Nprintf("MpMT::handleSetFocus(0x%X) INVALID: %smanaged, %sstarted\n",
            (int) pFlowGraph,
            (int) (isManagedFlowGraph(pFlowGraph)? "" : "NOT "),
            (int) (pFlowGraph->isStarted() ? "" : "NOT "), 0,0,0);
         return FALSE; // we aren't managing this flow graph, return FALSE
      }
   }

   if (mpFocus != NULL)
   {
#ifndef DISABLE_LOCAL_AUDIO
      // stop input stream
      MpAudioDriverManager* pAudioManager = MpAudioDriverManager::getInstance();
      if (pAudioManager)
      {
         pAudioManager->abortInputStream();
      }
#endif
      
      // remove focus from the flow graph that currently has it
      Nprintf("MpMT::handleSetFocus(0x%X): removing old focus (0x%X)\n",
         (int) pFlowGraph, (int) mpFocus, 0,0,0,0);
      mpFocus->loseFocus();
   }

   mpFocus = pFlowGraph;
   if (mpFocus != NULL)
   {
      // try to give focus to the indicated flow graph
      if (OS_SUCCESS != mpFocus->gainFocus())
      {
         Nprintf("MpMT::handleSetFocus(0x%X): attempt to give focus FAILED\n",
            (int) pFlowGraph, 0,0,0,0,0);
         mpFocus = NULL;
         return FALSE; // the flow graph did not accept focus.
      }

#ifndef DISABLE_LOCAL_AUDIO
      // start input stream
      MpAudioDriverManager* pAudioManager = MpAudioDriverManager::getInstance();
      if (pAudioManager)
      {
         pAudioManager->startInputStream();
      }
#endif
      Nprintf("MpMT::handleSetFocus(0x%X): attempt to give focus SUCCEEDED\n",
         (int) pFlowGraph, 0,0,0,0,0);
   }

   return TRUE;
}
Exemple #2
0
// Handles the SET_FOCUS message.
// Returns TRUE if the message was handled, otherwise FALSE.
UtlBoolean MpMediaTask::handleSetFocus(MpFlowGraphBase* pFlowGraph)
{
   if (pFlowGraph != NULL)
   {
      if (!isManagedFlowGraph(pFlowGraph) ||
          !pFlowGraph->isStarted())
      {
         Nprintf("MpMT::handleSetFocus(0x%p) INVALID: %smanaged, %sstarted\n",
            pFlowGraph,
            (int) (isManagedFlowGraph(pFlowGraph)? "" : "NOT "),
            (int) (pFlowGraph->isStarted() ? "" : "NOT "), 0,0,0);
         return FALSE; // we aren't managing this flow graph, return FALSE
      }
   }

   if (mpFocus != NULL)
   {
      // remove focus from the flow graph that currently has it
      Nprintf("MpMT::handleSetFocus(0x%p): removing old focus (0x%p)\n",
         pFlowGraph, mpFocus, 0,0,0,0);
      mpFocus->loseFocus();
   }

   mpFocus = pFlowGraph;
   if (mpFocus != NULL)
   {
      // try to give focus to the indicated flow graph
      if (OS_SUCCESS != mpFocus->gainFocus())
      {
         Nprintf("MpMT::handleSetFocus(0x%p): attempt to give focus FAILED\n",
            pFlowGraph, 0,0,0,0,0);
         mpFocus = NULL;
         return FALSE; // the flow graph did not accept focus.
      }
      Nprintf("MpMT::handleSetFocus(0x%p): attempt to give focus SUCCEEDED\n",
         pFlowGraph, 0,0,0,0,0);
   }

   return TRUE;
}
Exemple #3
0
        /* printf("take: 0x%08X (%d)\n", (int) ret, i-1); */
        return ret;
}

#ifdef BUFFER_INSTRUMENTATION /* [ */
void MpBuf_delRefX(MpBufPtr b, int line)
#else /* BUFFER_INSTRUMENTATION ] [ */
void MpBuf_delRef(MpBufPtr b)
#define line (-1)
#endif /* BUFFER_INSTRUMENTATION ] */
{
        MpBufPoolPtr l;
#ifdef BUFFER_INSTRUMENTATION /* [ */
        int this_time = incr_time_stamp();
#endif /* BUFFER_INSTRUMENTATION ] */

        int n;

        if (NULL == b) {
            return;
        }

        if (MpBuf_invalid(b, FALSE, TRUE)) {
            Zprintf("MpBuf_delRef(0x%X): invalid! line: %d\n",
                        (int) b, line, 0,0,0,0);
            // assert(!MpBuf_invalid(b, FALSE, TRUE));
            return;
        }

        l = b->pPool;

        n = b - l->table;
        if ((n < 0) || (n >= l->allocCnt)) {
            Zprintf("MpBuf_delRef: attempt to free 0x%X (%d) @%d\n",
                (int) b, n, line, 0,0,0);
        } else if (1 != b->status) {
            l->mpMutex->acquire();
            b->status = 2;
            l->mpMutex->release();
            Zprintf("MpBuf_delRef: attempt to free a free buffer"
                " -- 0x%X (%d) @%d\n", (int) b, n, line, 0,0,0);
        } else {
            Nprintf("!%d(%d)\n ", b - l->table, line,0,0,0,0);
            l->mpMutex->acquire();
            b->refCnt--;
            if (0 == b->refCnt) {
               b->status = 0;
               b->speech = MP_SPEECH_UNKNOWN;
#ifdef BUFFER_INSTRUMENTATION /* [ */
               l->nfree++;
               b->line_freed = line;
               b->time_freed = this_time;
#endif /* BUFFER_INSTRUMENTATION ] */
            }
            l->mpMutex->release();
        }
#undef line
} /* MpBuf_delRef, MpBuf_delRefX */
Exemple #4
0
        /* printf("take: 0x%08X (%d)\n", (int) ret, i-1); */
        return ret;
}

#ifdef BUFFER_INSTRUMENTATION /* [ */
void MpBuf_delRefX(MpBufPtr b, int line)
#else /* BUFFER_INSTRUMENTATION ] [ */
void MpBuf_delRef(MpBufPtr b)
#define line (-1)
#endif /* BUFFER_INSTRUMENTATION ] */
{
        MpBufPoolPtr l;
#ifdef BUFFER_INSTRUMENTATION /* [ */
        int this_time = incr_time_stamp();
#endif /* BUFFER_INSTRUMENTATION ] */

        int n;

        if (NULL == b) {
            return;
        }

        if (MpBuf_invalid(b, FALSE, TRUE)) {
            Zprintf("MpBuf_delRef(0x%X): invalid! line: %d\n",
                        (int) b, line, 0,0,0,0);
            // assert(!MpBuf_invalid(b, FALSE, TRUE));
            return;
        }

        l = b->pPool;

        n = b - l->table;
        if ((n < 0) || (n >= l->allocCnt)) {
            Zprintf("MpBuf_delRef: attempt to free 0x%X (%d) @%d\n",
                (int) b, n, line, 0,0,0);
        } else if (1 != b->status) {
            l->mpMutex->acquire();
            b->status = 2;
            l->mpMutex->release();
            Zprintf("MpBuf_delRef: attempt to free a free buffer"
                " -- 0x%X (%d) @%d\n", (int) b, n, line, 0,0,0);
        } else {
            Nprintf("!%d(%d)\n ", b - l->table, line,0,0,0,0);
            l->mpMutex->acquire();
            b->refCnt--;
            if (0 == b->refCnt) {
               b->status = 0;
               b->speech = MP_SPEECH_UNKNOWN;
#ifdef BUFFER_INSTRUMENTATION /* [ */
               l->nfree++;
               b->line_freed = line;
               b->time_freed = this_time;
#endif /* BUFFER_INSTRUMENTATION ] */
            }
            l->mpMutex->release();
        }
#undef line
} /* MpBuf_delRef, MpBuf_delRefX */

#ifdef BUFFER_INSTRUMENTATION /* [ */
void MpBuf_addRefX(MpBufPtr b, int line)
#else /* BUFFER_INSTRUMENTATION ] [ */
void MpBuf_addRef(MpBufPtr b)
#define line (-1)
#endif /* BUFFER_INSTRUMENTATION ] */
{
        MpBufPoolPtr l;

        int n;

        if (NULL == b) {
            return;
        }

        if (MpBuf_invalid(b, FALSE, TRUE)) {
            Zprintf("MpBuf_addRef(0x%X): invalid! line: %d\n",
                        (int) b, line, 0,0,0,0);
            return;
        }

        l = b->pPool;

        n = b - l->table;
        if ((n < 0) || (n >= l->allocCnt)) {
            Zprintf("MpBuf_addRef: attempt to free 0x%X (%d) @%d\n",
                (int) b, n, line, 0,0,0);
        } else if (1 != b->status) {
            l->mpMutex->acquire();
            b->status = 2;
            l->mpMutex->release();
            Zprintf("MpBuf_addRef: attempt to add ref to a free buffer"
                " -- 0x%X (%d) @%d\n", (int) b, n, line, 0,0,0);
        } else {
            Nprintf("!%d(%d)\n ", b - l->table, line,0,0,0,0);
            l->mpMutex->acquire();
            b->refCnt++;
            l->mpMutex->release();
        }
#undef line
} /* MpBuf_addRef, MpBuf_addRefX */
Exemple #5
0
OsStatus MpBuf_init(int samplesPerFrame, int numAudioBuffers)
{
   LowBufTable = 0xffffffff;
   HighBufTable = 0;

#ifdef BUFFER_INSTRUMENTATION /* [ */
   spCounterMutex = new OsMutex(OsMutex::Q_PRIORITY);
#endif /* BUFFER_INSTRUMENTATION ] */

   MpMisc.UcbPool = MpBufPool_MpBufPool(0,
                   samplesPerFrame*sizeof(Sample),
                        numAudioBuffers, 0);
   Nprintf("MpBuf_init: MpMisc.UcbPool = 0x%X\n",
                           (int) MpMisc.UcbPool, 0,0,0,0,0);
   if (NULL == MpMisc.UcbPool) {
      return OS_NO_MEMORY;
   }

   MpMisc.DMAPool = MpBufPool_MpBufPool(0,
                   8*samplesPerFrame*sizeof(Sample),
                        64, 32);
   Nprintf("MpBuf_init: MpMisc.DMAPool = 0x%X\n",
                           (int) MpMisc.DMAPool, 0,0,0,0,0);

   if (NULL == MpMisc.DMAPool) {
      return OS_NO_MEMORY;
   }

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

/*
 * Go get a buffer and fill with silence.  We will use this for muting
 * either or both of input and output, and whenever we are starved for
 * audio data.
 */

#ifdef N_SPARE_BUFS /* [ */
    /* For debugging... get a few buffers and set them aside... */
    {
        MpBufPtr sb;
        int i, j, n;
        Sample* dst;

        for (i=0; i<N_SPARE_BUFS; i++) {
            sb = MpBuf_getBuf(MpMisc.UcbPool, samplesPerFrame, 0, MP_FMT_T12);
            if (NULL == sb) {
                Zprintf("\n\nMpBuf_init: MpBuf_getBuf failed, quitting!\n\n\n",
                    0,0,0,0,0,0);
                MpBufPool_delete(MpMisc.UcbPool, 1);
                MpMisc.UcbPool = NULL;
                return OS_LIMIT_REACHED;
            }
            dst = MpBuf_getSamples(sb);
            n = MpBuf_getByteLen(sb) / sizeof(Sample);
            MpBuf_setNumSamples(sb, n);
            for (j=0; j<n; j++) {
                *dst++ = (i<<8) + j;
            }
            MpBuf_setSpeech(sb, (enum MpBufSpeech) MP_SPEECH_SPARE);
            spareBufs[i] = sb;
        }
        showSpareBufs(0, "MpBuf_Init: ");
    }
#endif /* N_SPARE_BUFS ] */
    {
        MpBufPtr sb;

        sb = MpBuf_getBuf(MpMisc.UcbPool, samplesPerFrame, 0, MP_FMT_T12);
        if (NULL == sb) {
            Zprintf("\n\nMpBuf_init: MpBuf_getBuf failed, quitting!\n\n\n",
                0,0,0,0,0,0);
            MpBufPool_delete(MpMisc.UcbPool, 1);
            MpMisc.UcbPool = NULL;
            return OS_LIMIT_REACHED;
        }
        memset(MpBuf_getSamples(sb), 0, MpBuf_getByteLen(sb));
        MpBuf_setSpeech(sb, MP_SPEECH_SILENT);
        MpMisc.XXXsilence = sb;
        Zprintf("MpBuf_init: MpMisc.silence = 0x%X\n",
                                (int) MpMisc.XXXsilence, 0,0,0,0,0);
    }
/*************************************************************************/

/*
 * Go get a DMA buffer and fill with silence.  We will use this for muting
 * either or both of input and output, and whenever we are starved for
 * audio data.
 */

    {
        MpBufPtr sb;

        sb = MpBuf_getBuf(MpMisc.DMAPool, 8*samplesPerFrame, 0, MP_FMT_T12);
        if (NULL == sb) {
            Zprintf("\n\nMpBuf_init: MpBuf_getBuf failed (DMA), quitting!\n\n\n",
                0,0,0,0,0,0);
            MpBufPool_delete(MpMisc.DMAPool, 1);
            MpMisc.DMAPool = NULL;
            return OS_LIMIT_REACHED;
        }
        memset(MpBuf_getSamples(sb), 0, MpBuf_getByteLen(sb));
        MpBuf_setSpeech(sb, MP_SPEECH_SILENT);
        MpMisc.XXXlongSilence = sb;
        Zprintf("MpBuf_init: MpMisc.longSilence = 0x%X\n",
                                (int) MpMisc.XXXlongSilence, 0,0,0,0,0);
    }
/*************************************************************************/
 /*
  * generate a buffer called comfort noise buffer. Even though the zero
  * initiation is not necessary, we do it as the silence buffer for safety.
  */
    {
        MpBufPtr cnb;

        cnb = MpBuf_getBuf(MpMisc.UcbPool, samplesPerFrame, 0, MP_FMT_T12);
        if (NULL == cnb) {
            Zprintf("\n\nMpBuf_init: MpBuf_getBuf failed, quitting!\n\n\n",
                0,0,0,0,0,0);
            MpBufPool_delete(MpMisc.UcbPool, 1);
            MpMisc.UcbPool = NULL;
            return OS_LIMIT_REACHED;
        }
        memset(MpBuf_getSamples(cnb), 0, MpBuf_getByteLen(cnb));
        MpBuf_setSpeech(cnb, MP_SPEECH_COMFORT_NOISE);
        MpMisc.comfortNoise = cnb;
        Zprintf("MpBuf_init: MpMisc.comfortNoise = 0x%X\n",
                                (int) MpMisc.comfortNoise, 0,0,0,0,0);
    }
/*************************************************************************/

   MpMisc.RtpPool = MpBufPool_MpBufPool(0, NETWORK_MTU, rtpNBufs, 0);
   Nprintf("MpBuf_init: MpMisc.RtpPool = 0x%X\n",
                           (int) MpMisc.RtpPool, 0,0,0,0,0);
   if (NULL == MpMisc.RtpPool) {
      MpBufPool_delete(MpMisc.UcbPool, 1);
      MpMisc.UcbPool = NULL;
      return OS_NO_MEMORY;
   }

   MpMisc.RtcpPool = MpBufPool_MpBufPool(0,
      MAX_RTCP_PACKET_LEN, rtcpNBufs, 0);
   Nprintf("MpBuf_init: MpMisc.RtcpPool = 0x%X\n",
                           (int) MpMisc.RtcpPool, 0,0,0,0,0);
   if (NULL == MpMisc.RtcpPool) {
      MpBufPool_delete(MpMisc.UcbPool, 1);
      MpMisc.UcbPool = NULL;
      MpBufPool_delete(MpMisc.RtpPool, 1);
      MpMisc.RtpPool = NULL;
      return OS_NO_MEMORY;
   }

   return OS_SUCCESS;
}
Exemple #6
0
/*************************************************************************/

   MpMisc.RtpPool = MpBufPool_MpBufPool(0, NETWORK_MTU, rtpNBufs, 0);
   Nprintf("MpBuf_init: MpMisc.RtpPool = 0x%X\n",
                           (int) MpMisc.RtpPool, 0,0,0,0,0);
   if (NULL == MpMisc.RtpPool) {
      MpBufPool_delete(MpMisc.UcbPool, 1);
      MpMisc.UcbPool = NULL;
      return OS_NO_MEMORY;
   }

   MpMisc.RtcpPool = MpBufPool_MpBufPool(0,
      MAX_RTCP_PACKET_LEN, rtcpNBufs, 0);
   Nprintf("MpBuf_init: MpMisc.RtcpPool = 0x%X\n",
                           (int) MpMisc.RtcpPool, 0,0,0,0,0);
   if (NULL == MpMisc.RtcpPool) {
      MpBufPool_delete(MpMisc.UcbPool, 1);
      MpMisc.UcbPool = NULL;
      MpBufPool_delete(MpMisc.RtpPool, 1);
      MpMisc.RtpPool = NULL;
      return OS_NO_MEMORY;
   }

   return OS_SUCCESS;
}

#ifdef BUFFER_INSTRUMENTATION /* [ */
        volatile int bufHang, doHang = 1;
        int we_are_logging = 0;

int bufUnHang(int x)
{
    int was = bufHang;
    bufHang = 0;
    doHang = x;
    return was;
}

int forceLogging(int on)
{
        int was = we_are_logging;

        we_are_logging = on;
        return was;
}

int incr_time_stamp()
{
        OsLock lock(*spCounterMutex);
        return buffer_time_stamp++;
}
#endif /* BUFFER_INSTRUMENTATION ] */

void MpBuf_insertSawTooth(MpBufPtr b)
{
    int i, n;
    Sample *s;

    if (NULL == b) return;
    if (!MpBuf_invalid(b, TRUE, TRUE)) {
        s = MpBuf_getSamples(b);
        n = MpBuf_getNumSamples(b);
        for (i=0; i<n; i++)
            *s++ = ((0xf & i) << 12);
    }
}

#ifdef BUFFER_INSTRUMENTATION /* [ */
MpBufPtr MpBuf_getBufX(MpBufPoolPtr Pool,
        int initSamples, int initOffset, MpBufFormat initFormat, int line)
#else /* BUFFER_INSTRUMENTATION ] [ */
MpBufPtr MpBuf_getBufY(MpBufPoolPtr Pool,
        int initSamples, int initOffset, MpBufFormat initFormat)
#endif /* BUFFER_INSTRUMENTATION ] */
{
        int i;
        int n;
        MpBufPtr ret, t;
        MpBufPoolPtr l = Pool;
        OsLock lock(*(Pool->mpMutex));
#ifdef BUFFER_INSTRUMENTATION /* [ */
        int this_time = incr_time_stamp();
#endif /* BUFFER_INSTRUMENTATION ] */

        ret = NULL;
        n = l->lastTaken;
        t = &(l->table[n]);
        for (i=0; ((NULL==ret) && (i<l->allocCnt)); i++) {
            if (n >= l->allocCnt) {
                n = 0;
                t = l->table;
            }
            if (0 == t->status) {
                n++;
                if (n >= l->allocCnt) {
                    n = 0;
                }
                l->lastTaken = n;
                ret = t;
                ret->status = 1;
                ret->speech = MP_SPEECH_UNKNOWN;
                ret->refCnt = 1;
                MpBuf_setFormat(ret, initFormat);
                MpBuf_setOffset(ret, initOffset);
                MpBuf_setNumSamples(ret, initSamples);
                MpBuf_setOsTC(ret, 0);
#define CLEAR_BUFFER
#undef CLEAR_BUFFER
#ifdef CLEAR_BUFFER /* [ */
                memset(MpBuf_getStorage(ret), 0, MpBuf_getByteLen(ret));
#endif /* CLEAR_BUFFER ] */
#define INSERT_SAWTOOTH
#undef INSERT_SAWTOOTH
#ifdef INSERT_SAWTOOTH /* [ */
                MpBuf_insertSawTooth(ret);
#endif /* INSERT_SAWTOOTH ] */
#ifdef BUFFER_INSTRUMENTATION /* [ */
                ret->line_taken = line;
                ret->time_taken = this_time;
#endif /* BUFFER_INSTRUMENTATION ] */
            }
            t++;
            n++;
        }

#ifdef BUFFER_INSTRUMENTATION /* [ */
        if (NULL != ret) l->nfree--;
        if (l->nfree < l->minfree) {
            l->minfree = l->nfree;
            if (2 < (l->allocCnt)) {
                showBufs(Pool, line);
            }
            if (15 < (l->allocCnt - l->nfree)) {
                /* dumpBufs(0); */
            }
        }
#endif /* BUFFER_INSTRUMENTATION ] */

        Nprintf(" +%02d(%d)\n", i-1, line, 0,0,0,0);
        Nprintf("take: 0x%08X (%d), at %d\n",
                                (int) ret, i-1, line, 0,0,0);
        /* printf("take: 0x%08X (%d)\n", (int) ret, i-1); */
        return ret;
}
Exemple #7
0
// Notification that this flow graph has just lost the focus.
// However, we did not want it.
OsStatus MpFlowGraphBase::loseFocus(void)
{
   Nprintf("MpFG::loseFocus(0x%p), not supported!\n", this, 0,0,0,0,0);
   return OS_INVALID_ARGUMENT;
}
Exemple #8
0
OsStatus mpStartUp(int sampleRate, int samplesPerFrame,
                   int numAudioBuffers, OsConfigDb* pConfigDb,
                   const size_t numCodecPaths, const UtlString codecPaths[])
{
    // TODO:
    // This should be broken down into separate arguments for:
    // Max number of flowgraphs
    // Max number of calls
    // Max calls/streams per flowgraph
    // Buffers used/stream or used/flowgraph
    // Approximate based upon current media interface initialization
    int maxCalls = numAudioBuffers / 16;

#ifdef _VXWORKS
        int defSilenceSuppressLevel = 10000;
#else
        int defSilenceSuppressLevel = 0;
#endif
        OsStatus  resCode;
        UtlBoolean silenceSuppressFlag;
        UtlString  silenceSuppressEnable;
        int       silenceSuppressLevel;

        assert(samplesPerFrame >= 8);

        showMpMisc(TRUE);

        RTL_START(100000000);
        setExternalRtlCollector(sRealtimeLogCollector);

        // First initialize static codecs
        mpStaticCodecInitializer();

        MpCodecFactory* pcf = MpCodecFactory::getMpCodecFactory();

        if(numCodecPaths != 0)
        {
           size_t i;
           for(i = 0; i < numCodecPaths; i++)
           {
              pcf->loadAllDynCodecs(codecPaths[i].data(), CODEC_PLUGINS_FILTER);
           }
        }
        else
        {
           pcf->loadAllDynCodecs(CODEC_PLUGIN_PATH, CODEC_PLUGINS_FILTER);
        }

#ifdef _VXWORKS /* [ */
        /* Rashly assumes page size is a power of two */
        MpMisc.mem_page_size = goGetThePageSize();
        MpMisc.mem_page_mask = MpMisc.mem_page_size - 1;
#endif /* _VXWORKS ] */

        MpMisc.sampleBytes = sizeof(MpAudioSample);
        MpMisc.frameSamples = samplesPerFrame;
        MpMisc.frameBytes = MpMisc.sampleBytes * MpMisc.frameSamples;
        MpMisc.rtpMaxBytes = /* sizeof(struct RtpHeader) */ 12 + 
            (((sampleRate + 24) / 25) * MpMisc.sampleBytes);

        // Create buffer for audio data in mediagraph
        MpMisc.RawAudioPool = new MpBufPool( samplesPerFrame*sizeof(MpAudioSample)
                                        + MpArrayBuf::getHeaderSize(),
                                      numAudioBuffers,
                                      "RawAudioPool");
        Nprintf( "mpStartUp: MpMisc.RawAudioPool = 0x%X\n"
               , (int) MpMisc.RawAudioPool, 0,0,0,0,0);
        if (NULL == MpMisc.RawAudioPool) {
            return OS_NO_MEMORY;
        }

        // Create buffer for audio headers
        int audioBuffers  = MpMisc.RawAudioPool->getNumBlocks();
        MpMisc.AudioHeadersPool = new MpBufPool(sizeof(MpAudioBuf), audioBuffers, "AudioHeadersPool");
        Nprintf( "mpStartUp: MpMisc.AudioHeadersPool = 0x%X\n"
               , (int) MpMisc.AudioHeadersPool, 0,0,0,0,0);
        if (NULL == MpMisc.AudioHeadersPool) {
            // TODO:: Think about proper resource deallocation on fail in mpStartUp()
            return OS_NO_MEMORY;
        }
        MpAudioBuf::smpDefaultPool = MpMisc.AudioHeadersPool;

        /*
        * Go get a buffer and fill with silence.  We will use this for muting
        * either or both of input and output, and whenever we are starved for
        * audio data.
        */
        {
            MpAudioBufPtr sb = MpMisc.RawAudioPool->getBuffer();
            if (!sb.isValid()) {
                Zprintf("\n\mpStartUp:"
                        " MpBufPool::getBuffer() failed, quitting!\n\n\n",
                        0,0,0,0,0,0);
                delete MpMisc.RawAudioPool;
                MpMisc.RawAudioPool = NULL;
                return OS_LIMIT_REACHED;
            }

            sb->setSamplesNumber(samplesPerFrame);
            memset(sb->getSamplesWritePtr(), 0, sb->getSamplesNumber()*sizeof(MpAudioSample));
            sb->setSpeechType(MP_SPEECH_SILENT);
            MpMisc.mpFgSilence = sb;
            Zprintf("mpStartUp: MpMisc.silence = 0x%X\n",
                (int) MpMisc.mpFgSilence, 0,0,0,0,0);
        }
Exemple #9
0
UtlBoolean MprDecode::doProcessFrame(MpBufPtr inBufs[],
                                    MpBufPtr outBufs[],
                                    int inBufsSize,
                                    int outBufsSize,
                                    UtlBoolean isEnabled,
                                    int samplesPerFrame,
                                    int samplesPerSecond)
{
#ifdef DEBUG_DECODING /* [ */
static int numFramesForWarnings = 0;
static int numWarnings = 0;
#endif /* DEBUG_DECODING ] */

   MpBufPtr rtp;
   MpBufPtr out;

#ifdef DEBUG_DECODING /* [ */
   numFramesForWarnings++;
#endif /* DEBUG_DECODING ] */

   MpDecoderBase* pCurDec;
   Sample* pSamples = NULL;

   mFrameCounter++;

   if (0 == outBufsSize) return FALSE;

   if (!isEnabled) {
      mPreloading = 1;
      *outBufs = MpBuf_getFgSilence();
      return TRUE;
   }

   {
      MprDejitter* pDej = getMyDejitter();
      int packetLen;
      int pt;

      while (NULL != (rtp = pDej->pullPacket())) {
         pt = MprDejitter::getPayloadType(rtp);
         pCurDec = mpConnection->mapPayloadType(pt);
         if (NULL != pCurDec) {
            unsigned char* pRtpH;
            pRtpH = ((unsigned char*) MpBuf_getStorage(rtp)) + 1;
            if (0x80 == (0x80 & *pRtpH)) {
               if ((mFrameLastMarkerNotice + MARKER_WAIT_FRAMES) <
                         mFrameCounter) {
                  mNumMarkerNotices = 0;
               }
               if (mNumMarkerNotices++ < MAX_MARKER_NOTICES)
               {
                  // osPrintf("MprDecode: RTP marker bit ON\n");
                  mFrameLastMarkerNotice = mFrameCounter;
               }
            }
            packetLen = pCurDec->decodeIn(rtp);
            if (packetLen > 0) {
               pushIntoJitterBuffer(rtp, packetLen);
            }
         }
         MpBuf_delRef(rtp);
      }
   }

   out = MpBuf_getBuf(MpMisc.UcbPool, samplesPerFrame, 0, MP_FMT_T12);
   if (out)
   {
      pSamples = MpBuf_getSamples(out);
      memset(pSamples, 0, samplesPerFrame * sizeof(Sample));
      MpBuf_setSpeech(out, MP_SPEECH_SILENT);
   }
   JB_inst* pJBState = mpConnection->getJBinst();
   if (pJBState) {
      // This should be a JB_something or other.  However the only
      // current choices is a short or long equivalant and this needs
      // to be a plain old int:
      int outLen;
      int res;
      res = JB_RecOut(pJBState, pSamples, &outLen);
      MpBuf_setSpeech(out, MP_SPEECH_UNKNOWN);
   }

   *outBufs = out;
   Nprintf("Decode_doPF: returning 0x%p\n", out, 0,0,0,0,0);
   return TRUE;
}