Beispiel #1
0
                void convert(rs2::frameset& frameset) override
                {
                    start_worker(
                        [this, &frameset] {
                            for (size_t i = 0; i < frameset.size(); i++) {
                                auto frame = frameset[i].as<rs2::depth_frame>();

                                if (frame && (_streamType == rs2_stream::RS2_STREAM_ANY || frame.get_profile().stream_type() == _streamType)) {
                                    if (frames_map_get_and_set(frame.get_profile().stream_type(), frame.get_frame_number())) {
                                        continue;
                                    }

                                    std::stringstream filename;
                                    filename << _filePath
                                        << "_" << frame.get_profile().stream_name()
                                        << "_" << frame.get_frame_number()
                                        << ".csv";

                                    std::string filenameS = filename.str();

                                    add_sub_worker(
                                        [filenameS, frame] {
                                            std::ofstream fs(filenameS, std::ios::trunc);

                                            if (fs) {
                                                for (int y = 0; y < frame.get_height(); y++) {
                                                    auto delim = "";

                                                    for (int x = 0; x < frame.get_width(); x++) {
                                                        fs << delim << frame.get_distance(x, y);
                                                        delim = ",";
                                                    }

                                                    fs << '\n';
                                                }

                                                fs.flush();
                                            }
                                        });
                                }
                            }

                            wait_sub_workers();
                        });
                }
Beispiel #2
0
static void	_expulse_player(t_ctrl *c, t_frame *fra, t_player *p, e_dir d)
{
  int		from;
  int		old_y;
  int		old_x;
  char		buff[64];

  unset_elem_from_map(c, fra, p->x, p->y);
  old_x = p->x;
  old_y = p->y;
  p->x = get_real_map_coord(p->x + gl_ops[d].op_x, getmapx(c));
  p->y = get_real_map_coord(p->y + gl_ops[d].op_y, getmapy(c));
  printf(GREEN"Expulsing player %d to (%d, %d)"END, p->id, p->x, p->y);
  set_elem_on_map(c, fra, p->x, p->y);
  from = get_frame_number(c, p, old_x, old_y);
  snprintf(buff, sizeof(buff) - 1, "deplacement : %d", from);
  jm_writeln(p->fd, buff);
}
Beispiel #3
0
    syncer_proccess_unit::syncer_proccess_unit()
        : _matcher((new timestamp_composite_matcher({})))
    {
        _matcher->set_callback([this](frame_holder f, syncronization_environment env)
        {

            std::stringstream ss;
            ss << "SYNCED: ";
            auto composite = dynamic_cast<composite_frame*>(f.frame);
            for (int i = 0; i < composite->get_embedded_frames_count(); i++)
            {
                auto matched = composite->get_frame(i);
                ss << matched->get_stream()->get_stream_type() << " " << matched->get_frame_number() << ", "<<std::fixed<< matched->get_frame_timestamp()<<"\n";
            }

            LOG_DEBUG(ss.str());
            env.matches.enqueue(std::move(f));
        });

        auto f = [&](frame_holder frame, synthetic_source_interface* source)
        {
            single_consumer_queue<frame_holder> matches;

            {
                std::lock_guard<std::mutex> lock(_mutex);
                _matcher->dispatch(std::move(frame), { source, matches });
            }

            frame_holder f;
            while (matches.try_dequeue(&f))
            {
                get_source().frame_ready(std::move(f));
            }
        };
        set_processing_callback(std::shared_ptr<rs2_frame_processor_callback>(
            new internal_frame_processor_callback<decltype(f)>(f)));
    }
Beispiel #4
0
/*
 * Find/display global/local variables which own the most heap memory in bytes
 */
CA_BOOL biggest_heap_owners_generic(unsigned int num, CA_BOOL all_reachable_blocks)
{
	CA_BOOL rc = CA_FALSE;
	unsigned int i;
	int nregs = 0;
	struct reg_value *regs_buf = NULL;
	size_t ptr_sz = g_ptr_bit >> 3;
	struct heap_owner *owners;
	struct heap_owner *smallest;

	struct ca_segment *segment;
	size_t total_bytes = 0;
	size_t processed_bytes = 0;

	struct inuse_block *inuse_blocks = NULL;
	unsigned long num_inuse_blocks;
	unsigned long inuse_index;

	struct inuse_block *blk;
	struct object_reference ref;
	size_t aggr_size;
	unsigned long aggr_count;
	address_t start, end, cursor;

	// Allocate an array for the biggest num of owners
	if (num == 0)
		return CA_FALSE;
	owners = (struct heap_owner *) calloc(num, sizeof(struct heap_owner));
	if (!owners)
		goto clean_out;
	smallest = &owners[num - 1];

	// First, create and populate an array of all in-use blocks
	inuse_blocks = build_inuse_heap_blocks(&num_inuse_blocks);
	if (!inuse_blocks || num_inuse_blocks == 0)
	{
		CA_PRINT("Failed: no in-use heap block is found\n");
		goto clean_out;
	}

	// estimate the work to enable progress bar
	for (i=0; i<g_segment_count; i++)
	{
		segment = &g_segments[i];
		if (segment->m_type == ENUM_STACK || segment->m_type == ENUM_MODULE_DATA)
			total_bytes += segment->m_fsize;
	}
	init_progress_bar(total_bytes);

	// Walk through all segments of threads' registers/stacks or globals
	for (i=0; i<g_segment_count; i++)
	{
		// bail out if user is impatient for the long searching
		if (user_request_break())
		{
			CA_PRINT("Abort searching biggest heap memory owners\n");
			goto clean_out;
		}

		// Only thread stack and global .data sections are considered
		segment = &g_segments[i];
		if (segment->m_type == ENUM_STACK || segment->m_type == ENUM_MODULE_DATA)
		{
			int tid = 0;
			// check registers if it is a thread's stack segment
			if (segment->m_type == ENUM_STACK)
			{
				tid = get_thread_id (segment);
				// allocate register value buffer for once
				if (!nregs && !regs_buf)
				{
					nregs = read_registers (NULL, NULL, 0);
					if (nregs)
						regs_buf = (struct reg_value*) malloc(nregs * sizeof(struct reg_value));
				}
				// check each register for heap reference
				if (nregs && regs_buf)
				{
					int k;
					int nread = read_registers (segment, regs_buf, nregs);
					for (k = 0; k < nread; k++)
					{
						if (regs_buf[k].reg_width == ptr_sz)
						{
							blk = find_inuse_block(regs_buf[k].value, inuse_blocks, num_inuse_blocks);
							if (blk)
							{
								ref.storage_type = ENUM_REGISTER;
								ref.vaddr = 0;
								ref.value = blk->addr;
								ref.where.reg.tid = tid;
								ref.where.reg.reg_num = k;
								ref.where.reg.name = NULL;
								calc_aggregate_size(&ref, ptr_sz, all_reachable_blocks, inuse_blocks, num_inuse_blocks, &aggr_size, &aggr_count);
								if (aggr_size > smallest->aggr_size)
								{
									struct heap_owner newowner;
									newowner.ref = ref;
									newowner.aggr_size = aggr_size;
									newowner.aggr_count = aggr_count;
									add_owner(owners, num, &newowner);
								}
							}
						}
					}
				}
			}

			// Calculate the memory region to search
			if (segment->m_type == ENUM_STACK)
			{
				start = get_rsp(segment);
				if (start < segment->m_vaddr || start >= segment->m_vaddr + segment->m_vsize)
					start = segment->m_vaddr;
				if (start - segment->m_vaddr >= segment->m_fsize)
					end = start;
				else
					end = segment->m_vaddr + segment->m_fsize;
			}
			else if (segment->m_type == ENUM_MODULE_DATA)
			{
				start = segment->m_vaddr;
				end = segment->m_vaddr + segment->m_fsize;
			}
			else
				continue;

			// Evaluate each variable or raw pointer in the target memory region
			cursor = ALIGN(start, ptr_sz);
			while (cursor < end)
			{
				size_t val_len = ptr_sz;
				address_t sym_addr;
				size_t    sym_sz;
				CA_BOOL known_sym = CA_FALSE;

				// If the address belongs to a known variable, include all its subfields
				// FIXME
				// consider subfields that are of pointer-like types, however, it will miss
				// references in an unstructured buffer
				ref.storage_type = segment->m_type;
				ref.vaddr = cursor;
				if (segment->m_type == ENUM_STACK)
				{
					ref.where.stack.tid = tid;
					ref.where.stack.frame = get_frame_number(segment, cursor, &ref.where.stack.offset);
					if (known_stack_sym(&ref, &sym_addr, &sym_sz) && sym_sz)
						known_sym = CA_TRUE;
				}
				else if (segment->m_type == ENUM_MODULE_DATA)
				{
					ref.where.module.base = segment->m_vaddr;
					ref.where.module.size = segment->m_vsize;
					ref.where.module.name = segment->m_module_name;
					if (known_global_sym(&ref, &sym_addr, &sym_sz) && sym_sz)
						known_sym = CA_TRUE;
				}
				if (known_sym)
				{
					if (cursor != sym_addr)
						ref.vaddr = cursor = sym_addr;	// we should never come to here!
					val_len = sym_sz;
				}

				// Query heap for aggregated memory size/count originated from the candidate variable
				if (val_len >= ptr_sz)
				{
					calc_aggregate_size(&ref, val_len, all_reachable_blocks, inuse_blocks, num_inuse_blocks, &aggr_size, &aggr_count);
					// update the top list if applies
					if (aggr_size >= smallest->aggr_size)
					{
						struct heap_owner newowner;
						if (val_len == ptr_sz)
							read_memory_wrapper(NULL, ref.vaddr, (void*)&ref.value, ptr_sz);
						else
							ref.value = 0;
						newowner.ref = ref;
						newowner.aggr_size = aggr_size;
						newowner.aggr_count = aggr_count;
						add_owner(owners, num, &newowner);
					}
				}
				cursor = ALIGN(cursor + val_len, ptr_sz);
			}
			processed_bytes += segment->m_fsize;
			set_current_progress(processed_bytes);
		}
	}
	end_progress_bar();

	if (!all_reachable_blocks)
	{
		// Big memory blocks may be referenced indirectly by local/global variables
		// check all in-use blocks
		for (inuse_index = 0; inuse_index < num_inuse_blocks; inuse_index++)
		{
			blk = &inuse_blocks[inuse_index];
			ref.storage_type = ENUM_HEAP;
			ref.vaddr = blk->addr;
			ref.where.heap.addr = blk->addr;
			ref.where.heap.size = blk->size;
			ref.where.heap.inuse = 1;
			calc_aggregate_size(&ref, ptr_sz, CA_FALSE, inuse_blocks, num_inuse_blocks, &aggr_size, &aggr_count);
			// update the top list if applies
			if (aggr_size >= smallest->aggr_size)
			{
				struct heap_owner newowner;
				ref.value = 0;
				newowner.ref = ref;
				newowner.aggr_size = aggr_size;
				newowner.aggr_count = aggr_count;
				add_owner(owners, num, &newowner);
			}
		}
	}

	// Print the result
	for (i = 0; i < num; i++)
	{
		struct heap_owner *owner = &owners[i];
		if (owner->aggr_size)
		{
			CA_PRINT("[%d] ", i+1);
			print_ref(&owner->ref, 0, CA_FALSE, CA_FALSE);
			CA_PRINT("    |--> ");
			print_size(owner->aggr_size);
			CA_PRINT(" (%ld blocks)\n", owner->aggr_count);
		}
	}
	rc = CA_TRUE;

clean_out:
	// clean up
	if (regs_buf)
		free (regs_buf);
	if (owners)
		free (owners);
	if (inuse_blocks)
		free_inuse_heap_blocks (inuse_blocks, num_inuse_blocks);

	return rc;
}
Beispiel #5
0
static int test3(const char* mxfFilename, const char* outFilename)
{
    MXFReader* input;
    int64_t frameCount;
    MXFClip* clip;
    MXFReaderListenerData data;
    MXFReaderListener listener;
    int64_t frameNumber;
    MXFFile* stdinMXFFile = NULL;
    MXFTimecode playoutTimecode;
    int i;
    MXFTimecode sourceTimecode;
    int type;
    int count;
    int result;

    memset(&data, 0, sizeof(MXFReaderListenerData));
    listener.data = &data;
    listener.accept_frame = accept_frame;
    listener.allocate_buffer = allocate_buffer;
    listener.deallocate_buffer = deallocate_buffer;
    listener.receive_frame = receive_frame;


    if (strcmp("-", mxfFilename) != 0)
    {
        if (!open_mxf_reader(mxfFilename, &input))
        {
            fprintf(stderr, "Failed to open MXF reader\n");
            return 0;
        }
    }
    else
    {
        if (!mxf_stdin_wrap_read(&stdinMXFFile))
        {
            fprintf(stderr, "Failed to open standard input MXF file\n");
            return 0;
        }
        if (!init_mxf_reader(&stdinMXFFile, &input))
        {
            mxf_file_close(&stdinMXFFile);
            fprintf(stderr, "Failed to open MXF reader using standard input\n");
            return 0;
        }
    }
    listener.data->input = input;

    if ((data.outFile = fopen(outFilename, "wb")) == NULL)
    {
        fprintf(stderr, "Failed to open output data file\n");
        return 0;
    }

    clip = get_mxf_clip(input);

    if (!position_at_frame(input, 10))
    {
        fprintf(stderr, "Failed to position at frame 10\n");
        return 0;
    }
    frameCount = 10;
    while (read_next_frame(input, &listener) == 1)
    {
        frameNumber = get_frame_number(input);
        printf("frame =  %"PFi64"\n", frameNumber);
        get_playout_timecode(input, &playoutTimecode);
        printf("playout timecode = ");
        print_timecode(&playoutTimecode);
        printf("\n");
        for (i = 0; i < get_num_source_timecodes(input); i++)
        {
            if ((result = get_source_timecode(input, i, &sourceTimecode, &type, &count)) == 1)
            {
                printf("source timecode (type = %d, count = %d) = ", type, count);
                print_timecode(&sourceTimecode);
                printf("\n");
            }
            else if (result == -1)
            {
                printf("source timecode (type = %d, count = %d) unavailable", type, count);
                printf("\n");
            }
        }
        frameCount++;
    }
    if (clip->duration != -1 && frameCount != clip->duration)
    {
        fprintf(stderr, "2) Frame count %"PFi64" != duration %"PFi64"\n", frameCount, clip->duration);
        return 0;
    }

    if (!position_at_frame(input, 0))
    {
        fprintf(stderr, "Failed to position at frame 0\n");
        return 0;
    }
    frameCount = 0;
    while (read_next_frame(input, &listener) == 1)
    {
        frameNumber = get_frame_number(input);
        printf("frame =  %"PFi64"\n", frameNumber);
        get_playout_timecode(input, &playoutTimecode);
        printf("playout timecode = ");
        print_timecode(&playoutTimecode);
        printf("\n");
        for (i = 0; i < get_num_source_timecodes(input); i++)
        {
            if ((result = get_source_timecode(input, i, &sourceTimecode, &type, &count)) == 1)
            {
                printf("source timecode (type = %d, count = %d) = ", type, count);
                print_timecode(&sourceTimecode);
                printf("\n");
            }
            else if (result == -1)
            {
                printf("source timecode (type = %d, count = %d) unavailable", type, count);
                printf("\n");
            }
        }
        frameCount++;
    }

    if (clip->duration != -1 && frameCount != clip->duration)
    {
        fprintf(stderr, "3) Frame count %"PFi64" != duration %"PFi64"\n", frameCount, clip->duration);
        return 0;
    }

    if (!position_at_frame(input, 5))
    {
        fprintf(stderr, "Failed to position at frame 5\n");
        return 0;
    }
    frameCount = 0;
    while (read_next_frame(input, &listener) == 1)
    {
        frameNumber = get_frame_number(input);
        printf("frame =  %"PFi64"\n", frameNumber);
        get_playout_timecode(input, &playoutTimecode);
        printf("playout timecode = ");
        print_timecode(&playoutTimecode);
        printf("\n");
        for (i = 0; i < get_num_source_timecodes(input); i++)
        {
            if ((result = get_source_timecode(input, i, &sourceTimecode, &type, &count)) == 1)
            {
                printf("source timecode (type = %d, count = %d) = ", type, count);
                print_timecode(&sourceTimecode);
                printf("\n");
            }
            else if (result == -1)
            {
                printf("source timecode (type = %d, count = %d) unavailable", type, count);
                printf("\n");
            }
        }
        frameCount++;
    }

    if (clip->duration != -1 && frameCount + 5 != clip->duration)
    {
        fprintf(stderr, "4) Frame count %"PFi64" != duration %"PFi64"\n", frameCount + 5, clip->duration);
        return 0;
    }


    close_mxf_reader(&input);
    fclose(data.outFile);
    if (data.buffer != NULL)
    {
        free(data.buffer);
    }

    return 1;
}
Beispiel #6
0
static int test1(const char* mxfFilename, MXFTimecode* startTimecode, int sourceTimecodeCount, const char* outFilename)
{
    MXFReader* input;
    MXFClip* clip;
    int64_t frameCount;
    int64_t frameNumber;
    MXFReaderListenerData data;
    MXFReaderListener listener;
    MXFFile* stdinMXFFile = NULL;
    MXFTimecode playoutTimecode;
    int i;
    MXFTimecode sourceTimecode;
    int type;
    int count;
    int result;
    uint32_t archiveCRC32;

    memset(&data, 0, sizeof(MXFReaderListenerData));
    listener.data = &data;
    listener.accept_frame = accept_frame;
    listener.allocate_buffer = allocate_buffer;
    listener.deallocate_buffer = deallocate_buffer;
    listener.receive_frame = receive_frame;

    if (strcmp("-", mxfFilename) != 0)
    {
        if (!open_mxf_reader(mxfFilename, &input))
        {
            fprintf(stderr, "Failed to open MXF reader\n");
            return 0;
        }
    }
    else
    {
        if (!mxf_stdin_wrap_read(&stdinMXFFile))
        {
            fprintf(stderr, "Failed to open standard input MXF file\n");
            return 0;
        }
        if (!init_mxf_reader(&stdinMXFFile, &input))
        {
            mxf_file_close(&stdinMXFFile);
            fprintf(stderr, "Failed to open MXF reader using standard input\n");
            return 0;
        }
    }
    listener.data->input = input;

    if ((data.outFile = fopen(outFilename, "wb")) == NULL)
    {
        fprintf(stderr, "Failed to open output data file\n");
        return 0;
    }

    clip = get_mxf_clip(input);
    printf("Clip frame rate = %d/%d fps\n", clip->frameRate.numerator, clip->frameRate.denominator);
    printf("Clip duration = %"PFi64" frames\n", clip->duration);

    if (startTimecode->hour != INVALID_TIMECODE_HOUR)
    {
        if (sourceTimecodeCount < 0)
        {
            if (!position_at_playout_timecode(input, startTimecode))
            {
                fprintf(stderr, "Failed to position files at start playout timecode\n");
                return 0;
            }
        }
        else
        {
            if (!position_at_source_timecode(input, startTimecode, SYSTEM_ITEM_TC_ARRAY_TIMECODE,
                                             sourceTimecodeCount))
            {
                fprintf(stderr, "Failed to position files at start source timecode\n");
                return 0;
            }
        }
    }

    frameCount = 0;
    while (read_next_frame(input, &listener) == 1)
    {
        frameNumber = get_frame_number(input);
        printf("frame =  %"PFi64"\n", frameNumber);
        get_playout_timecode(input, &playoutTimecode);
        printf("playout timecode = ");
        print_timecode(&playoutTimecode);
        printf("\n");
        for (i = 0; i < get_num_source_timecodes(input); i++)
        {
            if ((result = get_source_timecode(input, i, &sourceTimecode, &type, &count)) == 1)
            {
                printf("source timecode (type = %d, count = %d) = ", type, count);
                print_timecode(&sourceTimecode);
                printf("\n");
            }
            else if (result == -1)
            {
                printf("source timecode (type = %d, count = %d) unavailable", type, count);
                printf("\n");
            }
        }
        for (i = 0; i < get_num_archive_crc32(input); i++)
        {
            if (get_archive_crc32(input, i, &archiveCRC32))
            {
                printf("crc32 %d = 0x%08x\n", i, archiveCRC32);
            }
            else
            {
                printf("Failed to get archive crc-32\n");
            }
        }
        frameCount++;
    }
    if (clip->duration != -1 && frameCount != clip->duration)
    {
        fprintf(stderr, "1) Frame count %"PFi64" != duration %"PFi64"\n", frameCount, clip->duration);
        return 0;
    }

    close_mxf_reader(&input);
    fclose(data.outFile);
    if (data.buffer != NULL)
    {
        free(data.buffer);
    }

    return 1;
}
Beispiel #7
0
void draw_enhanced_actor(actor * actor_id)
{
	int i;
	double x_pos,y_pos,z_pos;
	float x_rot,y_rot,z_rot;
	//int texture_id;
	char *cur_frame;
	float healtbar_z=0;

	bind_texture_id(actor_id->texture_id);
	cur_frame=actor_id->tmp.cur_frame;

	//now, go and find the current frame
	i=get_frame_number(actor_id->body_parts->head, cur_frame);;
	if(i >= 0)healtbar_z=actor_id->body_parts->head->offsetFrames[i].box.max_z;

	glPushMatrix();//we don't want to affect the rest of the scene
	x_pos=actor_id->tmp.x_pos;
	y_pos=actor_id->tmp.y_pos;
	z_pos=actor_id->tmp.z_pos;

	if(z_pos==0.0f)//actor is walking, as opposed to flying, get the height underneath
		z_pos=-2.2f+height_map[actor_id->tmp.y_tile_pos*tile_map_size_x*6+actor_id->tmp.x_tile_pos]*0.2f;

	glTranslatef(x_pos+0.25f, y_pos+0.25f, z_pos);

	x_rot=actor_id->tmp.x_rot;
	y_rot=actor_id->tmp.y_rot;
	z_rot=actor_id->tmp.z_rot;
	z_rot+=180;//test
	z_rot=-z_rot;
	glRotatef(z_rot, 0.0f, 0.0f, 1.0f);
	glRotatef(x_rot, 1.0f, 0.0f, 0.0f);
	glRotatef(y_rot, 0.0f, 1.0f, 0.0f);

	if(actor_id->body_parts->legs)draw_model(actor_id->body_parts->legs,cur_frame,actor_id->ghost);
	if(actor_id->body_parts->torso)draw_model(actor_id->body_parts->torso,cur_frame,actor_id->ghost);
	if(actor_id->body_parts->head)draw_model(actor_id->body_parts->head,cur_frame,actor_id->ghost);

	if(actor_id->body_parts->weapon)
		{
			int glow;
			draw_model(actor_id->body_parts->weapon,cur_frame,actor_id->ghost);
			glow=actor_id->body_parts->weapon_glow;
			if(glow!=GLOW_NONE)draw_model_halo(actor_id->body_parts->weapon,cur_frame,glow_colors[glow].r,glow_colors[glow].g,glow_colors[glow].b);
		}

	if(actor_id->body_parts->shield)draw_model(actor_id->body_parts->shield,cur_frame,actor_id->ghost);
	if(actor_id->body_parts->helmet)draw_model(actor_id->body_parts->helmet,cur_frame,actor_id->ghost);
	if(actor_id->body_parts->cape)draw_model(actor_id->body_parts->cape,cur_frame,actor_id->ghost);


	//////
	glPopMatrix();//restore the scene
	//now, draw their damage

	glPushMatrix();
	glTranslatef(x_pos+0.25f, y_pos+0.25f, z_pos);
	glRotatef(-rz, 0.0f, 0.0f, 1.0f);

	draw_actor_banner(actor_id, healtbar_z);

	glPopMatrix();//we don't want to affect the rest of the scene
	//if(!actor_id->ghost)glEnable(GL_LIGHTING);

}