static gboolean gst_wavenc_event (GstPad * pad, GstEvent * event) { gboolean res = TRUE; GstWavEnc *wavenc; wavenc = GST_WAVENC (gst_pad_get_parent (pad)); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS:{ GST_DEBUG_OBJECT (wavenc, "got EOS"); #if 0 /* Write our metadata if we have any */ if (wavenc->metadata) { write_metadata (wavenc); write_cues (wavenc); write_labels (wavenc); } #endif /* write header with correct length values */ gst_wavenc_push_header (wavenc, wavenc->length); /* we're done with this file */ wavenc->finished_properly = TRUE; /* and forward the EOS event */ res = gst_pad_event_default (pad, event); break; } case GST_EVENT_NEWSEGMENT: /* Just drop it, it's probably in TIME format * anyway. We'll send our own newsegment event */ gst_event_unref (event); break; default: res = gst_pad_event_default (pad, event); break; } gst_object_unref (wavenc); return res; }
static gboolean gst_wavenc_event (GstPad * pad, GstObject * parent, GstEvent * event) { gboolean res = TRUE; GstWavEnc *wavenc; GstToc *toc; wavenc = GST_WAVENC (parent); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_CAPS: { GstCaps *caps; gst_event_parse_caps (event, &caps); gst_wavenc_sink_setcaps (pad, caps); /* have our own src caps */ gst_event_unref (event); break; } case GST_EVENT_EOS:{ GST_DEBUG_OBJECT (wavenc, "got EOS"); if (!wavenc->toc) { GST_DEBUG_OBJECT (wavenc, "have no toc, checking toc_setter"); wavenc->toc = gst_toc_setter_get_toc (GST_TOC_SETTER (wavenc)); } if (wavenc->toc) { GST_DEBUG_OBJECT (wavenc, "have toc"); gst_wavenc_write_toc (wavenc); } #if 0 /* Write our metadata if we have any */ if (wavenc->metadata) { write_metadata (wavenc); write_cues (wavenc); write_labels (wavenc); } #endif /* write header with correct length values */ gst_wavenc_push_header (wavenc, wavenc->length); /* we're done with this file */ wavenc->finished_properly = TRUE; /* and forward the EOS event */ res = gst_pad_event_default (pad, parent, event); break; } case GST_EVENT_SEGMENT: /* Just drop it, it's probably in TIME format * anyway. We'll send our own newsegment event */ gst_event_unref (event); break; case GST_EVENT_TOC: gst_event_parse_toc (event, &toc, NULL); if (toc) { if (wavenc->toc != toc) { if (wavenc->toc) gst_toc_unref (wavenc->toc); wavenc->toc = toc; } else { gst_toc_unref (toc); } } res = gst_pad_event_default (pad, parent, event); break; default: res = gst_pad_event_default (pad, parent, event); break; } return res; }
int run_assembly() { #ifdef _WIN32 struct _timeb time_start, time_end; _ftime(&time_start); #else struct timeb time_start, time_end; ftime(&time_start); #endif exit_code = EXIT_NORMAL; /*extern int generic_map[256]; ZeroMemory(generic_map, 256);*/ program_counter = 0x0000; stats_codesize = stats_datasize = stats_mintime = stats_maxtime = 0; last_label = NULL; error_occurred = false; listing_offset = 0; listing_for_line_done = false; line_start = NULL; old_line_num = 0; in_macro = 0; line_num = 0; #ifdef USE_BUILTIN_FCREATE cur_buf = 0; #endif #ifdef USE_REUSABLES curr_reusable = 0; total_reusables = 0; #endif expr_list = NULL; expr_list_tail = NULL; output_list = NULL; output_list_tail = NULL; assert(curr_input_file != NULL); //read in the input file if (!(mode & MODE_COMMANDLINE)) input_contents = (char *) get_file_contents (curr_input_file); if (!input_contents) { puts ("Couldn't open input file"); return EXIT_FATAL_ERROR; } out_ptr = output_contents; //along with the listing buffer, if required if ((mode & MODE_LIST)) { listing_buf = eb_init (LISTING_BUF_SIZE); listing_offset = 0; listing_on = true; } //find the path of the input file if (is_abs_path(curr_input_file)) { int i; strcpy(temp_path, curr_input_file); for (i = strlen(temp_path) - 1; temp_path[i] != '\\' && temp_path[i] != '/' && i > 0; i--); if (i >= 0) temp_path[i] = '\0'; else strcpy(temp_path, "."); } else { #ifdef WIN32 _getcwd(temp_path, sizeof (temp_path)); #else getcwd(temp_path, sizeof (temp_path)); #endif } //add the the input file's path to the include directories include_dirs = list_prepend (include_dirs, strdup (temp_path)); printf ("Pass one... \n"); int first_pass_session = StartSPASMErrorSession(); run_first_pass ((char *) input_contents); ReplayFatalSPASMErrorSession(first_pass_session); EndSPASMErrorSession(first_pass_session); //free include dirs when done if ((mode & MODE_COMMANDLINE) == 0) { release_file_contents(input_contents); input_contents = NULL; } list_free (include_dirs, true, NULL); include_dirs = NULL; //...and if there's output, run the second pass and write it to the output file if (mode & MODE_SYMTABLE || mode & MODE_NORMAL || mode & MODE_LIST) { printf ("Pass two... \n"); int second_pass_session = StartSPASMErrorSession(); run_second_pass (); ReplaySPASMErrorSession(second_pass_session); EndSPASMErrorSession(second_pass_session); if (mode & MODE_SYMTABLE) { char* fileName = change_extension(output_filename, "lab"); write_labels (fileName); free(fileName); } //run the output through the appropriate program export and write it to a file if (mode & MODE_NORMAL && output_filename != NULL) { write_file (output_contents, out_ptr - output_contents, output_filename); } //write the listing file if necessary if ((mode & MODE_LIST)) { FILE *file; char *name; //get file name name = change_extension (output_filename, "lst"); file = fopen (name, "wb"); if (!file) { printf ("Couldn't open listing file '%s'", name); free (name); return EXIT_FATAL_ERROR; } free (name); if (fwrite (listing_buf->start, 1, listing_offset, file) != listing_offset) { puts ("Error writing to listing file"); fclose (file); return EXIT_FATAL_ERROR; } fclose (file); eb_free(listing_buf); listing_buf = NULL; } //free the output buffer and all the names of input files list_free(input_files, true, NULL); input_files = NULL; } //if there's info to be dumped, do that if (mode & MODE_CODE_COUNTER) { fprintf (stdout, "Size: %u\nMin. execution time: %u\nMax. execution time: %u\n", stats_codesize, stats_mintime, stats_maxtime); } if (mode & MODE_STATS) { fprintf(stdout, "Number of labels: %u\nNumber of defines: %u\nCode size: %u\nData size: %u\nTotal size: %u\n", get_num_labels (), get_num_defines (), stats_codesize, stats_datasize, stats_codesize + stats_datasize); } #ifdef _WIN32 _ftime(&time_end); #else ftime(&time_end); #endif int s_diff = (int) (time_end.time - time_start.time); int ms_diff = time_end.millitm - time_start.millitm; if (ms_diff < 0) { ms_diff += 1000; s_diff -= 1; } else if (ms_diff > 1000) { ms_diff -= 1000; s_diff += 1; } printf("Assembly time: %0.3f seconds\n", (float) s_diff + ((float) ms_diff / 1000.0f)); return exit_code; }
int main(int argc, char **argv) { /** Argumetns. */ std::string path = argv[1]; int ID_IMG_i = std::stoi(argv[2]); int ID_IMG_e = std::stoi(argv[3]); /** * label = 0 // Reliabel ok * label = 1 // No-Reliabel missing occluder * label = 2 // No-Reliabel extra occluder * label = 3 // No geometry */ int N_LABELS = 4; if (argc == 5) N_LABELS = std::stoi(argv[4]); /** Big containers. */ float *sdepth, *descEr; int *neigh, *color; /** Set width and height */ int w, h; sdepth = new float[2000*2000]; // TODO: find a better way to get w and h read_sdepth(path + Utils::sprint("/labeling_cues/%08d.depth", ID_IMG_i), sdepth, w, h); delete[] sdepth; int N_IMGS = ID_IMG_e - ID_IMG_i + 1; int N_NODES = N_IMGS*w*h; // N pixels int *result = new int[N_NODES]; // Stores result of optimization sdepth = new float[N_NODES]; descEr = new float[N_NODES * 2]; neigh = new int[N_NODES*N_NEIGHS]; color = new int[N_NODES]; /**--------------------- Loading labeling cues ----------------------*/ memset(sdepth, 0, sizeof(float)*N_NODES); memset(descEr, 0, sizeof(float)*N_NODES * 2); memset(neigh, 0, sizeof(int)*N_NODES * N_NEIGHS); memset(color, 0, sizeof(int)*N_NODES); for (int i = 0; i <N_IMGS; i++) { int ID = ID_IMG_i + i; // Read cues std::string sdepth_name = path + Utils::sprint("/labeling_cues/%08d.depth", ID); std::string conf_name = path + Utils::sprint("/labeling_cues/%08d.conf", ID); std::string conf_neig = path + Utils::sprint("/labeling_cues/%08d.neig", ID); std::string color_name = path + Utils::sprint("/labeling_cues/%08d.color", ID); read_sdepth(sdepth_name, &sdepth[ i*h*w ], w, h); read_descErr(conf_name, &descEr[ i*h*w*2 ], w, h); read_neighbor(conf_neig, &neigh[ i*h*w*N_NEIGHS ], w, h); read_color(color_name, &color[ i*h*w ], w, h); } float mean_good, std_good, mean_bad, std_bad; std::string di_filename = path + Utils::sprint("/labeling_cues/di_distribution.txt"); read_di_distr(di_filename, mean_good, std_good, mean_bad, std_bad ); /**-------------------------------------------------------------------*/ try{ GCoptimizationGeneralGraph *gc = new GCoptimizationGeneralGraph( N_NODES, N_LABELS); // set up the needed data to pass to cost functions Img_cues cues; cues.numLab = N_LABELS; cues.w = w; cues.h = h; cues.sdepth = sdepth; cues.desc_er = descEr; //cues.neigh = neigh; cues.color = color; cues.mean_good = mean_good; cues.std_good = std_good; cues.mean_bad = mean_bad; cues.std_bad = std_bad; if (N_LABELS == 4) { gc->setDataCost(&dataFn_4, &cues); gc->setSmoothCost(&smoothFn_4, &cues); // smoothness comes from function pointer } else { gc->setDataCost(&dataFn_3, &cues); gc->setSmoothCost(&smoothFn_3, &cues); // smoothness comes from function pointer } /** ********************* Set up a grid neighborhood system ********************* */ // first set up horizontal neighbors for (int im_id = 0; im_id < N_IMGS; im_id++) for (int y = 0; y < h; y++ ) for (int x = 1; x < w; x++ ) gc->setNeighbors(x + y*w + im_id*w*h, x - 1 + y*w + im_id*w*h); // next set up vertical neighbors for (int im_id = 0; im_id < N_IMGS; im_id++) for (int y = 1; y < h; y++ ) for (int x = 0; x < w; x++ ) gc->setNeighbors(x + y*w + im_id*w*h, x + (y - 1)*w + im_id*w*h); // next set MV neighs for (int im_id = 0; im_id < N_IMGS; im_id++) { for (int y = STARTING_PADDING; y < h; y = y + MAX_PADDING) { for (int x = STARTING_PADDING; x < w; x = x + MAX_PADDING) { for (int layer_id = 0; layer_id < N_VIEWS_DAISY_ERR; layer_id ++) { int id_curr_px = x + y*w + im_id*w*h; int id_mv_px = neigh[x + y*w + im_id*w*h*N_NEIGHS + layer_id*w*h]; id_mv_px = id_mv_px - ID_IMG_i*w*h; // Remap the node id according if (id_mv_px < 0 || id_mv_px >= N_NODES) break; // No more neighbors gc->setNeighbors(id_curr_px, id_mv_px); }}}} delete[] neigh; //-------------------------------------------------------------------------------------- printf("\nBefore optimization energy is %d", gc->compute_energy()); gc->expansion(3);// run expansion for 2 iterations. For swap use gc->swap(num_iterations); //gc->expansion(-1);// run expansion for 2 iterations. For swap use gc->swap(num_iterations); //gc->swap(2); //gc->swap(-1); printf("\nAfter optimization energy is %d", gc->compute_energy()); for (int i = 0; i < N_NODES; i++) result[i] = gc->whatLabel(i); std::string labels_name = path + Utils::sprint("/labeling_cues/labels%u_from_%u_to_%u.bin", N_LABELS, ID_IMG_i, ID_IMG_e); write_labels(labels_name, result, N_LABELS, w, h, N_IMGS, N_NODES); delete gc; } catch (GCException e){ e.Report(); } delete[] result; delete[] sdepth; delete[] descEr; delete[] color; printf("\n Finished %d (%d) clock per sec %d", clock() / CLOCKS_PER_SEC, clock(), CLOCKS_PER_SEC); return 0; }
// ----------------------------------------------------------------------- int main(int argc, char **argv) { parse_args(argc, argv); // open input file yyin = fopen(argv[optind], "r"); if (!yyin) { printf("Error: cannot open input file, exiting.\n"); exit(1); } // parse program int res = yyparse(); fclose(yyin); yylex_destroy(); if (res != 0) { printf("Cannot parse source, exiting.\n"); nodelist_drop(program); exit(1); } // assembly binary image res = assembly(program->head); if (res < 0) { printf("Error at %s\n", assembly_error); nodelist_drop(program); exit(1); } res = img_write(output_file); if (res < 0) { if (res == E_IO_OPEN) { printf("Cannot open output file '%s', exiting.\n", output_file); } else if (res == E_IO_WRITE) { printf("Error: not all words written, output file '%s' is broken.\n", output_file); } else { printf("Unknown error during image write\n"); } } else { printf("Written %i words to '%s'.\n", res, output_file); } // write preprocessor output if (preprocessor) { char *pp_file = malloc(strlen(output_file)+10); sprintf(pp_file, "%s.pp.asm", output_file); printf("Writing preprocessor output to %s\n", pp_file); FILE *ppf = fopen(pp_file, "w"); if (!ppf) { printf("Cannot open preprocessor output file '%s' for writing, sorry.\n", pp_file); } preprocess(program, ppf); fclose(ppf); free(pp_file); } if (dump_labels) { char *lab_file = malloc(strlen(output_file)+10); sprintf(lab_file, "%s.lab", output_file); printf("Writing labels to %s\n", lab_file); FILE *labf = fopen(lab_file, "w"); if (!labf) { printf("Cannot open labels file '%s' for writing, sorry.\n", lab_file); } write_labels(labf); fclose(labf); free(lab_file); } free(output_file); nodelist_drop(program); labels_drop(); return 0; }