Exemple #1
0
UtlBoolean MprBridge::handleSetMixWeightsForInput(int bridgeInputPort,
                                                  int numWeights,
                                                  const MpBridgeGain gain[])
{
#ifdef TEST_PRINT
    UtlString weightString;
    for(int wIndex = 0; wIndex < numWeights; wIndex++)
    {
#  ifdef MP_FIXED_POINT
        weightString.appendFormat("%s%d", 
            wIndex > 0 ? ", " : "", gain[wIndex]);
#  else
        weightString.appendFormat("%s%f", 
            wIndex > 0 ? ", " : "", (double)gain[wIndex]);
#  endif
    }
    OsSysLog::add(FAC_MP, PRI_DEBUG,
        "MprBridge::handleSetMixWeightsForInput(inputPort: %d, numWeights: %d, weights[%s]",
        bridgeInputPort, numWeights, weightString.data());
#endif

   // New gains vector must fit into matrix
   assert(numWeights <= maxOutputs());
   if (numWeights > maxOutputs())
   {
      return FALSE;
   }

   // Set gain for input.
   mpBridgeAlg->setGainMatrixColumn(bridgeInputPort, numWeights, gain);

   return TRUE;
}
Exemple #2
0
OsStatus OsConfigDb::updateFile(const char* filename) const
{
   UtlString originalFileContents;
   long fileLength = OsFile::openAndRead(filename, originalFileContents);
   const char* unparsedBits = originalFileContents;
   int unparsedLength = originalFileContents.length();

   // Loop through and try to preserve comments, space and order
   int lineStart = 0;
   int lineEnd = 0;
   UtlHashBag writtenNames;
   UtlString newFileContents;
   UtlString name;
   UtlString value;
   UtlString newValue;

   while(lineStart < unparsedLength)
   {
      lineEnd = UtlTokenizer::nextDelim(unparsedBits, lineStart, unparsedLength, "\n\r");

      //printf("start: %d end: %d length: %d\n", lineStart, lineEnd, unparsedLength);

      UtlString oneLine(&unparsedBits[lineStart], lineEnd - lineStart);

      //printf("Line: <%s>\n", oneLine.data());

      // If line contains a parameter
      if(parseLine(oneLine, mCapitalizeName, filename, name, value))
      {
         //printf("name<%s> value<%s>\n", name.data(), value.data());
         if(get(name, newValue) == OS_SUCCESS &&
            !writtenNames.contains(&name))
         {
            //printf("Wrote name<%s>\n", name.data());
            // The parameter still exists in the configDb and we have not yet
            // written it out, write the potentially changed value
            newFileContents.appendFormat("%s : %s\n", name.data(), newValue.data());

            // Save names/parameters written so that we can figure out what has not
            // been written out
            writtenNames.insert(new UtlString(name));
         }
         // else the parameter was removed, do nothing
      }
   
      // The line was a comment or blank line, write it back out the same
      else
      {
         newFileContents.appendFormat("%s\n", oneLine.data());
      }

      lineStart = lineEnd + 1;
   }

   int paramIndex;
   int paramCount = numEntries();
   DbEntry* paramEntry;

   for (paramIndex = 0; paramIndex < paramCount; paramIndex++)
   {
      paramEntry = (DbEntry*) mDb.at(paramIndex);

      removeNewlineReturns(paramEntry->key);
      removeNewlineReturns(paramEntry->value);

      // We have not written the value yet
      if(!writtenNames.contains(&(paramEntry->key)))
      {
          newFileContents.appendFormat("%s : %s\n", paramEntry->key.data(), paramEntry->value.data());
          writtenNames.insert(new UtlString(paramEntry->key));
      }
   }

   fileLength = OsFile::openAndWrite(filename, newFileContents);
 
   writtenNames.destroyAll();

   return(fileLength > 0 ? OS_SUCCESS : OS_INVALID_ARGUMENT);
}
Exemple #3
0
UtlBoolean MprBridge::doProcessFrame(MpBufPtr inBufs[],
                                     MpBufPtr outBufs[],
                                     int inBufsSize,
                                     int outBufsSize,
                                     UtlBoolean isEnabled,
                                     int samplesPerFrame,
                                     int samplesPerSecond)
{
   MpAudioBufPtr in;
   UtlBoolean ret = FALSE;

   // We're disabled or have nothing to process.
   if ( outBufsSize == 0 || inBufsSize == 0 || !isEnabled )
   {
      return TRUE;
   }

   // We want correct in/out pairs
   if (inBufsSize != outBufsSize)
   {
      return FALSE;
   }

   ret = doMix(inBufs, inBufsSize, outBufs, outBufsSize, samplesPerFrame);

#ifdef PRINT_CLIPPING_STATS
   UtlString outputsClippingMessage;
   mClippedFramesCounted++;
   //OsSysLog::add(FAC_MP, PRI_DEBUG, "Bridge clipping frame count: %d outBufsSize: %d", 
   //   mClippedFramesCounted, outBufsSize);

   for(int outIndex = 0; outIndex < outBufsSize; outIndex++)
   {
      if(outBufs[outIndex].isValid())
      {
         MpAudioBufPtr audioBufPtr = outBufs[outIndex];

          mpOutputClippingCount[outIndex] +=
            MpDspUtils::countClippedValues(audioBufPtr->getSamplesPtr(), 
                                           audioBufPtr->getSamplesNumber());
      }

      if(mClippedFramesCounted >= PRINT_CLIPPING_FREQUENCY)
      {
         outputsClippingMessage.appendFormat("\noutput[%d]: %d", 
            outIndex, mpOutputClippingCount[outIndex]);

         mpOutputClippingCount[outIndex] = 0;
      }
   }

   if(mClippedFramesCounted >= PRINT_CLIPPING_FREQUENCY)
   {
      OsSysLog::add(FAC_MP, PRI_DEBUG,
         "Bridge clipping for last %d samples on:%s", 
         PRINT_CLIPPING_FREQUENCY * mpFlowGraph->getSamplesPerFrame(), 
         outputsClippingMessage.data());

      mClippedFramesCounted = 0;
   }

   //OsSysLog::add(FAC_MP, PRI_DEBUG, "Bridge clipping frame count: %d", mClippedFramesCounted);
#endif

#ifdef TEST_PRINT_CONTRIBUTORS
   for (int outIdx=0; outIdx < outBufsSize; outIdx++) {
      mpMixContributors->zero();

      // Keep track of the sources mixed for this output
      if (*mpLastOutputContributors[outIdx] != *mpMixContributors)
      {
         int contribIndex;
         printf("Bridge output: %d vector change: %d", 
                outIdx, mpMixContributors->get(0));
         for (contribIndex = 1; contribIndex < inBufsSize; contribIndex++)
         {
            printf(", %d", mpMixContributors->get(contribIndex));
         }
         printf("\n");

         *mpLastOutputContributors[outIdx] = *mpMixContributors;
      }
   }
#endif

   return ret;
}
MpResourceTopology* CpTopologyGraphFactoryImpl::buildMulticastConnectionResourceTopology()
{
    MpResourceTopology* resourceTopology = new MpResourceTopology();
    OsStatus result;

    // Add multicast RTP input
    result = resourceTopology->addResource(DEFAULT_MCAST_RTP_INPUT_RESOURCE_TYPE,
                                           DEFAULT_RTP_INPUT_RESOURCE_NAME);
    assert(result == OS_SUCCESS);

    // Add stream resources and link them with RTP input and bridge
    UtlString decodeName = DEFAULT_DECODE_RESOURCE_NAME;
    UtlString activityNotifName = DEFAULT_VOICE_ACTIVITY_NOTIFIER_RESOURCE_NAME;
    activityNotifName.append(CONNECTION_NAME_SUFFIX);
#ifdef INSERT_DELAY_RESOURCE // [
    UtlString delayName = DEFAULT_DELAY_RESOURCE_NAME;
    delayName.append(CONNECTION_NAME_SUFFIX);
#endif // INSERT_DELAY_RESOURCE ]
    for (int i=0; i<mNumMcastStreams; i++)
    {
       // Construct names of resources for this stream
       UtlString streamSuffix;
       streamSuffix.appendFormat(STREAM_NAME_SUFFIX, i);
       UtlString tmpDecodeName(decodeName);
       tmpDecodeName.append(streamSuffix);
       UtlString tmpActivityNotifName(activityNotifName);
       tmpActivityNotifName.append(streamSuffix);
#ifdef INSERT_DELAY_RESOURCE // [
       UtlString tmpDelayName(delayName);
       tmpDelayName.append(streamSuffix);
#endif // INSERT_DELAY_RESOURCE ]

       // Add decoder
       result = resourceTopology->addResource(DEFAULT_DECODE_RESOURCE_TYPE,
                                              tmpDecodeName,
                                              MP_INVALID_CONNECTION_ID,
                                              i);
       assert(result == OS_SUCCESS);

       // Add Voice Activity Notifier
       result = resourceTopology->addResource(DEFAULT_VOICE_ACTIVITY_NOTIFIER_RESOURCE_TYPE,
                                              tmpActivityNotifName,
                                              MP_INVALID_CONNECTION_ID,
                                              i);
       assert(result == OS_SUCCESS);

#ifdef INSERT_DELAY_RESOURCE // [
       // Add delay resource
       result = resourceTopology->addResource(DEFAULT_DELAY_RESOURCE_TYPE,
                                              tmpDelayName,
                                              MP_INVALID_CONNECTION_ID,
                                              i);
       assert(result == OS_SUCCESS);
#endif // INSERT_DELAY_RESOURCE ]

       // Link RTP input -> decoder
       result = resourceTopology->addConnection(DEFAULT_RTP_INPUT_RESOURCE_NAME, i,
                                                tmpDecodeName, 0);
       assert(result == OS_SUCCESS);
       UtlString &lastResourceName = tmpDecodeName;

       // -> Voice Activity Notifier
       result = resourceTopology->addConnection(lastResourceName, 0,
                                                tmpActivityNotifName, 0);
       assert(result == OS_SUCCESS);
       lastResourceName = tmpActivityNotifName;

#ifdef INSERT_DELAY_RESOURCE // [
       // -> Delay
       result = resourceTopology->addConnection(lastResourceName, 0,
                                                tmpDelayName, 0);
       assert(result == OS_SUCCESS);
       lastResourceName = tmpDelayName;
#endif // INSERT_DELAY_RESOURCE ]

       // Mark last resource as RTP Stream Output
       UtlString streamOutputName(VIRTUAL_NAME_RTP_STREAM_OUTPUT);
       streamOutputName.append(streamSuffix);
       result = resourceTopology->addVirtualOutput(lastResourceName, 0,
                                                   streamOutputName, 0);
       assert(result == OS_SUCCESS);

       // -> bridge
       result = resourceTopology->addConnection(lastResourceName, 0,
                                                VIRTUAL_NAME_CONNECTION_PORTS,
                                                MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT);
       assert(result == OS_SUCCESS);
    }


    addOutputConnectionTopology(resourceTopology, -1);

    return(resourceTopology);
}