void reply_avframe(AVPacket *pkt, AVCodec *codec) { ei_x_buff x; ei_x_new_with_version(&x); struct video_frame r; r.content = codec->type == AVMEDIA_TYPE_VIDEO ? frame_content_video : codec->type == AVMEDIA_TYPE_AUDIO ? frame_content_audio : 0; r.dts = pkt->dts / 90.0; r.pts = pkt->pts / 90.0; r.stream_id = 0; r.codec = codec->id == AV_CODEC_ID_H264 ? frame_codec_h264 : codec->id == AV_CODEC_ID_AAC ? frame_codec_aac : 0; r.flavor = pkt->flags & CODEC_FLAG_GLOBAL_HEADER ? frame_flavor_config : pkt->flags & AV_PKT_FLAG_KEY ? frame_flavor_keyframe : frame_flavor_frame; r.track_id = codec->type == AVMEDIA_TYPE_VIDEO ? 1 : 2; r.body.data = pkt->data; r.body.size = pkt->size; write_video_frame(&x, r); write_x(&x); ei_x_free(&x); }
void reply_atom(char *a) { ei_x_buff x; ei_x_new_with_version(&x); ei_x_encode_atom(&x, a); write_x(&x); ei_x_free(&x); }
static int write_name(bson_encoder_t encoder, const char *name) { size_t len = strlen(name); if (len > BSON_MAXNAME) { CODER_KILL(encoder, "node name too long"); } return write_x(encoder, name, len + 1); }
bool HomTransform::write(const yarp::os::idl::WireWriter& writer) const { if (!write_x(writer)) return false; if (!write_y(writer)) return false; if (!write_z(writer)) return false; if (!write_xx(writer)) return false; if (!write_xy(writer)) return false; if (!write_xz(writer)) return false; if (!write_yx(writer)) return false; if (!write_yy(writer)) return false; if (!write_yz(writer)) return false; if (!write_zx(writer)) return false; if (!write_zy(writer)) return false; if (!write_zz(writer)) return false; return !writer.isError(); }
int bson_encoder_append_binary(bson_encoder_t encoder, const char *name, bson_binary_subtype_t subtype, size_t size, const void *data) { CODER_CHECK(encoder); if (write_int8(encoder, BSON_BINDATA) || write_name(encoder, name) || write_int32(encoder, size) || write_int8(encoder, subtype) || write_x(encoder, data, size)) { CODER_KILL(encoder, "write error on BSON_BINDATA"); } return 0; }
int bson_encoder_append_string(bson_encoder_t encoder, const char *name, const char *string) { size_t len; CODER_CHECK(encoder); len = strlen(string) + 1; /* include trailing nul */ if (write_int8(encoder, BSON_STRING) || write_name(encoder, name) || write_int32(encoder, len) || write_x(encoder, string, len)) { CODER_KILL(encoder, "write error on BSON_STRING"); } return 0; }
void error(const char *fmt, ...) { va_list ap; if(in_fd != 0) { va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\r\n"); va_end(ap); } char *msg = NULL; va_start(ap, fmt); vasprintf(&msg, fmt, ap); va_end(ap); ei_x_buff x; ei_x_new_with_version(&x); ei_x_format_wo_ver(&x, "{~a,~s}","error", msg); write_x(&x); ei_x_free(&x); _exit(15); }
bool ContactPoint::write(yarp::os::idl::WireWriter& writer) { if (!write_x(writer)) return false; if (!write_y(writer)) return false; if (!write_z(writer)) return false; return !writer.isError(); }
int main(int argc, char** argv) { int i; unsigned int cmd; unsigned int val; unsigned int addr; char* file_path; clear_screen(); #ifdef DEBUG_MODE for (i = 0; i < argc; ++i) debug_message("argv[%2d] : '%s'", i, argv[i]); #endif printf("This is NES emulator.\n"); if (argc >= 2) { char* arg = argv[1]; int arg_len = strlen(arg); if (arg_len == 2) { if (arg[0] == '-' && (arg[1] == 't' || arg[1] == 'T')) // TEST ROM init_test_rom(&hdr, ROM, pattern_table); else if (arg[0] == '-' && (arg[1] == 'd' || arg[1] == 'D')) // Dumped image { FILE* rom_image; FILE* chr_image; if (argc < 3) return 1; #if defined _WIN32 && defined _MSC_VER fopen_s(&rom_image, argv[2], "rb"); fopen_s(&chr_image, argv[3], "rb"); #elif defined __linux__ || defined __GNUC__ rom_image = fopen(argv[2], "rb"); chr_image = fopen(argv[3], "rb"); #endif if (!rom_image || !chr_image) { debug_message("Could not open dumped ROM image!"); return 1; } if (fread(ROM, ROM_SIZE, 1, rom_image) != 1) return 1; if (fread(pattern_table, PPU_PATTERN_TABLE_SIZE, 1, chr_image) != 1) return 1; fclose(rom_image); fclose(chr_image); } else if (arg[0] == '-' && (arg[1] == 'r' || arg[1] == 'R')) { if (argc < 3) { debug_message("File name required."); return 1; } if (dump_test_rom(argv[2]) != 1) { debug_message("Could not dump test ROM!"); return 1; } debug_message("Test ROM dumped!"); return 0; } else { debug_message("Invalid command line arguments!"); return 1; } } else { file_path = argv[1]; if (read_rom_image(file_path) != 1) { printf("Reading ROM image failed!\n"); return 1; } } } else if (argc < 2) { printf("Emulation failed! No ROM image supplied!\n"); return 1; } if (emulator_init() != 1) { printf("Emulator initialization failed!\n"); return 1; } run(); // Comment this line for debuging. //clear_screen(); gotoxy(REGS_X, REGS_Y); update_regs(); gotoxy(CMD_X, CMD_Y); while (!finished_emulation) { clear_cmd_line(); cmd = getch(); putchar(cmd); switch (cmd) { case 's': case 'S': step(); update_regs(); break; // Finish emulation case 'q': case 'Q': finished_emulation = 1; break; case 'w': case 'W': if (scanf_s("%4x %2x", &addr, &val)) write(addr, val); break; case 'r': case 'R': if (scanf_s("%4x", &addr)) { val = read(addr); printf(" $%04x : %02X", addr, val); } break; case 'd': case 'D': if (scanf_s("%4x %u", &addr, &val)) for (i = 0; i < (int)val; ++i) printf("\n %04X : %02X\n", addr + i, read(addr + i)); break; case 'h': case 'H': printf("\n" " S : Step\n" " Q : Quit\n" " W Addr Val : Write memory\n" " R Addr : Read memory\n" " D Addr Sz : Dump memory\n" " C Val : Run for Val cycles\n" " H : Help\n" " E : Run to PC equals to Val\n" ); break; case 'a': case 'A': if (scanf_s("%2x", &val)) write_a(&p, val); break; case 'x': case 'X': if (scanf_s("%2x", &val)) write_x(&p, val); break; case 'y': case 'Y': if (scanf_s("%2x", &val)) write_y(&p, val); break; case 'p': case 'P': if (scanf_s("%2x", &val)) write_p(&p, val | FLAG_1); break; case 'c': case 'C': if (scanf_s("%u", &val)) { run_cycles(val); update_regs(); } break; case 'e': case 'E': if (scanf_s("%4x", &val)) { while (p.pc.w != val) step(); update_regs(); } break; default: break; } } emulator_close(); return 0; }
static int write_double(bson_encoder_t encoder, double d) { return write_x(encoder, &d, sizeof(d)); }
static int write_int64(bson_encoder_t encoder, int64_t i) { return write_x(encoder, &i, sizeof(i)); }
static int write_int8(bson_encoder_t encoder, int8_t b) { return write_x(encoder, &b, sizeof(b)); }
bool Pixel::write(const yarp::os::idl::WireWriter& writer) const { if (!write_x(writer)) return false; if (!write_y(writer)) return false; return !writer.isError(); }
int main(int argc, char **argv) { char *inputfile, *outfile; int i; int myid, nprocs; int n, ntot, logntot, rowsperproc; // n is padded with redundant rows if n!=2^i, i>=0 int lastrows, nofillprocs; // 1 when 1st and last rows on proc are 1st and last lines in a tridiagonal matrix and will not be swapped out int hasfirst = 0, haslast = 0; int prevrowproc, nextrowproc; // processor storing row before/after 1st/last row on myid int offset = 1; // doubles after each iteration; denotes the difference between the ranks of the processors in each pair // +1 after each iteration; denotes the difference between consecutive rows in each system on a processor (after all inter-proc row exchanges are done) int rowoffset = 1; int sendodds; // procs are divided (on each iteration) into pairs which trade rows, with one sending even rows and the other odds int *myrownums; double lognprocs; RowInfo *myrowinfo; Xsol *xsol, *x_all; MPI_Datatype MPI_Rowinfo; MPI_Datatype MPI_Xsol; if (argc != 4) { fprintf(stderr, "usage: %s infile outfile nrows\n", argv[0]); exit(1); } inputfile = argv[1]; outfile = argv[2]; n = atoi(argv[3]); MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); lognprocs = log2(nprocs); logntot = ceil(log2(n)); ntot = exp2(logntot); rowsperproc = ntot / nprocs; if (lognprocs != ceil(lognprocs)) { fprintf(stderr, "nprocs must be 2^i, for some integer i in {0, 1, ..., 10}\n"); MPI_Abort(MPI_COMM_WORLD, 1); } if (lognprocs >= logntot) { fprintf(stderr, "nprocs must be at most half of n\n"); MPI_Abort(MPI_COMM_WORLD, 1); } myrowinfo = (RowInfo *) malloc((rowsperproc + 2) * sizeof(RowInfo)); myrownums = (int *) malloc((rowsperproc + 2) * sizeof(int)); xsol = (Xsol *) malloc(rowsperproc * sizeof(RowInfo)); rows_init(myrowinfo, myrownums, rowsperproc + 2, myid * rowsperproc); MPI_Rowinfo = create_rowinfotype(); MPI_Xsol = create_xsoltype(); if (log2(n) != logntot) { int tmpread; int tmpub = rowsperproc + 2; if (myid == nprocs - 1) tmpub = rowsperproc + 1; nofillprocs = n / rowsperproc; lastrows = n % rowsperproc; if (myid < nofillprocs - 1) { if (!readtridiag(inputfile, myrowinfo, rowsperproc, rowsperproc, 12, myid, nprocs)) MPI_Abort(MPI_COMM_WORLD, 1); } else if (myid == nofillprocs - 1) { if (!lastrows) tmpread = rowsperproc - 1; else tmpread = rowsperproc; if (!readtridiag(inputfile, myrowinfo, rowsperproc, tmpread, 12, myid, nprocs)) MPI_Abort(MPI_COMM_WORLD, 1); } else if (myid == nofillprocs) { tmpread = lastrows - 1; if (myid == nprocs - 1) tmpread = lastrows; if (!readtridiag(inputfile, myrowinfo, rowsperproc, tmpread, 12, myid, nprocs)) MPI_Abort(MPI_COMM_WORLD, 1); myrowinfo[lastrows+1].a = 0.0; for (i = lastrows + 1; i < tmpub; ++i) myrowinfo[i].y = 0.0; } else for (i = 0; i < tmpub; ++i) myrowinfo[i].y = 0.0; } else { if (!readtridiag(inputfile, myrowinfo, rowsperproc, rowsperproc, 12, myid, nprocs)) MPI_Abort(MPI_COMM_WORLD, 1); } double starttime = MPI_Wtime(); // 1 and n are special cases if (myid == 0) hasfirst = 1; if (myid == nprocs - 1) haslast = 1; if (myid != 0) prevrowproc = myid - 1; if (myid != nprocs - 1) nextrowproc = myid + 1; if (nprocs > 1) { for (i = 0; i < lognprocs; ++i) { if (update_rowinfo(myrowinfo, rowsperproc, hasfirst, haslast) < 0) MPI_Abort(MPI_COMM_WORLD, 1); sendodds = (myid / offset) % 2; // the processor sending odd rows (receiving evens) is always the larger in each (exchanging) pair pack(myrowinfo, rowsperproc, 1, rowsperproc, sendodds); xchg_oddevens(myrowinfo, rowsperproc/2, 1, sendodds, myid, offset, MPI_Rowinfo); offset *= 2; update_rownums(myrownums, 1, rowsperproc, offset, sendodds); if (myrownums[1] == myid + 1) hasfirst = 1; if (myrownums[rowsperproc] == ntot - (nprocs - 1 - myid)) haslast = 1; xchg_bounds(myrowinfo, rowsperproc, myid, nprocs, offset, hasfirst, haslast, MPI_Rowinfo); } for (; i < logntot - 1; ++i, ++rowoffset) if (update_rowinfo_serial(myrowinfo, rowsperproc, rowoffset) < 0) MPI_Abort(MPI_COMM_WORLD, 1); } else for (i = 0; i < logntot - 1; ++i, ++rowoffset) if (update_rowinfo_serial(myrowinfo, rowsperproc, rowoffset) < 0) MPI_Abort(MPI_COMM_WORLD, 1); if (solve_2by2(&myrowinfo[1], xsol, rowsperproc) < 0) MPI_Abort(MPI_COMM_WORLD, 1); if (!myid) { printf("%f,", MPI_Wtime() - starttime); fflush(stdout); } if (!myid) x_all = (Xsol *) malloc(ntot * sizeof(Xsol)); MPI_Gather(xsol, rowsperproc, MPI_Xsol, x_all, rowsperproc, MPI_Xsol, 0, MPI_COMM_WORLD); if (!myid) if (!write_x(x_all, outfile, ntot)) MPI_Abort(MPI_COMM_WORLD, 1); MPI_Finalize(); return 0; }