Example #1
0
File: cli.c Project: modul/iris
static void do_store()
{
	input_stop();
	conf_store();
	input_start();
	OK();
}
Example #2
0
File: cli.c Project: modul/iris
static void do_load()
{
	input_stop();
	conf_load();
	OK();
	input_calibrate(CHANNELS);
	input_start();
}
Example #3
0
void playlist_prev(void)
{
    GList *plist_pos_list;
    gboolean restart_playing = FALSE;

    PL_LOCK();
    if (!playlist)
    {
        PL_UNLOCK();
        return;
    }

    plist_pos_list = find_playlist_position_list();

    if (!cfg.repeat && !g_list_previous(plist_pos_list))
    {
        PL_UNLOCK();
        return;
    }

    if (get_input_playing())
    {
        /* We need to stop before changing playlist_position */
        PL_UNLOCK();
        input_stop();
        PL_LOCK();
        restart_playing = TRUE;
    }

    plist_pos_list = find_playlist_position_list();
    if (g_list_previous(plist_pos_list))
        playlist_position = plist_pos_list->prev->data;
    else if (cfg.repeat)
    {
        GList *node;
        playlist_position = NULL;
        __playlist_generate_shuffle_list();
        if (cfg.shuffle)
            node = g_list_last(shuffle_list);
        else
            node = g_list_last(playlist);
        if (node)
            playlist_position = node->data;
    }
    PL_UNLOCK();
    playlist_check_pos_current();

    if (restart_playing)
        playlist_play();
    else
    {
        mainwin_set_info_text();
        playlistwin_update_list();
    }
}
Example #4
0
File: cli.c Project: modul/iris
static void do_conf()
{
	char c = 0;
	char line[64];
	int args, id, num, gain, min, max;
	struct chan *channel;

	gets(line);
	args = sscanf(line, "%c %u %u %i %i", &c, &num, &gain, &min, &max);
	if (args > 0) {
		id = CHANNEL_ID(c);
		if (id >= CHANNELS)
			NOK();
		else if (args == 1) {
			channel = conf_get(id);
			printf("%c %u %u %i %i\n", c, channel->num, channel->gain, channel->min, channel->max);
		}
		else {
			int tmp;
			input_stop();
			channel = conf_get(id);
			tmp = channel->gain;

			channel->num = limit(num, 0, AD_CHANNELS);

			if (args >= 3) {
				channel->gain = limit(gain, AD_GAIN_MIN, AD_GAIN_MAX);
				if (tmp != channel->gain)
					input_calibrate(id);
			}
			if (args == 4) {
				max = limit(min, 0, AD_VMAX);
				min = limit(-min, AD_VMIN, 0);
				channel->min = min;
				channel->max = max;
			}
			else if (args >= 5) {
				channel->min = limit(min, AD_VMIN, AD_VMAX);
				channel->max = limit(max, channel->min, AD_VMAX);
			}

			printf("ok %c %u %u %i %i\n", c, channel->num, channel->gain, channel->min, channel->max);
			input_start();
		}
	}
	else NOK();
}
Example #5
0
// Wait for some event
static bool poll_uv_loop(int32_t ms)
{
  bool timed_out;
  uv_run_mode run_mode = UV_RUN_ONCE;

  if (input_ready()) {
    // If there's a pending input event to be consumed, do it now
    return true;
  }

  input_start();
  timed_out = false;

  if (ms > 0) {
    // Timeout passed as argument to the timer
    timer.data = &timed_out;
    // We only start the timer after the loop is running, for that we
    // use an prepare handle(pass the interval as data to it)
    timer_prepare.data = &ms;
    uv_prepare_start(&timer_prepare, timer_prepare_cb);
  } else if (ms == 0) {
    // For ms == 0, we need to do a non-blocking event poll by
    // setting the run mode to UV_RUN_NOWAIT.
    run_mode = UV_RUN_NOWAIT;
  }

  do {
    // Run one event loop iteration, blocking for events if run_mode is
    // UV_RUN_ONCE
    uv_run(uv_default_loop(), run_mode);
  } while (
      // Continue running if ...
      !input_ready() && // we have no input
      !has_pending_events() && // no events are waiting to be processed
      run_mode != UV_RUN_NOWAIT && // ms != 0
      !timed_out  // we didn't get a timeout
      );

  input_stop();

  if (ms > 0) {
    // Stop the timer
    uv_timer_stop(&timer);
  }

  return input_ready() || has_pending_events();
}
Example #6
0
void playlist_set_position(int pos)
{
    GList *node;
    gboolean restart_playing = FALSE;

    PL_LOCK();
    if (!playlist)
    {
        PL_UNLOCK();
        return;
    }

    node = g_list_nth(playlist, pos);
    if (!node)
    {
        PL_UNLOCK();
        return;
    }

    if (get_input_playing())
    {
        /* We need to stop before changing playlist_position */
        PL_UNLOCK();
        input_stop();
        PL_LOCK();
        restart_playing = TRUE;
    }

    playlist_position = node->data;
    PL_UNLOCK();
    playlist_check_pos_current();

    if (restart_playing)
        playlist_play();
    else
    {
        mainwin_set_info_text();
        playlistwin_update_list();
    }

    /*
     * Regenerate the shuffle list when the user set a position
     * manually
     */
    playlist_generate_shuffle_list();
}
Example #7
0
int input_stop_all() {

	registry_lock();

	int res = POM_OK;

	struct input *tmp;
	for (tmp = input_head; tmp ; tmp = tmp->next) {
		if (tmp->running == INPUT_RUN_RUNNING) {
			res += input_stop(tmp);
		}
	}

	registry_unlock();

	return (res == POM_OK ? POM_OK : POM_ERR);
}
Example #8
0
void playlist_eof_reached(void)
{
    GList *plist_pos_list;

    input_stop();

    PL_LOCK();
    plist_pos_list = find_playlist_position_list();

    if (cfg.no_playlist_advance)
    {
        PL_UNLOCK();
        mainwin_clear_song_info();
        if (cfg.repeat)
            playlist_play();
        return;
    }
    if (queued_list)
        play_queued();
    else if (!g_list_next(plist_pos_list))
    {
        if (cfg.shuffle)
        {
            playlist_position = NULL;
            __playlist_generate_shuffle_list();
        }
        else
            playlist_position = playlist->data;
        if (!cfg.repeat)
        {
            PL_UNLOCK();
            mainwin_clear_song_info();
            mainwin_set_info_text();
            return;
        }
    }
    else
        playlist_position = plist_pos_list->next->data;
    PL_UNLOCK();
    playlist_check_pos_current();
    playlist_play();
    mainwin_set_info_text();
    playlistwin_update_list();
}
Example #9
0
void playlist_clear(void)
{
    GList *node;
    PlaylistEntry *entry;

    if (get_input_playing())
        input_stop();

    PL_LOCK();
    if (playlist)
    {
        node = playlist;
        while (node)
        {
            entry = node->data;
            if (entry->filename)
                g_free(entry->filename);
            if (entry->title)
                g_free(entry->title);
            g_free(entry);
            node = node->next;
        }
        g_list_free(playlist);
        playlist = NULL;
        playlist_position = NULL;
    }

    if (queued_list)
    {
        g_list_free(queued_list);
        queued_list = NULL;
    }

    PL_UNLOCK();
    playlist_generate_shuffle_list();
    playlistwin_update_list();
}
Example #10
0
File: cli.c Project: modul/iris
static void do_info()
{
	char c;
	int i, tmp;
	struct chan *channel;

	input_stop();
	if ((c = getchar()) == 'V') {
		tmp = AD7793_voltmon();
		printf("%u.%uV\n", tmp/1000000, tmp%1000000);
	}
	else if (c == 'T') {
		tmp = AD7793_temperature();
		printf("%u.%uC\n", tmp/10000, tmp%10000);
	}
	else {
		if ((i = CHANNEL_ID(c)) < CHANNELS) // print only one channel
			tmp = i+1;
		else { // print all channels and state information
			i = 0;
			tmp = CHANNELS;
			printf("%s\n", STATE_NAME(state_getState()));
		}
		
		while (i < tmp) {
			channel = conf_get(i);
			printf("%c %s ch%u %ux %i ... %i %iuV\n", 
				CHANNEL_NAME(i), ERROR_NAME(state_getError(i)), 
				channel->num, 1<<channel->gain,
				channel->min, channel->max,
				input_latest(i));
			i++;
		}
	}
	input_start();
}
Example #11
0
// Wait for some event
bool event_poll(int32_t ms)
{
  uv_run_mode run_mode = UV_RUN_ONCE;

  if (input_ready()) {
    // If there's a pending input event to be consumed, do it now
    return true;
  }

  static int recursive = 0;

  if (!(recursive++)) {
    // Only needs to start the libuv handle the first time we enter here
    input_start();
  }

  uv_timer_t timer;
  uv_prepare_t timer_prepare;
  TimerData timer_data = {.ms = ms, .timed_out = false, .timer = &timer};

  if (ms > 0) {
    uv_timer_init(uv_default_loop(), &timer);
    // This prepare handle that actually starts the timer
    uv_prepare_init(uv_default_loop(), &timer_prepare);
    // Timeout passed as argument to the timer
    timer.data = &timer_data;
    // We only start the timer after the loop is running, for that we
    // use a prepare handle(pass the interval as data to it)
    timer_prepare.data = &timer_data;
    uv_prepare_start(&timer_prepare, timer_prepare_cb);
  } else if (ms == 0) {
    // For ms == 0, we need to do a non-blocking event poll by
    // setting the run mode to UV_RUN_NOWAIT.
    run_mode = UV_RUN_NOWAIT;
  }

  do {
    // Run one event loop iteration, blocking for events if run_mode is
    // UV_RUN_ONCE
    uv_run(uv_default_loop(), run_mode);
    // Process immediate events outside uv_run since libuv event loop not
    // support recursion(processing events may cause a recursive event_poll
    // call)
    event_process(false);
  } while (
      // Continue running if ...
      !input_ready() &&   // we have no input
      !event_has_deferred() &&   // no events are waiting to be processed
      run_mode != UV_RUN_NOWAIT &&   // ms != 0
      !timer_data.timed_out);  // we didn't get a timeout

  if (!(--recursive)) {
    // Again, only stop when we leave the top-level invocation
    input_stop();
  }

  if (ms > 0) {
    // Ensure the timer-related handles are closed and run the event loop
    // once more to let libuv perform it's cleanup
    uv_close((uv_handle_t *)&timer, NULL);
    uv_close((uv_handle_t *)&timer_prepare, NULL);
    uv_run(uv_default_loop(), UV_RUN_NOWAIT);
    event_process(false);
  }

  return input_ready() || event_has_deferred();
}

bool event_has_deferred()
{
  return !kl_empty(get_queue(true));
}

// Push an event to the queue
void event_push(Event event, bool deferred)
{
  *kl_pushp(Event, get_queue(deferred)) = event;
}
Example #12
0
static int input_pcap_read(struct input *i) {

	struct input_pcap_priv *p = i->priv;

	if (p->type == input_pcap_type_dir && !p->tpriv.dir.files) {
		if (input_pcap_dir_open(i) != POM_OK) {
			// Don't error out if the scan was interrupted
			if (p->tpriv.dir.interrupt_scan)
				return POM_OK;
			return POM_ERR;
		}
	}

	struct pcap_pkthdr *phdr;
	const u_char *data;
	int result = pcap_next_ex(p->p, &phdr, &data);
	if (phdr->len > phdr->caplen && !p->warning) {
		pomlog(POMLOG_WARN "Warning, some packets were truncated at capture time on input %s", i->name);
		p->warning = 1;
	}

	if (result < 0) { // End of file or error 

		if (p->type == input_pcap_type_dir) {

			if (result != -2)
				pomlog(POMLOG_WARN "Error while reading packet from file : %s. Moving on the next file ...", pcap_geterr(p->p), p->tpriv.dir.cur_file->filename);
			
			pcap_close(p->p);
			p->p = NULL;
			p->warning = 0;

			if (input_pcap_dir_open_next(p) != POM_OK)
				return POM_ERR;

			if (!p->tpriv.dir.cur_file) {
				// No more file
				return input_stop(i);
			}

			result = pcap_next_ex(p->p, &phdr, &data);
			if (result < 0) {
				pomlog(POMLOG_ERR "Error while reading first packet of new file");
				return POM_ERR;
			}
		} else {
			if (result == -2) // EOF
				return input_stop(i);

			pomlog(POMLOG_ERR "Error while reading file : %s", pcap_geterr(p->p));
			return POM_ERR;
		}
	}

	if (result == 0) // Timeout
		return POM_OK;

	struct packet *pkt = packet_alloc();
	if (!pkt)
		return POM_ERR;

	if (packet_buffer_alloc(pkt, phdr->caplen - p->skip_offset, p->align_offset) != POM_OK) {
		packet_release(pkt);
		return POM_ERR;
	}

	pkt->input = i;
	pkt->datalink = p->datalink_proto;
	pkt->ts = pom_timeval_to_ptime(phdr->ts);
	memcpy(pkt->buff, data + p->skip_offset, phdr->caplen - p->skip_offset);

	unsigned int flags = 0, affinity = 0;

	if (p->type == input_pcap_type_interface)
		flags = CORE_QUEUE_DROP_IF_FULL;

#ifdef DLT_MPEG_2_TS
	if (p->datalink_type == DLT_MPEG_2_TS) {
		// MPEG2 TS has thread affinity based on the PID
		flags |= CORE_QUEUE_HAS_THREAD_AFFINITY;
		affinity = ((((char*)pkt->buff)[1] & 0x1F) << 8) | ((char *)pkt->buff)[2];
	}
#endif

	return core_queue_packet(pkt, flags, affinity);
}
Example #13
0
void playlist_play(void)
{
    char *filename = NULL;

    if (get_playlist_length() == 0)
        return;

    /* If the user wants a skin randomly selected on play */
    if (cfg.random_skin_on_play)
    {
        /* Get the current skin list */
        scan_skins();
        /* If there are entries */
        if (g_list_length(skinlist)) {
            /* Get a random value to select the skin to use */
            int randval = (gint)(random() / (RAND_MAX + 1.0) * (g_list_length(skinlist) + 1));
            /* If the random value is 0, use the default skin */
            /* Otherwise subtract 1 from the random value and */
            /* select the skin */
            if (randval == 0)
                load_skin(NULL);
            else
            {
                struct SkinNode *skin;
                skin = g_list_nth(skinlist, randval - 1)->data;
                load_skin(skin->path);
            }
        }
        /* Call scan_skins() again to make sure skin selector */
        /* is up to date */
        scan_skins();
    }

    if (get_input_playing())
        input_stop();

    vis_clear_data(mainwin_vis);
    vis_clear_data(playlistwin_vis);
    svis_clear_data(mainwin_svis);
    mainwin_disable_seekbar();

    PL_LOCK();
    if (playlist)
    {
        if (!playlist_position)
        {
            if (cfg.shuffle)
                playlist_position = shuffle_list->data;
            else
                playlist_position = playlist->data;
        }
        filename = playlist_position->filename;
    }
    PL_UNLOCK();

    if (!filename)
        return;

    input_play(filename);

    if (input_get_time() != -1)
    {
        equalizerwin_load_auto_preset(filename);
        input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp,
                     cfg.equalizer_bands);
    }
    playlist_check_pos_current();
}
Example #14
0
void playlist_delete_node(GList *node, gboolean *set_info_text, gboolean *restart_playing)
{
    /* Caller should hold playlist mutex */
    PlaylistEntry *entry = node->data;
    GList *playing_song = NULL;
    GList *queued_song = NULL;

    /*
     * We call g_list_find manually here because
     * we don't want an item in the shuffle_list
     */
    if (playlist_position)
        playing_song = g_list_find(playlist, playlist_position);

    /*
     * Remove the song from the queue first if it is there, so
     * that that we avoid trying to play it again
     */
    if ((queued_song = g_list_find(queued_list, entry)) != NULL)
    {
        queued_list = g_list_remove_link(queued_list, queued_song);
        g_list_free_1(queued_song);
    }

    if (playing_song == node)
    {
        *set_info_text = TRUE;
        if (get_input_playing())
        {
            PL_UNLOCK();
            input_stop();
            PL_LOCK();
            *restart_playing = TRUE;
        }
        playing_song = find_playlist_position_list();
        if (queued_list)
            play_queued();
        else if (g_list_next(playing_song))
            playlist_position = playing_song->next->data;
        else if (g_list_previous(playing_song))
            playlist_position = playing_song->prev->data;
        else
            playlist_position = NULL;
        /* Make sure the entry did not disappear under us */
        if (g_list_index(get_playlist(), entry) == -1)
            return;
    }
    else if (playing_song &&
             g_list_position(playlist, playing_song) >
             g_list_position(playlist, node))
        *set_info_text = TRUE;

    if (entry->filename)
        g_free(entry->filename);
    if (entry->title)
        g_free(entry->title);
    shuffle_list = g_list_remove(shuffle_list, entry);
    playlist = g_list_remove_link(playlist, node);
    g_free(entry);
    g_list_free_1(node);
}