Exemplo n.º 1
0
MpBufPtr MpBuf_getFgSilence()
{
   MpBuf_addRef(MpMisc.XXXsilence);
   return(MpMisc.XXXsilence);
}
Exemplo n.º 2
0
MpBufPtr MpBuf_getDmaSilence()
{
   MpBuf_addRef(MpMisc.XXXlongSilence);
   return(MpMisc.XXXlongSilence);
}
Exemplo n.º 3
0
UtlBoolean MprRecorder::doProcessFrame(MpBufPtr inBufs[],
                                   MpBufPtr outBufs[],
                                   int inBufsSize,
                                   int outBufsSize,
                                   UtlBoolean isEnabled,
                                   int samplesPerFrame,
                                   int samplesPerSecond)
{
   int numBytes = 0;
   int numSamples = 0;
   MpBufPtr in = NULL;
   Sample* input;

   // Lock so that mFileDescriptor and file contents cannot be changed out
   // from under us while we are updating the file.
   OsLock lock(mMutex);

   //try to pass along first input
   if (inBufsSize > 0)
   {
      in = *inBufs;
   }

   if (numOutputs() > 0)
   {
      if (inBufsSize > 0) *inBufs = NULL;
      *outBufs = in;
   }

   if (!isEnabled) {
      return TRUE;
   }

   if (mFileDescriptor < 0)
   {
      OsSysLog::add(FAC_MP, PRI_DEBUG, "MprRecorder::doProcessFrame to disable recording because mFileDescriptor=%d, mStatus=%d",
            mFileDescriptor, mStatus);
      disable(RECORD_STOPPED); // just in case...
   }

   if (inBufsSize == 0) {
      // no input buffers, indicate config error
      disable(INVALID_SETUP);
      return TRUE;
   }

   // maximum record time reached or final silence timeout.
   if ((0 >= mFramesToRecord--) || (mSilenceLength <= mConsecutiveInactive)) {
      // Get previous MinVoiceEnergy for debug printouts, and reset it to MIN_SPEECH_ENERGY_THRESHOLD.
      unsigned long prevValue = MpBuf_setMVE(MIN_SPEECH_ENERGY_THRESHOLD);

      OsSysLog::add(FAC_MP, PRI_INFO,
         "MprRecorder::doProcessFrame to disable recording because"
         " mFramesToRecord=%d, mStatus=%d mSilenceLength=%d,"
         " mConsecutiveInactive=%d, MinVoiceEnergy=%lu", mFramesToRecord,
         mStatus, mSilenceLength, mConsecutiveInactive, prevValue);
      disable(RECORD_FINISHED);
   } else {

      int bytesWritten = 0;

      //now write the buffer out

      if (NULL == in) {
         in = MpBuf_getFgSilence();
      } else {
        MpBuf_addRef(in);
      }

      if (MpBuf_isActiveAudio(in)) {
        mConsecutiveInactive = 0;
      } else {
        mConsecutiveInactive++;
      }

      input = MpBuf_getSamples(in);
      numSamples = MpBuf_getNumSamples(in);
      numBytes = numSamples * sizeof(Sample);
      if (mFileDescriptor > -1)
      {
#ifdef __BIG_ENDIAN__
         //We are running on a big endian processor - 16-bit samples are in the big endian
         //byte order - convert them to little endian before writing them to the file.
         unsigned short *pData;
         int index;

         for ( index = 0, pData = (unsigned short *)input; index < numSamples; index++, pData++ )
             *pData = htoles(*pData);
#endif
         bytesWritten = write(mFileDescriptor, (char *)input, numBytes);
#ifdef __BIG_ENDIAN__
         if (numOutputs() > 1)
         {
             //There is more than one output - convert the samples back to big endian
             for ( index = 0, pData = (unsigned short *)input; index < numSamples; index++, pData++ )
                 *pData = letohs(*pData);
         }
#endif
      }

      if (bytesWritten != numBytes) {
         disable(WRITE_ERROR);
      } else {
         mTotalBytesWritten += numBytes;
         mTotalSamplesWritten += samplesPerFrame;
      }
      MpBuf_delRef(in);
   }
   return TRUE;
}