Example #1
0
/* 'pos' parameter is in milliseconds. */
int video_seek(int pos, int flags)
{
	gint64 len, cur;
	GstFormat fmt = GST_FORMAT_TIME;
	GstElement *sink = get_sink();

	if (!sink) return VIDEO_ERROR;
	
	if (!(gst_element_query(sink, GST_QUERY_POSITION, &fmt, &cur) &&
		  gst_element_query(sink, GST_QUERY_TOTAL, &fmt, &len))) 
		return VIDEO_ERROR;

	if (flags & VIDEO_SEEK_RELATIVE)
		cur += pos * GST_SECOND;
	else
		cur = pos * GST_SECOND;

	if (cur >= len) return video_stop();
	if (cur <= 0) cur = 0;
	
	if (!gst_element_seek(
			sink,
			GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH | GST_FORMAT_TIME,
			cur))
		return VIDEO_ERROR;

	return VIDEO_OK;
}
void sink_manager_heartbeat(ip_t ip, uint8_t *buf)
{
    sink_t *sink = get_sink(ip);

    if (sink != NULL) {
        sink->last_heartbeat = util_time_now();
    } else {
        sink_t new_sink;
        if (sink_initialize(&new_sink, ip, buf) != RET_OK) {
            return;
        }
        new_sink.last_heartbeat = util_time_now();
        add_sink(new_sink);
    }
    
    purge_dead_sinks();
}
Example #3
0
int video_get_pos_frames(unsigned long *_pos, unsigned long *_len)
{
	gint64 len, pos;
	GstFormat fmt = GST_FORMAT_DEFAULT;
	GstElement *sink = get_sink();

	if (!sink) return VIDEO_ERROR;
	
	if (gst_element_query (sink, GST_QUERY_POSITION, &fmt, &pos) &&
		gst_element_query (sink, GST_QUERY_TOTAL, &fmt, &len)) 
	{
		*_pos = pos;
		*_len = len;
		return VIDEO_OK;
	}
	return VIDEO_ERROR;
}
Example #4
0
int video_get_pos_msec(unsigned long *_pos, unsigned long *_len)
{
	gint64 len, pos;
	GstFormat fmt = GST_FORMAT_TIME;
	GstElement *sink = get_sink();

	if (!sink) return VIDEO_ERROR;

	if (gst_element_query (sink, GST_QUERY_POSITION, &fmt, &pos) &&
		gst_element_query (sink, GST_QUERY_TOTAL, &fmt, &len)) 
	{
		*_pos = ((pos) / GST_MSECOND);
		*_len = ((len) / GST_MSECOND);

		return VIDEO_OK;
	}
	return VIDEO_ERROR;
}
Example #5
0
bool Traffic_source::send(void) {
#ifdef DEBUG
    assert(can_send());
#endif 

    pLink link = (pLink) get_sink();
    pFlit a_flit = get_flit();
    link->receive(a_flit);
    if ( a_flit->is_header() ) {
    // Mark the time at which the packet leaves the source queue
    pPacket current_packet = a_flit->get_packet();
    current_packet->set_sent_time(net_clock.get_clock());
    }

    // Congestion monitor
    if ( (src_monitoring) && (net_clock.get_clock() > param.warmup_period) )  {
      if (a_flit->is_tail()) {
	unsigned int prev = src_congestion_monitor.back();
	src_congestion_monitor.push_back(net_clock.get_clock());
	src_congestion_monitor.push_back(prev-packet_size);
      } // if (a_flit..


      pPacket p = a_flit->get_packet();
      int flit_type = 1;  //assume header
      if (a_flit->is_tail())
        flit_type = 3;   //tail
      else if (!a_flit->is_header())
        flit_type = 2;  //body
      
      buffer_monitor.push_back(p->get_id());
      buffer_monitor.push_back(a_flit->get_sequence_id());
      buffer_monitor.push_back(flit_type);
      buffer_monitor.push_back(net_clock.get_clock());
      buffer_monitor.push_back(0);
      buffer_monitor.push_back(p->get_src_position().x);
      buffer_monitor.push_back(p->get_src_position().y);
      buffer_monitor.push_back(p->get_dst_position().x);
      buffer_monitor.push_back(p->get_dst_position().y);
      buffer_monitor.push_back(buffer.get_num_of_flits());
    }      // Congestion monitor
    
    return true;
}
Example #6
0
    int MFGraph::decompose(const int componentID, std::ostream & patt_stream, std::string chr)
    {
        IdMap<ListDigraph, ListDigraph::Node> idmap(mfGraph);
        
        // compute total flow
        float total_flow = this->total_flow();
#ifndef NDEBUG
        std::cout << "total flow:: " << total_flow << std::endl;
#endif
        
        int flownum = 0;
        
        // iterate while residual flow
        while (total_flow > 0.00001) {
            
            // compute residual flow for each arc
            ListDigraph::ArcMap<float> residual_flow(mfGraph);
            for (ListDigraph::ArcIt arc(mfGraph); arc != INVALID; ++arc) {
                residual_flow[arc] = (total_flow - flow_map[arc]);
                if(flow_map[arc] != 0){
// #ifndef NDEBUG
//                     std::cout << "source: " << mfGraph.id(mfGraph.source(arc))<< ", target: " << mfGraph.id(mfGraph.target(arc)) << ", flow: " << flow_map[arc] <<std::endl;
// #endif
                }
                
            }
#ifndef NDEBUG
            std::cout << "run the min-max dijkstra algorithm " << std::endl;
#endif
            // run the min-max dijkstra algorithm
            ListDigraph::NodeMap<float> dist(mfGraph);
            Dijkstra<ListDigraph, ListDigraph::ArcMap<float> >
            ::SetOperationTraits<DijkstraMinMaxOperationTraits<float> >
            ::Create dijkstra(mfGraph, residual_flow);
            dijkstra.distMap(dist);
            dijkstra.run(source, sink);
#ifndef NDEBUG
            std::cout << "get the resulting path and it's flow " << std::endl;
#endif
            // get the resulting path and it's flow
            Path<ListDigraph> shortestPath = dijkstra.path(sink);
            float path_flow = total_flow - dijkstra.dist(sink);

            // break out if this is not a valid path
            if (path_flow == 0) {
#ifndef NDEBUG
              std::cout << "Found invalid path" << std::endl;
#endif
              break;
            }

            // construct a meth fragment from path here
            // and remove path flow from each arc in path
#ifndef NDEBUG
            std::cout << "dijkstra.dist: " << dijkstra.dist(sink) << ", path_flow:" << path_flow << ", total flow: " << total_flow << " length: " << shortestPath.length() << std::endl;
#endif

            // it's a valid pattern, so increase number of paths found
            flownum++;

            std::stringstream region_list;
            MethylRead* pattern = NULL;
            int start, end;
            //MethylRead pattern = MethylRead(*read_map[source]);
            //int start = read_map[source]->start();
            //int end = read_map[sink]->end();
            
            for(Path<ListDigraph>::ArcIt arc(shortestPath); arc != INVALID; ++arc) {
                ListDigraph::Node s = mfGraph.source(arc);
                ListDigraph::Node t = mfGraph.target(arc);
                if (s == source) {
                    pattern = new MethylRead(*read_map[t]);
                    start = read_map[t]->start();
                    end = read_map[t]->end();
                    // end = read_map[sink]->end();

#ifndef NDEBUG
                    std::cout << "Original pattern = " << pattern->getMethString() << std::endl;
#endif
                    break;
                }
                
            }

#ifndef NDEBUG
            if (!pattern) {
              std::cout << "We should not hit this" << std::endl;
              for (Path<ListDigraph>::ArcIt arc(shortestPath); arc != INVALID; ++arc) {
                ListDigraph::Node s = mfGraph.source(arc);
                ListDigraph::Node t = mfGraph.target(arc);
                std::cout << mfGraph.id(s) << " -> " << mfGraph.id(t) << std::endl;
              }
            }
#endif
             
            for(Path<ListDigraph>::ArcIt arc(shortestPath); arc != INVALID; ++arc) {
// #ifndef NDEBUG
//                 std::cout << " After finding a path, " << "source: " << mfGraph.id(mfGraph.source(arc))<< ", target: " << mfGraph.id(mfGraph.target(arc)) << ", flow: " << flow_map[arc] << " ,arc - pathFlow: " << flow_map[arc] - path_flow << std::endl;
// #endif
                
                ListDigraph::Node s = mfGraph.source(arc);
                ListDigraph::Node t = mfGraph.target(arc);
                
                MethylRead *read = read_map[t];

                // don't print the source node or nodes connected to sink
                if (s != source && t != get_sink()) {
                    region_list << idmap[s];
                    if (!childless[t]) {
                        region_list << ",";
                    }
                }
                
                flow_map[arc] -= path_flow;
                
                // delete arc if no residual flow
                if (flow_map[arc] < 1e-6) {
                    mfGraph.erase(arc);
                }
                
                if (s == source) {
                    continue;
                }
                
                
                if (!read  || t == get_sink()) {
                    continue;
                }
                
             
                if (s != source && t != get_sink()) {
                    pattern->merge(read);
                    end = read->end();
                    //std::cout << "new pattern = " << pattern->getMethString() << std::endl;
                }
                
              
              //  if (childless[t]) {
              //      end = read->end();
              //  }
                
                
            }

#ifndef NDEBUG
            std::cout << "new pattern = " << pattern->getMethString() << std::endl;
#endif

            //Note we add source one nucleotide before every read
            patt_stream << chr << "\t" << start << "\t" << end;
            patt_stream << "\t" << componentID << "\t" << flownum << "\t" << path_flow;
            patt_stream << "\t" << pattern->getMethString() << "\t" << region_list.str() << std::endl;

            delete pattern;
            
            // recompute residual flow
            total_flow -= path_flow;
        }
        
        // all done
        return flownum;
    }
Example #7
0
pConnector Traffic_source::get_receiver(void) const {
    pLink link = (pLink) get_sink();
    return link->get_sink();
}