Пример #1
0
static void
bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) {
    sl_log("bqPlayerCallback!!!\n");
    struct sl_source* source = (struct sl_source*)context;
    if(source->is_loop) {
        sl_log("bqPlayerCallback!!! loop it!!!\n");
        _source_enqueue(source);
    }
}
Пример #2
0
/***************************************************************************
 * dlog_streamproc():
 * Save MiniSEED records in an old style SeisComP/datalog
 * directory/file structure.  The appropriate directories and files
 * are created if nesecessary.  If files already exist they are
 * appended to.  If both 'basedir' and 'msr' are NULL then
 * ds_shutdown() will be called to close all open files and free all
 * associated memory.
 *
 * Returns 0 on success, -1 on error.
 ***************************************************************************/
int
dlog_streamproc (const char *basedir, const SLMSrecord *msr, int reclen,
		 int type, int idletimeout)
{
  static DataStream *streamroot = NULL;
  char format[400];

  /* Check if this is a call to shut everything down */
  if (basedir == NULL && msr == NULL)
    {
      sl_log (0, 1, "Shutting down SC/datalog archiving\n");
      ds_streamproc (&streamroot, NULL, NULL, 0, 0, 0);
      return 0;
    }

  if ( ! strncmp(msr->fsdh.location, "  ", 2) )
    { /* No location code */
      snprintf (format, sizeof(format),
		"%s/%%s/%%c.%%t/%%s.%%n.%%c.%%t.%%Y.%%j.#H#M",
		basedir);
    }
  else
    { /* Location code present */
      snprintf (format, sizeof(format),
		"%s/%%s/%%l.%%c.%%t/%%s.%%n.%%c.%%t.%%Y.%%j.#H#M",
		basedir);
    }

  return ds_streamproc (&streamroot, format, msr, reclen, type, idletimeout);
}				/* End of dlog_streamproc() */
Пример #3
0
/***************************************************************************
 * packet_handler():
 * Process a received packet based on packet type.
 ***************************************************************************/
static void
packet_handler (char *msrecord, int packet_type, int seqnum, int packet_size)
{
  static SLMSrecord * msr = NULL;

  double dtime;			/* Epoch time */
  double secfrac;		/* Fractional part of epoch time */
  time_t itime;			/* Integer part of epoch time */
  char timestamp[20];
  struct tm *timep;

  /* The following is dependent on the packet type values in libslink.h */
  char *type[]  = { "Data", "Detection", "Calibration", "Timing",
		    "Message", "General", "Request", "Info",
                    "Info (terminated)", "KeepAlive" };

  /* Build a current local time string */
  dtime   = sl_dtime ();
  secfrac = (double) ((double)dtime - (int)dtime);
  itime   = (time_t) dtime;
  timep   = localtime (&itime);
  snprintf (timestamp, 20, "%04d.%03d.%02d:%02d:%02d.%01.0f",
	    timep->tm_year + 1900, timep->tm_yday + 1, timep->tm_hour,
	    timep->tm_min, timep->tm_sec, secfrac);

  /* Process waveform data */
  if ( packet_type == SLDATA )
    {
      sl_log (0, 1, "%s, seq %d, Received %s blockette:\n",
	      timestamp, seqnum, type[packet_type]);

      sl_msr_parse (slconn->log, msrecord, &msr, 1, 0);

      if ( verbose || ppackets )
	sl_msr_print (slconn->log, msr, ppackets);
    }
  else if ( packet_type == SLKEEP )
    {
      sl_log (0, 2, "Keep alive packet received\n");
    }
  else
    {
      sl_log (0, 1, "%s, seq %d, Received %s blockette\n",
	      timestamp, seqnum, type[packet_type]);
    }
}				/* End of packet_handler() */
Пример #4
0
long 
strtol(const char *in, char **out, int base)
{
	long total=0;
	int i=0;

	if (out || base != 10) {
		sl_log(LOG_ERR, "incomplete strtol called in unsupported mode");
		return 0;
	}

	while (in[i] >= '0' && in[i] <= '9') {
		total *= 10;
		total += in[i] - '0';
		i++;
	}
	return total;
}
Пример #5
0
/***************************************************************************
 * arch_streamproc(): 
 * Save MiniSEED records in a custom directory/file structure.  The
 * appropriate directories and files are created if nesecessary.  If
 * files already exist they are appended to.  If both 'archformat' and
 * 'msr' are NULL then ds_shutdown() will be called to close all open files
 * and free all associated memory.
 *
 * Returns 0 on success, -1 on error.
 ***************************************************************************/
int
arch_streamproc (const char *archformat, const SLMSrecord *msr, int reclen,
		 int type, int idletimeout)
{
  static DataStream *streamroot = NULL;
  char format[400];

  /* Check if this is a call to shut everything down */
  if (archformat == NULL && msr == NULL)
    {
      sl_log (0, 1, "Shutting down stream archiving\n");
      ds_streamproc (&streamroot, NULL, NULL, 0, 0, 0);
      return 0;
    }

  strncpy (format, archformat, sizeof(format) - 1);

  return ds_streamproc (&streamroot, format, msr, reclen, type, idletimeout);
}				/* End of arch_streamproc() */
Пример #6
0
/***************************************************************************
 * bud_streamproc(): 
 * Save MiniSEED records in a BUD directory/file structure.  The
 * appropriate directories and files are created if nesecessary.  If
 * files already exist they are appended to.  If both 'basedir' and 'msr'
 * are NULL then ds_shutdown() will be called to close all open files and
 * free all associated memory.
 *
 * Returns 0 on success, -1 on error.
 ***************************************************************************/
int
bud_streamproc (const char *basedir, const SLMSrecord *msr, int reclen,
	        int idletimeout)
{
  static DataStream *streamroot = NULL;
  char format[400];

  /* Check if this is a call to shut everything down */
  if (basedir == NULL && msr == NULL)
    {
      sl_log (0, 1, "Shutting down BUD archiving\n");
      ds_streamproc (&streamroot, NULL, NULL, 0, 0, 0);
      return 0;
    }

  snprintf (format, sizeof(format),
	    "%s/%%n/%%s/%%s.%%n.%%l.%%c.%%Y.%%j",
	    basedir);

  return ds_streamproc (&streamroot, format, msr, reclen, SLDATA, idletimeout);
}				/* End of bud_streamproc() */
Пример #7
0
/***************************************************************************
 * parameter_proc:
 *
 * Process the command line parameters.
 *
 * Returns 0 on success, and -1 on failure
 ***************************************************************************/
static int
parameter_proc (int argcount, char **argvec)
{
  int optind;
  int error = 0;
  
  char *streamfile  = 0;	/* stream list file for configuring streams */
  char *multiselect = 0;
  char *selectors   = 0;

  if (argcount <= 1)
    error++;

  /* Process all command line arguments */
  for (optind = 1; optind < argcount; optind++)
    {
      if (strcmp (argvec[optind], "-V") == 0)
	{
	  fprintf(stderr, "%s version: %s\n", PACKAGE, VERSION);
	  exit (0);
	}
      else if (strcmp (argvec[optind], "-h") == 0)
	{
	  usage();
	  exit (0);
	}
      else if (strncmp (argvec[optind], "-v", 2) == 0)
	{
	  verbose += strspn (&argvec[optind][1], "v");
	}
      else if (strcmp (argvec[optind], "-p") == 0)
	{
	  ppackets = 1;
	}
      else if (strcmp (argvec[optind], "-nt") == 0)
	{
	  slconn->netto = atoi (argvec[++optind]);
	}
      else if (strcmp (argvec[optind], "-nd") == 0)
	{
	  slconn->netdly = atoi (argvec[++optind]);
	}
      else if (strcmp (argvec[optind], "-k") == 0)
	{
	  slconn->keepalive = atoi (argvec[++optind]);
	}
      else if (strcmp (argvec[optind], "-l") == 0)
	{
	  streamfile = argvec[++optind];
	}
      else if (strcmp (argvec[optind], "-s") == 0)
	{
	  selectors = argvec[++optind];
	}
      else if (strcmp (argvec[optind], "-S") == 0)
	{
	  multiselect = argvec[++optind];
	}
      else if (strcmp (argvec[optind], "-x") == 0)
	{
	  statefile = argvec[++optind];
	}
      else if (strncmp (argvec[optind], "-", 1 ) == 0)
	{
	  fprintf(stderr, "Unknown option: %s\n", argvec[optind]);
	  exit (1);
	}
      else if (!slconn->sladdr)
	{
	  slconn->sladdr = argvec[optind];
	}
      else
	{
	  fprintf(stderr, "Unknown option: %s\n", argvec[optind]);
	  exit (1);
	}
    }


  /* Make sure a server was specified */
  if ( ! slconn->sladdr )
    {
      fprintf(stderr, "%s version: %s\n\n", PACKAGE, VERSION);
      fprintf(stderr, "No SeedLink server specified\n\n");
      fprintf(stderr, "Usage: %s [options] [host][:port]\n", PACKAGE);
      fprintf(stderr, "Try '-h' for detailed help\n");
      exit (1);
    }

  /* Initialize the verbosity for the sl_log function */
  sl_loginit (verbose, NULL, NULL, NULL, NULL);
  
  /* Report the program version */
  sl_log (0, 1, "%s version: %s\n", PACKAGE, VERSION);
  
  /* If errors then report the usage message and quit */
  if (error)
    {
      usage ();
      exit (1);
    }

  /* If verbosity is 2 or greater print detailed packet infor */
  if ( verbose >= 2 )
    ppackets = 1;
  
  /* Load the stream list from a file if specified */
  if ( streamfile )
    sl_read_streamlist (slconn, streamfile, selectors);
  
  /* Parse the 'multiselect' string following '-S' */
  if ( multiselect )
    {
      if ( sl_parse_streamlist (slconn, multiselect, selectors) == -1 )
	return -1;
    }
  else if ( !streamfile )
    {			 /* No 'streams' array, assuming uni-station mode */
      sl_setuniparams (slconn, selectors, -1, 0);
    }
  
  /* Attempt to recover sequence numbers from state file */
  if (statefile)
    {
      if (sl_recoverstate (slconn, statefile) < 0)
	{
	  sl_log (2, 0, "state recovery failed\n");
	}
    }
  
  return 0;
}				/* End of parameter_proc() */
Пример #8
0
struct sl_source*
sl_source_gen() {
    struct sl_source* ret = (struct sl_source*)malloc(sizeof(*ret));
    if(!ret)
        return NULL;

    SLresult result;

    // configure audio source
    SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
    SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM, 1, SL_SAMPLINGRATE_44_1,
        SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16,
        SL_SPEAKER_FRONT_CENTER, SL_BYTEORDER_LITTLEENDIAN};
    SLDataSource audioSrc = {&loc_bufq, &format_pcm};

    // configure audio sink
    SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, ENV.outputMixObject};
    SLDataSink audioSnk = {&loc_outmix, NULL};

    // create audio player
    const SLInterfaceID ids[3] = {SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND,
            /*SL_IID_MUTESOLO,*/ SL_IID_VOLUME};
    const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE,
            /*SL_BOOLEAN_TRUE,*/ SL_BOOLEAN_TRUE};
    sl_log("sl_source_gen!!!! begin!!!\n");
    result = (*ENV.engineEngine)->CreateAudioPlayer(ENV.engineEngine, &ret->bqPlayerObject, &audioSrc, &audioSnk,
            3, ids, req);
    sl_log("sl_source_gen!!!! end : %d!!!\n", result);
    _check_result(result);

    // realize the player
    result = (*ret->bqPlayerObject)->Realize(ret->bqPlayerObject, SL_BOOLEAN_FALSE);
    _check_result(result);


    // get the play interface
    result = (*ret->bqPlayerObject)->GetInterface(ret->bqPlayerObject, SL_IID_PLAY, &ret->bqPlayerPlay);
    _check_result(result);

    // get the buffer queue interface
    result = (*ret->bqPlayerObject)->GetInterface(ret->bqPlayerObject, SL_IID_BUFFERQUEUE,
            &ret->bqPlayerBufferQueue);
    _check_result(result);

    // register callback on the buffer queue
    result = (*ret->bqPlayerBufferQueue)->RegisterCallback(ret->bqPlayerBufferQueue, bqPlayerCallback, (void*)ret);
    _check_result(result);

    // get the volume interface
    result = (*ret->bqPlayerObject)->GetInterface(ret->bqPlayerObject, SL_IID_VOLUME, &ret->bqPlayerVolume);
    _check_result(result);

    // get the pitch interface, may be feature unsupported
    result = (*ret->bqPlayerObject)->GetInterface(ret->bqPlayerObject, SL_IID_PITCH, &ret->bqPlayerPitch);

    // set the player's state to playing
    result = (*ret->bqPlayerPlay)->SetPlayState(ret->bqPlayerPlay, SL_PLAYSTATE_PLAYING);
    _check_result(result);

    source_buffer_add(&ENV.source_record, ret);
    return ret;

ERROR:
    sl_source_free(ret);
    return NULL;
}