Exemplo n.º 1
0
bool CConfigList::Load (void)
{
  DIR *dptr;
  struct dirent *fptr;

  dptr = opendir(m_directory);
  if (dptr == NULL) {
    error_message("Can't open directory %s", m_directory);
    return false;
  }
  
  while ((fptr = readdir(dptr)) != NULL) {
    char fname[PATH_MAX];
    sprintf(fname, "%s/%s", m_directory, fptr->d_name);
    struct stat buf;
    if (stat(fname, &buf) >= 0 &&
	S_ISREG(buf.st_mode)) {
      debug_message("trying %s", fname);
      m_config_list = CreateConfigInt(fname, m_config_list);
      m_config_list->Initialize();
      if (m_config_list->IsValid()) {
	m_config_count++;
	debug_message("loaded %s config %s", 
		      m_config_type, 
		      m_config_list->GetName());
	m_config_list->Update();
      }
    }
  }
  closedir(dptr);
  return true;
}
Exemplo n.º 2
0
// Audio encoding main process
int CAudioEncoder::ThreadMain(void) 
{
  CMsg* pMsg;
  bool stop = false;

  debug_message("audio encoder thread %s %s %s start", Profile()->GetName(),
		Profile()->GetStringValue(CFG_AUDIO_ENCODER), 
		Profile()->GetStringValue(CFG_AUDIO_ENCODING));

  while (stop == false && SDL_SemWait(m_myMsgQueueSemaphore) == 0) {
    pMsg = m_myMsgQueue.get_message();
    if (pMsg != NULL) {
      switch (pMsg->get_value()) {
      case MSG_NODE_STOP_THREAD:
	DoStopAudio();
	stop = true;
	break;
      case MSG_NODE_START:
	// DoStartTransmit();  Anything ?
	break;
      case MSG_NODE_STOP:
	DoStopAudio();
	break;
      case MSG_SINK_FRAME: {
	uint32_t dontcare;
	CMediaFrame *mf = (CMediaFrame*)pMsg->get_message(dontcare);
	if (m_stop_thread == false)
	  ProcessAudioFrame(mf);
	if (mf->RemoveReference()) {
	  delete mf;
	}
	break;
      }
      }
      
      delete pMsg;
    }
  }
  while ((pMsg = m_myMsgQueue.get_message()) != NULL) {
    if (pMsg->get_value() == MSG_SINK_FRAME) {
      uint32_t dontcare;
      CMediaFrame *mf = (CMediaFrame*)pMsg->get_message(dontcare);
      if (mf->RemoveReference()) {
	delete mf;
      }
    }
    delete pMsg;
  }

  if (m_audioResample != NULL) {
    for (uint ix = 0; ix < m_audioDstChannels; ix++) {
      st_resample_stop(m_audioResample[ix]);
      m_audioResample[ix] = NULL;
    }
    free(m_audioResample);
  }
  CHECK_AND_FREE(m_audioPreEncodingBuffer);
  debug_message("audio encoder thread %s exit", Profile()->GetName());
  return 0;
}
Exemplo n.º 3
0
static void
msvcrt_delete(void *p)
{
  debug_message("delete(%p) called: ", p);
  w32api_mem_free(p);
  debug_message("deleted.\n");
}
Exemplo n.º 4
0
static void restore_stat_list (const char * file, mudlib_stats_t ** list)
{
    FILE *f;
    char fname_buf[MAXPATHLEN];
    char *fname = fname_buf;
    mudlib_stats_t *entry;

    if (file) {
	if (strchr(file, '/')) {
	    if (file[0] == '/')
		file++;
	    f = fopen(file, "r");
	} else {
	    sprintf(fname, "%s/%s", LOG_DIR, file);
	    if (fname[0] == '/')
		fname++;
	    f = fopen(fname, "r");
	}
    } else {
	debug_message("*Warning: call to save_stat_list with null filename\n");
	return;
    }
    if (!f) {
	debug_message("*Warning: unable to open stat file %s for reading.\n",
		file);
	return;
    }
    while (fscanf(f, "%s", fname) != EOF) {
	entry = add_stat_entry(fname, list);
	fscanf(f, "%d %d\n", &entry->moves, &entry->heart_beats);
    }
    fclose(f);
}
Exemplo n.º 5
0
static void save_stat_list (const char * file, mudlib_stats_t * list)
{
    FILE *f;
    char fname_buf[MAXPATHLEN];
    char *fname = fname_buf;

    if (file) {
	if (strchr(file, '/')) {
	    if (file[0] == '/')
		file++;
	    f = fopen(file, "w");
	} else {
	    sprintf(fname, "%s/%s", LOG_DIR, file);
	    if (fname[0] == '/')
		fname++;
	    f = fopen(fname, "w");
	}
    } else {
	debug_message("*Warning: call to save_stat_list with null filename\n");
	return;
    }
    if (!f) {
	debug_message("*Error: unable to open stat file %s for writing.\n",
		file);
	return;
    }
    while (list) {
	fprintf(f, "%s %d %d\n", list->name,
		list->moves, list->heart_beats);
	list = list->next;
    }
    fclose(f);
}
Exemplo n.º 6
0
static bool ReadNextLine (text_file_data_t *tptr)
{
    off_t start;
    start = ftello(tptr->m_file);
    if (fgets(tptr->m_buffer, PATH_MAX, tptr->m_file) == NULL) {
        tptr->m_max_index = tptr->m_index;
        return false;
    }
    char *end = tptr->m_buffer + strlen(tptr->m_buffer) - 1;
    while (isspace(*end) && end > tptr->m_buffer) {
        *end = '\0';
        end--;
    }
    debug_message("Read line %u %s", tptr->m_index, tptr->m_buffer);

    if (tptr->m_line_offset_tail == NULL ||
            tptr->m_line_offset_tail->index < tptr->m_index) {
        text_line_offset_t *tlptr = MALLOC_STRUCTURE(text_line_offset_t);
        tlptr->next_line = NULL;
        tlptr->index = tptr->m_index;
        tlptr->offset = start;
        if (tptr->m_line_offset_head == NULL) {
            tptr->m_line_offset_head = tptr->m_line_offset_tail = tlptr;
        } else {
            tptr->m_line_offset_tail->next_line = tlptr;
            tptr->m_line_offset_tail = tlptr;
        }
        debug_message("Add to end");
    }
    tptr->m_index++;
    return true;
}
Exemplo n.º 7
0
void InstallSignalHandler (const char *sig,
			   void (*sighandler)(int),
			   bool setsigint)
{
  struct sigaction act;
  bool sigintset = false;

  act.sa_handler = sighandler;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;

  int maxsigs = sizeof(sig_str_to_value) / sizeof(sig_str_to_value[0]);
  if (sig != NULL && *sig != '\0') {
    debug_message("sigals are %s", sig);
    for (int ix = 0; ix < maxsigs; ix++) {
      if (strcasestr(sig, sig_str_to_value[ix].str) != NULL) {
	debug_message("installing sig %s", sig_str_to_value[ix].str);
	sigaction(sig_str_to_value[ix].value, &act, 0);
	if (sig_str_to_value[ix].value == SIGINT) {
	  sigintset = true;
	}
      }
    }
  }

  if (setsigint && sigintset == false) {
    sigaction(SIGINT, &act, 0);
  }
}
Exemplo n.º 8
0
static int
write_device(AudioDevice *ad, unsigned char *data, int size)
{
  ALSA_data *alsa = (ALSA_data *)ad->private_data;
  snd_pcm_sframes_t r;
  ssize_t unit = snd_pcm_samples_to_bytes(alsa->fd, 1) * ad->channels;
  snd_pcm_uframes_t count = size / unit;

  while (count > 0) {
    if ((r = snd_pcm_writei(alsa->fd, data, count)) == -EAGAIN) {
      //debug_message_fnc(" EAGAIN\n");
      snd_pcm_wait(alsa->fd, 1000);
    } else if (r > 0) {
      //debug_message_fnc(" wrote %d bytes\n", (int)(r * unit));
      ad->bytes_written += r * unit;
      count -= r;
      data += r * unit;
    } else if (r == -EPIPE) {
      debug_message_fnc("EPIPE: ");
      if (snd_pcm_state(alsa->fd) == SND_PCM_STATE_XRUN) {
	if ((r = snd_pcm_prepare(alsa->fd)) < 0) {
	  debug_message("failed\n");
	  warning_fnc("snd_pcm_prepare() failed.");
	} else {
	  debug_message("OK\n");
	}
      }
    } else {
      warning_fnc(" r = %d < 0...\n", (int)r);
    }
  }

  return 1;
}
Exemplo n.º 9
0
static void GoToLine (text_file_data_t *tptr, uint index)
{
    uint ix;
    debug_message("go to line %u", index);
    if (tptr->m_line_offset_tail != NULL) {
        debug_message("tail index %u", index);
    }
    if (tptr->m_line_offset_tail != NULL &&
            tptr->m_line_offset_tail->index >= index) {
        debug_message("Looking for tail");
        text_line_offset_t *tlptr;
        for (ix = 0, tlptr = tptr->m_line_offset_head; ix < index; ix++) {
            tlptr = tlptr->next_line;
        }
        if (tlptr->index != index) {
            error_message("Seek not right %u %u", tlptr->index, index);
        }
        GoToLine(tptr, tlptr);
        return;
    }
    uint start_index = 0;
    if (tptr->m_line_offset_tail) {
        start_index = tptr->m_line_offset_tail->index;
        GoToLine(tptr, tptr->m_line_offset_tail);
    }
    for (ix = start_index; ix < index; ix++) {
        if (ReadNextLine(tptr) == false)
            return;
    }
}
Exemplo n.º 10
0
bool CMediaSource::AddSink(CMediaSink* pSink) 
{
  bool rc = false;
  int i;
  if (SDL_LockMutex(m_pSinksMutex) == -1) {
    debug_message("AddSink LockMutex error");
    return rc;
  }
  for (i = 0; i < MAX_SINKS; i++) {
    if (m_sinks[i] == pSink) {
      SDL_UnlockMutex(m_pSinksMutex);
      return true;
    }
  }
  for (i = 0; i < MAX_SINKS; i++) {
    if (m_sinks[i] == NULL) {
      m_sinks[i] = pSink;
      rc = true;
      break;
    }
  }
  if (SDL_UnlockMutex(m_pSinksMutex) == -1) {
    debug_message("UnlockMutex error");
  }
  return rc;
}
Exemplo n.º 11
0
void 
free_vector(struct vector *p)
{
    int i;
    
    if (!p->ref || --p->ref > 0)
	return;
#if 0
    if (p->ref < 0) {
	debug_message("Array reference count < 0 in free_vector.\n");
	return;
    }
#endif
#if defined(DEBUG)
    if (p == &null_vector)
    {
	p->ref = 1;
	debug_message("Tried to free the zero-size shared vector.\n");
	return;
    }
#endif
    for (i = 0; i < p->size; i++)
	free_svalue(&p->item[i]);
    num_arrays--;
    total_array_size -= sizeof (struct vector) + sizeof (struct svalue) *
	(p->size-1);
    free((char *)p);
}
bool Player::load(void)
{
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_BLENDER);

   bitmap = al_load_bitmap(getResource("gfx/ship.tga"));
   if (!bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/ship.tga"));
      return false;
   }

   trans_bitmap = al_create_bitmap(al_get_bitmap_width(bitmap),
      al_get_bitmap_height(bitmap));
   if (!trans_bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/ship_trans.tga"));
      al_destroy_bitmap(bitmap);
      return false;
   }

   /* Make a translucent copy of the ship */
   al_set_target_bitmap(trans_bitmap);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_draw_tinted_bitmap(bitmap, al_map_rgba(255, 255, 255, 160),
      0, 0, 0);
   al_restore_state(&state);

   trail_bitmap = al_load_bitmap(getResource("gfx/trail.tga"));
   if (!trail_bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/trail.tga"));
      al_destroy_bitmap(bitmap);
      al_destroy_bitmap(trans_bitmap);
      return false;
   }

   icon = al_load_bitmap(getResource("gfx/ship_icon.tga"));
   if (!icon) {
      debug_message("Error loading %s\n", getResource("gfx/icon.tga"));
      al_destroy_bitmap(bitmap);
      al_destroy_bitmap(trans_bitmap);
      al_destroy_bitmap(trail_bitmap);
      return false;
   }

   highscoreBitmap = al_create_bitmap(300, 200);
   al_set_target_bitmap(highscoreBitmap);
   al_clear_to_color(al_map_rgba(0, 0, 0, 0));

   al_restore_state(&state);

   draw_radius = al_get_bitmap_width(bitmap)/2;
   radius = draw_radius / 2;

   newGame();
   reset();

   return true;
}
Exemplo n.º 13
0
void
string_list(void)
{
    debug_message(
        "-------------------- String Table ------------------------\n");
    table_walk_items(gdata->string_table, &list_item, NULL);
    debug_message(
        "----------------------------------------------------------\n");
}
void
loader_list(void)
{
    debug_message(
        "--------------------- Loader Table ------------------------\n");
    table_walk_items(gdata->loader_table, &list_item, NULL);
    debug_message(
        "----------------------------------------------------------\n");
}
Exemplo n.º 15
0
void
object_list(void)
{
    debug_message( 
        "--------------------- Object Table ------------------------\n");
    table_walk_items(gdata->object_table, &list_item, NULL);
    debug_message(
        "----------------------------------------------------------\n");
}
Exemplo n.º 16
0
void
site_list(void)
{
    debug_message( 
        "--------------------- Site Table ------------------------\n");
    table_walk_items(gdata->site_table, &list_item, NULL);
    debug_message(
        "----------------------------------------------------------\n");
}
Exemplo n.º 17
0
void
frame_list(void)
{
    debug_message(
        "--------------------- Frame Table ------------------------\n");
    table_walk_items(gdata->frame_table, &list_item, NULL);
    debug_message(
        "----------------------------------------------------------\n");
}
Exemplo n.º 18
0
int CALSAAudioSource::ThreadMain(void) 
{
  debug_message("alsa start");
  while (true) {
    int rc;

    if (m_source) {
      rc = SDL_SemTryWait(m_myMsgQueueSemaphore);
    } else {
      rc = SDL_SemWait(m_myMsgQueueSemaphore);
    }

    // semaphore error
    if (rc == -1) {
      break;
    } 

    // message pending
    if (rc == 0) {
      CMsg* pMsg = m_myMsgQueue.get_message();
		
      if (pMsg != NULL) {
        switch (pMsg->get_value()) {
        case MSG_NODE_STOP_THREAD:
          DoStopCapture();	// ensure things get cleaned up
          delete pMsg;
          debug_message("alsa stop thread");
          return 0;
        case MSG_NODE_START:
          DoStartCapture();
          break;
        case MSG_NODE_STOP:
          DoStopCapture();
          break;
        }

        delete pMsg;
      }
    }

    if (m_source) {
      try {
        //debug_message("processaudio");
        ProcessAudio();
      }
      catch (...) {
        error_message("alsa stop capture");
        DoStopCapture();	
        break;
      }
    }
  }

  debug_message("alsa thread exit");
  return -1;
}
Exemplo n.º 19
0
/* 将ob设置为master对象 */
void set_master(object_t *  ob) {
#if defined(PACKAGE_UIDS) || defined(PACKAGE_MUDLIB_STATS)
    int first_load = (!master_ob);
#endif
#ifdef PACKAGE_UIDS
    svalue_t *ret;
#endif

    get_master_applies(ob);			/* master load好之后,要apply一下? */
    master_ob = ob;
    /* Make sure master_ob is never made a dangling pointer. */
    add_ref(master_ob, "set_master");
#ifndef PACKAGE_UIDS
#  ifdef PACKAGE_MUDLIB_STATS
    if (first_load) {
        set_backbone_domain("BACKBONE");
        set_master_author("NONAME");
    }
#  endif
#else
    ret = apply_master_ob(APPLY_GET_ROOT_UID, 0);
    /* can't be -1 or we wouldn't be here */
    if (!ret) {
        debug_message("No function %s() in master object; possibly the mudlib doesn't want PACKAGE_UIDS to be defined.\n",
                      applies_table[APPLY_GET_ROOT_UID]);
        exit(-1);
    }
    if (ret->type != T_STRING) {
        debug_message("%s() in master object does not work.\n",
                      applies_table[APPLY_GET_ROOT_UID]);
        exit(-1);
    }
    if (first_load) {											/* 第一次load master? */
        master_ob->uid = set_root_uid(ret->u.string);
        master_ob->euid = master_ob->uid;
#  ifdef PACKAGE_MUDLIB_STATS
        set_master_author(ret->u.string);
#  endif
        ret = apply_master_ob(APPLY_GET_BACKBONE_UID, 0);
        if (ret == 0 || ret->type != T_STRING) {
            debug_message("%s() in the master file does not work\n",
                          applies_table[APPLY_GET_BACKBONE_UID]);		/* apply有多个,装table */
            exit(-1);
        }
        set_backbone_uid(ret->u.string);
#  ifdef PACKAGE_MUDLIB_STATS
        set_backbone_domain(ret->u.string);
#  endif
    } else {
        master_ob->uid = add_uid(ret->u.string);
        master_ob->euid = master_ob->uid;
    }
#endif
}
Exemplo n.º 20
0
void myread(int file, char *cmd, char *buffer) {
	debug_message("READ1\n");

	int len;
	mywrite(file, cmd);
	len = read(file, buffer, BUFFER_SIZE);

	if (len >= 0) buffer[len] = 0; 
	else buffer[0] = 0;

	debug_message("BUFFER: %s\n", buffer);
	debug_message("READ2\n");
}
Exemplo n.º 21
0
// ValidateAddressAndPort does a number of things - verifies that the
// address and port are in a valid range, set all streams with similiar
// profiles to that address, and makes sure there are no duplicate addresses
void ValidateIpAddressAndPort (CMediaStreamList *stream_list, 
			       CMediaStream *s,
			       config_index_t profile_ix, 
			       config_index_t fixed_ix,
			       config_index_t addr_ix, 
			       config_index_t port_ix)
{
  bool corrected;
  debug_message("Checking %s %s %s %s:%u",
		s->GetName(),
		s->GetNameFromIndex(profile_ix),
		s->GetStringValue(profile_ix),
		s->GetStringValue(addr_ix),
		s->GetIntegerValue(port_ix));
  do {
    if (ValidateIpAddress(s->GetStringValue(addr_ix)) == false) {
      struct in_addr in;
      debug_message("Stream %s %s address was invalid \"%s\"",
		    s->GetName(),
		    s->GetNameFromIndex(profile_ix),
		    s->GetStringValue(addr_ix));
      in.s_addr = GetRandomMcastAddress();
      s->SetStringValue(addr_ix, inet_ntoa(in));
      debug_message("changed to \"%s\"", s->GetStringValue(addr_ix));
    }
    
    if (s->GetIntegerValue(port_ix) >= 0xffff ||
	ValidateIpPort(s->GetIntegerValue(port_ix)) == false) {
      debug_message("Stream %s %s address was invalid %u",
		    s->GetName(),
		    s->GetNameFromIndex(profile_ix),
		    s->GetIntegerValue(port_ix));
      s->SetIntegerValue(port_ix, GetRandomPort());
      debug_message("Changed to %u", s->GetIntegerValue(port_ix));
    }

    if (s->GetBoolValue(fixed_ix) == false) {
      SetRestOfProfile(s, profile_ix, fixed_ix, addr_ix, port_ix);
    }
    corrected = CheckAddressForDup(stream_list, 
				   s,
				   profile_ix,
				   addr_ix, 
				   port_ix);
    if (corrected == true) {
      // keep address, move port - by setting port to 0, we will trigger
      // the above 
      s->SetIntegerValue(port_ix, 0);
    }
  } while (corrected);
}
Exemplo n.º 22
0
void render_printmatrix(matrix* mat) // FLAG use this? erase?
{

	debug_message("Matrix:\n");
	int i,j;
	for(i=0;i<4;i++)
	{
		for(j=0;j<4;j++)
		{
			debug_message(" %2.3f",mat->cell[i+4*j]);
		}
		debug_message("\n");
	}
}
Exemplo n.º 23
0
void
f_replace_program P2(int, num_arg, int, instruction)
{
    replace_ob_t *tmp;
    int name_len;
    char *name, *xname;
    program_t *new_prog;
    int var_offset;

    if (sp->type != T_STRING)
	bad_arg(1, instruction);
#ifdef DEBUG
    if (d_flag)
	debug_message("replace_program called\n");
#endif
    if (!current_object)
	error("replace_program called with no current object\n");
    if (current_object == simul_efun_ob)
	error("replace_program on simul_efun object\n");

    if (current_object->prog->func_ref)
	error("cannot replace a program with function references.\n");

    name_len = strlen(sp->u.string);
    name = (char *) DMALLOC(name_len + 3, TAG_TEMPORARY, "replace_program");
    xname = name;
    strcpy(name, sp->u.string);
    if (name[name_len - 2] != '.' || name[name_len - 1] != 'c')
	strcat(name, ".c");
    if (*name == '/')
	name++;
    new_prog = search_inherited(name, current_object->prog, &var_offset);
    FREE(xname);
    if (!new_prog) {
	error("program to replace the current with has to be inherited\n");
    }
    if (!(tmp = retrieve_replace_program_entry())) {
	tmp = ALLOCATE(replace_ob_t, TAG_TEMPORARY, "replace_program");
	tmp->ob = current_object;
	tmp->next = obj_list_replace;
	obj_list_replace = tmp;
    }
    tmp->new_prog = new_prog;
    tmp->var_offset = var_offset;
#ifdef DEBUG
    if (d_flag)
	debug_message("replace_program finished\n");
#endif
    free_string_svalue(sp--);
}
Exemplo n.º 24
0
  bool EncodeFrame (const char *fptr) {
    ADV_SPACE(fptr);
    CHECK_AND_FREE(m_encodedFrame);
    if (*fptr == 'A' || *fptr == '<') {
      // we have an already formatted href
      const char *check = fptr + 1;
      if (*check == '<') {
	check++;
      }
      if (strncmp(check, m_base_url, m_base_url_len) == 0) {
	check += m_base_url_len;
	m_encodedFrame = (char *)malloc(strlen(check) + 
					*fptr == 'A' ? 2 : 1);
	char *copyto = m_encodedFrame;
	if (*fptr == 'A') {
	  *copyto++ = 'A';
	}
	*copyto++ = '<';
	strcpy(copyto, check);
	debug_message("%s", m_encodedFrame);
      } else {
	m_encodedFrame = strdup(fptr);
      }
      chomp();
    } else {
      // we need to add <> and maybe an A
      uint32_t size = strlen(fptr) + 1; // add \0 at end
      if (strncmp(fptr, m_base_url, m_base_url_len) == 0) {
	fptr += m_base_url_len;
      }
      debug_message("string \"%s\"", fptr);
      size += 2; // add <>
      if (Profile()->GetBoolValue(CFG_TEXT_HREF_MAKE_AUTOMATIC)) size++;
      m_encodedFrame = (char *)malloc(size);
      char *write = m_encodedFrame;
      if (Profile()->GetBoolValue(CFG_TEXT_HREF_MAKE_AUTOMATIC)) {
	*write++ = 'A';
      }
      *write++ = '<';
      *write = '\0';
      strcat(write, fptr);
      debug_message("before chomp \"%s\"", m_encodedFrame);
      chomp();
      strcat(write, ">");
      debug_message("\"%s\"", m_encodedFrame);
    }
    m_encodedFrameLen = strlen(m_encodedFrame) + 1;
    return true;
  };
Exemplo n.º 25
0
bool SampleResource::load(void)
{
    if (!al_is_audio_installed()) {
        debug_message("Skipped loading sample %s\n", filename.c_str());
        return true;
    }

    sample_data = al_load_sample(filename.c_str());
    if (!sample_data) {
        debug_message("Error loading sample %s\n", filename.c_str());
        return false;
    }

    return true;
}
Exemplo n.º 26
0
bool CALSAAudioCapabilities::ProbeDevice()
{
  if (allSampleRateTableSize > NUM_ELEMENTS_IN_ARRAY(m_samplingRates)) {
    error_message("Number of sample rates exceeds audio cap array");
    return false;
  }

  // Open PCM
  snd_pcm_t *pcm_handle;
  snd_pcm_stream_t stream = SND_PCM_STREAM_CAPTURE;
  snd_pcm_hw_params_t *hwparams;
  snd_pcm_hw_params_alloca(&hwparams);
	int err;
  if ((err= snd_pcm_open(&pcm_handle, m_deviceName, stream, SND_PCM_NONBLOCK)) < 0) {
    error_message("Failed to open %s: %s", m_deviceName, snd_strerror(err));
    return false;
  }
  m_canOpen = true;

  if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) {
    error_message("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err));
    return false;
  }

  // union of valid sampling rates for MP3 and AAC
  // for all possible sampling rates
  u_int8_t i;
  for (i = 0; i < allSampleRateTableSize; i++) {
    u_int32_t targetRate = allSampleRateTable[i];
    if (snd_pcm_hw_params_test_rate(pcm_handle, hwparams, targetRate, 0) != 0) {
      debug_message("audio device %s doesn't support sampling rate %u",
                    m_deviceName, targetRate);
      continue;
    }
    debug_message("sampling rate %u supported", targetRate);

    // valid sampling rate
    m_samplingRates[m_numSamplingRates++] = targetRate;
  }

  // zero out remaining sampling rate entries
  for (i = m_numSamplingRates; i < allSampleRateTableSize; i++) {
    m_samplingRates[i] = 0;
  }

  snd_pcm_close(pcm_handle);
  return true;
}
Exemplo n.º 27
0
/*
 * push_file () pushes an input file on the input stack, saving the
 * current file name and line number.  If next is non-NULL, this push
 * invalidates a call to push_string_init (), whose storage are
 * consequentely released.
 */
void
push_file (FILE *fp, const char *title)
{
  input_block *i;

  if (next != NULL)
    {
      obstack_free (current_input, next);
      next = NULL;
    }

  if (debug_level & DEBUG_TRACE_INPUT)
    debug_message ("input read from %s", title);

  i = (input_block *) obstack_alloc (current_input,
				     sizeof (struct input_block));
  i->type = INPUT_FILE;

  i->u.u_f.name = current_file;
  i->u.u_f.lineno = current_line;
  i->u.u_f.out_lineno = output_current_line;
  i->u.u_f.advance_line = start_of_input_line;
  current_file = obstack_copy0 (current_input, title, strlen (title));
  current_line = 1;
  output_current_line = -1;

  i->u.u_f.file = fp;
  i->prev = isp;
  isp = i;
}
Exemplo n.º 28
0
static void GB2Big(char *istr, char *ostr, int inlen)
{
  unsigned char s[2];

#ifdef DEBUG
  debug_message("translate GB to BIG5.\n");
#endif

  while(inlen >= 2)
  {
    s[0] = *istr++;
    s[1] = *istr++;

    if(is_GB1(s[0]) && is_GB2(s[1]))
    {
      g2b(s);
      *ostr++ = s[0];
      *ostr++ = s[1];
      inlen -= 2;
    }
    else
    {
      *ostr++ = s[0];
      istr--;
      inlen--;
    }
  }

  if(inlen > 0)
    *ostr++ = *istr;

  *ostr = '\0';
}
Exemplo n.º 29
0
static void Big2GB(char *istr, char *ostr, int inlen)
{
  unsigned char s[2];

#ifdef DEBUG
  debug_message("translate BIG5 to GB.\n");
#endif

  while(inlen >= 2)
  {
    s[0] = *istr++;
    s[1] = *istr++;

    if(is_B51(s[0]) && is_B52(s[1]))
    {
      b2g(s);
      *ostr++ = s[0];
      *ostr++ = s[1];
      inlen -= 2;
    }
    else
    {
      *ostr++ = s[0];
      istr--;
      inlen--;
    }
  }

  if(inlen > 0)
    *ostr++ = *istr;

  *ostr = '\0';
}
Exemplo n.º 30
0
/*
 * The function pop_input () pops one level of input sources.  If the
 * popped input_block is a file, current_file and current_line are reset
 * to the saved values before the memory for the input_block are
 * released.
 */
static void
pop_input (void)
{
  input_block *tmp = isp->prev;

  switch (isp->type)
    {
    case INPUT_STRING:
    case INPUT_MACRO:
      break;
    case INPUT_FILE:
      if (debug_level & DEBUG_TRACE_INPUT)
	debug_message ("input reverted to %s, line %d",
		       isp->u.u_f.name, isp->u.u_f.lineno);

      fclose (isp->u.u_f.file);
      current_file = isp->u.u_f.name;
      current_line = isp->u.u_f.lineno;
      output_current_line = isp->u.u_f.out_lineno;
      start_of_input_line = isp->u.u_f.advance_line;
      if (tmp != NULL)
	output_current_line = -1;
      break;
    default:
      internal_error ("Input stack botch in pop_input ()");
      break;
    }
  obstack_free (current_input, isp);
  next = NULL;			/* might be set in push_string_init () */

  isp = tmp;
}