//----------------------------------------------------------------------------- // Name: Main // Desc: ... //----------------------------------------------------------------------------- int main( int argc, char *argv[] ) { /* Check Arguments */ if ( argc != 2 ) { printf("Usage: %s: Input Audio\n", argv[0]); return EXIT_FAILURE; } /* Initialize SRC Algorithm */ initialize_src_type(); /* Initialize Glut */ initialize_glut(argc, argv); /* Initialize PortAudio */ initialize_audio(argv[1]); /* Start Curses Mode */ initscr(); cbreak(); // Line Buffering Disabled noecho(); // Comment This Out if You Want to Show Characters When They Are Typed curs_set(0); // Make ncurses Cursor Invisible /* Print Help Menu and GUI */ help(); printGUI(); /* Main Interactive Loop, Quits With 'q' */ glutMainLoop(); return EXIT_SUCCESS; }
action_t config_audio::execute() { reply r; r("207 OK RECEIVING AUDIO SETTINGS"); reset_settings(); read_settings(); if(initialize_audio()) { r("203-Opened a playback stream"); r("203 OK AUDIO INITIALIZED"); } else { r("400-Cannot open a playback stream"); r("400 ERROR AUDIO NOT INITIALIZED"); } return action_continue; }
//----------------------------------------------------------------------------- // Name: main( ) // Desc: entry point //----------------------------------------------------------------------------- int main( int argc, char ** argv ) { // initialize GLUT glutInit( &argc, argv ); // double buffer, use rgb color, enable depth buffer glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); // initialize the window size glutInitWindowSize( g_width, g_height ); // set the window postion glutInitWindowPosition( 100, 100 ); // create the window glutCreateWindow( "rt_lpc" ); // set the idle function - called when idle glutIdleFunc( idleFunc ); // set the display function - called when redrawing glutDisplayFunc( displayFunc ); // set the reshape function - called when client area changes glutReshapeFunc( reshapeFunc ); // set the keyboard function - called on keyboard events glutKeyboardFunc( keyboardFunc ); // set the mouse function - called on mouse stuff glutMouseFunc( mouseFunc ); // do our own initialization initialize_graphics( ); if( !initialize_audio( ) ) { fprintf( stderr, "rt_lpc: error initializing audio, exiting...\n" ); return -3; } initialize_analysis( ); // let GLUT handle the current thread from here glutMainLoop(); return 0; }
/** * * Main function * * This function is the main entry of the interrupt test. It does the following: * Initialize the audio * Initialize the debug uart * Enable the interrupts * * @param None * * @return * - XST_SUCCESS if example finishes successfully * - XST_FAILURE if example fails. * * @note None. * ******************************************************************************/ int main(void) { init_platform(); InitMotorBoard(); xil_printf("\r\n--- Entering main() --- \r\n"); int status = XST_SUCCESS; status |= initialize_audio(&sIic, &sAxiAudioDma); status |= fnInitInterruptController(&sIntc); status |= initialize_uart(&sUartLite); status |= initialize_video(&sVideoCapt, &sIntc); status |= initialize_targeting(&sAxiTargetingDma); status |= SetupSdGpio(&sGpio); if (status != XST_SUCCESS) { xil_printf("Failed to initialize system.\r\n"); return XST_FAILURE; } // Initialize static variables. for (int i = 0; i < FILE_ID_MAX; i++) { sSdFileBoard[i].loaded = false; } sSdFileMemTip = (u32 *) AUDIO_BASE_ADDR; sButtonState = 0; sLoopSelect = DEFAULT_LOOP; fnEnableInterrupts(&sIntc, &ivt[0], sizeof(ivt)/sizeof(ivt[0])); register_uart_response("test", test_fcn); register_uart_response("record", uart_rec_audio); register_uart_response("play", uart_play_audio); register_uart_response("kill", end_fcn); register_uart_response("exit", end_fcn); register_uart_response("dump", dump_mem); // Commands to run self-tests register_uart_response("lowlevel", LowLevelTest); register_uart_response("highlevel", HighLevelTest); register_uart_response("lasertest", EnterLaserTest); register_uart_response("motortest", EnterMotorTest); register_uart_response("stop", stopTest); register_uart_response("load_sounds", loadSounds); register_uart_response("load_images", loadImages); register_uart_response("still_alive", playPortalSong); register_uart_response("gun", playGunSound); register_uart_response("portal_gun", playPortalGunSound); register_uart_response("target", playTargetAcquired); register_uart_response("playpos", playPos); register_uart_response("playneg", playNeg); register_uart_response("manual", EnterManualMainLoop); register_uart_response("auto", EnterAutomaticMainLoop); register_uart_response("passthrough", passthroughHdmi); register_uart_response("runip", EnterIpTest); register_uart_response("videoinfo", print_video_info); register_uart_response("df1", df1); register_uart_response("df2", df2); register_uart_response("df0", df0); register_uart_response("vf1", vf1); register_uart_response("vf2", vf2); register_uart_response("vf0", vf0); register_uart_response("ipinfo", print_ip_info); register_uart_response("ipouttoggle", toggle_ip_output); register_uart_response("dummytarget", setDummyTarget); register_uart_response("lemon", DisplayLemon); register_uart_response("heman", DisplayHeman); register_uart_response("pass", SetPassthroughMode); register_uart_response("gray", SetGrayscaleMode); register_uart_response("sobel", SetSobelMode); register_uart_response("thresh", SetThresholdMode); register_uart_response("label", SetLabelMode); register_uart_response("colour", SetColourMode); register_uart_response("laser", SetLaserMode); register_uart_response("flood1", SetFlood1Mode); register_uart_response("flood2", SetFlood2Mode); register_uart_response("laseron", LaserOn); register_uart_response("laseroff", LaserOff); register_uart_response("redthresh", SetRedThreshold); register_uart_response("sobelthresh", SetSobelThreshold); register_uart_response("f1thresh", SetFlood1Threshold); register_uart_response("f2thresh", SetFlood2Threshold); register_uart_response("setminsize", SetSizeThreshold); register_uart_response("setobjid", SetObjId); register_uart_response("test_args", TestArgs); xil_printf("\r\n--- Done registering UART commands --- \r\n"); initialSetup(); xil_printf(PROMPT_STRING); while (do_run) { switch (sLoopSelect) { case MANUAL_MODE: ManualMainLoop(); break; case AUTOMATIC_MODE: AutoMainLoop(); break; case LASER_TEST: LaserTest(); break; case MOTOR_TEST: MotorPatternTest(); break; case IP_TEST: runImageProcessing(); sLoopSelect = DEFAULT_LOOP; break; default: MB_Sleep(100); break; } } xil_printf("\r\n--- Exiting main() --- \r\n"); return XST_SUCCESS; }
int main(int argc, char ** argv) { int s = -1, s_new = -1, s_ctl = -1; connection_t conn; struct sockaddr_storage their_addr[2]; u[0].storage = &their_addr[0]; u[1].storage = &their_addr[1]; socklen_t addr_size; struct pollfd fd; /* Parses input and sets the global variables */ parse_input(argc, argv); #ifdef _WIN32 if ( daemonize ) FreeConsole(); #else /* Should we fork and kill our parent? :p */ if ( daemonize ) { if ( debug ) log_printf("Forking into background ...\n"); int i = fork(); if ( i < 0 ) exit(1); if ( i > 0 ) exit(0); /* Forking into background */ } #endif #ifdef HAVE_SYSLOG if (use_syslog) openlog("rsd", 0, LOG_USER); #endif /* Sets up listening socket */ s = set_up_socket(); if ( s < 0 ) { log_printf("Couldn't set up listening socket. Exiting ...\n"); exit(1); } // Need to have a global socket so that we can cleanly close the socket in the signal handling routines. listen_socket = s; if ( debug ) log_printf("Listening for connection ...\n"); fd.fd = s; fd.events = POLLIN; /* Set up listening socket */ if ( listen(s, 10) == -1 ) { log_printf("Couldn't listen for connections \"%s\"...\n", strerror(errno)); exit(1); } #ifdef _WIN32 atexit(cleanup); #else /* Sets up interface for cleanly shutting down the server */ write_pid_file(); signal(SIGINT, cleanup); signal(SIGTERM, cleanup); // SIGPIPE may cause trouble ;) signal(SIGPIPE, SIG_IGN); #endif /* In case our backend API needs some initializing functions */ initialize_audio(); #ifdef _WIN32 printf( "==============================================================================\n" ":: RSD server : Win32 : %s - Copyright (C) 2010-2011 Hans-Kristian Arntzen ::\n" "==============================================================================\n", RSD_VERSION); #endif /* We're accepting two connects after each other, as we have one stream socket for audio data and one for controlling the server. Currently, the control socket is only useful for determining quickly when the client has hung up the connection. In case a control socket isn't supplied in a short time window (nmap, port scanners, etc), we shut down the connection. The connection, if accepted, will be handled in a new thread. */ for(;;) { addr_size = sizeof (their_addr[0]); s_new = accept(s, u[0].addr, &addr_size); if ( s_new == -1 ) { log_printf("Accepting failed... Errno: %d\n", errno); log_printf("%s\n", strerror( errno ) ); continue; } /* Accepts a ctl socket. They have to come from same source. * Times out very quickly (in case the server is being queried from an unknown source. */ if (poll(&fd, 1, 200) < 0) { perror("poll"); close(s_new); close(s_ctl); close(s); exit(1); } /* Accepts the connection if there's one pending */ if (fd.revents & POLLIN) { addr_size = sizeof (their_addr[0]); s_ctl = accept(s, u[1].addr, &addr_size); } /* We didn't get a control socket, so we don't care about it :) If s_ctl is 0, the backend will not perform any operations on it. */ else { if ( debug ) log_printf("CTL-socket timed out. Ignoring CTL-socket. \n"); s_ctl = 0; } if ( s_ctl == -1 ) { close(s_new); s_new = -1; log_printf("%s\n", strerror( errno ) ); continue; } /* Checks if they are from same source, if not, close the connection. */ /* Check will be ignored if there is no ctl-socket active. */ /* TODO: Security here is *retarded* :D */ if ( (s_ctl > 0) && valid_ips(their_addr) < 0 ) { close(s_new); s_new = -1; close(s_ctl); s_ctl = -1; continue; } conn.socket = s_new; conn.ctl_socket = s_ctl; new_sound_thread(conn); s_new = -1; // Makes sure that we cannot clutter the backend connection in any way. s_ctl = -1; } return 0; }