Esempio n. 1
0
int main(int argc, char* argv[])
{
  if(argc==1) {
    return ProcessStream(cin, cout);
  }
  else if(argv[1][0]=='-' || argc > 1+1) {
    cout << usage;
    return 1;
  }
  else {
    CNcbiIfstream in(argv[1]);
    if( !in.good() ) {
      cerr << "Error - cannot open for reading: " << argv[1] << "\n";
      return 1;
    }
    return ProcessStream(in, cout);
  }
}
Esempio n. 2
0
void Video::Run(){
	server = CameraServer::GetInstance();

	LiveConfigure();
	SelectFront();

	while (!myConfig->StopCapture)
	{
		// Check for a camera toggle
		if (myController->Get_ButtonState().LeftBumper) ToggleView();
		ProcessStream();
		if (myConfig->configUpdateCount > currentUpdate) LiveConfigure();
	}
}
Esempio n. 3
0
inline void PAPlayer::ProcessStreams(double &delay, double &buffer)
{
  CSharedLock sharedLock(m_streamsLock);
  if (m_isFinished && m_streams.empty() && m_finishing.empty())
  {
    m_isPlaying = false;
    delay       = 0;
    m_callback.OnPlayBackEnded();
    return;
  }

  /* destroy any drained streams */
  for(StreamList::iterator itt = m_finishing.begin(); itt != m_finishing.end();)
  {
    StreamInfo* si = *itt;
    if (si->m_stream->IsDrained())
    {      
      itt = m_finishing.erase(itt);
      CAEFactory::FreeStream(si->m_stream);
      delete si;
      CLog::Log(LOGDEBUG, "PAPlayer::ProcessStreams - Stream Freed");
    }
    else
      ++itt;
  }

  sharedLock.Leave();
  CExclusiveLock lock(m_streamsLock);

  for(StreamList::iterator itt = m_streams.begin(); itt != m_streams.end(); ++itt)
  {
    StreamInfo* si = *itt;
    if (!m_currentStream && !si->m_started)
    {
      m_currentStream = si;
      UpdateGUIData(si); //update for GUI
    }
    /* if the stream is finishing */
    if ((si->m_playNextTriggered && si->m_stream && !si->m_stream->IsFading()) || !ProcessStream(si, delay, buffer))
    {
      if (!si->m_prepareTriggered)
      {
        si->m_prepareTriggered = true;
        m_callback.OnQueueNextItem();
      }

      /* remove the stream */
      itt = m_streams.erase(itt);
      /* if its the current stream */
      if (si == m_currentStream)
      {
        /* if it was the last stream */
        if (itt == m_streams.end())
        {
          /* if it didnt trigger the next queue item */
          if (!si->m_prepareTriggered)
          {
            m_callback.OnQueueNextItem();
            si->m_prepareTriggered = true;
          }
          m_currentStream = NULL;
        }
        else
        {
          m_currentStream = *itt;
          UpdateGUIData(*itt); //update for GUI
        }
      }

      /* unregister the audio callback */
      si->m_stream->UnRegisterAudioCallback();
      si->m_decoder.Destroy();      
      si->m_stream->Drain();
      m_finishing.push_back(si);
      return;
    }

    if (!si->m_started)
      continue;

    /* is it time to prepare the next stream? */
    if (si->m_prepareNextAtFrame > 0 && !si->m_prepareTriggered && si->m_framesSent >= si->m_prepareNextAtFrame)
    {
      si->m_prepareTriggered = true;
      m_callback.OnQueueNextItem();
    }

    /* it is time to start playing the next stream? */
    if (si->m_playNextAtFrame > 0 && !si->m_playNextTriggered && si->m_framesSent >= si->m_playNextAtFrame)
    {
      if (!si->m_prepareTriggered)
      {
        si->m_prepareTriggered = true;
        m_callback.OnQueueNextItem();
      }

      if (!m_isFinished)
      {
        if (m_upcomingCrossfadeMS)
        {
          si->m_stream->FadeVolume(1.0f, 0.0f, m_upcomingCrossfadeMS);
          si->m_fadeOutTriggered = true;
        }
        m_currentStream = NULL;

        /* unregister the audio callback */
        si->m_stream->UnRegisterAudioCallback();
      }

      si->m_playNextTriggered = true;
    }
  }
}
Esempio n. 4
0
Int2 Main(void)
{
  Char             app [64];
  CharPtr          directory;
  CharPtr          ptr;
  Char             sfx [32];
  OutputStreamData osd;
  InputStreamData  isd;
  AsnStreamData    asd;
  Int4             gap_sizes[2];
  Int4             rval = 0;
  Int4             u_eq = 0, u_gteq = -1, k_eq = 0, k_gteq = -1;

  /* standard setup */

  ErrSetFatalLevel (SEV_MAX);
  ErrClearOptFlags (EO_SHOW_USERSTR);
  UseLocalAsnloadDataAndErrMsg ();
  ErrPathReset ();

  /* finish resolving internal connections in ASN.1 parse tables */

  if (! AllObjLoad ()) {
    Message (MSG_FATAL, "AllObjLoad failed");
    return 1;
  }
  if (! SubmitAsnLoad ()) {
    Message (MSG_FATAL, "SubmitAsnLoad failed");
    return 1;
  }
  if (! FeatDefSetLoad ()) {
    Message (MSG_FATAL, "FeatDefSetLoad failed");
    return 1;
  }
  if (! SeqCodeSetLoad ()) {
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
    return 1;
  }
  if (! GeneticCodeTableLoad ()) {
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
    return 1;
  }

  SetUpAsnStreamData (&asd);

  /* initialize OuputStreamData */
  MemSet (&osd, 0, sizeof (osd));

  /* initialize InputStreamData */
  MemSet (&isd, 0, sizeof (isd));

  /* initialize gap_sizes */
  gap_sizes[0] = 0;
  gap_sizes[1] = 0;

  /* process command line arguments */

  sprintf (app, "raw2delt %s", RAW2DELT_APPLICATION);
  if (! GetArgs (app, sizeof (myargs) / sizeof (Args), myargs)) {
    return 0;
  }

  u_eq = (Int4) myargs [u_argEqUnknownGap].intvalue;
  u_gteq = (Int4) myargs [U_argGTEqUnknownGap].intvalue;
  k_eq = (Int4) myargs [k_argEqUnknownGap].intvalue;
  k_gteq = (Int4) myargs [K_argGtEqUnknownGap].intvalue;

  if (u_eq < 1 && u_gteq < 1 && k_eq < 1 && k_gteq < 1) {
    Message (MSG_FATAL, "Must specify values for at least one of -u, -U, -k, -K");
    return 1;
  } else if (u_eq > -1 && u_gteq > -1) {
    Message (MSG_FATAL, "May only specify value for -u or -U, not both");
    return 1;
  } else if (k_eq > -1 && k_gteq > -1) {
    Message (MSG_FATAL, "May only specify value for -k or -K, not both");
    return 1;
  }
    
  if (u_eq > 0) {
    gap_sizes[0] = u_eq;
  } else if (u_gteq > 0) {
    gap_sizes[0] = 0 - u_gteq;
  }

  if (k_eq > 0) {
    gap_sizes[1] = k_eq;
  } else if (k_gteq > 0) {
    gap_sizes[1] = 0 - k_gteq;
  }

  if (gap_sizes[0] == gap_sizes[1]) {
    Message (MSG_FATAL, "Cannot specify the same size for known and unknown length gaps");
    return 1;
  }

  directory = (CharPtr) myargs [p_argInputPath].strvalue;
  osd.results_dir = (CharPtr) myargs [r_argOutputPath].strvalue;
  if (StringHasNoText (osd.results_dir)) {
    osd.results_dir = NULL;
  }
  osd.suffix = (CharPtr) myargs [x_argSuffix].strvalue;
  osd.outsuffix = (CharPtr) myargs [s_argOutSuffix].strvalue;
  osd.base = (CharPtr) myargs [i_argInputFile].strvalue;
  osd.outfile = (CharPtr) myargs [o_argOutputFile].strvalue;
  if (StringHasNoText (osd.outfile)) {
    osd.outfile = NULL;
  }
  osd.is_binary = (Boolean) myargs [d_argOutputBinary].intvalue;

  if (osd.base == "stdin") {
    osd.base = NULL;
  }

  /* if we don't have an output directory or an output file, and the user hasn't provided an
   * output suffix, add a default.
   */
  if (osd.results_dir == NULL && osd.outfile == NULL && StringHasNoText (osd.outsuffix)) {
    osd.outsuffix = ".delta";
  } 

  isd.is_binary = (Boolean) myargs [b_argInputBinary].intvalue;
  isd.is_seqentry = (Boolean) myargs [e_argInputSeqEntry].intvalue;
  isd.directory = directory;
  isd.base = osd.base;
  isd.suffix = osd.suffix;

  if (StringDoesHaveText (osd.outfile)) {
    osd.aip = AsnIoOpen (osd.outfile, "w");
    if (osd.aip == NULL) {
      Message (MSG_FATAL, "Unable to open output file");
      return 1;
    }
  } else {
    if (StringHasNoText (osd.results_dir)) {
      osd.results_dir = directory;
    }
    /* if we're putting the results in a separate directory, strip the directory name from the output base */
    if (!StringHasNoText (osd.results_dir) && !StringHasNoText (osd.base)) {
#ifdef OS_MSWIN
      ptr = StringRChr (osd.base, '\\');
#else
      ptr = StringRChr (osd.base, '/');
#endif;
      if (ptr != NULL) {
        osd.base = ptr + 1;
      }
    }
  }


  if (StringHasNoText(directory) && StringHasNoText(osd.base)) {
    rval = ProcessStream (&isd, &osd, &asd, gap_sizes);
  } else if (StringDoesHaveText (osd.base)) {
    ptr = StringRChr (osd.base, '.');
    sfx[0] = '\0';
    if (ptr != NULL) {
      StringNCpy_0 (sfx, ptr, sizeof (sfx));
      *ptr = '\0';
    }
    osd.suffix = sfx;
    isd.suffix = sfx;
    if (isd.is_binary) {
      rval = ProcessStream (&isd, &osd, &asd, gap_sizes);
    } else {
      rval = ProcessOneRecord (directory, &osd, gap_sizes);
    }
  } else {

    rval = FileRecurse (directory, &isd, &osd, &asd, gap_sizes);
  }

  if (osd.aip != NULL) {
    AsnIoFlush (osd.aip);
    AsnIoClose (osd.aip);
  }
  return rval;
}
Esempio n. 5
0
/* return -1 on failure, 0 on success */
static Int4 FileRecurse (
  CharPtr         directory,
  InputStreamPtr  isp,
  OutputStreamPtr osp,
  AsnStreamPtr    asp,
  Int4Ptr         gap_sizes
)

{
  Char        path [PATH_MAX];
  CharPtr     ptr;
  CharPtr     str;
  ValNodePtr  head, vnp;
  CharPtr     orig_dir, orig_base;
  Int4        rval = 0;

  /* get list of all files in source directory */

  head = DirCatalog (directory);

  for (vnp = head; vnp != NULL; vnp = vnp->next) {
    if (vnp->choice == 0) {
      str = (CharPtr) vnp->data.ptrvalue;
      if (StringDoesHaveText (str)) {

        /* does filename have desired substring? */

        ptr = StringStr (str, osp->suffix);

        if (ptr != NULL) {

          /* make sure detected suffix is really at end of filename */

          if (StringCmp (ptr, osp->suffix) == 0) {
            *ptr = '\0';

            /* process file that has desired suffix (usually .fsa) */
            osp->base = str;
            orig_dir = isp->directory;
            isp->directory = directory;
            orig_base = isp->base;
            isp->base = str;
            if (isp->is_binary) {
              rval |= ProcessStream (isp, osp, asp, gap_sizes);
            } else {
              rval |= ProcessOneRecord (directory, osp, gap_sizes);
            }
            isp->directory = orig_dir;
            isp->base = orig_base;
            osp->base = NULL;
          }
        }
      }
    } else if (vnp->choice == 1) {

      /* recurse into subdirectory */

      StringNCpy_0 (path, directory, sizeof (path));
      str = (CharPtr) vnp->data.ptrvalue;
      FileBuildPath (path, str, NULL);
      rval |= FileRecurse (path, isp, osp, asp, gap_sizes);
    }
  }

  /* clean up file list */

  ValNodeFreeData (head);
  return rval;
}
Esempio n. 6
0
int main(int argc, char *argv[])
#endif
{
    int       list_s;
    int       sock;
    short int port;
    struct    sockaddr_in servaddr;
    int maxBuffer = PHS_GetRequestBufferLength();
    unsigned char* request;
    unsigned int requestLen;
    unsigned int responseType;
    int res;
    unsigned char responseHeader[4];
    unsigned char* response;
    unsigned int responseLength;
    char** cursor;
    int ok;
    int repeat;

#if defined(WIN32)
    WSADATA data;
    if(WSAStartup(MAKEWORD(2, 2), &data))
    {
	printf("WSAStartup failed\n");
	exit(1);
    }
#endif

    request = malloc(maxBuffer);

    if(argc < 3)
    {
	printf("Usage %s [ip4address:]port request ...\n",argv[0]);
	printf("where request is one of\n");
	printf("  status logid\n");
	printf("  fetch logid blockid\n");
	printf("  stream logid latency buffersize\n");
	exit(1);
    }

    /* Set up server address */
    if(!FillAddress(argv[1],&servaddr))
    {
	printf( "%s: Invalid server address %s\n",argv[0], argv[1]);
	exit(1);
    }
    cursor = argv+2;
    argc-=2;

    /*  Create the socket  */
    if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
    {
      printf( "Error creating socket %d.\n",sock);
	perror("Error");
	exit(1);
    }

    if(connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr))<0)
    {
	printf("Error calling connect()\n");
	exit(1);
    }

    /* Loop round all requests on the command line */
    ok = 1;
    while(argc)
    {
	/* Create a request */
	if(!strcmp("status",cursor[0]))
	{
	    int logid;
	    if(argc<2)
	    {
		printf("Usage: status logid\n");
		exit(1);
	    }
	    logid = ParseInt(cursor[1],&ok);
	    if(!ok)
	    {
		printf("Invalid logid\n");
		exit(1);
	    }
	    requestLen = PHS_MakeStatusRequest(request,maxBuffer,&responseType,logid);
	    printf("Sending Status Request logid %d\n",logid);
	    cursor += 2;
	    argc -= 2;
	}
	else if(!strcmp("fetch",cursor[0]))
	{
	    int logid, blockid;
	    if(argc<3)
	    {
		printf("Usage: fetch logid blockid\n");
		exit(1);
	    }
	    logid = ParseInt(cursor[1],&ok);
	    if(!ok)
	    {
		printf("Invalid logid\n");
		exit(1);
	    }
	    blockid = ParseInt(cursor[2],&ok);
	    if(!ok)
	    {
		printf("Invalid blockid\n");
		exit(1);
	    }
	    requestLen = PHS_MakeFetchRequest(request,maxBuffer,&responseType,
					      logid,blockid);
	    printf("Sending Fetch Request logid %d blockid %d\n",
		   logid,blockid);
	    cursor += 3;
	    argc -= 3;
	}
	else if(!strcmp("stream",cursor[0]))
	{
	    int logid, latency, buffersize, tag;
	    if(argc<5)
	    {
		printf("Usage: stream logid latency buffersize highesttag\n");
		exit(1);
	    }
	    logid = ParseInt(cursor[1],&ok);
	    if(!ok)
	    {
		printf("Invalid logid\n");
		exit(1);
	    }
	    latency = ParseInt(cursor[2],&ok);
	    if(!ok)
	    {
		printf("Invalid latency\n");
		exit(1);
	    }
	    buffersize = ParseInt(cursor[3],&ok);
	    if(!ok)
	    {
		printf("Invalid buffersize\n");
		exit(1);
	    }
	    tag = ParseInt(cursor[4],&ok);
	    if(!ok)
	    {
		printf("Invalid highesttag\n");
		exit(1);
	    }
	    requestLen = PHS_MakeStreamRequest(request,maxBuffer,&responseType,
					       logid,latency,buffersize,tag);
	    printf("Sending Stream Request logid %d latency %d buffersize %d tag %d\n",
		   logid,latency,buffersize,tag);
	    cursor += 5;
	    argc -= 5;
	}
	else
	{
	    printf("Request %s is not understood\n",cursor[0]);
	    exit(1);
	}

	/* Send request out */
	res = send(sock,request,requestLen,0);
	if(res != requestLen)
	{
	    printf("Expected to write %d but only wrote %d\n",requestLen,res);
	}

	repeat = 1;
	while(repeat)
	{
	    /* Read the length back */
	    res = Recv(sock,responseHeader,4,0);
	    if(res != 4)
	    {
		printf("Could not read response header\n");
		exit(1);
	    }

	    /* Make space for the response */
	    responseLength=PHS_GetResponseRemaining(responseHeader);
	    response = malloc(responseLength);

	    /* Read the rest of the response */
	    res = Recv(sock,response,responseLength,0);
	    if(res != responseLength)
	    {
		printf("Could not read response body\n");
		exit(1);
	    }

	    printf("Read %d bytes in body\n",responseLength);

	    /* Check that response is valid or in error */
	    res = PHS_GetResponseError(response,responseLength,responseType);
	    if(res)
	    {
		printf("Response has error %d\n",res);
		exit(1);
	    }

	    switch(responseType)
	    {
	    case PHS_RQ_STATUS:
		ProcessStatus(response);
		repeat = 0;
		break;
	    case PHS_RQ_FETCH:
		ProcessFetch(response);
		repeat = 0;
		break;
	    case PHS_RQ_STREAM:
		ProcessStream(response);
		break;
	    default:
		printf("Cannot handle response type %d\n",responseType);
		break;
	    }
	    free(response);
	}
    }
    return 0;
}