示例#1
0
int iterate_usb(int (is_interesting)(struct usb_device *), 
	int (do_open)(struct usb_dev_handle *),
	int (do_process)(struct usb_dev_handle *),
	int (do_close)(struct usb_dev_handle *)
	)
{
	usb_find_busses();
	usb_find_devices();

	int result = 0;
	struct usb_bus *bus;
	struct usb_device *dev;
 
	for (bus = usb_busses; bus; bus = bus->next) {
		for (dev = bus->devices; dev; dev = dev->next) {
			if (is_interesting(dev)) {
				struct usb_dev_handle *handle = open_handle_for_device(dev, do_open);
				if (handle) {
					if (do_process) 
						result += do_process(handle);
					
					if (do_close)
						result += close_handle(handle, do_close);
				}
				else {
					result += 1;
				}
			}
		}
	}
	return result;
}
示例#2
0
	void web_connection_base::get_specific_peer_info(peer_info& p) const
	{
		if (is_interesting()) p.flags |= peer_info::interesting;
		if (is_choked()) p.flags |= peer_info::choked;
		if (!is_connecting() && m_server_string.empty())
			p.flags |= peer_info::handshake;
		if (is_connecting()) p.flags |= peer_info::connecting;

		p.client = m_server_string;
	}
void InterestingPositionProcessor::UpdateInterestingRead(const PositionDescriptionMap &ps) {
    vector<size_t> interesting_in_read;
    for (const auto &pos : ps) {
        if (is_interesting(pos.first)) {
            interesting_in_read.push_back(pos.first);
        }
    }
    if (interesting_in_read.size() >= 2) {
        WeightedPositionalRead wr(interesting_in_read, ps, contig_);
        size_t cur_id = wr_storage_.size();
        wr_storage_.push_back(wr);
        for (size_t i = 0; i < interesting_in_read.size(); i++) {
            TRACE(interesting_in_read[i] << " " << contig_.length());
            read_ids_[interesting_in_read[i]].push_back(cur_id);
        }
    }
}
示例#4
0
inline void do_test(AF&& af, BF&& bf, Predicate&& p, const char* desc) {
  test_cases_state_t& state = test_cases_state;
  const char* step = "beginning";
  bool success = false;
  state.checkpoint = desc;
  try {
    step = "evaluating A";
    auto&& a(af());
    step = "evaluating B";
    auto&& b(bf());
    step = "evaluating comparison";
    success = p(a, b);
    if(!success && state.error_log) {
      *state.error_log << "Failed: " << desc << ":\n    A = " << std::flush;
      step = "evaluating ostream << A";
      *state.error_log << a;
      if(is_interesting(b)) {
        *state.error_log << "; B = " << std::flush;
        step = "evaluating ostream << B";
        *state.error_log << b;
      }
    }
  }
  catch(std::exception& e) {
    success = false;
    if(state.error_log) {
      *state.error_log << desc << ":\n  caught unexpected exception when " << step << ":\n    " << std::flush;
      step = "caught unexpected exception; evaluating e.what()";
      *state.error_log << e.what();
    }
  }
  if(!success && state.error_log) {*state.error_log << std::endl;}
  ++state.num_checks_run;

  if(!success) {++state.num_checks_failed;}
}
示例#5
0
文件: recorder.c 项目: kudrom/noapp
/*
 * The callback will record when mute isn't activated and:
 *    - it'll always record the first SILENCE_BREAKPOINTS events that are 
 *    above the low_point but below the high_point (these are normally the 
 *    trailing of a utterance).
 *    - it'll always record if the event is well below the high_level 
 *    (these are normally the utterances)
 *
 * The counter_activity (which is one of the responsible to record after all, 
 * see the above comment) is reseted mainly by a detected high_point utterance 
 * or when we have detected a long streak of idle.
 *
 * The callback will split an utterance when nothing interesting has been 
 * said in the last HOT_ZONE seconds.
 */
static void stream_request_cb(pa_stream *stream, size_t length, void *userdata)
{
    const void *data;
    size_t size = 0;
    double power, low_point, high_point;
    int retval, retries;
    time_t current_time;
    recorder_context_t *rctx = (recorder_context_t *) userdata;

    if (rctx->dirty_filename){
        fclose(rctx->recording_file);
        fclose(rctx->length_file);

        retries = 0;
        do{
            retval = init_filenames(rctx);
            retries++;
        } while(retval != 0 && retries < 20);
        if (retries == 20){
            Log(LOG_ERR, 
                "There was some nasty problems with the opening of %s file.\n",
                rctx->filename);
            stop_recording(rctx, false);
        }

        rctx->dirty_filename = false;
    }

    if (!rctx->mute){
        pa_stream_peek(stream, &data, &size);
        rctx->is_recording = false;

        power = calculate_rms_power(data, size);
        low_point = rctx->threshold * LOW_BREAKPOINT;
        high_point = rctx->threshold * HIGH_BREAKPOINT;
        rctx->total_activity++;
        if (data){
            if (power >= low_point){
                if (rctx->counter_silence < SILENCE_BREAKPOINT ||
                    power > high_point){

                    rctx->counter_idle = 0;

                    current_time = time(NULL);
                    if (difftime(current_time, rctx->timestamp) >= HOT_ZONE){
                        if (is_interesting(rctx)){
                            dump(rctx);
                            rctx->high_activity = rctx->total_activity = 0;
                        }
                        rctx->timestamp = current_time;
                    }

                    if (power <= high_point){
                        rctx->counter_silence++;
                    }else{
                        rctx->counter_silence = 0;
                        rctx->high_activity++;
                    }

                    rctx->is_recording = true;
                    buffer(rctx, data, size);

                    Log(LOG_DEBUG,
                        "-> power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
                }else{
                    Log(LOG_DEBUG,
                        "SS power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
                }
            }else{
                rctx->counter_idle = fmin(++rctx->counter_idle, IDLE_BREAKPOINT);
                if (rctx->counter_idle == IDLE_BREAKPOINT)
                    rctx->counter_silence = 0;
                Log(LOG_DEBUG,
                    "   power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
            }
            pa_stream_drop(stream);
        }
    }
}
示例#6
0
/*
 * get uri
 * create playbin
 * check that we have video
 * for each potential location
 *   check for cancel
 *   grab snapshot
 *   interesting?
 *   return if so, other spin loop
 *
 * for future, check metadata for artwork and don't reject non-video streams (see totem)
 *
 * TODO: all error paths leak
 */
static void
gst_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
                        GCancellable               *cancellable,
                        TumblerFileInfo            *info)
{
  /* These positions are taken from Totem */
  const double positions[] = {
    1.0 / 3.0,
    2.0 / 3.0,
    0.1,
    0.9,
    0.5
  };
  GstElement             *playbin;
  gint64                  duration;
  unsigned int            i;
  GstBuffer              *frame;
  GdkPixbuf              *shot;
  TumblerThumbnail       *thumbnail;
  TumblerThumbnailFlavor *flavour;
  TumblerImageData        data;
  GError                 *error = NULL;

  g_return_if_fail (IS_GST_THUMBNAILER (thumbnailer));
  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
  g_return_if_fail (TUMBLER_IS_FILE_INFO (info));

  /* Check for early cancellation */
  if (g_cancellable_is_cancelled (cancellable))
    return;

  playbin = make_pipeline (info, cancellable);
  if (playbin == NULL) {
    /* TODO: emit an error, but the specification won't let me. */
    return;
  }

  duration = get_duration (playbin);

  /* Now we have a pipeline that we know has video and is paused, ready for
     seeking */
  for (i = 0; i < G_N_ELEMENTS (positions); i++) {
    /* Check if we've been cancelled */
    if (g_cancellable_is_cancelled (cancellable)) {
      gst_element_set_state (playbin, GST_STATE_NULL);
      g_object_unref (playbin);
      return;
    }

    LOG ("trying position %f", positions[i]);

    gst_element_seek_simple (playbin,
                             GST_FORMAT_TIME,
                             GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT,
                             (gint64)(positions[i] * duration));

    if (gst_element_get_state (playbin, NULL, NULL, 1 * GST_SECOND) == GST_STATE_CHANGE_FAILURE) {
      LOG ("Could not seek");
      return;
    }

    g_object_get (playbin, "frame", &frame, NULL);

    if (frame == NULL) {
      LOG ("No frame found!");
      continue;
    }

    thumbnail = tumbler_file_info_get_thumbnail (info);
    flavour = tumbler_thumbnail_get_flavor (thumbnail);
    /* This frees the buffer for us */
    shot = convert_buffer_to_pixbuf (frame, cancellable, flavour);
    g_object_unref (flavour);

    /* If it's not interesting, throw it away and try again*/
    if (is_interesting (shot)) {
      /* Got an interesting image, break out */
      LOG ("Found an interesting image");
      break;
    }

    /*
     * If we've still got positions to try, free the current uninteresting
     * shot. Otherwise we'll make do with what we have.
     */
    if (i + 1 < G_N_ELEMENTS (positions) && shot) {
      g_object_unref (shot);
      shot = NULL;
    }

    /* Spin mainloop so we can pick up the cancels */
    while (g_main_context_pending (NULL)) {
      g_main_context_iteration (NULL, FALSE);
    }
  }

  gst_element_set_state (playbin, GST_STATE_NULL);
  g_object_unref (playbin);

  if (shot) {
    data.data = gdk_pixbuf_get_pixels (shot);
    data.has_alpha = gdk_pixbuf_get_has_alpha (shot);
    data.bits_per_sample = gdk_pixbuf_get_bits_per_sample (shot);
    data.width = gdk_pixbuf_get_width (shot);
    data.height = gdk_pixbuf_get_height (shot);
    data.rowstride = gdk_pixbuf_get_rowstride (shot);
    data.colorspace = (TumblerColorspace) gdk_pixbuf_get_colorspace (shot);

    tumbler_thumbnail_save_image_data (thumbnail, &data,
                                       tumbler_file_info_get_mtime (info),
                                       NULL, &error);

    g_object_unref (shot);

    if (error != NULL) {
      g_signal_emit_by_name (thumbnailer, "error",
                             tumbler_file_info_get_uri (info),
                             error->code, error->message);
      g_error_free (error);
    } else {
      g_signal_emit_by_name (thumbnailer, "ready",
                             tumbler_file_info_get_uri (info));
    }
  }
}