static gboolean my_bus_callback( GstBus* bus, GstMessage *message, gpointer data ) { Gst* gst = ( Gst* ) data; switch( GST_MESSAGE_TYPE (message) ) { case GST_MESSAGE_ERROR: { g_print ("\nGot %s message\n", GST_MESSAGE_TYPE_NAME (message)); GError *err; gchar *debug; gst_message_parse_error( message, &err, &debug ); g_print ("\nError: %s\n", err->message); g_error_free (err); g_free (debug); g_main_loop_quit ( gst->loop ); break; } case GST_MESSAGE_EOS: { g_print ("\nGot %s message\n", GST_MESSAGE_TYPE_NAME (message)); state_handler ( gst, GST_STATE_NULL); /* end-of-stream */ g_main_loop_quit ( gst->loop ); break; } default: /* unhandled message */ break; } /* we want to be notified again the next time there is a message * on the bus, so returning TRUE (FALSE means we want to stop watching * for messages on the bus and our callback should not be called again) */ return TRUE; }
int run_pipeline( GtkWidget *widget, gpointer data ) { Gst* gst = ( Gst* ) data; gtk_widget_set_sensitive (widget,FALSE); gtk_widget_set_sensitive ( (GtkWidget*) gst->stopButton,TRUE); /* Initialize elements */ if( create_elements( gst, "D:\\test.avi") != 0 ) return -1; /* Add function to watch bus */ if( bus_watcher( gst ) != 0 ) return -1; /* Add elements to pipeline, and link them */ if( pipeline_make( gst ) != 0 ) return -1; /* Set the pipeline to "playing" state*/ if( state_handler( gst, GST_STATE_PLAYING) !=0 ) return -1; g_print ("Running...\n"); g_main_loop_run ( gst->loop); return 0; }
int MainWindowQuit( GtkComboBox *widget, gpointer data ) { if( !flag ) { Gst* gst = ( Gst* ) data; g_print(" stop pipeline\n"); if( state_handler( gst, GST_STATE_NULL) !=0 ) return -1; g_main_loop_quit ( gst->loop ); } gtk_main_quit (); return 0; }
/* This is a callback function. */ int stop_pipeline( GtkWidget *widget, gpointer data ) { Gst* gst = ( Gst* ) data; gtk_widget_set_sensitive (widget,FALSE); gtk_widget_set_sensitive ( (GtkWidget*)gst->startButton,TRUE); g_print(" stop pipeline\n"); if( state_handler( gst, GST_STATE_NULL) !=0 ) return -1; g_main_loop_quit ( gst->loop ); return 0; }
int main(){ /* INITIAL SETUP */ /* ====================================== */ std::cout <<"\n\n____ __________ " << std::endl; std::cout << "\\ \\ / / __ \\ " << std::endl; std::cout << " \\ Y /> < " << std::endl; std::cout << " \\ // -- \\" << std::endl; std::cout << " \\___/ \\______ /" << std::endl; std::cout << " \\/" << std::endl; std::cout << "\nV8 Engine version xx \n" << std::endl; std::cout << "Performing initial setup...." << std::endl; std::cout << "=======================================\n" << std::endl; /* Random seed to time */ srand (time(NULL)); std::cout << "Initializing SDL..." << std::endl; if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "FATAL ERROR: Failed to initialize SDL, see errorlog for details."<<std::endl; SDLerrorLogger("FATAL ERROR: SDL initialization"); exit(EXIT_FAILURE); } std::cout << "SDL initialized!\n" << std::endl; std::cout << "=======================================\n" << std::endl; std::cout << "Initializing utility variables..." << std::endl; if (!init_utility_vars()){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "FATAL ERROR: Failed to initialize utility variables!"<<std::endl; errorlogger("FATAL ERROR: Failed to initialize utility variables!"); exit(EXIT_FAILURE); } std::cout << "Utility variables initialized!\n" << std::endl; std::cout << "=======================================\n" << std::endl; #ifdef REBUILD_ASSETS std::cout << "Converting images..." << std::endl; if (!convert_all_images()){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "FATAL ERROR: Failed to convert images."<<std::endl; errorlogger("FATAL ERROR: Failed to convert images."); exit(EXIT_FAILURE); } std::cout << "Images converted!\n" << std::endl; std::cout << "=======================================\n" << std::endl; std::cout << "Converting models..." << std::endl; if (!convert_all_models()){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "FATAL ERROR: Failed to convert models."<<std::endl; errorlogger("FATAL ERROR: Failed to convert models."); exit(EXIT_FAILURE); } std::cout << "Models converted!\n" << std::endl; std::cout << "=======================================\n" << std::endl; #endif /* ====================================== */ /* MAIN VARS */ /* ====================================== */ std::cout << "Initializing main data structures...\n" << std::endl; std::cout << "------ Initializing resource_manager..." << std::endl; Resource_manager resource_manager; std::cout << "------ Resource_manager initialized!\n" << std::endl; std::cout << "------ Initializing renderer..." << std::endl; Renderer renderer(resource_manager); std::cout << "------ Renderer initialized!\n" << std::endl; std::cout << "------ Initializing state_handler..." << std::endl; State_handler state_handler(resource_manager, renderer); std::cout << "------ State_handler initialized!\n" << std::endl; std::cout << "------ Initializing world..." << std::endl; World world(resource_manager, renderer); std::cout << "------ World initialized!\n" << std::endl; std::cout << "------ Initializing timers..." << std::endl; Timer cap_timer; Timer move_timer; Timer performance_timer; std::cout << "------ Timers initialized!\n" << std::endl; std::cout << "Sucessfully initialized main data structures!\n" << std::endl; std::cout << "=======================================\n" << std::endl; /* ====================================== */ /* Main loop */ /*=======================================================*/ std::cout << "Engine running~\n" << std::endl; std::cout << "=======================================" << std::endl; std::cout << "=======================================\n" << std::endl; GLuint average_render_time = 0; GLuint pooled_render_time = 0; GLuint num_frames_average = 30; GLuint frame_counter = 0; GLuint peak_ms = 0; while(state_handler.game_is_running()){ performance_timer.restart(); #if DISABLE_VSYNC //Start cap timer cap_timer.restart(); #endif /* Handle events in the queue */ state_handler.handle_events(); /* Update the position of all world objects */ float timedelta = move_timer.get_ticks() / 1000.0f; if (!world.update_positions(timedelta, renderer)){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "FATAL ERROR: Failed to update world positions!" << std::endl; errorlogger("FATAL ERROR: Failed to update world positions!"); exit(EXIT_FAILURE); } move_timer.restart(); /* Resolve all collisions */ if (!world.resolve_collisions()){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "FATAL ERROR: Failed to resolve world collisions!" << std::endl; errorlogger("FATAL ERROR: Failed to resolve world collisions!"); exit(EXIT_FAILURE); } /* Render to screen */ if(!world.render_world(renderer)){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "FATAL ERROR: Failed to render world!" << std::endl; errorlogger("FATAL ERROR: Failed to render world!"); exit(EXIT_FAILURE); } #if DISABLE_VSYNC /* If frame finished early */ GLuint frame_ticks = cap_timer.get_ticks(); if (frame_ticks < Utility_consts::SCREEN_TICKS_PER_FRAME) { /* Wait remaining time */ SDL_Delay(Utility_consts::SCREEN_TICKS_PER_FRAME - frame_ticks); } #endif GLint performance_ticks = performance_timer.get_ticks(); performance_timer.pause(); if (frame_counter < num_frames_average) { ++frame_counter; pooled_render_time += performance_ticks; } else{ frame_counter = 0; average_render_time = pooled_render_time / num_frames_average; if (average_render_time > peak_ms) { peak_ms = average_render_time; } pooled_render_time = 0; } std::cout << '\r' << std::setw(5) << std::setfill('0') << "Avg. render time: "<< average_render_time << " ms" << " Peak render time: " << peak_ms << " ms " << std::flush; } /*=======================================================*/ std::cout << "\n=======================================" << std::endl; std::cout << "=======================================\n" << std::endl; std::cout << "Engine shutting down...\n" << std::endl; renderer.save_settings(); SDL_Quit(); std::cout << "Shutdown complete!\n" << std::endl; return 0; }
int main(void) { watchdog_clear_status(); #ifdef USING_PRINTF serial_init(); #endif cli(); clear_radio_strings(); system_schedule = new_schedule(); //Be aware: order may matter, especially with si4703/5_init and nokia5110_init. (they all share a reset pin) watchdog_set(WD_INTERRUPT_AND_SYSTEM_RESET, WD_TIMEOUT_1_S); set_data_directions(); timer0_pwm_prescaler_compare_A(0, 3, true, false); timer1_pwm_prescaler_compare(0, MAX_BRIGHTNESS, 1, 1, false, false); timer2_ctc(0.001, true); nokia5110_spi_init(0x51); i2c_init(); nokia5110_power_on(); set_volume(0); ADC_init(ADC_PC3, ADC_NO_TRIGGER, ADC_REFERENCE_1V1, true, true); //ADC_TIMER0_OVERFLOW sei(); ds1307_getdate_s(&time); //If the clock isn't set, it reads all values as zero. Set a default time if (time.year == 0) { ds1307_setdate(14,10,21,12,28,30); } time_alarm_A.hour = eeprom_read_byte(&alarm_A_hours); time_alarm_A.minute = eeprom_read_byte(&alarm_A_minutes); alarm_A_is_beep = eeprom_read_byte(&alarm_A_tone_setting); if (time_alarm_A.hour >= time_limits[hours]) { time_alarm_A.hour = 0; eeprom_update_byte(&alarm_A_hours, time_alarm_A.hour); } if (time_alarm_A.minute >= time_limits[minutes]) { time_alarm_A.minute = 0; eeprom_update_byte(&alarm_A_minutes, time_alarm_A.minute); } if (alarm_A_is_beep > true) { alarm_A_is_beep = true; } time_alarm_B.hour = eeprom_read_byte(&alarm_B_hours); time_alarm_B.minute = eeprom_read_byte(&alarm_B_minutes); alarm_B_is_beep = eeprom_read_byte(&alarm_B_tone_setting); if (time_alarm_B.hour >= time_limits[hours]) { time_alarm_B.hour = 0; eeprom_update_byte(&alarm_B_hours, time_alarm_B.hour); } if (time_alarm_B.minute >= time_limits[minutes]) { time_alarm_B.minute = 0; eeprom_update_byte(&alarm_B_minutes, time_alarm_B.minute); } if (alarm_B_is_beep > true) { alarm_B_is_beep = true; } channel = eeprom_read_word(&saved_channel); if (channel < SI4705_FM_LOW || channel > SI4705_FM_HIGH) channel = 889; for (err = 0; err < NUMBER_OF_PRESETS; err++) { presets[err] = eeprom_read_word(&saved_presets[err]); if (presets[err] < SI4705_FM_LOW || presets[err] > SI4705_FM_HIGH) presets[err] = 945; } ms_clock = 0; while(true) { if (is_fresh) { is_fresh = false; check_schedule(); switch(state) { case home: home_state(); break; case menu: menu_state(); break; case set_clock: set_clock_state(); break; case set_alarm_A: case set_alarm_B: set_alarm_state(); break; case alarm_A: case alarm_B: alarm_state(); break; case radio: radio_state(); break; case preset: preset_state(); break; default: break; } init = false; state_handler(); watchdog_entertain(); } } }