static void network_test_delay(void) { int i, j; BYTE new_frame_delta; BYTE buf[0x60]; long packet_delay[NUM_OF_TESTPACKETS]; char st[256]; vsyncarch_init(); ui_display_statustext(translate_text(IDGS_TESTING_BEST_FRAME_DELAY), 0); if (network_mode == NETWORK_SERVER_CONNECTED) { for (i = 0; i < NUM_OF_TESTPACKETS; i++) { *((unsigned long*)buf) = vsyncarch_gettime(); if (network_send_buffer(network_socket, buf, sizeof(buf)) < 0 || network_recv_buffer(network_socket, buf, sizeof(buf)) < 0) return; packet_delay[i] = vsyncarch_gettime() - *((unsigned long*)buf); } /* Sort the packets delays*/ for (i = 0; i < NUM_OF_TESTPACKETS - 1; i++) { for (j = i + 1; j < NUM_OF_TESTPACKETS; j++) { if (packet_delay[i] < packet_delay[j]) { long d = packet_delay[i]; packet_delay[i] = packet_delay[j]; packet_delay[j] = d; } } #ifdef NETWORK_DEBUG log_debug("packet_delay[%d]=%ld",i,packet_delay[i]); #endif } #ifdef NETWORK_DEBUG log_debug("vsyncarch_frequency = %ld", vsyncarch_frequency()); #endif /* calculate delay with 90% of packets beeing fast enough */ /* FIXME: This needs some further investigation */ new_frame_delta = 5 + (BYTE)(vsync_get_refresh_frequency() * packet_delay[(int)(0.1 * NUM_OF_TESTPACKETS)] / (float)vsyncarch_frequency()); network_send_buffer(network_socket, &new_frame_delta, sizeof(new_frame_delta)); } else { /* network_mode == NETWORK_CLIENT */ for (i = 0; i < NUM_OF_TESTPACKETS; i++) { if (network_recv_buffer(network_socket, buf, sizeof(buf)) < 0 || network_send_buffer(network_socket, buf, sizeof(buf)) < 0) return; } network_recv_buffer(network_socket, &new_frame_delta, sizeof(new_frame_delta)); } network_free_frame_event_list(); frame_delta = new_frame_delta; network_init_frame_event_list(); sprintf(st, translate_text(IDGS_USING_D_FRAMES_DELAY), frame_delta); log_debug("netplay connected with %d frames delta.", frame_delta); ui_display_statustext(st, 1); }
void ui_sound_record_settings_dialog(video_canvas_t *canvas) { APTR window; int val; sound_canvas = canvas; window = mui_make_simple_window(build_gui_record(), translate_text(IDS_SOUND_RECORD_SETTINGS)); if (window != NULL) { mui_add_window(window); ui_get_to(ui_to_from_record); set(format, MUIA_Cycle_Active, 1); set(window, MUIA_Window_Open, TRUE); if (mui_run() == BTN_OK) { ui_get_from(ui_to_from_record); get(format, MUIA_Cycle_Active, (APTR)&val); resources_set_string("SoundRecordDeviceName", ""); resources_set_string("SoundRecordDeviceName", ui_sound_formats[val]); ui_display_statustext(translate_text(IDS_SOUND_RECORDING_STARTED), 1); } set(window, MUIA_Window_Open, FALSE); mui_rem_window(window); MUI_DisposeObject(window); } }
static void network_hook_connected_send(void) { BYTE *local_event_buf = NULL; unsigned int send_len; BYTE send_len4[4]; /* create and send current event buffer */ network_event_record(EVENT_LIST_END, NULL, 0); send_len = network_create_event_buffer(&local_event_buf, &(frame_event_list[current_frame])); #ifdef NETWORK_DEBUG t1 = vsyncarch_gettime(); #endif util_int_to_le_buf4(send_len4, (int)send_len); if (network_send_buffer(network_socket, send_len4, 4) < 0 || network_send_buffer(network_socket, local_event_buf, send_len) < 0) { ui_display_statustext(translate_text(IDGS_REMOTE_HOST_DISCONNECTED), 1); network_disconnect(); } #ifdef NETWORK_DEBUG t2 = vsyncarch_gettime(); #endif lib_free(local_event_buf); }
static void sound_record_stop(void) { char *retval; resources_set_string("SoundRecordDeviceName", ""); retval = util_concat(_("Sound Recording stopped"), "...", NULL); ui_display_statustext(retval, 10); lib_free(retval); }
void uicommands_sound_record_stop(void) { char *retval; if (sound_is_recording()) { sound_stop_recording(); retval = util_concat(_("Sound Recording stopped"), "...", NULL); ui_display_statustext(retval, 10); lib_free(retval); } }
static void end_sound_record_dialog(HWND hwnd) { TCHAR st[MAX_PATH]; char s[MAX_PATH]; int i; i = (int)SendMessage(GetDlgItem(hwnd, IDC_SOUND_RECORD_FORMAT), CB_GETCURSEL, 0, 0); GetDlgItemText(hwnd, IDC_SOUND_RECORD_FILE, st, MAX_PATH); system_wcstombs(s, st, MAX_PATH); util_add_extension_maxpath(s, sound_format[i], MAX_PATH); resources_set_string("SoundRecordDeviceName", ""); resources_set_string("SoundRecordDeviceArg", s); resources_set_string("SoundRecordDeviceName", sound_format[i]); resources_set_int("Sound", 1); ui_display_statustext(translate_text(IDS_SOUND_RECORDING_STARTED), 1); }
static void sound_record_start(char *format, char *extension) { ui_button_t button; char *s; vsync_suspend_speed_eval(); resources_set_string("SoundRecordDeviceName", ""); s = ui_select_file(_("Record sound to file"), NULL, 0, 0, NULL, extension, &button, 0, NULL); if (button == UI_BUTTON_OK && s != NULL) { util_add_extension(&s, format); resources_set_string("SoundRecordDeviceArg", s); resources_set_string("SoundRecordDeviceName", format); resources_set_int("Sound", 1); lib_free(s); ui_display_statustext(_("Sound Recording started..."),10); } }
int network_start_server(void) { vice_network_socket_address_t * server_addr = NULL; int ret = -1; do { if (network_mode != NETWORK_IDLE) break; server_addr = vice_network_address_generate(server_bind_address, server_port); if ( ! server_addr ) { break; } listen_socket = vice_network_server(server_addr); if ( ! listen_socket ) { break; } /* Set proper settings */ if (resources_set_event_safe() < 0) { ui_error("Warning! Failed to set netplay-safe settings."); } network_mode = NETWORK_SERVER; vsync_suspend_speed_eval(); ui_display_statustext(translate_text(IDGS_SERVER_IS_WAITING_FOR_CLIENT), 1); ret = 0; } while (0); if (server_addr) { vice_network_address_close(server_addr); } return ret; }
static void sound_record_start(char *format, uilib_file_filter_enum_t extension) { ui_button_t button; char *s; char *retval; vsync_suspend_speed_eval(); resources_set_string("SoundRecordDeviceName", ""); s = ui_select_file(_("Record sound to file"), NULL, 0, soundrecordpath, &extension, 1, &button, 0, NULL, UI_FC_SAVE); if (button == UI_BUTTON_OK && s != NULL) { lib_free(soundrecordpath); util_fname_split(s, &soundrecordpath, NULL); util_add_extension(&s, format); resources_set_string("SoundRecordDeviceArg", s); resources_set_string("SoundRecordDeviceName", format); resources_set_int("Sound", 1); lib_free(s); retval = util_concat(_("Sound Recording started"), "...", NULL); ui_display_statustext(retval, 10); lib_free(retval); } }
static void select_wmm(void) { resources_set_string("SoundDeviceName", "wmm"); ui_display_statustext(translate_text(IDS_SOUND_DRIVER_WMM), 1); }
static void select_dx(void) { resources_set_string("SoundDeviceName", "dx"); ui_display_statustext(translate_text(IDS_SOUND_DRIVER_DIRECTX), 1); }
static void sound_record_stop(void) { resources_set_string("SoundRecordDeviceName", ""); ui_display_statustext(_("Sound Recording stopped..."),10); }
int network_start_server(void) { #ifdef HAVE_IPV6 struct sockaddr_in6 server_addr6; #endif int return_value; struct sockaddr_in server_addr; if (network_init() < 0) return -1; if (network_mode != NETWORK_IDLE) return -1; #ifdef HAVE_IPV6 if (netplay_ipv6) { bzero((char*)&server_addr6, sizeof(struct sockaddr_in6)); server_addr6.sin6_port = htons(server_port); server_addr6.sin6_family = PF_INET6; server_addr6.sin6_addr=in6addr_any; } else { #endif server_addr.sin_port = htons(server_port); server_addr.sin_addr.s_addr = htonl(0); server_addr.sin_family = PF_INET; #ifndef MINIX_SUPPORT memset(server_addr.sin_zero, 0, sizeof(server_addr.sin_zero)); #endif #ifdef HAVE_IPV6 } if (netplay_ipv6) listen_socket = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); else #endif listen_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (listen_socket == INVALID_SOCKET) return -1; #ifdef HAVE_IPV6 if (netplay_ipv6) return_value=bind(listen_socket, (struct sockaddr *)&server_addr6, sizeof(server_addr6)); else #endif return_value=bind(listen_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)); if (return_value < 0) { closesocket(listen_socket); return -1; } if (listen(listen_socket, 2) < 0) { closesocket(listen_socket); return -1; } /* Set proper settings */ if (resources_set_event_safe() < 0) ui_error("Warning! Failed to set netplay-safe settings."); network_mode = NETWORK_SERVER; vsync_suspend_speed_eval(); #ifdef HAS_TRANSLATION ui_display_statustext(translate_text(IDGS_SERVER_IS_WAITING_FOR_CLIENT), 1); #else ui_display_statustext(_("Server is waiting for a client..."), 1); #endif return 0; }
static void network_server_connect_trap(WORD addr, void *data) { FILE *f; BYTE *buf; size_t buf_size; BYTE send_size4[4]; long i; event_list_state_t settings_list; vsync_suspend_speed_eval(); /* Create snapshot and send it */ snapshotfilename = archdep_tmpnam(); if (machine_write_snapshot(snapshotfilename, 1, 1, 0) == 0) { f = fopen(snapshotfilename, MODE_READ); if (f == NULL) { #ifdef HAS_TRANSLATION ui_error(translate_text(IDGS_CANNOT_LOAD_SNAPSHOT_TRANSFER)); #else ui_error(_("Cannot load snapshot file for transfer")); #endif lib_free(snapshotfilename); return; } buf_size = util_file_length(f); buf = lib_malloc(buf_size); fread(buf, 1, buf_size, f); fclose(f); #ifdef HAS_TRANSLATION ui_display_statustext(translate_text(IDGS_SENDING_SNAPSHOT_TO_CLIENT), 0); #else ui_display_statustext(_("Sending snapshot to client..."), 0); #endif util_int_to_le_buf4(send_size4, (int)buf_size); network_send_buffer(network_socket, send_size4, 4); i = network_send_buffer(network_socket, buf, (int)buf_size); lib_free(buf); if (i < 0) { #ifdef HAS_TRANSLATION ui_error(translate_text(IDGS_CANNOT_SEND_SNAPSHOT_TO_CLIENT)); #else ui_error(_("Cannot send snapshot to client")); #endif ui_display_statustext("", 0); lib_free(snapshotfilename); return; } network_mode = NETWORK_SERVER_CONNECTED; /* Send settings that need to be the same */ event_register_event_list(&settings_list); resources_get_event_safe_list(&settings_list); buf_size = (size_t)network_create_event_buffer(&buf, &(settings_list)); util_int_to_le_buf4(send_size4, (int)buf_size); network_send_buffer(network_socket, send_size4, 4); network_send_buffer(network_socket, buf, (int)buf_size); event_clear_list(&settings_list); lib_free(buf); current_send_frame = 0; last_received_frame = 0; network_test_delay(); } else { #ifdef HAS_TRANSLATION ui_error(translate_text(IDGS_CANNOT_CREATE_SNAPSHOT_FILE_S), snapshotfilename); #else ui_error(_("Cannot create snapshot file %s"), snapshotfilename); #endif } lib_free(snapshotfilename); }
static void network_hook_connected_receive(void) { BYTE *remote_event_buf = NULL; unsigned int recv_len; BYTE recv_len4[4]; event_list_state_t *remote_event_list; event_list_state_t *client_event_list, *server_event_list; suspended = 0; if (current_frame == frame_delta - 1) frame_buffer_full = 1; if (frame_buffer_full) { do { if (network_recv_buffer(network_socket, recv_len4, 4) < 0) { ui_display_statustext(translate_text(IDGS_REMOTE_HOST_DISCONNECTED), 1); network_disconnect(); return; } recv_len = util_le_buf4_to_int(recv_len4); if (recv_len == 0 && suspended == 0) { /* remote host suspended emulation */ ui_display_statustext(translate_text(IDGS_REMOTE_HOST_SUSPENDING), 0); suspended = 1; vsync_suspend_speed_eval(); } } while (recv_len == 0); if (suspended == 1) ui_display_statustext("", 0); remote_event_buf = lib_malloc(recv_len); if (network_recv_buffer(network_socket, remote_event_buf, recv_len) < 0) { lib_free(remote_event_buf); return; } #ifdef NETWORK_DEBUG t3 = vsyncarch_gettime(); #endif remote_event_list = network_create_event_list(remote_event_buf); lib_free(remote_event_buf); if (network_mode == NETWORK_SERVER_CONNECTED) { client_event_list = remote_event_list; server_event_list = &(frame_event_list[frame_to_play]); } else { server_event_list = remote_event_list; client_event_list = &(frame_event_list[frame_to_play]); } /* test for sync */ if (client_event_list->base->type == EVENT_SYNC_TEST && server_event_list->base->type == EVENT_SYNC_TEST) { int i; for (i = 0; i < 5; i++) { if (((DWORD *)client_event_list->base->data)[i] != ((DWORD *)server_event_list->base->data)[i]) { ui_error(translate_text(IDGS_NETWORK_OUT_OF_SYNC)); network_disconnect(); /* shouldn't happen but resyncing would be nicer */ break; } } } /* replay the event_lists; server first, then client */ event_playback_event_list(server_event_list); event_playback_event_list(client_event_list); event_clear_list(remote_event_list); lib_free(remote_event_list); } network_prepare_next_frame(); #ifdef NETWORK_DEBUG t4 = vsyncarch_gettime(); #endif }
int network_connect_client(void) { vice_network_socket_address_t * server_addr; FILE *f; BYTE *buf; BYTE recv_buf4[4]; size_t buf_size; if (network_mode != NETWORK_IDLE) return -1; vsync_suspend_speed_eval(); snapshotfilename = NULL; f = archdep_mkstemp_fd(&snapshotfilename, MODE_WRITE); if (f == NULL) { ui_error(translate_text(IDGS_CANNOT_CREATE_SNAPSHOT_S_SELECT)); return -1; } server_addr = vice_network_address_generate(server_name, server_port); if (server_addr == NULL) { ui_error(translate_text(IDGS_CANNOT_RESOLVE_S), server_name); return -1; } network_socket = vice_network_client(server_addr); vice_network_address_close(server_addr); server_addr = NULL; if ( ! network_socket ) { ui_error(translate_text(IDGS_CANNOT_CONNECT_TO_S), server_name, server_port); lib_free(snapshotfilename); return -1; } ui_display_statustext(translate_text(IDGS_RECEIVING_SNAPSHOT_SERVER), 0); if (network_recv_buffer(network_socket, recv_buf4, 4) < 0) { lib_free(snapshotfilename); vice_network_socket_close(network_socket); return -1; } buf_size = (size_t)util_le_buf4_to_int(recv_buf4); buf = lib_malloc(buf_size); if (network_recv_buffer(network_socket, buf, (int)buf_size) < 0) { lib_free(snapshotfilename); vice_network_socket_close(network_socket); return -1; } if (fwrite(buf, 1, buf_size, f) <= 0) { log_debug("network_connect_client write failed."); } fclose(f); lib_free(buf); interrupt_maincpu_trigger_trap(network_client_connect_trap, (void *)0); vsync_suspend_speed_eval(); return 0; }