void _main(void) { #if DEBUG usbgecko_init(); usbgecko_printf("_main()\n"); #endif ios_reload(); #if DEBUG usbgecko_printf("ios_reload()\n"); #endif sync_before_read((void*)0x93010010, 0x1800); _memcpy((void*)0x80001800, (void*)0x93010010, 0x1800); sync_after_write((void*)0x80001800, 0x1800); if(*(vu32*)0xC0001804 == 0x53545542 && *(vu32*)0xC0001808 == 0x48415858) //stubhaxx { __asm( "sync ; isync\n" "lis %r3, 0x8000\n" "ori %r3, %r3, 0x1800\n" "mtlr %r3\n" "blr\n" ); } #if DEBUG usbgecko_printf("no loader stub, using internal\n"); #endif ios_cleanup(); #if DEBUG usbgecko_printf("ios_cleanup()\n"); #endif es_init(); #if DEBUG usbgecko_printf("es_init()\n"); #endif u64 ios_titleid = TITLE_ID(1, 35); //just to get away from the kernel es_launchtitle(ios_titleid); #if DEBUG usbgecko_printf("es_launchtitle()\n"); #endif es_init(); #if DEBUG usbgecko_printf("es_init()\n"); #endif es_launchtitle(HBC_LULZ); es_launchtitle(HBC_108); es_launchtitle(HBC_JODI); es_launchtitle(HBC_HAXX); es_launchtitle(SYSTEM_MENU); #if DEBUG usbgecko_printf("es_launchtitle()\n"); #endif while (1); }
// Check every op manipulates the stack correctly TEST op_stack_size() { for (size_t i = 0; i < E_OP__LENGTH; i++) { const tele_op_t *op = tele_ops[i]; if (op->get != NULL) { scene_state_t ss = {}; // initalise to empty // (needs dedicated initaliser) exec_state_t es; es_init(&es); es_push(&es); es_variables(&es)->script_number = 1; command_state_t cs; cs_init(&cs); // add params to stack (plus an extra 2, to check that too many // values aren't removed, warning: note the maximum stack size in // state.h) const int16_t stack_extra = 2; for (int j = 0; j < op->params + stack_extra; j++) cs_push(&cs, 0); // execute get op->get(op->data, &ss, &es, &cs); // check that the stack has the correct number of items in it if (op->returns) { ASSERT_EQm(op->name, cs_stack_size(&cs), stack_extra + 1); } else { ASSERT_EQm(op->name, cs_stack_size(&cs), stack_extra); } } if (op->set != NULL) { scene_state_t ss = {}; // initalise to empty // (needs dedicated initaliser) exec_state_t es; es_init(&es); command_state_t cs; cs_init(&cs); // add params to stack (plus an extra 2, to check that too many // values aren't removed, warning: note the maximum stack size in // state.h) // set functions require an extra value on the stack const int16_t stack_extra = 2; for (int j = 0; j < op->params + stack_extra + 1; j++) cs_push(&cs, 0); // execute get op->set(op->data, &ss, &es, &cs); // check that the stack has the correct number of items in it ASSERT_EQm(op->name, cs_stack_size(&cs), stack_extra); } } PASS(); }
// Check every mod manipulates the stack correctly TEST mod_stack_size() { for (size_t i = 0; i < E_MOD__LENGTH; i++) { const tele_mod_t *mod = tele_mods[i]; scene_state_t ss = {}; // initalise to empty // (needs dedicated initaliser) exec_state_t es; es_init(&es); command_state_t cs; cs_init(&cs); // add params to stack (plus an extra 2, to check that too many // values aren't removed, warning: note the maximum stack size in // state.h) const int16_t stack_extra = 2; for (int j = 0; j < mod->params + stack_extra; j++) cs_push(&cs, 0); // execute func const tele_command_t sub_command = { .length = 1, .separator = 0, .data = { { .tag = OP, .value = E_OP_A } } }; mod->func(&ss, &es, &cs, &sub_command); // check that the stack has the correct number of items in it ASSERT_EQm(mod->name, cs_stack_size(&cs), stack_extra); }
// Everything needs to call this to execute code. An execution // context is required for proper operation of DEL, THIS, L, W, IF process_result_t run_script_with_exec_state(scene_state_t *ss, exec_state_t *es, size_t script_no) { #ifdef TELETYPE_PROFILE tele_profile_script(script_no); #endif process_result_t result = {.has_value = false, .value = 0 }; es_set_script_number(es, script_no); for (size_t i = 0; i < ss_get_script_len(ss, script_no); i++) { es_set_line_number(es, i); // Commented code doesn't run. if (ss_get_script_comment(ss, script_no, i)) continue; // BREAK implemented with break... if (es_variables(es)->breaking) break; do { // TODO: Check for 0-length commands before we bother? result = process_command(ss, es, ss_get_script_command(ss, script_no, i)); // and WHILE implemented with while! } while (es_variables(es)->while_continue && !es_variables(es)->breaking); } es_variables(es)->breaking = false; ss_update_script_last(ss, script_no); #ifdef TELETYPE_PROFILE tele_profile_script(script_no); #endif return result; } // Only the test framework should call this, and it needs to follow up its // es_init() with an es_push(). // es_variables()->script_number should be set to test SCRIPT process_result_t run_command(scene_state_t *ss, const tele_command_t *cmd) { exec_state_t es; process_result_t o; es_init(&es); es_push(&es); // the lack of a script number here is a bug, so if you use this code, // something needs to set the script number // es_variables(es)->script_number = do { o = process_command(ss, &es, cmd); } while (es_variables(&es)->while_continue && !es_variables(&es)->breaking); return o; }
int main(int argc, char *argv[]) { char *secret_cred_file = NULL; char *clear_cred_file = NULL; int err = 0; int opt; if (argc == 1) { printf("Usage: %s -s secret_cred_file -c clear_cred_file\n", argv[0]); exit(0); } while ((opt = getopt(argc, argv, "c:s:")) != -1) { switch (opt) { case 'c': clear_cred_file = optarg; break; case 's': secret_cred_file = optarg; break; } } if (secret_cred_file == NULL || clear_cred_file == NULL) { fprintf(stderr, "ERROR: missing credential files\n"); err = 1; } if (err == 0) err = es_init(secret_cred_file, clear_cred_file); printf("TC_RESULT=%s ;;; TC_NAME=es_decrypt_secret_cred\n", err ? "FAIL" : "PASS"); exit(err == 0 ? 0 : 1); }
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { mlt_filter filter = mlt_frame_pop_service( frame ); *format = mlt_image_rgb24; mlt_properties_set_int( MLT_FRAME_PROPERTIES(frame), "consumer_deinterlace", 1 ); int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); if ( !error && *image ) { videostab self = filter->child; mlt_position length = mlt_filter_get_length2( filter, frame ); int h = *height; int w = *width; // Service locks are for concurrency control mlt_service_lock( MLT_FILTER_SERVICE( filter ) ); if ( !self->initialized ) { // Initialize our context self->initialized = 1; self->es = es_init( w, h ); self->pos_i = (vc*) malloc( length * sizeof(vc) ); self->pos_h = (vc*) malloc( length * sizeof(vc) ); self->pos_y = (vc*) malloc( h * sizeof(vc) ); self->rs = rs_init( w, h ); } char *vectors = mlt_properties_get( MLT_FILTER_PROPERTIES(filter), "vectors" ); if ( !vectors ) { // Analyse int pos = (int) mlt_filter_get_position( filter, frame ); self->pos_i[pos] = vc_add( pos == 0 ? vc_zero() : self->pos_i[pos - 1], es_estimate( self->es, *image ) ); // On last frame if ( pos == length - 1 ) { mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE(filter) ); double fps = mlt_profile_fps( profile ); // Filter and store the results hipass( self->pos_i, self->pos_h, length, fps ); serialize_vectors( self, length ); } } else { // Apply if ( self->initialized != 2 ) { // Load analysis results from property self->initialized = 2; deserialize_vectors( self, vectors, length ); } if ( self->initialized == 2 ) { // Stabilize float shutter_angle = mlt_properties_get_double( MLT_FRAME_PROPERTIES(frame) , "shutterangle" ); float pos = mlt_filter_get_position( filter, frame ); int i; for (i = 0; i < h; i ++) self->pos_y[i] = interp( self->lanc_kernels,self->pos_h, length, pos + (i - h / 2.0) * shutter_angle / (h * 360.0) ); rs_resample( self->lanc_kernels,self->rs, *image, self->pos_y ); } } mlt_service_unlock( MLT_FILTER_SERVICE( filter ) ); } return error; }
void ZmqServer::start() { // init estate if(this->peers.size() < 1) es_init(this->estate_node_address.c_str(), this->estate_node_port); else es_init_with_peers(this->estate_node_address.c_str(), this->estate_node_port, this->peers.c_str()); cout << "ZMQ API server listening to port: " << this->local_api_port << endl; while (true) { // prepare messages zmqpp::message response_msg; zmqpp::message request_msg; // receive requests this->recv_socket->receive(request_msg); // work on request if(request_msg.parts() > 1) { //cout << "received: " << request_msg.get(0) << " " << request_msg.get(1) << endl; if(request_msg.get(0) == "SET") { //--- SET command es_set(request_msg.get(1).c_str(), request_msg.get(2).c_str()); response_msg.push_back("OK"); } else if(request_msg.get(0) == "GET") { //--- GET command const char* data = es_get(request_msg.get(1).c_str()); response_msg.push_back("OK"); response_msg.push_back(data); } else if(request_msg.get(0) == "DEL") { //--- DEL command es_del(request_msg.get(1).c_str()); response_msg.push_back("OK"); } else if(request_msg.get(0) == "GET_GLOBAL") { //--- GET_GLOBAL command if(request_msg.get(2) == "LATEST") { const char* data = es_get_global(request_msg.get(1).c_str(), reduce_latest); response_msg.push_back("OK"); response_msg.push_back(data); } else if(request_msg.get(2) == "SUM") { const char* data = es_get_global(request_msg.get(1).c_str(), reduce_sum); response_msg.push_back("OK"); response_msg.push_back(data); } else if(request_msg.get(2) == "AVG") { const char* data = es_get_global(request_msg.get(1).c_str(), reduce_avg); response_msg.push_back("OK"); response_msg.push_back(data); } else { response_msg.push_back("ERROR"); response_msg.push_back("reduce function not implemented"); } } else { response_msg.push_back("ERROR"); response_msg.push_back("unknown command"); } } else { response_msg.push_back("ERROR"); response_msg.push_back("missing message parts"); } // send reply //cout << "sending: " << response_msg.get(0) << endl; this->recv_socket->send(response_msg); } }
process_result_t run_script(scene_state_t *ss, size_t script_no) { exec_state_t es; es_init(&es); es_push(&es); return run_script_with_exec_state(ss, &es, script_no); }
int main(int argc, char *argv[]) { int opt_shutter_angle = 0; int opt_mjpeg_quality = 100; int nf, i, nc, nr; int tfs, fps; vc *pos_i, *pos_h, *pos_y; es_ctx *es; rs_ctx *rs; opterr = 0; while ((i = getopt(argc, argv, "r:q:")) != -1) { switch (i) { case 'r': opt_shutter_angle = atoi(optarg); break; case 'q': opt_mjpeg_quality = atoi(optarg); break; default: print_help(argv); } } if (argc < optind + 2) print_help(argv); if (AVI_open_movie(argv[optind], &mv_in) != AVI_ERROR_NONE) { printf("error: can't read from %s\n", argv[optind]); return EXIT_FAILURE; } if (mv_in.header->Streams < 1 || mv_in.streams[0].sh.Type != AVIST_VIDEO) { printf("error: video stream not found on %s\n", argv[optind]); return EXIT_FAILURE; } if (AVI_open_compress(argv[optind + 1], &mv_out, 1, AVI_FORMAT_MJPEG) != AVI_ERROR_NONE) { printf("error: can't write to %s\n", argv[optind + 1]); return EXIT_FAILURE; } printf("status: setup\n"); prepare_lanc_kernels(); nc = mv_in.header->Width; nr = mv_in.header->Height; tfs = mv_in.header->TotalFrames; fps = 1000000 / mv_in.header->MicroSecPerFrame; pos_i = (vc *)malloc(tfs * sizeof(vc)); pos_h = (vc *)malloc(tfs * sizeof(vc)); pos_y = (vc *)malloc(nr * sizeof(vc)); AVI_set_compress_option(&mv_out, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &nc); AVI_set_compress_option(&mv_out, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_HEIGHT, &nr); AVI_set_compress_option(&mv_out, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_FRAMERATE, &fps); AVI_set_compress_option(&mv_out, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_QUALITY, &opt_mjpeg_quality); es = es_init(nc, nr); rs = rs_init(nc, nr); printf("status: estimating\n"); for (nf = 0; nf < tfs; nf ++) { unsigned char *fr = (unsigned char *)AVI_read_frame(&mv_in, AVI_FORMAT_RGB24, nf, 0); pos_i[nf] = vc_add( nf > 0 ? pos_i[nf - 1] : vc_set(0.0, 0.0), es_estimate(es, fr) ); free(fr); if ((nf + 1) % 10 == 0) { printf("."); fflush(stdout); } } printf("\nstatus: filtering\n"); hipass(pos_i, pos_h, tfs, fps / 2); printf("status: resampling\n"); for (nf = 0; nf < tfs; nf ++) { unsigned char *fr = (unsigned char *)AVI_read_frame(&mv_in, AVI_FORMAT_RGB24, nf, 0); for (i = 0; i < nr; i ++) { pos_y[i] = interp( pos_h, tfs, nf + (i - nr / 2.0) * opt_shutter_angle / (nr * 360.0) ); } rs_resample(rs, fr, pos_y); AVI_write_frame(&mv_out, nf, AVI_FORMAT_RGB24, fr, nc * nr * 3 * sizeof(unsigned char)); if ((nf + 1) % 10 == 0) { printf("."); fflush(stdout); } } printf("\nstatus: closing\n"); es_free(es); rs_free(rs); free_lanc_kernels(); AVI_close(&mv_in); AVI_close_compress(&mv_out); return EXIT_SUCCESS; }
int main() { char *in; time_t t; error_t status; int i; srand((unsigned)time(&t)); // tele_command_t stored; // stored.data[0].t = OP; // stored.data[0].v = 2; // stored.data[1].t = NUMBER; // stored.data[1].v = 8; // stored.data[2].t = NUMBER; // stored.data[2].v = 10; // stored.separator = -1; // stored.l = 3; // printf("\nstored process: "); // process(&stored); in = malloc(256); printf("teletype. (blank line quits)\n\n"); scene_state_t ss; ss_init(&ss); do { printf("> "); fgets(in, 256, stdin); i = 0; while (in[i]) { in[i] = toupper(in[i]); i++; } tele_command_t temp; exec_state_t es; es_init(&es); char error_msg[TELE_ERROR_MSG_LENGTH]; status = parse(in, &temp, error_msg); if (status == E_OK) { status = validate(&temp, error_msg); printf("validate: %s", tele_error(status)); if (error_msg[0]) printf(": %s", error_msg); printf("\n"); if (status == E_OK) { process_result_t output = process_command(&ss, &es, &temp); if (output.has_value) { printf(">>> %i\n", output.value); } } } else { printf("ERROR: %s", tele_error(status)); if (error_msg[0]) printf(": %s", error_msg); printf("\n"); } // tele_tick(100); printf("\n"); } while (in[0] != 10); free(in); printf("(teletype exit.)\n"); }