static void history_file_update(struct stats_file *data_file, const char *history_file_name) { struct stats_file _history_file; struct stats_file tempory_file; struct stats_file *history_file = NULL; if (stats_open(&_history_file, history_file_name) == 0) history_file = &_history_file; if (stats_open(&tempory_file, NULL) < 0) { if (history_file) stats_close(history_file); return; } summarize(data_file, history_file, &tempory_file, 13); swap_and_close_files(history_file, &tempory_file); }
int main(int argc, char **argv) { int err = 0; lua_State *L; dictionary *d = 0; setup_signal_handler(); message_handle_missing(MESSAGE_MISSING_REPLACE); /* parse arguments again, to override ini file */ err = parse_args(argc, argv); if (err != 0) { return (err > 0) ? 0 : err; } d = parse_config(inifile); if (!d) { log_error("could not open ini configuration %s\n", inifile); } locale_init(); L = lua_init(d); game_init(); bind_monsters(L); err = eressea_run(L, luafile); if (err) { log_error("script %s failed with code %d\n", luafile, err); return err; } game_done(); lua_done(L); log_close(); stats_write(stdout, ""); stats_close(); if (d) { iniparser_freedict(d); } return 0; }
int main(int argc, char **argv) { struct context ctx = {0}; struct event *signal_int; struct evhttp_bound_socket *handle; char listen_addr[256]; if (argc != 2) { printf("usage: statsrv STATS\n"); return -1; } if (stats_cl_create(&ctx.cl) != S_OK) { printf("Failed to allocate stats counter list\n"); return ERROR_FAIL; } if (stats_sample_create(&ctx.sample) != S_OK) { printf("Failed to allocate stats sample\n"); return ERROR_FAIL; } if (stats_sample_create(&ctx.prev_sample) != S_OK) { printf("Failed to allocate stats sample\n"); return ERROR_FAIL; } ctx.stats = open_stats(argv[1]); if (!ctx.stats) { printf("Failed to open stats %s\n", argv[1]); return ERROR_FAIL; } ctx.base = event_base_new(); if (!ctx.base) { printf("Could not allocate event base\n"); return 1; } /* add a handler for SIGINT */ signal_int = evsignal_new(ctx.base, SIGINT, sigint_cb, event_self_cbarg()); evsignal_add(signal_int,0); /* Create a new evhttp object to handle requests. */ ctx.http = evhttp_new(ctx.base); if (!ctx.http) { printf("could not create evhttp.\n"); return ERROR_FAIL; } evhttp_set_gencb(ctx.http, http_request_cb, &ctx); /* Now we tell the evhttp what port to listen on */ handle = evhttp_bind_socket_with_handle(ctx.http, "0.0.0.0", 8080); if (!handle) { printf("couldn't bind to http port %d.\n", (int)8080); return ERROR_FAIL; } if (http_get_address(handle, listen_addr, sizeof(listen_addr)) == S_OK) printf("http: listening at %s\n", listen_addr); event_base_dispatch(ctx.base); event_free(signal_int); #if 0 start_time = current_time(); while (!signal_received) { err = stats_get_sample(stats,cl,sample); if (err != S_OK) { printf("Error %08x (%s) getting sample\n",err,error_message(err)); } clear(); sample_time = TIME_DELTA_TO_NANOS(start_time, sample->sample_time); mvprintw(0,0,"SAMPLE @ %6lld.%03llds SEQ:%d\n", sample_time / 1000000000ll, (sample->sample_time % 1000000000ll) / 1000000ll, sample->sample_seq_no); n = 1; maxy = getmaxy(stdscr); col = 0; for (j = 0; j < cl->cl_count; j++) { counter_get_key(cl->cl_ctr[j],counter_name,MAX_COUNTER_KEY_LENGTH+1); mvprintw(n,col+0,"%s", counter_name); mvprintw(n,col+29,"%15lld", stats_sample_get_value(sample,j)); mvprintw(n,col+46,"%15lld", stats_sample_get_delta(sample,prev_sample,j)); if (++n == maxy) { col += 66; n = 1; } } refresh(); tmp = prev_sample; prev_sample = sample; sample = tmp; FD_ZERO(&fds); FD_SET(0,&fds); now = current_time(); tv.tv_sec = 0; tv.tv_usec = 1000000 - (now % 1000000000) / 1000; ret = select(1, &fds, NULL, NULL, &tv); if (ret == 1) { ch = getch(); if (ch == 'c' || ch == 'C') { stats_reset_counters(stats); } } } close_screen(); #endif if (ctx.base) event_base_free(ctx.base); if (ctx.http) evhttp_free(ctx.http); if (ctx.stats) { stats_close(ctx.stats); stats_free(ctx.stats); } if (ctx.cl) stats_cl_free(ctx.cl); if (ctx.sample) stats_sample_free(ctx.sample); if (ctx.prev_sample) stats_sample_free(ctx.prev_sample); return 0; }
int main(int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; struct stats_file_header *hdr; struct stats_file data, *data_file; struct stats_record *rec; time_t start_ts; int err; rec = NULL; data_file = &data; putenv("TZ=GMT0"); context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else g_printerr("An unknown error occurred\n"); exit(1); } g_option_context_free(context); if (argc < 2) { printf("Usage: %s [FILENAME]\n", argv[0]); exit(0); } err = stats_open(data_file, argv[1]); if (err < 0) { fprintf(stderr, "failed open file %s\n", argv[1]); exit(1); } if (option_last_file_name) { struct stats_file last; if (stats_open(&last, option_last_file_name) < 0) { fprintf(stderr, "failed open file %s\n", option_last_file_name); exit(1); } rec = get_end(&last); } if (option_start_ts == -1) start_ts = time(NULL); else start_ts = option_start_ts; if (option_create > 0) stats_create(data_file, option_create, option_interval, start_ts, rec); hdr = get_hdr(data_file); if (hdr->magic != MAGIC) { fprintf(stderr, "header file magic test failed\n"); goto err; } stats_file_update_cache(data_file); stats_hdr_info(data_file); if (option_dump) stats_print_entries(data_file); if (option_summary) stats_print_diff(data_file); if (option_info_file_name) history_file_update(data_file, option_info_file_name); err: stats_close(data_file); return 0; }
int main(int argc, const char **argv) { AppInput app_input = {0}; VpxVideoWriter *writer = NULL; VpxVideoInfo info = {0}; vpx_codec_ctx_t codec; vpx_codec_enc_cfg_t enc_cfg; SvcContext svc_ctx; uint32_t i; uint32_t frame_cnt = 0; vpx_image_t raw; vpx_codec_err_t res; int pts = 0; /* PTS starts at 0 */ int frame_duration = 1; /* 1 timebase tick per frame */ FILE *infile = NULL; int end_of_stream = 0; int frames_received = 0; memset(&svc_ctx, 0, sizeof(svc_ctx)); svc_ctx.log_print = 1; exec_name = argv[0]; parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg); // Allocate image buffer if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, enc_cfg.g_w, enc_cfg.g_h, 32)) die("Failed to allocate image %dx%d\n", enc_cfg.g_w, enc_cfg.g_h); if (!(infile = fopen(app_input.input_filename, "rb"))) die("Failed to open %s for reading\n", app_input.input_filename); // Initialize codec if (vpx_svc_init(&svc_ctx, &codec, vpx_codec_vp9_cx(), &enc_cfg) != VPX_CODEC_OK) die("Failed to initialize encoder\n"); info.codec_fourcc = VP9_FOURCC; info.time_base.numerator = enc_cfg.g_timebase.num; info.time_base.denominator = enc_cfg.g_timebase.den; if (vpx_svc_get_layer_resolution(&svc_ctx, svc_ctx.spatial_layers - 1, (unsigned int *)&info.frame_width, (unsigned int *)&info.frame_height) != VPX_CODEC_OK) { die("Failed to get output resolution"); } if (!(app_input.passes == 2 && app_input.pass == 1)) { // We don't save the bitstream for the 1st pass on two pass rate control writer = vpx_video_writer_open(app_input.output_filename, kContainerIVF, &info); if (!writer) die("Failed to open %s for writing\n", app_input.output_filename); } // skip initial frames for (i = 0; i < app_input.frames_to_skip; ++i) vpx_img_read(&raw, infile); // Encode frames while (!end_of_stream) { vpx_codec_iter_t iter = NULL; const vpx_codec_cx_pkt_t *cx_pkt; if (frame_cnt >= app_input.frames_to_code || !vpx_img_read(&raw, infile)) { // We need one extra vpx_svc_encode call at end of stream to flush // encoder and get remaining data end_of_stream = 1; } res = vpx_svc_encode(&svc_ctx, &codec, (end_of_stream ? NULL : &raw), pts, frame_duration, VPX_DL_GOOD_QUALITY); printf("%s", vpx_svc_get_message(&svc_ctx)); if (res != VPX_CODEC_OK) { die_codec(&codec, "Failed to encode frame"); } while ((cx_pkt = vpx_codec_get_cx_data(&codec, &iter)) != NULL) { switch (cx_pkt->kind) { case VPX_CODEC_CX_FRAME_PKT: { if (cx_pkt->data.frame.sz > 0) vpx_video_writer_write_frame(writer, cx_pkt->data.frame.buf, cx_pkt->data.frame.sz, cx_pkt->data.frame.pts); printf("SVC frame: %d, kf: %d, size: %d, pts: %d\n", frames_received, !!(cx_pkt->data.frame.flags & VPX_FRAME_IS_KEY), (int)cx_pkt->data.frame.sz, (int)cx_pkt->data.frame.pts); ++frames_received; break; } case VPX_CODEC_STATS_PKT: { stats_write(&app_input.rc_stats, cx_pkt->data.twopass_stats.buf, cx_pkt->data.twopass_stats.sz); break; } default: { break; } } } if (!end_of_stream) { ++frame_cnt; pts += frame_duration; } } printf("Processed %d frames\n", frame_cnt); fclose(infile); if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec"); if (app_input.passes == 2) stats_close(&app_input.rc_stats, 1); if (writer) { vpx_video_writer_close(writer); } vpx_img_free(&raw); // display average size, psnr printf("%s", vpx_svc_dump_statistics(&svc_ctx)); vpx_svc_release(&svc_ctx); return EXIT_SUCCESS; }
int main(int argc, const char **argv_) { vpx_codec_ctx_t encoder; const char *in_fn = NULL, *out_fn = NULL, *stats_fn = NULL; int i; FILE *infile, *outfile; vpx_codec_enc_cfg_t cfg; vpx_codec_err_t res; int pass, one_pass_only = 0; stats_io_t stats; vpx_image_t raw; const struct codec_item *codec = codecs; int frame_avail, got_data; struct arg arg; char **argv, **argi, **argj; int arg_usage = 0, arg_passes = 1, arg_deadline = 0; int arg_ctrls[ARG_CTRL_CNT_MAX][2], arg_ctrl_cnt = 0; int arg_limit = 0; static const arg_def_t **ctrl_args = no_args; static const int *ctrl_args_map = NULL; int verbose = 0, show_psnr = 0; int arg_use_i420 = 1; int arg_have_timebase = 0; unsigned long cx_time = 0; unsigned int file_type, fourcc; y4m_input y4m; exec_name = argv_[0]; if (argc < 3) usage_exit(); /* First parse the codec and usage values, because we want to apply other * parameters on top of the default configuration provided by the codec. */ argv = argv_dup(argc - 1, argv_ + 1); for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { arg.argv_step = 1; if (arg_match(&arg, &codecarg, argi)) { int j, k = -1; for (j = 0; j < sizeof(codecs) / sizeof(codecs[0]); j++) if (!strcmp(codecs[j].name, arg.val)) k = j; if (k >= 0) codec = codecs + k; else die("Error: Unrecognized argument (%s) to --codec\n", arg.val); } else if (arg_match(&arg, &passes, argi)) { arg_passes = arg_parse_uint(&arg); if (arg_passes < 1 || arg_passes > 2) die("Error: Invalid number of passes (%d)\n", arg_passes); } else if (arg_match(&arg, &pass_arg, argi)) { one_pass_only = arg_parse_uint(&arg); if (one_pass_only < 1 || one_pass_only > 2) die("Error: Invalid pass selected (%d)\n", one_pass_only); } else if (arg_match(&arg, &fpf_name, argi)) stats_fn = arg.val; else if (arg_match(&arg, &usage, argi)) arg_usage = arg_parse_uint(&arg); else if (arg_match(&arg, &deadline, argi)) arg_deadline = arg_parse_uint(&arg); else if (arg_match(&arg, &best_dl, argi)) arg_deadline = VPX_DL_BEST_QUALITY; else if (arg_match(&arg, &good_dl, argi)) arg_deadline = VPX_DL_GOOD_QUALITY; else if (arg_match(&arg, &rt_dl, argi)) arg_deadline = VPX_DL_REALTIME; else if (arg_match(&arg, &use_yv12, argi)) { arg_use_i420 = 0; } else if (arg_match(&arg, &use_i420, argi)) { arg_use_i420 = 1; } else if (arg_match(&arg, &verbosearg, argi)) verbose = 1; else if (arg_match(&arg, &limit, argi)) arg_limit = arg_parse_uint(&arg); else if (arg_match(&arg, &psnrarg, argi)) show_psnr = 1; else argj++; } /* Ensure that --passes and --pass are consistent. If --pass is set and --passes=2, * ensure --fpf was set. */ if (one_pass_only) { /* DWIM: Assume the user meant passes=2 if pass=2 is specified */ if (one_pass_only > arg_passes) { fprintf(stderr, "Warning: Assuming --pass=%d implies --passes=%d\n", one_pass_only, one_pass_only); arg_passes = one_pass_only; } if (arg_passes == 2 && !stats_fn) die("Must specify --fpf when --pass=%d and --passes=2\n", one_pass_only); } /* Populate encoder configuration */ res = vpx_codec_enc_config_default(codec->iface, &cfg, arg_usage); if (res) { fprintf(stderr, "Failed to get config: %s\n", vpx_codec_err_to_string(res)); return EXIT_FAILURE; } /* Now parse the remainder of the parameters. */ for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { arg.argv_step = 1; if (0); else if (arg_match(&arg, &threads, argi)) cfg.g_threads = arg_parse_uint(&arg); else if (arg_match(&arg, &profile, argi)) cfg.g_profile = arg_parse_uint(&arg); else if (arg_match(&arg, &width, argi)) cfg.g_w = arg_parse_uint(&arg); else if (arg_match(&arg, &height, argi)) cfg.g_h = arg_parse_uint(&arg); else if (arg_match(&arg, &timebase, argi)) { cfg.g_timebase = arg_parse_rational(&arg); arg_have_timebase = 1; } else if (arg_match(&arg, &error_resilient, argi)) cfg.g_error_resilient = arg_parse_uint(&arg); else if (arg_match(&arg, &lag_in_frames, argi)) cfg.g_lag_in_frames = arg_parse_uint(&arg); else if (arg_match(&arg, &dropframe_thresh, argi)) cfg.rc_dropframe_thresh = arg_parse_uint(&arg); else if (arg_match(&arg, &resize_allowed, argi)) cfg.rc_resize_allowed = arg_parse_uint(&arg); else if (arg_match(&arg, &resize_up_thresh, argi)) cfg.rc_resize_up_thresh = arg_parse_uint(&arg); else if (arg_match(&arg, &resize_down_thresh, argi)) cfg.rc_resize_down_thresh = arg_parse_uint(&arg); else if (arg_match(&arg, &resize_down_thresh, argi)) cfg.rc_resize_down_thresh = arg_parse_uint(&arg); else if (arg_match(&arg, &end_usage, argi)) cfg.rc_end_usage = arg_parse_uint(&arg); else if (arg_match(&arg, &target_bitrate, argi)) cfg.rc_target_bitrate = arg_parse_uint(&arg); else if (arg_match(&arg, &min_quantizer, argi)) cfg.rc_min_quantizer = arg_parse_uint(&arg); else if (arg_match(&arg, &max_quantizer, argi)) cfg.rc_max_quantizer = arg_parse_uint(&arg); else if (arg_match(&arg, &undershoot_pct, argi)) cfg.rc_undershoot_pct = arg_parse_uint(&arg); else if (arg_match(&arg, &overshoot_pct, argi)) cfg.rc_overshoot_pct = arg_parse_uint(&arg); else if (arg_match(&arg, &buf_sz, argi)) cfg.rc_buf_sz = arg_parse_uint(&arg); else if (arg_match(&arg, &buf_initial_sz, argi)) cfg.rc_buf_initial_sz = arg_parse_uint(&arg); else if (arg_match(&arg, &buf_optimal_sz, argi)) cfg.rc_buf_optimal_sz = arg_parse_uint(&arg); else if (arg_match(&arg, &bias_pct, argi)) { cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg); if (arg_passes < 2) fprintf(stderr, "Warning: option %s ignored in one-pass mode.\n", arg.name); } else if (arg_match(&arg, &minsection_pct, argi)) { cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg); if (arg_passes < 2) fprintf(stderr, "Warning: option %s ignored in one-pass mode.\n", arg.name); } else if (arg_match(&arg, &maxsection_pct, argi)) { cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg); if (arg_passes < 2) fprintf(stderr, "Warning: option %s ignored in one-pass mode.\n", arg.name); } else if (arg_match(&arg, &kf_min_dist, argi)) cfg.kf_min_dist = arg_parse_uint(&arg); else if (arg_match(&arg, &kf_max_dist, argi)) cfg.kf_max_dist = arg_parse_uint(&arg); else if (arg_match(&arg, &kf_disabled, argi)) cfg.kf_mode = VPX_KF_DISABLED; else argj++; } /* Handle codec specific options */ #if CONFIG_VP8_ENCODER if (codec->iface == &vpx_codec_vp8_cx_algo) { ctrl_args = vp8_args; ctrl_args_map = vp8_arg_ctrl_map; } #endif for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { int match = 0; arg.argv_step = 1; for (i = 0; ctrl_args[i]; i++) { if (arg_match(&arg, ctrl_args[i], argi)) { match = 1; if (arg_ctrl_cnt < ARG_CTRL_CNT_MAX) { arg_ctrls[arg_ctrl_cnt][0] = ctrl_args_map[i]; arg_ctrls[arg_ctrl_cnt][1] = arg_parse_int(&arg); arg_ctrl_cnt++; } } } if (!match) argj++; } /* Check for unrecognized options */ for (argi = argv; *argi; argi++) if (argi[0][0] == '-' && argi[0][1]) die("Error: Unrecognized option %s\n", *argi); /* Handle non-option arguments */ in_fn = argv[0]; out_fn = argv[1]; if (!in_fn || !out_fn) usage_exit(); memset(&stats, 0, sizeof(stats)); for (pass = one_pass_only ? one_pass_only - 1 : 0; pass < arg_passes; pass++) { int frames_in = 0, frames_out = 0; unsigned long nbytes = 0; struct detect_buffer detect; /* Parse certain options from the input file, if possible */ infile = strcmp(in_fn, "-") ? fopen(in_fn, "rb") : stdin; if (!infile) { fprintf(stderr, "Failed to open input file\n"); return EXIT_FAILURE; } fread(detect.buf, 1, 4, infile); detect.valid = 0; if (file_is_y4m(infile, &y4m, detect.buf)) { if (y4m_input_open(&y4m, infile, detect.buf, 4) >= 0) { file_type = FILE_TYPE_Y4M; cfg.g_w = y4m.pic_w; cfg.g_h = y4m.pic_h; /* Use the frame rate from the file only if none was specified * on the command-line. */ if (!arg_have_timebase) { cfg.g_timebase.num = y4m.fps_d; cfg.g_timebase.den = y4m.fps_n; } arg_use_i420 = 0; } else { fprintf(stderr, "Unsupported Y4M stream.\n"); return EXIT_FAILURE; } } else if (file_is_ivf(infile, &fourcc, &cfg.g_w, &cfg.g_h, detect.buf)) { file_type = FILE_TYPE_IVF; switch (fourcc) { case 0x32315659: arg_use_i420 = 0; break; case 0x30323449: arg_use_i420 = 1; break; default: fprintf(stderr, "Unsupported fourcc (%08x) in IVF\n", fourcc); return EXIT_FAILURE; } } else { file_type = FILE_TYPE_RAW; detect.valid = 1; } #define SHOW(field) fprintf(stderr, " %-28s = %d\n", #field, cfg.field) if (verbose && pass == 0) { fprintf(stderr, "Codec: %s\n", vpx_codec_iface_name(codec->iface)); fprintf(stderr, "Source file: %s Format: %s\n", in_fn, arg_use_i420 ? "I420" : "YV12"); fprintf(stderr, "Destination file: %s\n", out_fn); fprintf(stderr, "Encoder parameters:\n"); SHOW(g_usage); SHOW(g_threads); SHOW(g_profile); SHOW(g_w); SHOW(g_h); SHOW(g_timebase.num); SHOW(g_timebase.den); SHOW(g_error_resilient); SHOW(g_pass); SHOW(g_lag_in_frames); SHOW(rc_dropframe_thresh); SHOW(rc_resize_allowed); SHOW(rc_resize_up_thresh); SHOW(rc_resize_down_thresh); SHOW(rc_end_usage); SHOW(rc_target_bitrate); SHOW(rc_min_quantizer); SHOW(rc_max_quantizer); SHOW(rc_undershoot_pct); SHOW(rc_overshoot_pct); SHOW(rc_buf_sz); SHOW(rc_buf_initial_sz); SHOW(rc_buf_optimal_sz); SHOW(rc_2pass_vbr_bias_pct); SHOW(rc_2pass_vbr_minsection_pct); SHOW(rc_2pass_vbr_maxsection_pct); SHOW(kf_mode); SHOW(kf_min_dist); SHOW(kf_max_dist); } if(pass == (one_pass_only ? one_pass_only - 1 : 0)) { if (file_type == FILE_TYPE_Y4M) /*The Y4M reader does its own allocation. Just initialize this here to avoid problems if we never read any frames.*/ memset(&raw, 0, sizeof(raw)); else vpx_img_alloc(&raw, arg_use_i420 ? VPX_IMG_FMT_I420 : VPX_IMG_FMT_YV12, cfg.g_w, cfg.g_h, 1); // This was added so that ivfenc will create monotically increasing // timestamps. Since we create new timestamps for alt-reference frames // we need to make room in the series of timestamps. Since there can // only be 1 alt-ref frame ( current bitstream) multiplying by 2 // gives us enough room. cfg.g_timebase.den *= 2; } outfile = strcmp(out_fn, "-") ? fopen(out_fn, "wb") : stdout; if (!outfile) { fprintf(stderr, "Failed to open output file\n"); return EXIT_FAILURE; } if (stats_fn) { if (!stats_open_file(&stats, stats_fn, pass)) { fprintf(stderr, "Failed to open statistics store\n"); return EXIT_FAILURE; } } else { if (!stats_open_mem(&stats, pass)) { fprintf(stderr, "Failed to open statistics store\n"); return EXIT_FAILURE; } } cfg.g_pass = arg_passes == 2 ? pass ? VPX_RC_LAST_PASS : VPX_RC_FIRST_PASS : VPX_RC_ONE_PASS; #if VPX_ENCODER_ABI_VERSION > (1 + VPX_CODEC_ABI_VERSION) if (pass) { cfg.rc_twopass_stats_in = stats_get(&stats); } #endif write_ivf_file_header(outfile, &cfg, codec->fourcc, 0); /* Construct Encoder Context */ vpx_codec_enc_init(&encoder, codec->iface, &cfg, show_psnr ? VPX_CODEC_USE_PSNR : 0); ctx_exit_on_error(&encoder, "Failed to initialize encoder"); /* Note that we bypass the vpx_codec_control wrapper macro because * we're being clever to store the control IDs in an array. Real * applications will want to make use of the enumerations directly */ for (i = 0; i < arg_ctrl_cnt; i++) { if (vpx_codec_control_(&encoder, arg_ctrls[i][0], arg_ctrls[i][1])) fprintf(stderr, "Error: Tried to set control %d = %d\n", arg_ctrls[i][0], arg_ctrls[i][1]); ctx_exit_on_error(&encoder, "Failed to control codec"); } frame_avail = 1; got_data = 0; while (frame_avail || got_data) { vpx_codec_iter_t iter = NULL; const vpx_codec_cx_pkt_t *pkt; struct vpx_usec_timer timer; if (!arg_limit || frames_in < arg_limit) { frame_avail = read_frame(infile, &raw, file_type, &y4m, &detect); if (frame_avail) frames_in++; fprintf(stderr, "\rPass %d/%d frame %4d/%-4d %7ldB \033[K", pass + 1, arg_passes, frames_in, frames_out, nbytes); } else frame_avail = 0; vpx_usec_timer_start(&timer); // since we halved our timebase we need to double the timestamps // and duration we pass in. vpx_codec_encode(&encoder, frame_avail ? &raw : NULL, (frames_in - 1) * 2, 2, 0, arg_deadline); vpx_usec_timer_mark(&timer); cx_time += vpx_usec_timer_elapsed(&timer); ctx_exit_on_error(&encoder, "Failed to encode frame"); got_data = 0; while ((pkt = vpx_codec_get_cx_data(&encoder, &iter))) { got_data = 1; switch (pkt->kind) { case VPX_CODEC_CX_FRAME_PKT: frames_out++; fprintf(stderr, " %6luF", (unsigned long)pkt->data.frame.sz); write_ivf_frame_header(outfile, pkt); fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile); nbytes += pkt->data.raw.sz; break; case VPX_CODEC_STATS_PKT: frames_out++; fprintf(stderr, " %6luS", (unsigned long)pkt->data.twopass_stats.sz); stats_write(&stats, pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz); nbytes += pkt->data.raw.sz; break; case VPX_CODEC_PSNR_PKT: if (show_psnr) { int i; for (i = 0; i < 4; i++) fprintf(stderr, "%.3lf ", pkt->data.psnr.psnr[i]); } break; default: break; } } fflush(stdout); } /* this bitrate calc is simplified and relies on the fact that this * application uses 1/timebase for framerate. */ fprintf(stderr, "\rPass %d/%d frame %4d/%-4d %7ldB %7ldb/f %7"PRId64"b/s" " %7lu %s (%.2f fps)\033[K", pass + 1, arg_passes, frames_in, frames_out, nbytes, nbytes * 8 / frames_in, nbytes * 8 *(int64_t)cfg.g_timebase.den/2/ cfg.g_timebase.num / frames_in, cx_time > 9999999 ? cx_time / 1000 : cx_time, cx_time > 9999999 ? "ms" : "us", (float)frames_in * 1000000.0 / (float)cx_time); vpx_codec_destroy(&encoder); fclose(infile); if (!fseek(outfile, 0, SEEK_SET)) write_ivf_file_header(outfile, &cfg, codec->fourcc, frames_out); fclose(outfile); stats_close(&stats); fprintf(stderr, "\n"); if (one_pass_only) break; } vpx_img_free(&raw); free(argv); return EXIT_SUCCESS; }
/* =============================== =============================== */ void destroy_soar_agent (agent * delete_agent) { //print(delete_agent, "\nDestroying agent %s.\n", delete_agent->name); /* AGR 532 */ ///////////////////////////////////////////////////////// // Soar Modules - could potentially rely on hash tables ///////////////////////////////////////////////////////// // cleanup exploration for ( int i=0; i<EXPLORATION_PARAMS; i++ ) delete delete_agent->exploration_params[ i ]; // cleanup Soar-RL delete_agent->rl_params->apoptosis->set_value( rl_param_container::apoptosis_none ); delete delete_agent->rl_prods; delete delete_agent->rl_params; delete delete_agent->rl_stats; delete_agent->rl_params = NULL; // apoptosis needs to know this for excise_all_productions below // cleanup select select_init( delete_agent ); delete delete_agent->select; // cleanup predict delete delete_agent->prediction; // cleanup wma delete_agent->wma_params->activation->set_value( off ); delete delete_agent->wma_forget_pq; delete delete_agent->wma_touched_elements; delete delete_agent->wma_touched_sets; delete delete_agent->wma_params; delete delete_agent->wma_stats; delete delete_agent->wma_timers; // cleanup epmem epmem_close( delete_agent ); delete delete_agent->epmem_params; delete delete_agent->epmem_stats; delete delete_agent->epmem_timers; delete delete_agent->epmem_node_removals; delete delete_agent->epmem_node_mins; delete delete_agent->epmem_node_maxes; delete delete_agent->epmem_edge_removals; delete delete_agent->epmem_edge_mins; delete delete_agent->epmem_edge_maxes; delete delete_agent->epmem_id_repository; delete delete_agent->epmem_id_replacement; delete delete_agent->epmem_id_ref_counts; delete delete_agent->epmem_id_removes; delete delete_agent->epmem_wme_adds; delete delete_agent->epmem_promotions; delete delete_agent->epmem_db; // cleanup smem smem_close( delete_agent ); delete delete_agent->smem_changed_ids; delete delete_agent->smem_params; delete delete_agent->smem_stats; delete delete_agent->smem_timers; delete delete_agent->smem_db; // cleanup statistics db stats_close( delete_agent ); delete delete_agent->stats_db; delete_agent->stats_db = 0; delete delete_agent->debug_params; ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// remove_built_in_rhs_functions(delete_agent); getSoarInstance()->Delete_Agent(delete_agent->name); /* Free structures stored in agent structure */ free(delete_agent->name); free(delete_agent->top_dir_stack->directory); free(delete_agent->top_dir_stack); /* Freeing the agent's multi attributes structure */ multi_attribute* lastmattr = 0; for ( multi_attribute* curmattr = delete_agent->multi_attributes; curmattr != 0; curmattr = curmattr->next ) { symbol_remove_ref(delete_agent, curmattr->symbol); free_memory(delete_agent, lastmattr, MISCELLANEOUS_MEM_USAGE); lastmattr = curmattr; } free_memory(delete_agent, lastmattr, MISCELLANEOUS_MEM_USAGE); /* Freeing all the productions owned by this agent */ excise_all_productions(delete_agent, false); /* Releasing all the predefined symbols */ release_predefined_symbols(delete_agent); /* Releasing rete stuff RPM 11/06 */ free_with_pool(&delete_agent->rete_node_pool, delete_agent->dummy_top_node); free_with_pool(&delete_agent->token_pool, delete_agent->dummy_top_token); /* Cleaning up the various callbacks TODO: Not clear why callbacks need to take the agent pointer essentially twice. */ soar_remove_all_monitorable_callbacks(delete_agent); /* RPM 9/06 begin */ free_memory(delete_agent, delete_agent->left_ht, HASH_TABLE_MEM_USAGE); free_memory(delete_agent, delete_agent->right_ht, HASH_TABLE_MEM_USAGE); free_memory(delete_agent, delete_agent->rhs_variable_bindings, MISCELLANEOUS_MEM_USAGE); /* Releasing memory allocated in inital call to start_lex_from_file from init_lexer */ free_memory_block_for_string(delete_agent, delete_agent->current_file->filename); free_memory (delete_agent, delete_agent->current_file, MISCELLANEOUS_MEM_USAGE); /* Releasing trace formats (needs to happen before tracing hashtables are released) */ remove_trace_format (delete_agent, FALSE, FOR_ANYTHING_TF, NIL); remove_trace_format (delete_agent, FALSE, FOR_STATES_TF, NIL); Symbol *evaluate_object_sym = find_sym_constant (delete_agent, "evaluate-object"); remove_trace_format (delete_agent, FALSE, FOR_OPERATORS_TF, evaluate_object_sym); remove_trace_format (delete_agent, TRUE, FOR_STATES_TF, NIL); remove_trace_format (delete_agent, TRUE, FOR_OPERATORS_TF, NIL); /* Releasing hashtables allocated in init_tracing */ for (int i=0; i<3; i++) { free_hash_table(delete_agent, delete_agent->object_tr_ht[i]); free_hash_table(delete_agent, delete_agent->stack_tr_ht[i]); } /* Releasing memory allocated in init_rete */ for (int i=0; i<16; i++) { free_hash_table(delete_agent, delete_agent->alpha_hash_tables[i]); } /* Releasing other hashtables */ free_hash_table(delete_agent, delete_agent->variable_hash_table); free_hash_table(delete_agent, delete_agent->identifier_hash_table); free_hash_table(delete_agent, delete_agent->sym_constant_hash_table); free_hash_table(delete_agent, delete_agent->int_constant_hash_table); free_hash_table(delete_agent, delete_agent->float_constant_hash_table); /* Releasing memory pools */ memory_pool* cur_pool = delete_agent->memory_pools_in_use; memory_pool* next_pool; while(cur_pool != NIL) { next_pool = cur_pool->next; free_memory_pool(delete_agent, cur_pool); cur_pool = next_pool; } /* RPM 9/06 end */ // dynamic memory pools (cleared in the last step) for ( std::map< size_t, memory_pool* >::iterator it=delete_agent->dyn_memory_pools->begin(); it!=delete_agent->dyn_memory_pools->end(); it++ ) { delete it->second; } delete delete_agent->dyn_memory_pools; delete delete_agent->dyn_counters; // JRV: Frees data used by XML generation xml_destroy( delete_agent ); /* Free soar agent structure */ delete delete_agent; }