Ejemplo n.º 1
0
void HumanBodyLaser::saveInitInfos(const int lvl)
{
	string savefn;
	string lvlstr = type2string(lvl);
    float disscl = stereoPyr[lvl]->GetDisScale();

	Mat dispim;

	(stereoPyr[lvl]->GetDispL()).convertTo(dispim, CV_8UC1, disscl);
	savefn = outdir + "/init_dispL_" + lvlstr + ".jpg";
	imwrite(savefn ,dispim);
	savefn = outdir + "/init_dispL_" + lvlstr + ".yml";
	saveDispYML(savefn, stereoPyr[lvl]->GetDispL());
		
	(stereoPyr[lvl]->GetDispR()).convertTo(dispim, CV_8UC1, disscl);
	savefn = outdir + "/init_dispR_" + lvlstr + ".jpg";
	imwrite(savefn, dispim);
	savefn = outdir + "/init_dispR_" + lvlstr + ".yml";
	saveDispYML(savefn, stereoPyr[lvl]->GetDispR());

	(stereoPyr[lvl]->GetDisp()).convertTo(dispim, CV_8UC1, disscl);
	savefn = outdir + "/init_disp_" + lvlstr + ".jpg";
	imwrite(savefn, dispim);
	savefn = outdir + "/init_disp_" + lvlstr + ".yml";
	saveDispYML(savefn, stereoPyr[lvl]->GetDisp());

	(stereoPyr[lvl]->GetDispSeed()).convertTo(dispim, CV_8UC1, disscl);
	savefn = outdir + "/disp_seed_" + lvlstr + ".jpg";
	imwrite(savefn, dispim);

	savefn = outdir + "/seed_matches_" + lvlstr + ".list";
	saveCMatches(savefn, stereoPyr[lvl]->GetMcostSeeds());

	savefn = outdir + "/init_matches_" + lvlstr + ".list";
	saveAllMatches(savefn, stereoPyr[lvl]->GetDisp(), stereoPyr[lvl]->GetBestMcost(), stereoPyr[lvl]->GetBestPrior());

	savefn = outdir + "/init_mcost_" + lvlstr + ".yml";
	saveBestCostYML(savefn, stereoPyr[lvl]->GetBestMcost());

	if(lvl == maxLevels - 1)
	{
		for(int k = 0; k <= stereoPyr[lvl]->GetDisRanges(); ++k)
		{
			savefn = outdir + "/mcost_" + lvlstr + "_0" + type2string(k) + ".yml";
			saveBestCostYML(savefn, (stereoPyr[lvl]->GetCostVol(0))[k]);
			savefn = outdir + "/mcost_" + lvlstr + "_1" + type2string(k) + ".yml";
			saveBestCostYML(savefn, (stereoPyr[lvl]->GetCostVol(1))[k]);
		}
	}
	
}
Ejemplo n.º 2
0
static struct shared_dumper	*dumper_open(enum type t, uint32_t id)
{
  struct shared_dumper		*d;

  d = malloc(sizeof (struct shared_dumper));
  d->filename = malloc(strlen(sessions_file_format) + strlen(type2string(t, 0)) + 16);
  sprintf(d->filename, sessions_file_format, type2string(t, 0), id);
  d->filedesc = pcap_dump_open(nids_params.pcap_desc, d->filename);
  if (NULL == d->filedesc)
    dumper_too_many_open_files(&d);
  ++dumper_fd_count;
  d->references = 1;
  return d;
}
Ejemplo n.º 3
0
/**
 * Watcher we use to process session events. In particular,
 * when it receives a ZOO_CONNECTED_STATE event, we set the
 * connected variable so that we know that the session has
 * been established.
 */
void main_watcher (zhandle_t *zkh,
                   int type,
                   int state,
                   const char *path,
                   void* context)
{
    /*
     * zookeeper_init might not have returned, so we
     * use zkh instead.
     */
    if (type == ZOO_SESSION_EVENT) {
        if (state == ZOO_CONNECTED_STATE) {
            connected = 1;

            LOG_DEBUG(("Received a connected event."));
        } else if (state == ZOO_CONNECTING_STATE) {
            if(connected == 1) {
                LOG_WARN(("Disconnected."));
            }
            connected = 0;
        } else if (state == ZOO_EXPIRED_SESSION_STATE) {
            expired = 1;
            connected = 0;
            zookeeper_close(zkh);
        }
    }
    LOG_DEBUG(("Event: %s, %d", type2string(type), state));
}
Ejemplo n.º 4
0
void workers_watcher (zhandle_t *zh, int type, int state, const char *path,void *watcherCtx) {
    if( type == ZOO_CHILD_EVENT) {
        assert( !strcmp(path, "/workers") );
        get_workers();
    } else {
        LOG_DEBUG(("Watched event: ", type2string(type)));
    }
}
Ejemplo n.º 5
0
void HumanBodyLaser::saveRegionVoteInfos(const int lvl)
{
	string savefn;
	string lvlstr = type2string(lvl);
	float disscl = stereoPyr[lvl]->GetDisScale();

	Mat dispim;

	savefn = outdir + "/rv_dispL_" + type2string(lvl) + ".yml";
	saveDispYML(savefn, stereoPyr[lvl]->GetDispL());
	savefn = outdir + "/rv_dispL_" + type2string(lvl) + ".jpg";
	(stereoPyr[lvl]->GetDispL()).convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);
	
	dispim = imread(savefn, CV_LOAD_IMAGE_COLOR);
	savefn = outdir + "/outliers_rv_dispL_" + type2string(lvl) + ".jpg";
	saveOutliers(savefn, dispim, stereoPyr[lvl]->GetOutliersL());

	savefn = outdir + "/rv_dispR_" + type2string(lvl) + ".yml";
	saveDispYML(savefn, stereoPyr[lvl]->GetDispR());
	savefn = outdir + "/rv_dispR_" + type2string(lvl) + ".jpg";
	(stereoPyr[lvl]->GetDispR()).convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);
	
	dispim = imread(savefn, CV_LOAD_IMAGE_COLOR);
	savefn = outdir + "/outliers_rv_dispR_" + type2string(lvl) + ".jpg";
	saveOutliers(savefn, dispim ,stereoPyr[lvl]->GetOutliersR());
}
Ejemplo n.º 6
0
bool 
printUTIL_SEQUENCE_REQ(FILE * out, const Uint32 * data, Uint32 l, Uint16 b){
  UtilSequenceReq* sig = (UtilSequenceReq*)data;
  fprintf(out, " senderData: %d sequenceId: %d RequestType: %s\n",
	  sig->senderData,
	  sig->sequenceId,
	  type2string((UtilSequenceReq::RequestType)sig->requestType));
  return true;
}
Ejemplo n.º 7
0
bool 
printUTIL_SEQUENCE_CONF(FILE * out, const Uint32 * data, Uint32 l, Uint16 b){
  UtilSequenceConf* sig = (UtilSequenceConf*)data;
  fprintf(out, " senderData: %d sequenceId: %d RequestType: %s\n",
	  sig->senderData,
	  sig->sequenceId,
	  type2string((UtilSequenceReq::RequestType)sig->requestType));
  fprintf(out, " val: [ %d %d ]\n", 
	  sig->sequenceValue[0],
	  sig->sequenceValue[1]);
  return true;
}
Ejemplo n.º 8
0
void master_exists_watcher (zhandle_t *zh,
                            int type,
                            int state,
                            const char *path,
                            void *watcherCtx) {
    if( type == ZOO_DELETED_EVENT) {
        assert( !strcmp(path, "/master") );
        run_for_master();
    } else {
        LOG_DEBUG(("Watched event: ", type2string(type)));
    }
}
Ejemplo n.º 9
0
void HumanBodyLaser::saveFinalDispInfos(const int lvl)
{
	string savefn;
	string lvlstr = type2string(lvl);
	float disscl = stereoPyr[lvl]->GetDisScale();

	Mat dispim;

	savefn = outdir + "/disp_" + type2string(lvl) + ".jpg";
	(stereoPyr[lvl]->GetDisp()).convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);

	savefn = outdir + "/disp_" + type2string(lvl) + ".yml";
	saveDispYML(savefn, stereoPyr[lvl]->GetDisp());

	savefn = outdir + "/matches_" + type2string(lvl) + ".list";
	saveAllMatches(savefn, stereoPyr[lvl]->GetDisp(), stereoPyr[lvl]->GetBestMcost(), stereoPyr[lvl]->GetBestPrior());
		
	savefn = outdir + "/mcost_" + type2string(lvl) + ".yml";
	saveBestCostYML(savefn, stereoPyr[lvl]->GetBestMcost());

	savefn = outdir + "/display_disp_" + type2string(lvl) + ".jpg";
	Mat msk = stereoPyr[lvl]->GetMskL();

	Mat erode_msk = erodeMask(msk, stereoPyr[lvl]->GetWsize() * 2 + 5);
	Mat erode_dispim;
	dispim.copyTo(erode_dispim, erode_msk);
	imwrite(savefn, erode_dispim);
}
Ejemplo n.º 10
0
void sfcloseout(CSOUND *csound)
{
    OPARMS  *O = csound->oparms;
    int     nb;

    alloc_globals(csound);
    if (!STA(osfopen))
      return;
    if ((nb = (O->outbufsamps - STA(outbufrem)) * sizeof(MYFLT)) > 0) {
      /* flush outbuffer */
      csound->nrecs++;
      csound->audtran(csound, STA(outbuf), nb);
    }
    if (STA(pipdevout) == 2 && (!STA(isfopen) || STA(pipdevin) != 2)) {
      /* close only if not open for input too */
      csound->rtclose_callback(csound);
    }
    if (STA(pipdevout) == 2)
      goto report;
    if (STA(outfile) != NULL) {
      if (!STA(pipdevout) && O->outformat != AE_VORBIS)
        sf_command(STA(outfile), SFC_UPDATE_HEADER_NOW, NULL, 0);
      sf_close(STA(outfile));
      STA(outfile) = NULL;
    }
#ifdef PIPES
    if (STA(pout) != NULL) {
      _pclose(STA(pout));
      STA(pout) = NULL;
    }
#endif

 report:
    if (STA(pipdevout) == 2) {
      csound->Message(csound,
                      "%"PRIi32" %d %s%lu%s%s\n",
                      csound->nrecs, O->outbufsamps, Str("sample blks of "),
                      (unsigned long)sizeof(MYFLT)*8,Str("-bit floats written to "),
                      STA(sfoutname));
    }
    else {
      csound->Message(csound, Str("%"PRIi32" %d sample blks of %s written to %s"),
                      O->outbufsamps, O->outbufsamps * O->sfsampsize,
                      getstrformat(O->outformat), STA(sfoutname));
      if (O->sfheader == 0)
        csound->Message(csound, Str(" (raw)\n"));
      else
        csound->Message(csound, " (%s)\n", type2string(O->filetyp));
    }
    STA(osfopen) = 0;
}
Ejemplo n.º 11
0
/**
 *
 * Watcher function called when the list of tasks
 * changes.
 *
 */
void tasks_watcher (zhandle_t *zh,
                    int type,
                    int state,
                    const char *path,
                    void *watcherCtx) {
    LOG_DEBUG(("Tasks watcher triggered %s %d", path, state));
    if( type == ZOO_CHILD_EVENT) {
        assert( !strcmp(path, "/tasks") );
        get_tasks();
    } else {
        LOG_INFO(("Watched event: %s", type2string(type)));
    }
    LOG_DEBUG(("Tasks watcher done"));
}
Ejemplo n.º 12
0
/**
 * connman_network_create:
 * @identifier: network identifier (for example an unqiue name)
 *
 * Allocate a new network and assign the #identifier to it.
 *
 * Returns: a newly-allocated #connman_network structure
 */
struct connman_network *connman_network_create(const char *identifier,
						enum connman_network_type type)
{
	struct connman_network *network;
	connman_uint8_t strength = 0;
	const char *str;
	char *temp;

	_DBG_NETWORK("identifier %s type %d", identifier, type);

	network = g_try_new0(struct connman_network, 1);
	if (network == NULL)
		return NULL;

	_DBG_NETWORK("network %p", network);

	__connman_element_initialize(&network->element);

	//temp = connman_dbus_encode_string(identifier);
	if (identifier == NULL) {
		temp = g_strdup_printf("hidden_%d", hidden_counter++);
		network->hidden = TRUE;
	} else
		temp = g_strdup(identifier);

	if (temp == NULL) {
		g_free(network);
		return NULL;
	}

	network->element.name = temp;
	network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;

	network->element.network = network;
	network->element.destruct = network_destruct;

	str = type2string(type);
	if (str != NULL)
		connman_element_set_string(&network->element, "Type", str);

	connman_element_set_uint8(&network->element, "Strength", strength);

	network->type       = type;
	network->secondary  = FALSE;
	network->identifier = g_strdup(temp);

	return network;
}
Ejemplo n.º 13
0
void HumanBodyLaser::saveSoInfos(const int lvl)
{
	string savefn;
	string lvlstr = type2string(lvl);
	float disscl = stereoPyr[lvl]->GetDisScale();

	Mat dispim;

	savefn = outdir + "/so_dispL_" + lvlstr + ".jpg";
	stereoPyr[lvl]->GetDispL().convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);

	savefn = outdir + "/so_dispR_" + lvlstr + ".jpg";
	stereoPyr[lvl]->GetDispR().convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);
}
Ejemplo n.º 14
0
static void			sessions_del(struct session *elt)
{
  struct tcp_stream		*tcp;

  if (NULL == elt)
    return;
  --sessions_count;
  if ((bonus_time || verbose) && (!elt->parent_id || verbose > 1))
    printf("Session #%d (%s) closed at %s (active sessions total: %d)\n",
	elt->parent_id ? elt->parent_id : elt->id,
	type2string(elt->type, 1),
	timestamp_to_string(&nids_last_pcap_header->ts),
	sessions_count);
  if (NULL != elt->next)
    elt->next->prev = elt->prev;
  if (NULL != elt->prev)
    elt->prev->next = elt->next;
  else
    first_session = elt->next;

  /*
   * If this is a TCP connection, tell libnids we do not
   * want to be notified of new data in this connection.
   *
   * We must not do it when the stream is already in a
   * closing state (NIDS_CLOSE, NIDS_TIMED_OUT, NIDS_RESET
   * or NIDS_EXITING) because nids_free_tcp_stream() would
   * then be called twice, resulting in a crash.
   */
  if ((elt->type & TYPE_TCP) &&
      (NULL != (tcp = nids_find_tcp_stream(&elt->addr))) &&
      (NIDS_DATA == tcp->nids_state))
    nids_free_tcp_stream(tcp);

# ifdef HAVE_LIBOSIPPARSER2
  /*
   * If this is a SIP session, finally free the memory
   * allocated for the call ID (couldn't be done before)
   */
  if (elt->type & TYPE_SIP)
    if (NULL != elt->u.sip_params.call_id)
      osip_call_id_free(elt->u.sip_params.call_id);
# endif

  dumper_close(elt->dumper);
  free(elt);
}
Ejemplo n.º 15
0
void logEvent(struct input_event* ev)
{
  char defaultCodeString[64];
  sprintf(defaultCodeString, "%X", ev->code);

  const char* scode = code2string(ev->type, ev->code, defaultCodeString);
  DOUT((s64)ev->time.tv_sec << " " << (s64)ev->time.tv_usec << " " << type2string(ev->type) << " code:" << scode << " val:" << ev->value);

/*  if(ev->type != EV_ABS)
  {
    printf("%d %d %s code:%s  val:%d  \n", ev->time.tv_sec, ev->time.tv_usec, type2string(ev->type), scode, ev->value);
  }
  else if(ev->type)
  {
    const char* abscode = abscode2string(ev->code);
    printf("%d %d %s code:%s  val:%d  \n", ev->time.tv_sec, ev->time.tv_usec, type2string(ev->type), abscode, ev->value);
  }*/
}
Ejemplo n.º 16
0
static struct session		*sessions_add(enum type t, struct tuple4 *addr, struct session *parent)
{
  struct session		*elt;
  static uint32_t		counter = 0;

  if (!(t & sessions_track_types))
    return NULL;
  elt = calloc(1, sizeof (struct session));
  elt->addr = *addr;
  elt->type = t;
  elt->id = ++counter;
  if (sessions_expiration_delay)
    elt->timeout = nids_last_pcap_header->ts.tv_sec + sessions_expiration_delay;
  if (t & TYPE_SIP)
    elt->callback = sip_callback;
  else
    if (t & TYPE_H225_RAS)
      elt->callback = h225_ras_callback;
    else
      if (t & TYPE_H225_CS)
	elt->callback = h225_cs_callback;
      else
	elt->callback = NULL;
  if (NULL != parent) {
    elt->parent_id = parent->id;
    elt->dumper = parent->dumper;
    elt->dumper->references++;
  } else
    elt->dumper = sessions_file_format ? dumper_open(t, elt->id) : NULL;
  elt->next = first_session;
  if (NULL != elt->next)
    elt->next->prev = elt;
  elt->prev = NULL;
  first_session = elt;
  ++sessions_count;
  if (verbose && (!elt->parent_id || verbose > 1))
    printf("Session #%d (%s) opened at %s (active sessions total: %d)\n",
	elt->parent_id ? elt->parent_id : elt->id,
	type2string(t, 1),
	timestamp_to_string(&nids_last_pcap_header->ts),
	sessions_count);
  return elt;
}
Ejemplo n.º 17
0
void list_rdr(SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id)
{
        SaErrorT        err;
	SaHpiEntryIdT	current_rdr;
	SaHpiEntryIdT	next_rdr;
	SaHpiRdrT	rdr;

	printf("RDR Info:\n");
	next_rdr = SAHPI_FIRST_ENTRY;
	do {
		int i;
		current_rdr = next_rdr;
		err = saHpiRdrGet(session_id, resource_id, current_rdr, 
				&next_rdr, &rdr);
		if (SA_OK != err) {
			if (current_rdr == SAHPI_FIRST_ENTRY)
				printf("Empty RDR table\n");
			else
				error("saHpiRdrGet", err);
			return;			
		}
		
		printf("\tRecordId: %x\n", rdr.RecordId);
		printf("\tRdrType: %s\n", rdrtype2str(rdr.RdrType));
		printf("\tEntity: \n");
		for ( i=0; i<SAHPI_MAX_ENTITY_PATH; i++)
		{
			SaHpiEntityT tmp = rdr.Entity.Entry[i];
			if (tmp.EntityType <= SAHPI_ENT_UNSPECIFIED)
				break;
				printf("\t\t{%s, %i}\n", 
				type2string(tmp.EntityType),
				tmp.EntityInstance);
		}
		printf("\tIdString: ");
	       	display_id_string(rdr.IdString);
	}while(next_rdr != SAHPI_LAST_ENTRY);
}
Ejemplo n.º 18
0
void HumanBodyLaser::saveOutlierInfos(const int lvl)
{
	string savefn;
	string lvlstr = type2string(lvl);

	Mat dispim;	
	
	savefn = outdir + "/rematch_dispL_" + lvlstr + ".jpg";
	dispim = imread(savefn, CV_LOAD_IMAGE_COLOR);
	savefn = outdir + "/outliers_rematch_dispL_" + lvlstr + ".jpg";
	saveOutliers(savefn, dispim, stereoPyr[lvl]->GetOutliersL());
		
	savefn = outdir + "/rematch_dispR_" + lvlstr + ".jpg";
	dispim = imread(savefn, CV_LOAD_IMAGE_COLOR);
	savefn = outdir + "/outliers_rematch_dispR_" + lvlstr + ".jpg";
	saveOutliers(savefn, dispim ,stereoPyr[lvl]->GetOutliersR());

	savefn = outdir + "/outlierL_" + lvlstr + ".yml";
	saveOutliersYML(savefn, stereoPyr[lvl]->GetOutliersL());

	savefn = outdir + "/outlierR_" + lvlstr + ".yml";
	saveOutliersYML(savefn, stereoPyr[lvl]->GetOutliersR());			
}
Ejemplo n.º 19
0
void HumanBodyLaser::saveRematchInfos(const int lvl)
{
	string savefn;
	string lvlstr = type2string(lvl);
	float disscl = stereoPyr[lvl]->GetDisScale();
	
	Mat dispim;

	savefn = outdir + "/rematch_dispL_" + lvlstr + ".jpg";
	(stereoPyr[lvl]->GetDispL()).convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);
		
	savefn = outdir + "/rematch_dispL_" + lvlstr + ".yml";
	saveDispYML(savefn, stereoPyr[lvl]->GetDispL());

	savefn = outdir + "/rematch_dispR_" + lvlstr + ".jpg";
	(stereoPyr[lvl]->GetDispR()).convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);
	
	savefn = outdir + "/rematch_dispR_" + lvlstr + ".yml";
	saveDispYML(savefn, stereoPyr[lvl]->GetDispR());

	savefn = outdir + "/rematch_KL_" + lvlstr + ".yml";
	saveBestkYML(savefn, stereoPyr[lvl]->GetBestKL());
	savefn = outdir + "/rematch_KR_" + lvlstr + ".yml";
	saveBestkYML(savefn, stereoPyr[lvl]->GetBestKR());

	savefn = outdir + "/rematch_mcostL_" + lvlstr + ".yml";
	saveBestCostYML(savefn, stereoPyr[lvl]->GetBestCostL());
	savefn = outdir + "/rematch_mcostR_" + lvlstr + ".yml";
	saveBestCostYML(savefn, stereoPyr[lvl]->GetBestCostR());

	savefn = outdir + "/rematch_priorL_" + lvlstr + ".yml";
	saveBestPriorYML(savefn, stereoPyr[lvl]->GetBestPriorL());
	savefn = outdir + "/rematch_priorR_" + lvlstr + ".yml";
	saveBestPriorYML(savefn, stereoPyr[lvl]->GetBestPriorR());
}
Ejemplo n.º 20
0
//send data to command socket and wait - blocking - for a reply (an error message or a data dump)
int KernelNetlinkProtocol::send_and_parse(const std::string& data)
{
    int ret = send_to(cmd_sock_, data, cmd_tx_buff_size_, reinterpret_cast<sockaddr*>(&cmd_peer_addr_));

    if (ret <= 0)
    {
        tnt::Log::warning("KernelNetlinkProtocol::send_and_parse: send_to returned ", ret);

        return ret;
    }

    //tnt::Log::info(colors::green, "\n==> KernelNetlinkProtocol sent new data (", ret, " bytes) to socket ", cmd_sock_);

    static std::vector<std::string> messages;
    static uint16_t multi_type;

    int error = 5;
    bool all = false;
    int dim = 0;

    while (!all)
    {
        dim = recv(cmd_sock_, cmd_rx_buffer_.data(), cmd_rx_buffer_.size(), 0);

        // sanity checks
        if (dim <= 0)
        {
            if (dim < -1)
            {
                tnt::Log::error("KernelNetlinkProtocol::send_and_parse: recv returned ", dim);
            }

            return dim;
        }

        //tnt::Log::info(colors::blue, "\n==> received new data from socket ", cmd_sock_, " (command socket)");

        std::string raw_input(cmd_rx_buffer_.data(), dim);
        size_t len = raw_input.size();
        size_t pos = 0;

        for (const nlmsghdr* nlh = reinterpret_cast<const nlmsghdr*>(raw_input.data()); NLMSG_OK(nlh, len); nlh = NLMSG_NEXT(nlh, len))
        {
            if (netlink_debug) print_nlmsghdr_info(nlh);

            pos += nlh->nlmsg_len;

            //tnt::Log::info(raw_input.size() - pos, " of ", raw_input.size()," bytes left");

            if (nlh->nlmsg_flags & NLM_F_MULTI)	// Multipart message
            {
                if (nlh->nlmsg_type == NLMSG_DONE)	// Multipart message ended, we can start parsing all the previous messages all together
                {
                    //tnt::Log::info(colors::green, "\n----> multipart ended, now parsing");

                    switch (multi_type)
                    {
                    case RTM_NEWLINK:
                        tnt::Application::raise(event::PortList(parse_multi<std::shared_ptr<NetworkPort>>(messages, link_parser)), this);
                        break;

                    case RTM_NEWADDR:
                        tnt::Application::raise(event::AddressList(parse_multi<AddressInfo>(messages, address_parser)), this);
                        break;

                    case RTM_NEWROUTE:
                        tnt::Application::raise(event::RouteList(parse_multi<RouteInfo>(messages, route_parser)), this);
                        break;

                    default:
                        break;
                    }

                    messages.clear();
                    error = 0;
                }
                else
                {
                    multi_type = nlh->nlmsg_type;
                    messages.push_back(raw_input.substr(pos - nlh->nlmsg_len, pos));

                    continue;	// do not parse yet, thus continue;
                }
            }
            else	// single message
            {
                //tnt::Log::info(colors::green, "\n----> single message, now parsing");

                if (nlh->nlmsg_type == NLMSG_ERROR)
                {
                    nlmsgerr* nl_err = reinterpret_cast<nlmsgerr*>(NLMSG_DATA(nlh));

                    if (nl_err->error)
                    {
                        tnt::Log::warning("error message, code: ", nl_err->error, "\tin reply to message ", type2string(nl_err->msg.nlmsg_type), ", sequence ", nl_err->msg.nlmsg_seq);
                    }
                    else
                    {
                        //tnt::Log::info("ACK message\tin reply to message ", type2string(nl_err->msg.nlmsg_type), ", sequence ", nl_err->msg.nlmsg_seq);
                    }

                    error = -(nl_err->error);
                }
            }

            all = true;
        }

        // sanity checks
        if (raw_input.size() - pos > 0)
        {
            tnt::Log::warning(colors::red, "unable to parse everything (", len, " bytes remaining)");
            raw_input = raw_input.substr(pos);
        }
        else
        {
            raw_input.clear();
        }
    }

    return error;
}
Ejemplo n.º 21
0
const char *__connman_device_get_type(struct connman_device *device)
{
	return type2string(device->type);
}
Ejemplo n.º 22
0
static void append_notify(DBusMessageIter *dict,
                          struct connman_session *session)
{
    struct session_info *info = session->info;
    struct session_info *info_last = session->info_last;
    struct connman_service *service;
    enum connman_service_type type;
    const char *name, *bearer;
    char *ifname;
    int idx;

    if (session->append_all || info->state != info_last->state) {
        const char *state = state2string(info->state);

        connman_dbus_dict_append_basic(dict, "State",
                                       DBUS_TYPE_STRING,
                                       &state);
        info_last->state = info->state;
    }

    if (session->append_all || session->service != session->service_last) {
        if (session->service) {
            service = session->service;
            name = __connman_service_get_name(service);
            idx = __connman_service_get_index(service);

            ifname = connman_inet_ifname(idx);
            if (!ifname)
                ifname = g_strdup("");

            type = connman_service_get_type(service);
            bearer = service2bearer(type);
        } else {
            service = NULL;
            name = "";
            ifname = g_strdup("");
            bearer = "";
        }

        connman_dbus_dict_append_basic(dict, "Name",
                                       DBUS_TYPE_STRING,
                                       &name);

        connman_dbus_dict_append_dict(dict, "IPv4",
                                      append_ipconfig_ipv4,
                                      service);

        connman_dbus_dict_append_dict(dict, "IPv6",
                                      append_ipconfig_ipv6,
                                      service);

        connman_dbus_dict_append_basic(dict, "Interface",
                                       DBUS_TYPE_STRING,
                                       &ifname);

        connman_dbus_dict_append_basic(dict, "Bearer",
                                       DBUS_TYPE_STRING,
                                       &bearer);

        g_free(ifname);

        session->service_last = session->service;
    }

    if (session->append_all ||
            info->config.type != info_last->config.type) {
        const char *type = type2string(info->config.type);

        connman_dbus_dict_append_basic(dict, "ConnectionType",
                                       DBUS_TYPE_STRING,
                                       &type);
        info_last->config.type = info->config.type;
    }

    if (session->append_all ||
            info->config.allowed_bearers != info_last->config.allowed_bearers) {
        connman_dbus_dict_append_array(dict, "AllowedBearers",
                                       DBUS_TYPE_STRING,
                                       append_allowed_bearers,
                                       info);
        info_last->config.allowed_bearers = info->config.allowed_bearers;
    }

    session->append_all = false;
}
Ejemplo n.º 23
0
const char *__connman_network_get_type(struct connman_network *network)
{
	return type2string(network->type);
}
Ejemplo n.º 24
0
void sfopenin(CSOUND *csound)           /* init for continuous soundin */
{
    OPARMS  *O = csound->oparms;
    char    *sfname, *fullName;
    SF_INFO sfinfo;
    int     fileType = (int) TYP_RAW;
    int     isfd = 0;   /* stdin */

    alloc_globals(csound);
    STA(inbufrem) = (uint32) 0;    /* start with empty buffer */
    sfname = O->infilename;
    if (UNLIKELY(sfname == NULL || sfname[0] == '\0'))
      csound->Die(csound, Str("error: no input file name"));

    if (strcmp(sfname, "stdin") == 0) {
      STA(pipdevin) = 1;
    }
#ifdef PIPES
    else if (sfname[0] == '|') {
      STA(pin) = _popen(sfname + 1, "r");
      isfd = fileno(STA(pin));
      STA(pipdevin) = 1;
    }
#endif
    else {
      csRtAudioParams   parm;
      /* check for real time audio input, and get device name/number */
      parm.devNum = check_rtaudio_name(sfname, &(parm.devName), 0);
      if (parm.devNum >= 0) {
        /* set device parameters */
        parm.bufSamp_SW   =
          (unsigned int) O->inbufsamps / (unsigned int) csound->inchnls;
        parm.bufSamp_HW   = O->oMaxLag;
        parm.nChannels    = csound->inchnls;
        parm.sampleFormat = O->informat;
        parm.sampleRate   = (float) csound->esr;
        /* open devaudio for input */
        if (UNLIKELY(csound->recopen_callback(csound, &parm) != 0))
          csoundDie(csound, Str("Failed to initialise real time audio input"));
        /*  & redirect audio gets  */
        csound->audrecv = csound->rtrecord_callback;
        STA(pipdevin) = 2;       /* no backward seeks !     */
        goto inset;             /* no header processing    */
      }
    }
    /* open file */
    memset(&sfinfo, 0, sizeof(SF_INFO));
    if (STA(pipdevin)) {
      STA(infile) = sf_open_fd(isfd, SFM_READ, &sfinfo, 0);
      if (UNLIKELY(STA(infile) == NULL)) {
        /* open failed: possibly raw file, but cannot seek back to try again */
        const char *sfError = Str(sf_strerror(NULL));
        csoundDie(csound, Str("isfinit: cannot open %s -- %s"), sfname, sfError);
      }
    }
    else {
      fullName = csoundFindInputFile(csound, sfname, "SFDIR;SSDIR");
      if (UNLIKELY(fullName == NULL))                     /* if not found */
        csoundDie(csound, Str("isfinit: cannot open %s"), sfname);
      STA(infile) = sf_open(fullName, SFM_READ, &sfinfo);
      if (STA(infile) == NULL) {
        /* open failed: maybe raw file ? */
        memset(&sfinfo, 0, sizeof(SF_INFO));
        sfinfo.samplerate = (int) MYFLT2LRND(csound->esr);
        sfinfo.channels = csound->nchnls;
        /* FIXME: assumes input sample format is same as output */
        sfinfo.format = TYPE2SF(TYP_RAW) | FORMAT2SF(O->outformat);
        STA(infile) = sf_open(fullName, SFM_READ, &sfinfo);  /* try again */
      }
      if (UNLIKELY(STA(infile) == NULL)) {
        const char *sfError = Str(sf_strerror(NULL));
        csoundDie(csound, Str("isfinit: cannot open %s -- %s"), fullName, sfError);
      }
      /* only notify the host if we opened a real file, not stdin or a pipe */
      csoundNotifyFileOpened(csound, fullName,
                              sftype2csfiletype(sfinfo.format), 0, 0);
      sfname = fullName;
    }
    /* chk the hdr codes  */
    if (sfinfo.samplerate != (int) MYFLT2LRND(csound->esr)) {
      csound->Warning(csound, Str("audio_in %s has sr = %d, orch sr = %d"),
                              sfname, (int) sfinfo.samplerate,
                              (int) MYFLT2LRND(csound->esr));
    }
    if (sfinfo.channels != csound->inchnls) {
      csound->Warning(csound, Str("audio_in %s has %d chnls, orch %d chnls_i"),
                              sfname, (int) sfinfo.channels, csound->inchnls);
    }
    /* Do we care about the format?  Can assume float?? */
    O->informat = SF2FORMAT(sfinfo.format);
    fileType = (int) SF2TYPE(sfinfo.format);
    csound->audrecv = readsf;           /* will use standard audio gets  */
    if ((O->informat == AE_FLOAT || O->informat == AE_DOUBLE) &&
        !(fileType == TYP_WAV || fileType == TYP_AIFF || fileType == TYP_W64)) {
      /* do not scale "raw" floating point files */
      csound->spinrecv = sndfilein_noscale;
    }

 inset:
    /* calc inbufsize reqd */
    STA(inbufsiz) = (unsigned) (O->inbufsamps * sizeof(MYFLT));
    STA(inbuf) = (MYFLT*) csound->Calloc(csound,
                                         STA(inbufsiz)); /* alloc inbuf space */
    if (STA(pipdevout) == 2)
      csound->Message(csound,
                      Str("reading %d sample blks of %lu-bit floats from %s\n"),
                      O->inbufsamps * O->sfsampsize,
                      (unsigned long) sizeof(MYFLT)*8, sfname);
    else {
      csound->Message(csound,
                      Str("reading %d-byte blks of %s from %s (%s)\n"),
                      O->inbufsamps * (int) sfsampsize(FORMAT2SF(O->informat)),
                      getstrformat(O->informat), sfname, type2string(fileType));
    }
    STA(isfopen) = 1;
}
Ejemplo n.º 25
0
void sfopenout(CSOUND *csound)                  /* init for sound out       */
{                                               /* (not called if nosound)  */
    OPARMS  *O = csound->oparms;
    char    *s, *fName, *fullName;
    SF_INFO sfinfo;
    int     osfd = 1;   /* stdout */

    alloc_globals(csound);
    if (O->outfilename == NULL) {
      switch (O->filetyp) {
      case TYP_WAV:
      case TYP_W64:
      case TYP_WAVEX:
      case TYP_RF64:
        O->outfilename = "test.wav";
        break;
      case TYP_AIFF:
        O->outfilename = "test.aif";
        break;
      case TYP_AU:
        O->outfilename = "test.au";
        break;
      case TYP_PAF:
        O->outfilename = "test.paf";
        break;
      case TYP_SVX:
        O->outfilename = "test.svx";
        break;
      case TYP_NIST:
        O->outfilename = "test.sph";
        break;
      case TYP_VOC:
        O->outfilename = "test.voc";
        break;
      /* case TYP_IRCAM: */
      /*   O->outfilename = ""; */
      /*   break; */
      /* case TYP_MAT4: */
      /*   O->outfilename = ""; */
      /*   break;  */
      /* case TYP_MAT5: */
      /*   O->outfilename = ""; */
      /*   break;  */
      /* case TYP_PVF: */
      /*   O->outfilename = ""; */
      /*   break;   */
      case TYP_XI:
        O->outfilename = "test.xi";
        break;
      /* case TYP_HTK: */
      /*   O->outfilename = ""; */
      /*   break;   */
      /* case TYP_SDS: */
      /*   O->outfilename = "test.sds"; */
      /*   break;   */
      case TYP_AVR:
        O->outfilename = "test.avr";
        break;
      case TYP_SD2:
        O->outfilename = "test.sd2";
        break;
      case TYP_FLAC:
        O->outfilename = "test.flac";
        break;
      case TYP_CAF:
        O->outfilename = "test.caf";
        break;
      case TYP_OGG:
        O->outfilename = "test.ogg";
        break;
      /* case TYP_MPC2K: */
      /*   O->outfilename = ""; */
      /*   break; */
      default:
        O->outfilename = "test";
        break;
      }
    }
    STA(sfoutname) = fName = O->outfilename;

    if (strcmp(fName, "stdout") == 0) {
      STA(pipdevout) = 1;
    }
#ifdef PIPES
    else if (fName[0] == '|') {
      STA(pout) = _popen(fName+1, "w");
      osfd = fileno(STA(pout));
      STA(pipdevout) = 1;
      if (O->filetyp == TYP_AIFF || O->filetyp == TYP_WAV) {
        char fmt_name[6];
        if (O->sfsampsize == 8) {
          strcpy(fmt_name, "AU");
          O->filetyp = TYP_AU;
        }
        else {
          strcpy(fmt_name, "IRCAM");
          O->filetyp = TYP_IRCAM;
        }
        csound->Message(csound, Str("Output file type changed to %s "
                                    "for use in pipe\n"), fmt_name);
      }
    }
#endif
    else {
      csRtAudioParams   parm;
      /* check for real time audio output, and get device name/number */
      parm.devNum = check_rtaudio_name(fName, &(parm.devName), 1);
      if (parm.devNum >= 0) {
        /* set device parameters */
        parm.bufSamp_SW   = (unsigned int) O->outbufsamps / csound->nchnls;
        parm.bufSamp_HW   = O->oMaxLag;
        parm.nChannels    = csound->nchnls;
        parm.sampleFormat = O->outformat;
        parm.sampleRate   = (float) csound->esr;
        csound->spoutran  = spoutsf;
        /* open devaudio for output */
        if (UNLIKELY(csound->playopen_callback(csound, &parm) != 0))
          csoundDie(csound, Str("Failed to initialise real time audio output"));
        /*  & redirect audio puts  */
        csound->audtran = csound->rtplay_callback;
        STA(outbufrem)  = parm.bufSamp_SW * parm.nChannels;
        STA(pipdevout)  = 2;      /* no backward seeks !   */
        if (O->realtime == 1)     /* set realtime priority mode */
          csound->realtime_audio_flag = 1;
        goto outset;              /* no header needed      */
      }
      else if (strcmp(fName, "null") == 0) {
        STA(outfile) = NULL;
        if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT &&
            csound->oparms->outformat!=AE_DOUBLE) {
          if (csound->oparms->outformat==AE_SHORT)
            if (csound->dither_output==1)
              csound->audtran = writesf_dither_16;
            else
              csound->audtran = writesf_dither_u16;
          else if (csound->oparms->outformat==AE_CHAR)
            if (csound->dither_output==1)
              csound->audtran = writesf_dither_8;
            else
              csound->audtran = writesf_dither_u8;
          else
            csound->audtran = writesf;
        }
        else
          csound->audtran = writesf;
        goto outset;
      }
    }
    /* set format parameters */
    memset(&sfinfo, 0, sizeof(SF_INFO));
    //sfinfo.frames     = 0;
    sfinfo.samplerate = (int) MYFLT2LRND(csound->esr);
    sfinfo.channels   = csound->nchnls;
    sfinfo.format     = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat);
    /* open file */
    if (STA(pipdevout)) {
      STA(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0);
#ifdef PIPES
      if (STA(outfile) == NULL) {
        char fmt_name[6];
        if (O->sfsampsize == 8) {
          if (UNLIKELY(O->filetyp == TYP_AU))
            csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd,
                      Str(sf_strerror(NULL)));
          strcpy(fmt_name, "AU");
          O->filetyp = TYP_AU;
        }
        else {
          if (UNLIKELY(O->filetyp == TYP_IRCAM))
            csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd,
                      Str(sf_strerror(NULL)));
          strcpy(fmt_name, "IRCAM");
          O->filetyp = TYP_IRCAM;
        }
        csound->Message(csound, Str("Output file type changed to %s "
                                    "for use in pipe\n"), fmt_name);
        sfinfo.format = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat);
        STA(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0);
      }
#endif
      if (UNLIKELY(STA(outfile) == NULL))
        csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd,
                  Str(sf_strerror(NULL)));
      sf_command(STA(outfile), SFC_SET_VBR_ENCODING_QUALITY,
                 &O->quality, sizeof(double));
    }
    else {
      fullName = csoundFindOutputFile(csound, fName, "SFDIR");
      if (UNLIKELY(fullName == NULL))
        csoundDie(csound, Str("sfinit: cannot open %s"), fName);
      STA(sfoutname) = fullName;
      STA(outfile)   = sf_open(fullName, SFM_WRITE, &sfinfo);
      if (UNLIKELY(STA(outfile) == NULL))
        csoundDie(csound, Str("sfinit: cannot open %s\n%s"),
                  fullName, sf_strerror (NULL));
      sf_command(STA(outfile), SFC_SET_VBR_ENCODING_QUALITY,
                 &O->quality, sizeof(double));
      /* only notify the host if we opened a real file, not stdout or a pipe */
      csoundNotifyFileOpened(csound, fullName,
                              type2csfiletype(O->filetyp, O->outformat), 1, 0);
    }
    /* IV - Feb 22 2005: clip integer formats */
    if (O->outformat != AE_FLOAT && O->outformat != AE_DOUBLE)
      sf_command(STA(outfile), SFC_SET_CLIPPING, NULL, SF_TRUE);
    sf_command(STA(outfile), SFC_SET_ADD_PEAK_CHUNK,
               NULL, (csound->peakchunks ? SF_TRUE : SF_FALSE));
#ifdef SOME_FINE_DAY
    if (csound->dither_output) {        /* This may not be written yet!! */
      SF_DITHER_INFO  ditherInfo;
      memset(&ditherInfo, 0, sizeof(SF_DITHER_INFO));
      ditherInfo.type  = SFD_TRIANGULAR_PDF | SFD_DEFAULT_LEVEL;
      ditherInfo.level = 1.0;
      ditherInfo.name  = (char*) NULL;
      sf_command(STA(outfile), SFC_SET_DITHER_ON_WRITE,
                 &ditherInfo, sizeof(SF_DITHER_INFO));
    }
#endif
    if (!(O->outformat == AE_FLOAT || O->outformat == AE_DOUBLE) ||
        (O->filetyp == TYP_WAV || O->filetyp == TYP_AIFF ||
         O->filetyp == TYP_W64))
      csound->spoutran = spoutsf;       /* accumulate output */
    else
      csound->spoutran = spoutsf_noscale;
    if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT &&
        csound->oparms->outformat!=AE_DOUBLE) {
      if (csound->oparms->outformat==AE_SHORT)
        csound->audtran = writesf_dither_16;
      else if (csound->oparms->outformat==AE_CHAR)
        csound->audtran = writesf_dither_8;
      else
        csound->audtran = writesf;
    }
    else
      csound->audtran = writesf;
    /* Write any tags. */
    if ((s = csound->SF_id_title) != NULL && *s != '\0')
      sf_set_string(STA(outfile), SF_STR_TITLE, s);
    if ((s = csound->SF_csd_licence) == NULL || *s == '\0')
      s = csound->SF_id_copyright;
    if (s != NULL && *s != '\0')
      sf_set_string(STA(outfile), SF_STR_COPYRIGHT, s);
    else if (csound->SF_id_scopyright>=0) {
      char buff[256];
      time_t tt = time(NULL);
      strftime(buff, 256, "Copyright %Y: ", gmtime(&tt));
      strncat(buff,copyrightcode(csound->SF_id_scopyright), 255);
      buff[255] = '\0';
      sf_set_string(STA(outfile), SF_STR_COPYRIGHT, buff);
    }
    if ((s = csound->SF_id_software) != NULL && *s != '\0')
      sf_set_string(STA(outfile), SF_STR_SOFTWARE, s);
    if ((s = csound->SF_id_artist) != NULL && *s != '\0')
      sf_set_string(STA(outfile), SF_STR_ARTIST, s);
    if ((s = csound->SF_id_comment) != NULL && *s != '\0')
      sf_set_string(STA(outfile), SF_STR_COMMENT, s);
    if ((s = csound->SF_id_date) != NULL && *s != '\0')
      sf_set_string(STA(outfile), SF_STR_DATE, s);
    /* file is now open */
    STA(osfopen) = 1;

 outset:
    O->sfsampsize = (int) sfsampsize(FORMAT2SF(O->outformat));
    /* calc outbuf size & alloc bufspace */
    STA(outbufsiz) = O->outbufsamps * sizeof(MYFLT);
    STA(outbufp)   = STA(outbuf) = csound->Malloc(csound, STA(outbufsiz));
    if (STA(pipdevout) == 2)
      csound->Message(csound,
                      Str("writing %d sample blks of %lu-bit floats to %s\n"),
                      O->outbufsamps, (unsigned long) sizeof(MYFLT)*8,
                      STA(sfoutname));
    else {
     csound->Message(csound, Str("writing %d-byte blks of %s to %s"),
                    O->outbufsamps * O->sfsampsize,
                    getstrformat(O->outformat), STA(sfoutname));

    if (O->sfheader == 0)
      csound->Message(csound, Str(" (raw)\n"));
    else
      csound->Message(csound, " (%s)\n", type2string(O->filetyp));
    }
    STA(osfopen)   = 1;
    STA(outbufrem) = O->outbufsamps;
}
Ejemplo n.º 26
0
void HumanBodyLaser::BestDEBUG()
{	
	/*stereoPyr[tlvl]->GetDispL().convertTo(testim, CV_8UC1, stereoPyr[tlvl]->GetDisScale());
	imshow("testim", testim);
	waitKey(0);
	destroyWindow("testim");*/

	cout << "\n\t * DEBUG * " << endl;
	
	/*int tlvl = 0;
	int tlvlsz = 2 * 5 + 1;*/
		
	int tlvl = 0;
	int tlvlsz = 2 * (5 - tlvl) + 1;

	stereoPyr[tlvl]->setWsize(tlvlsz);
	stereoPyr[tlvl]->setMeanLR();
	stereoPyr[tlvl]->setPatchParams(tlvlsz + 2);
	stereoPyr[tlvl]->setVotingParams(tlvlsz);
		
	float disscl = stereoPyr[tlvl]->GetDisScale();
	string tlvlstr = type2string(tlvl), fn;

	Mat tim;
	Mat timK;
	Mat testim;

	double maxk, mink;

	fn = outdir + "/d_rematch_dispL_0.jpg";
	testim = imread(fn, CV_LOAD_IMAGE_GRAYSCALE);
	tim = erodeMask(stereoPyr[tlvl]->GetMskL(), stereoPyr[tlvl]->GetWsize() * 8);
	
	Mat saveim;
	testim.copyTo(saveim, tim);
	fn = outdir + "/d_erode_dispL_0.jpg";
	imwrite(fn, saveim);

	exit(1);

	fn = outdir + "/init_disp_0.yml";
	readInDispYML(fn, tim);
	
	Mat timR = Mat::zeros(tim.size(), CV_32FC1);
	Mat tmskR = stereoPyr[tlvl]->GetMskR();
	Mat tmskL = stereoPyr[tlvl]->GetMskL();
	int H = timR.size().height;
	int W = timR.size().width;
	for(int y = 0; y < H; ++y)
	{
		uchar * pmL = (uchar *)tmskL.ptr<uchar>(y);
		uchar * pmR = (uchar *)tmskR.ptr<uchar>(y);
		float * pdisL = (float *)tim.ptr<float>(y);
		float * pdisR = (float *)timR.ptr<float>(y);
		for(int x = 0; x < W; ++x)
		{
			if(pmL[x] == 0) continue;
			if(pdisL[x] == 0.f) continue;

			float d = pdisL[x];
			int rx = x - (int)d;

			if(rx < 0 || rx > W) continue;
			if(pmR[rx] == 0) continue;
			pdisR[rx] = d;
		}
	}

	tim.convertTo(testim, CV_8UC1, disscl );
	imwrite("d_dispL_0.jpg", testim);
	timR.convertTo(testim, CV_8UC1, disscl);
	imwrite("d_dispR_0.jpg", testim);
	
	stereoPyr[tlvl]->setDispL(tim);
	stereoPyr[tlvl]->setDispR(timR);

	Matfloat2uint(tim, timK);
	stereoPyr[tlvl]->setBestKL(timK);
	Matfloat2uint(timR, timK);
	stereoPyr[tlvl]->setBestKR(timK);

	stereoPyr[tlvl]->rematch(0);
	stereoPyr[tlvl]->rematch(1);

	fn = "d_rematch_dispL_" + tlvlstr + ".jpg";
	(stereoPyr[tlvl]->GetDispL()).convertTo(testim, CV_8UC1, disscl);
	imwrite(fn, testim);
	
	fn = "d_rematch_dispL_" + tlvlstr + ".yml";
	saveDispYML(fn, stereoPyr[tlvl]->GetDispL());

	fn = "d_rematch_dispR_" + tlvlstr + ".jpg";
	(stereoPyr[tlvl]->GetDispR()).convertTo(testim, CV_8UC1, disscl);
	imwrite(fn, testim);
	
	fn = "d_rematch_dispR_" + tlvlstr + ".yml";
	saveDispYML(fn, stereoPyr[tlvl]->GetDispR());

	exit(1);

		/*--------------------------------------------------------------------------------------------------------------------*/
		/*                                         disparity refinement : region voting                                   */
		/*-------------------------------------------------------------------------------------------------------------------*/

	cout << "\n\tdisparity general refinement ."   << endl;		
	
	/*stereoPyr[tlvl]->detectOutliers(minDisp-DISP_OCCLUSION, minDisp-DISP_MISMATCH, 0);
    fn = "d_rematch_dispL_" + tlvlstr + ".jpg";
	testim = imread(fn, CV_LOAD_IMAGE_COLOR);
	fn = "d_outliers_rematch_dispL_" + tlvlstr + ".jpg";
	saveOutliers(fn, testim, stereoPyr[tlvl]->GetOutliersL());
		
	fn = "d_rematch_dispR_" + tlvlstr + ".jpg";
	testim = imread(fn, CV_LOAD_IMAGE_COLOR);
	fn = "d_outliers_rematch_dispR_" + tlvlstr + ".jpg";
	saveOutliers(fn, testim ,stereoPyr[tlvl]->GetOutliersR());

	fn = "d_outlierL_rematch_" + tlvlstr + ".yml";
	saveOutliersYML(fn, stereoPyr[tlvl]->GetOutliersL());

	fn = "d_outlierR_rematch_" + tlvlstr + ".yml";
	saveOutliersYML(fn, stereoPyr[tlvl]->GetOutliersR());	*/
	
	fn = "d_dispL_" + tlvlstr + ".jpg";
	testim = imread(fn, CV_LOAD_IMAGE_COLOR);
	
	tim = Mat::zeros(testim.size(), CV_8UC1);
	Mat msk = stereoPyr[tlvl]->GetMskL();
	Mat disp = stereoPyr[tlvl]->GetDispL();
	for(int y = 0; y < H; ++y)
	{
		uchar * pm = (uchar *)msk.ptr<uchar>(y);
		uchar * pt = (uchar *)tim.ptr<uchar>(y);
		float * pd = (float *)disp.ptr<float>(y);
		for(int x = 0; x < W; ++x)
		{
			if(pm[x] == 0) continue;
			if(pd[x] == 0)
				pt[x] = 1;
		}
	}
	stereoPyr[tlvl]->setOutlierL(tim);
	fn = "d_outliers_dispL_" + tlvlstr + ".jpg";
	saveOutliers(fn, testim, stereoPyr[tlvl]->GetOutliersL());
		
	fn = "d_dispR_" + tlvlstr + ".jpg";
	testim = imread(fn, CV_LOAD_IMAGE_COLOR);
	tim = Mat::zeros(testim.size(), CV_8UC1);
	msk = stereoPyr[tlvl]->GetMskR();
	disp = stereoPyr[tlvl]->GetDispR();
	for(int y = 0; y < H; ++y)
	{
		uchar * pm = (uchar *)msk.ptr<uchar>(y);
		uchar * pt = (uchar *)tim.ptr<uchar>(y);
		float * pd = (float *)disp.ptr<float>(y);
		for(int x = 0; x < W; ++x)
		{
			if(pm[x] == 0) continue;
			if(pd[x] == 0)
				pt[x] = 1;
		}
	}
	stereoPyr[tlvl]->setOutlierR(tim);
	fn = "d_outliers_dispR_" + tlvlstr + ".jpg";
	saveOutliers(fn, testim ,stereoPyr[tlvl]->GetOutliersR());
	
	stereoPyr[tlvl]->calPatchBorders();		
	stereoPyr[tlvl]->regionVoting();   

	fn = "d_rv_dispL_" + type2string(tlvl) + ".yml";
	saveDispYML(fn, stereoPyr[tlvl]->GetDispL());
	fn = "d_rv_dispL_" + type2string(tlvl) + ".jpg";
	(stereoPyr[tlvl]->GetDispL()).convertTo(testim, CV_8UC1, disscl);
	imwrite(fn, testim);
	
	testim = imread(fn, CV_LOAD_IMAGE_COLOR);
	fn = "d_outliers_rv_dispL_" + type2string(tlvl) + ".jpg";
	saveOutliers(fn, testim, stereoPyr[tlvl]->GetOutliersL());

	fn = "d_rv_dispR_" + type2string(tlvl) + ".yml";
	saveDispYML(fn, stereoPyr[tlvl]->GetDispR());
	fn = "d_rv_dispR_" + type2string(tlvl) + ".jpg";
	(stereoPyr[tlvl]->GetDispR()).convertTo(testim, CV_8UC1, disscl);
	imwrite(fn, testim);
	
	testim = imread(fn, CV_LOAD_IMAGE_COLOR);
	fn = "d_outliers_rv_dispR_" + type2string(tlvl) + ".jpg";
	saveOutliers(fn, testim ,stereoPyr[tlvl]->GetOutliersR());

		
		/*--------------------------------------------------------------------------------------------------------------------*/
		/*                                             save results                                                       */
		/*-------------------------------------------------------------------------------------------------------------------*/

	stereoPyr[tlvl]->saveDisparity();
	fn = "d_disp_" + type2string(tlvl) + ".jpg";
	(stereoPyr[tlvl]->GetDisp()).convertTo(testim, CV_8UC1, disscl);
	imwrite(fn, testim);

	fn = "d_disp_" + type2string(tlvl) + ".yml";
	saveDispYML(fn, stereoPyr[tlvl]->GetDisp());

	stereoPyr[tlvl]->beelerRefine();

	fn = "d_refined_subpixel_disp_" + type2string(tlvl) + ".yml";
	saveDispYML(fn, stereoPyr[tlvl]->GetDisp());


//	fn = outdir + "/rv_dispL_" + type2string(tlvl) + ".yml";
//	readInDispYML(fn, tim);
//	stereoPyr[tlvl]->setDispL(tim);
//	fn = outdir + "/rv_dispR_" + type2string(tlvl) + ".yml";
//	readInDispYML(fn, tim);
//	stereoPyr[tlvl]->setDispR(tim);
//
//	stereoPyr[tlvl]->beelerRefine();
//
//	printf( "\n\t--------------------------------------------------------\n" );
//	printf( "\trefined by Beeler's formula. \n");
//	printf( "\t--------------------------------------------------------\n" );
//#ifdef  _DEBUG
//	fn = "refined_subpixel_disp_" + type2string(tlvl) + ".yml";
//	saveDispYML(fn, stereoPyr[tlvl]->GetDisp());
//#endif

	/*fn = outdir + "/refined_subpixel_disp_" + type2string(tlvl) + ".yml";
	readInDispYML(fn, tim);
	stereoPyr[tlvl]->setDisp(tim);*/


	return;
	

	//re-matching
	//fn = outdir + "/propagate_dispL_" + tlvlstr + ".yml";
	//readInDispYML(fn, tim);
	//stereoPyr[tlvl]->setDispL(tim);
	//Matfloat2uint(tim, timK);
	//stereoPyr[tlvl]->setBestKL(timK);
	
	//fn = outdir + "/propagate_dispR_" + tlvlstr + ".yml";
	//readInDispYML(fn, tim);
	//stereoPyr[tlvl]->setDispR(tim);
	//Matfloat2uint(tim, timK);
	//stereoPyr[tlvl]->setBestKR(timK);

	////rematch
	//stereoPyr[tlvl]->rematch(0);
	//stereoPyr[tlvl]->rematch(1);
	//
	//Mat dispim;

	//fn = "rematch_dispL_" + tlvlstr + ".jpg";
	//(stereoPyr[tlvl]->GetDispL()).convertTo(dispim, CV_8UC1, disscl);
	//imwrite(fn, dispim);
	//
	//fn = "rematch_dispL_" + tlvlstr + ".yml";
	//saveDispYML(fn, stereoPyr[tlvl]->GetDispL());

	//fn = "rematch_dispR_" + tlvlstr + ".jpg";
	//(stereoPyr[tlvl]->GetDispR()).convertTo(dispim, CV_8UC1, disscl);
	//imwrite(fn, dispim);
	
	//fn = "rematch_dispR_" + tlvlstr + ".yml";
	//saveDispYML(fn, stereoPyr[tlvl]->GetDispR());

	////bestk的访问方式
	//exit(1);

	//scanline optimization
	fn = outdir + "/rematch_dispL_" + tlvlstr + ".yml";
	readInDispYML(fn, tim);
	stereoPyr[tlvl]->setDispL(tim);
	fn = outdir + "/rematch_dispR_" + tlvlstr + ".yml";
	readInDispYML(fn ,tim);
	stereoPyr[tlvl]->setDispR(tim);
	fn = outdir + "/rematch_KL_" + tlvlstr + ".yml";
	readInBestkYML(fn, tim);
	stereoPyr[tlvl]->setBestKL(tim);
	fn = outdir + "/rematch_KR_" + tlvlstr + ".yml";
	readInBestkYML(fn, tim);
	stereoPyr[tlvl]->setBestKR(tim);
	fn = outdir + "/rematch_mcostL_" + tlvlstr + ".yml";
	readInBestCostYML(fn, tim);
	stereoPyr[tlvl]->setBestCostL(tim);
	fn = outdir + "/rematch_mcostR_" + tlvlstr + ".yml";
	readInBestCostYML(fn, tim);
	stereoPyr[tlvl]->setBestCostR(tim);
	fn = outdir + "/rematch_priorL_" + tlvlstr + ".yml";
	readInBestPriorYML(fn, tim);
	fn = outdir + "/rematch_priorR_" + tlvlstr + ".yml";
	readInBestPriorYML(fn, tim);
	stereoPyr[tlvl]->setBestPriorR(tim);

	int disRanges = stereoPyr[tlvl]->GetDisRanges();
	Mat * tcostvolL = new Mat[disRanges+1];
	Mat * tcostvolR = new Mat[disRanges+1];
	for(int k = 0; k<=disRanges; ++k)
	{
		fn = outdir + "/mcost_" + tlvlstr + "_0" + type2string(k) + ".yml";
		readInBestCostYML(fn, tim);
		tcostvolL[k] = tim.clone();
		fn = outdir + "/mcost_" + tlvlstr + "_1" + type2string(k) + ".yml";
		readInBestCostYML(fn, tim);
		tcostvolR[k] = tim.clone();
	}

	cout << "read in dispL/R, bestCostL/R, bestKL/R, bestPriorL/R, costVolL/R done." << endl;
	stereoPyr[tlvl]->setCostVol(0, tcostvolL);
	stereoPyr[tlvl]->setCostVol(1, tcostvolR);
	stereoPyr[tlvl]->scanlineOptimization(0);
	stereoPyr[tlvl]->scanlineOptimization(1);

	Mat dispim;
	string savefn;

	savefn = "so_dispL_" + tlvlstr + ".jpg";
	stereoPyr[tlvl]->GetDispL().convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);

	savefn = "so_dispR_" + tlvlstr + ".jpg";
	stereoPyr[tlvl]->GetDispR().convertTo(dispim, CV_8UC1, disscl);
	imwrite(savefn, dispim);
	exit(1);
}
Ejemplo n.º 27
0
static void append_notify(DBusMessageIter *dict,
					struct connman_session *session)
{
	struct session_info *info = session->info;
	struct session_info *info_last = session->info_last;
	struct connman_service *service;
	const char *name, *ifname, *bearer;

	if (session->append_all == TRUE ||
			info->state != info_last->state) {
		const char *state = state2string(info->state);

		connman_dbus_dict_append_basic(dict, "State",
						DBUS_TYPE_STRING,
						&state);
		info_last->state = info->state;
	}

	if (session->append_all == TRUE ||
			info->entry != info_last->entry) {
		if (info->entry == NULL) {
			name = "";
			ifname = "";
			service = NULL;
			bearer = "";
		} else {
			name = info->entry->name;
			ifname = info->entry->ifname;
			service = info->entry->service;
			bearer = info->entry->bearer;
		}

		connman_dbus_dict_append_basic(dict, "Name",
						DBUS_TYPE_STRING,
						&name);

		connman_dbus_dict_append_dict(dict, "IPv4",
						append_ipconfig_ipv4,
						service);

		connman_dbus_dict_append_dict(dict, "IPv6",
						append_ipconfig_ipv6,
						service);

		connman_dbus_dict_append_basic(dict, "Interface",
						DBUS_TYPE_STRING,
						&ifname);

		connman_dbus_dict_append_basic(dict, "Bearer",
						DBUS_TYPE_STRING,
						&bearer);

		info_last->entry = info->entry;
	}

	if (session->append_all == TRUE ||
			info->config.type != info_last->config.type) {
		const char *type = type2string(info->config.type);

		connman_dbus_dict_append_basic(dict, "ConnectionType",
						DBUS_TYPE_STRING,
						&type);
		info_last->config.type = info->config.type;
	}

	if (session->append_all == TRUE ||
			info->config.allowed_bearers != info_last->config.allowed_bearers) {
		connman_dbus_dict_append_array(dict, "AllowedBearers",
						DBUS_TYPE_STRING,
						append_allowed_bearers,
						info);
		info_last->config.allowed_bearers = info->config.allowed_bearers;
	}

	session->append_all = FALSE;
}
Ejemplo n.º 28
0
SaErrorT discover_domain(SaHpiDomainIdT domain_id)
{
	SaErrorT 	err;
	SaHpiSessionIdT session_id;
	SaHpiRptInfoT	rpt_info_before;
	SaHpiRptInfoT	rpt_info_after;
	SaHpiEntryIdT	current;
	SaHpiEntryIdT	next = SAHPI_FIRST_ENTRY;
	SaHpiRptEntryT	entry;
	
	if (next == SAHPI_LAST_ENTRY)
		return SA_OK;

	/* every domain requires a new session */
  	err = saHpiSessionOpen(domain_id, &session_id, NULL);
	if (SA_OK != err) {
		error("saHpiSessionOpen", err);
		return err;
	}

	/* force regeneration of the RPT */
 	err = saHpiResourcesDiscover(session_id);
	if (SA_OK != err) {
		error("saHpiResourcesDiscover", err);
		return err;
	}

	/* grab copy of the update counter before traversing RPT */
	err = saHpiRptInfoGet(session_id, &rpt_info_before);
	if (SA_OK != err) {
		error("saHpiRptInfoGet", err);
		return err;
	}

	do {
		int i;
		current = next;
		err = saHpiRptEntryGet(session_id, current, &next, &entry);
		if (SA_OK != err) {
			error("saHpiRptEntryGet", err);
			return err;
		}

		printf("%s\n", (char *)entry.ResourceTag.Data);
		printf("Entry ID: %x\n", (int) entry.EntryId);
		printf("Resource ID: %x\n", (int) entry.ResourceId);
		printf("Domain ID: %x\n", (int) entry.DomainId);
		printf("Revision: %c\n", entry.ResourceInfo.ResourceRev);
		printf("Version: %c\n", entry.ResourceInfo.SpecificVer);
		printf("Severity: %s\n",severity2str(entry.ResourceSeverity));

		printf("Entity Path:\n");
		for ( i=0; i<SAHPI_MAX_ENTITY_PATH; i++ )
		{
			SaHpiEntityT tmp = entry.ResourceEntity.Entry[i];
			if (tmp.EntityType <= SAHPI_ENT_UNSPECIFIED)
				break;

			printf("\t{%s, %i}\n", type2string(tmp.EntityType),
			       tmp.EntityInstance);
		}

		display_entity_capabilities(entry.ResourceCapabilities);
		printf("\n");

		/* if the resource is also a domain, then 
		 * traverse its RPT */	
		if (entry.ResourceCapabilities & SAHPI_CAPABILITY_DOMAIN) {
			err = discover_domain(entry.DomainId);
			if (SA_OK != err)
				return err;
		}
	} while (next != SAHPI_LAST_ENTRY);

	/* get a copy of update counter to see if we missed anything */
	err = saHpiRptInfoGet(session_id, &rpt_info_after);
	if (SA_OK != err) {
		error("saHpiRptInfoGet", err);
		return err;
	}

	if (rpt_info_after.UpdateCount != rpt_info_before.UpdateCount) {
		err = SA_ERR_HPI_ERROR;
		error("RPT table changed while obtaining resource info", err);
		return err;
	}

	return SA_OK;
}
Ejemplo n.º 29
0
void 
ddd_add_member(DDD p,
	       void *address, 
	       int blockcount, 
	       MPI_Datatype type)
{
  char err_msg[MAX_CHAR_IN_INPUT];
  int i;
  int n;

  i = p->num_members;
  
  if ( blockcount == 0 )
    {
      sr = sprintf(err_msg, "Attempt to add member %d type %s w/ 0 length!",
		   i, type2string(type));
      EH(-1, err_msg);
    }

  if ( address == NULL )
    {
      sprintf(err_msg, 
	      "attempt to add member %d type %s blockcount %d with a NULL address!",
	      i, type2string(type), blockcount);
#ifdef DEBUG_HKM
      printf("%s\n", err_msg); fflush(stdout);
#endif
      EH(-1, err_msg);
    }

  if ( i > p->max_members-1 )
    {
      p->max_members += SZ_DDD_INIT_MAX_MEMBERS;
      n = p->max_members;

      p->block_count = (int *) realloc(p->block_count, n*sizeof(int));
      p->data_type   = (MPI_Datatype *) realloc(p->data_type, 
						n*sizeof(MPI_Datatype));
      p->address     = (MPI_Aint *) realloc(p->address, n*sizeof(MPI_Aint));
    }

  p->block_count[i] = blockcount;
  p->data_type[i]   = type;
#ifdef PARALLEL
  /*
   *  This is just the identity operator on most systems
   */
  MPI_Get_address(address, &p->address[i]);
#ifdef DEBUG
   /* the check below does not work on dec or tflop */
  if ((int) address != p->address[i]) {
    printf("MPI_ADDRESS DOES SOMETHING WHOOHOO\n");
    printf("address = %d  p->address[i] = %d\n",
	   (int) address, p->address[i]);
  }
#endif

#endif
  p->num_members++;

#ifdef DEBUG_HKM
#ifdef USE_CHEMKIN
  ddd_size += blockcount;
  binMPI(blockcount, type);
#endif
#endif
  return;
}
Ejemplo n.º 30
0
void				sessions_exit(void)
{
  struct session		*elt;
  struct session		*elt_next;
  time_t			one_minute_later = 0;

  /*
   * Last pass to close timeout'd session... It is needed
   * because the last packet of a session marked for
   * deletion can be followed only by non-IP packets, so
   * it won't be deleted by ip_callback and would otherwise
   * appear as unclosed in the report generated below.
   * We jump forward one minute in order to timeout TCP
   * sessions that were opened during the last minute
   * of capture, which were given 60 seconds to complete
   * handshake but failed to do so.
   *
   * Also close SIP sessions that did not result in a call:
   * it happens often and the resulting spam in the report
   * generated below can be really annoying.
   */
  if (NULL != nids_last_pcap_header)
    one_minute_later = nids_last_pcap_header->ts.tv_sec + 60;
  for (elt = first_session; NULL != elt; elt = elt_next) {
    elt_next = elt->next;
    if (elt->timeout && (one_minute_later >= elt->timeout)) {
      sessions_del(elt);
      continue;
    }
# ifdef HAVE_LIBOSIPPARSER2
    if ((elt->type & TYPE_SIP) && !elt->u.sip_params.picked_up)
      sessions_del(elt);
# endif
  }

  /*
   * Print a report about unclosed sessions.
   */
  if (sessions_count) {
    fprintf(stderr,
	    "%d unclosed %s (id, type, last, source, destination, bytes):\n",
	    sessions_count, sessions_count > 1 ? "sessions" : "session");
    while (NULL != first_session) {
      fprintf(stderr, "#%d\t", first_session->id);
      fprintf(stderr, "%s\t", type2string(first_session->type, 1));
      fprintf(stderr, "%s\t", timestamp_to_string(&first_session->lastseen));
      fprintf(stderr, "%15s:%-5d\t",
	  inet_ntoa(*((struct in_addr *)&first_session->addr.saddr)),
	  first_session->addr.source);
      fprintf(stderr, "%15s:%-5d\t",
	  inet_ntoa(*((struct in_addr *)&first_session->addr.daddr)),
	  first_session->addr.dest);
      fprintf(stderr, "%12d\n", first_session->bytes);
      dumper_close(first_session->dumper);
      if (NULL != first_session->next) {
	first_session = first_session->next;
	free(first_session->prev);
	first_session->prev = NULL;
      } else {
	free(first_session);
	first_session = NULL;
      }
      --sessions_count;
    }
  }
  track_sessions = 0;
  nids_exit();
}