static void writeFiles()
{
  int i;
  int size = listSize(fileWriteList);
  for(i=0;i<size;i++)
  {
    struct FileWriteObject *object = getElement(fileWriteList,i);
    if(object->fileStatus == 1)
    {
      while(listSize(object->writeObjects) > 0)
      {
        // TODO: optomize this method.
        // When writing lots of small blocks of data, they should be combined into a single 
        // larger file write.
        struct node *obj = popData(object->writeObjects);
        struct bufferData *data = obj->data;
        destroyList(obj);

        if(object->wav == NULL)
          fwrite(data->data,sizeof(short),data->length,object->stream);
        else
          WAV_WriteData(object->wav,object->stream,data);
      }
    }
  }
}
static void openPendingFiles()
{
  struct node *listObject;
  struct FileWriteObject *object;
  pthread_mutex_lock(&writeMutex);
  if(listSize(fileOpenList) > 0)
  {
    listObject = popData(fileOpenList);
    pthread_mutex_unlock(&writeMutex);
    object = (struct FileWriteObject*)listObject->data;
    destroyList(listObject);

    // Warning: this can block.
    FILE *stream = fopen(object->fileName,"w");
    if(stream != NULL)
    {
      object->stream = stream;

      pthread_mutex_lock(&writeMutex);
      object->fileStatus = 1;
      pthread_mutex_unlock(&writeMutex);
      addToWritePendingList(object);

    }
    else
    {
      object->fileStatus = -1;	
      pthread_mutex_unlock(&writeMutex);
    }
  }
  else
    pthread_mutex_unlock(&writeMutex);

}
Exemple #3
0
void MprDelay::MprDelayFifo::pushData(MpAudioBufPtr& databuff)
{
   // Update number of active frames.
   if (databuff.isValid() && isActiveAudio(databuff->getSpeechType()))
   {
      mNumActiveFrames++;
   }

   // Store original start position and move it forward.
   int origStartPosition = mStartPosition;
   mStartPosition++;
   if (mStartPosition >= mBuffSize)
   {
      mStartPosition = 0;
   }

   // Store frame to the buffer.
   mBuff[origStartPosition].swap(databuff);

   // Check for overflow by checking start and end pointers equality.
   // If they're equal after we've moved mStartPosition, then queue was
   // full and have an overflow now.
   if (mEndPosition == mStartPosition)
   {
      // In case of overflow we must (1) bump mEndPosition and (2) adjust
      // mNumActiveFrames value according to the overwritten frame activity.
      MpAudioBufPtr emptyBuf;
      popData(emptyBuf);
      OsSysLog::add(FAC_AUDIO, PRI_WARNING,
                    "Delay FIFO buffer has overflowed! "
                    "Increase capacity of MprDelayFifo.");
   }
}
static void closePendingFiles()
{
  if(listSize(fileCloseList) > 0)
  {
    int size = 0;

    do  
    {
      struct FileWriteObject *object;
      struct node *listObject;

      pthread_mutex_lock(&writeMutex);
      size = listSize(fileCloseList) ;
      if(size > 0)
        listObject = popData(fileCloseList);
      else  
        // The fileCloseList is empty, nothing to do.
        break;
      pthread_mutex_unlock(&writeMutex);


      object = (struct FileWriteObject*)listObject->data;
      destroyList(listObject);
      listObject = NULL;

      // Remove the object from the writing list. 
      popElement(fileWriteList,object);


      flushOutstandingDataInObjectToFile(object);
      if(object->wav == NULL)
        fclose(object->stream);
      else
        closeWavSink(object->wav,object->stream);
      destroyWriteObject(object);

      size --;
    }while(size > 0);
  }
}
Exemple #5
0
static void openPendingFiles()
{
  struct node *listObject;
  struct FileReadObject *object;
  pthread_mutex_lock(&readMutex);


    if(listSize(fileOpenList) != 0)
      printf("Size is non-zero\n");
  
  
  if(listSize(fileOpenList) > 0)
  {
    listObject = popData(fileOpenList);
    pthread_mutex_unlock(&readMutex);
    object = (struct FileReadObject*)listObject->data;
    destroyList(listObject);

    // Warning: this can block.
    FILE *stream = fopen(object->fileName,"r");
    if(stream != NULL)
    {
      object->stream = stream;

      pthread_mutex_lock(&readMutex);
      object->fileStatus = 1;
      pthread_mutex_unlock(&readMutex);
      addToReadPendingList(object);

    }
    else
    {
      object->fileStatus = -1;	
      pthread_mutex_unlock(&readMutex);
    }
  }
  else
    pthread_mutex_unlock(&readMutex);

}
/**
 * Wait for the next data package to be ready and send it down to earth
 */
void DataHandler::sendData() {
    char* binaryData = (char*) malloc(MAPT_PACKAGE_SIZE * sizeof(char));
    popData(binaryData);
    s3tpHandler.send(binaryData, MAPT_PACKAGE_SIZE);
    delete binaryData;
}