int main (void) { int dummy; //int matrix; //only for test of ledmdrv int i; //int temp_current_val; //temporary //int first_ec=1; //Setup oscillator/ports/pins first setup_oscillator(); setup_ports(); setup_peripheral_pin_select(); setup_interrupt_priorities(); #ifdef USE_DIO setup_dio(); #endif #ifdef USE_ADC setup_adc(); #endif #ifdef USE_ETHERCAT while (!eeprom_loaded()) //Wait until ESC is ready //ToggleHeartbeatLED(); //Success SetHeartbeatLED; setup_ethercat(); ClrHeartbeatLED; #endif setup_interrupt_priorities(); dummy = U1RXREG; while(1){ if (i++%20001==0) { ToggleHeartbeatLED(); #if defined USE_ETHERCAT //&& ! defined M3_MAX2_BDC_ARMH step_ethercat(); #endif } } }
static void setup_finish_ports( void ) { setup_ports(); P1DIR &= ~PING_BTN; P1REN |= PING_BTN; P1OUT |= PING_BTN; P2DIR &= ~RX_BIT; P2DIR &= ~XSTATUS; }
static inline gboolean omx_init (GstOmxBaseSink * self) { if (self->gomx->omx_error) return FALSE; setup_ports (self); return TRUE; }
int main (void) { int on=0, ID, calb; int batt_voltage = 0; //init(); //ID = readID(); //calb = readCalibration(); // GPIO_SetValue(RED_LED_PORT, RED_LED_BIT,1); int i = 0; /* Used in main loop */ uint32_t value = 0xaa; setup_ports(); sc_time_t one_sec_timer = sc_get_timer(); /* Initialise the timer variable */ sc_time_t test_in_timer = sc_get_timer(); /* Initialise the timer variable */ /* Set LEDs to known states, i.e. on */ red_led(ON); yellow_led(ON); GPIO_SetValue(CAN_EN_PORT, CAN_EN_BIT, ON); scandal_register_in_channel_handler(0, &in_channel_0_handler); /* This is the main loop, go for ever! */ while (1) { /* This checks whether there are pending requests from CAN, and sends a heartbeat message. * The heartbeat message encodes some data in the first 4 bytes of the CAN message, such as * the number of errors and the version of scandal */ handle_scandal(); /* * scandal_send_channel(TELEM_LOW, ID_VOLT, readVoltage()); * scandal_send_channel(TELEM_LOW, ID_TEMP, readTemperature()); * scandal_send_channel(TELEM_LOW, ID_VOLT, readVoltage()); */ if(sc_get_timer() >= one_sec_timer + 1000) { toggle_red_led(); toggle_yellow_led(); one_sec_timer = sc_get_timer(); batt_voltage = readVoltage(); scandal_send_channel(TELEM_LOW, // priority 0, // channel num batt_voltage // value ); } } }
static inline gboolean omx_init (GstOmxBaseSink *self) { g_omx_core_init (self->gomx, self->omx_library, self->omx_component); if (self->gomx->omx_error) return FALSE; setup_ports (self); return TRUE; }
int main (void) { unsigned int pb_clock = 0; unsigned char message[] = "Ready to receive...", data = '\0'; // extern inline unsigned int __attribute__((always_inline)) SYSTEMConfigPerformance(unsigned int sys_clock) pb_clock = SYSTEMConfigPerformance (SYSTEM_CLOCK); setup_ports (); //Uncomment if using an additional UART to receive from: //setup_UART1 (pb_clock); setup_UART2( pb_clock); initialize_CLS (); putsUART2 (message); while (1) { //To receive from another UART and display on PmodCLS: //uncomment and setup receiving UART. /* if (DataRdyUART1 ()) //Checks if data is available to be read from UART { data = ReadUART1 (); //Reads one character from UART putcUART2 (data); //Displays character onto PmodCLS } */ } return 0; }
int main (void) { // int i; int ret; char *emergency="! EMERGENCY !"; char *welcome="Welcome."; char *enter_pin="Please Enter PIN."; char button_read = FALSE; // Local snapshot of Global 'Button' /* error handling - reset LEDs */ atexit(closing_time); signal(SIGINT, closing_time); term_initio(); rs232_open(); setup_ports(); ret = pthread_create( &keypad_thread, NULL, keypad, NULL); // display_string(welcome,PADDED,BLOCKING); while(alive){ if(state == EMERGENCY){ display_string(emergency,PADDED,NOT_BLOCKING); continue; } switch(state){ case WAITING_LOGGED_OUT: display_string(enter_pin,PADDED,NOT_BLOCKING); digits[0] = 0x80; // Set cursor position while(!button && alive && state == WAITING_LOGGED_OUT){ // Just Wait usleep(SLEEP); } if(state == EMERGENCY) break; // Get out if there's an emergency if(button >= '0' && button <= '9'){ state = INPUTTING_PIN; // Fall through to next state } else{ break; } case INPUTTING_PIN: if(button_read = button){ // Intentionally Assignment input_pin(button_read); // Sends a snapshot of button } cursor_blink(); break; case WAITING_LOGGED_IN: display_string("Enter Track Number.",PADDED,NOT_BLOCKING); digits[0] = 0x80; // Set cursor position while(!button && alive && state == WAITING_LOGGED_IN){ // Just Wait usleep(SLEEP); } if(state == EMERGENCY) break; // Get out if there's an emergency if(button >= '0' && button <= '9'){ state = INPUTTING_TRACK_NUMBER; // Fall through to next state } else if(button == ENTER_MENU){ state = MENU_SELECT; // Fall through to next state break; } else{ break; } case INPUTTING_TRACK_NUMBER: if(button_read = button){ // Intentionally Assignment input_track_number(button_read); // Sends a snapshot of button } cursor_blink(); break; case MENU_SELECT: display_string("MENU.",PADDED,NOT_BLOCKING); menu_select(); break; default: break; } delay(); } pthread_join(keypad_thread, NULL); term_exitio(); rs232_close(); return 0; }
static GstFlowReturn render (GstBaseSink *gst_base, GstBuffer *buf) { GOmxCore *gomx; GOmxPort *in_port; GstOmxBaseSink *self; GstFlowReturn ret = GST_FLOW_OK; self = GST_OMX_BASE_SINK (gst_base); gomx = self->gomx; GST_LOG_OBJECT (self, "begin"); GST_LOG_OBJECT (self, "gst_buffer: size=%lu", GST_BUFFER_SIZE (buf)); GST_LOG_OBJECT (self, "state: %d", gomx->omx_state); if (G_UNLIKELY (gomx->omx_state == OMX_StateLoaded)) { GST_INFO_OBJECT (self, "omx: prepare"); setup_ports (self); g_omx_core_prepare (self->gomx); } in_port = self->in_port; if (G_LIKELY (in_port->enabled)) { guint buffer_offset = 0; if (G_UNLIKELY (gomx->omx_state == OMX_StateIdle)) { GST_INFO_OBJECT (self, "omx: play"); g_omx_core_start (gomx); } if (G_UNLIKELY (gomx->omx_state != OMX_StateExecuting)) { GST_ERROR_OBJECT (self, "Whoa! very wrong"); } while (G_LIKELY (buffer_offset < GST_BUFFER_SIZE (buf))) { OMX_BUFFERHEADERTYPE *omx_buffer; GST_LOG_OBJECT (self, "request_buffer"); omx_buffer = g_omx_port_request_buffer (in_port); if (G_LIKELY (omx_buffer)) { GST_DEBUG_OBJECT (self, "omx_buffer: size=%lu, len=%lu, flags=%lu, offset=%lu, timestamp=%lld", omx_buffer->nAllocLen, omx_buffer->nFilledLen, omx_buffer->nFlags, omx_buffer->nOffset, omx_buffer->nTimeStamp); if (omx_buffer->nOffset == 0 && share_input_buffer) { { GstBuffer *old_buf; old_buf = omx_buffer->pAppPrivate; if (old_buf) { gst_buffer_unref (old_buf); } else if (omx_buffer->pBuffer) { g_free (omx_buffer->pBuffer); } } /* We are going to use this. */ gst_buffer_ref (buf); omx_buffer->pBuffer = GST_BUFFER_DATA (buf); omx_buffer->nAllocLen = GST_BUFFER_SIZE (buf); omx_buffer->nFilledLen = GST_BUFFER_SIZE (buf); omx_buffer->pAppPrivate = buf; } else { omx_buffer->nFilledLen = MIN (GST_BUFFER_SIZE (buf) - buffer_offset, omx_buffer->nAllocLen - omx_buffer->nOffset); memcpy (omx_buffer->pBuffer + omx_buffer->nOffset, GST_BUFFER_DATA (buf) + buffer_offset, omx_buffer->nFilledLen); } GST_LOG_OBJECT (self, "release_buffer"); g_omx_port_release_buffer (in_port, omx_buffer); buffer_offset += omx_buffer->nFilledLen; } else { GST_WARNING_OBJECT (self, "null buffer"); /* ret = GST_FLOW_ERROR; */ } } } else { GST_WARNING_OBJECT (self, "done"); ret = GST_FLOW_UNEXPECTED; } GST_LOG_OBJECT (self, "end"); return ret; }
static void output_loop (gpointer data) { GstPad *pad; GOmxCore *gomx; GOmxPort *out_port; GstOmxBaseFilter *self; GstFlowReturn ret = GST_FLOW_OK; pad = data; self = GST_OMX_BASE_FILTER (gst_pad_get_parent (pad)); gomx = self->gomx; GST_LOG_OBJECT (self, "begin"); /* do not bother if we have been setup to bail out */ if ((ret = g_atomic_int_get (&self->last_pad_push_return)) != GST_FLOW_OK) goto leave; if (!self->ready) { g_error ("not ready"); return; } out_port = self->out_port; if (G_LIKELY (out_port->enabled)) { OMX_BUFFERHEADERTYPE *omx_buffer = NULL; GST_LOG_OBJECT (self, "request buffer"); omx_buffer = g_omx_port_request_buffer (out_port); GST_LOG_OBJECT (self, "omx_buffer: %p", omx_buffer); if (G_UNLIKELY (!omx_buffer)) { GST_WARNING_OBJECT (self, "null buffer: leaving"); ret = GST_FLOW_WRONG_STATE; goto leave; } log_buffer (self, omx_buffer); if (G_LIKELY (omx_buffer->nFilledLen > 0)) { GstBuffer *buf; #if 1 /** @todo remove this check */ if (G_LIKELY (self->in_port->enabled)) { GstCaps *caps = NULL; caps = gst_pad_get_negotiated_caps (self->srcpad); #ifdef ANDROID if (!caps || gomx->settings_changed) { #else if (!caps) { #endif /** @todo We shouldn't be doing this. */ GST_WARNING_OBJECT (self, "faking settings changed notification"); if (gomx->settings_changed_cb) gomx->settings_changed_cb (gomx); #ifdef ANDROID gomx->settings_changed = FALSE; #endif } else { GST_LOG_OBJECT (self, "caps already fixed: %" GST_PTR_FORMAT, caps); gst_caps_unref (caps); } } #endif /* buf is always null when the output buffer pointer isn't shared. */ buf = omx_buffer->pAppPrivate; /** @todo we need to move all the caps handling to one single * place, in the output loop probably. */ if (G_UNLIKELY (omx_buffer->nFlags & 0x80)) { GstCaps *caps = NULL; GstStructure *structure; GValue value = { 0, {{0} } }; caps = gst_pad_get_negotiated_caps (self->srcpad); caps = gst_caps_make_writable (caps); structure = gst_caps_get_structure (caps, 0); g_value_init (&value, GST_TYPE_BUFFER); buf = gst_buffer_new_and_alloc (omx_buffer->nFilledLen); memcpy (GST_BUFFER_DATA (buf), omx_buffer->pBuffer + omx_buffer->nOffset, omx_buffer->nFilledLen); gst_value_set_buffer (&value, buf); gst_buffer_unref (buf); gst_structure_set_value (structure, "codec_data", &value); g_value_unset (&value); gst_pad_set_caps (self->srcpad, caps); } else if (buf && !(omx_buffer->nFlags & OMX_BUFFERFLAG_EOS)) { GST_BUFFER_SIZE (buf) = omx_buffer->nFilledLen; if (self->use_timestamps) { GST_BUFFER_TIMESTAMP (buf) = gst_util_uint64_scale_int (omx_buffer->nTimeStamp, GST_SECOND, OMX_TICKS_PER_SECOND); } omx_buffer->pAppPrivate = NULL; omx_buffer->pBuffer = NULL; ret = push_buffer (self, buf); gst_buffer_unref (buf); } else { /* This is only meant for the first OpenMAX buffers, * which need to be pre-allocated. */ /* Also for the very last one. */ ret = gst_pad_alloc_buffer_and_set_caps (self->srcpad, GST_BUFFER_OFFSET_NONE, omx_buffer->nFilledLen, GST_PAD_CAPS (self->srcpad), &buf); if (G_LIKELY (buf)) { memcpy (GST_BUFFER_DATA (buf), omx_buffer->pBuffer + omx_buffer->nOffset, omx_buffer->nFilledLen); if (self->use_timestamps) { GST_BUFFER_TIMESTAMP (buf) = gst_util_uint64_scale_int (omx_buffer->nTimeStamp, GST_SECOND, OMX_TICKS_PER_SECOND); } if (self->share_output_buffer) { GST_WARNING_OBJECT (self, "couldn't zero-copy"); /* If pAppPrivate is NULL, it means it was a dummy * allocation, free it. */ if (!omx_buffer->pAppPrivate) { g_free (omx_buffer->pBuffer); omx_buffer->pBuffer = NULL; } } ret = push_buffer (self, buf); } else { GST_WARNING_OBJECT (self, "couldn't allocate buffer of size %lu", omx_buffer->nFilledLen); } } } else { GST_WARNING_OBJECT (self, "empty buffer"); } if (self->share_output_buffer && !omx_buffer->pBuffer && omx_buffer->nOffset == 0) { GstBuffer *buf; GstFlowReturn result; GST_LOG_OBJECT (self, "allocate buffer"); result = gst_pad_alloc_buffer_and_set_caps (self->srcpad, GST_BUFFER_OFFSET_NONE, omx_buffer->nAllocLen, GST_PAD_CAPS (self->srcpad), &buf); if (G_LIKELY (result == GST_FLOW_OK)) { gst_buffer_ref (buf); omx_buffer->pAppPrivate = buf; omx_buffer->pBuffer = GST_BUFFER_DATA (buf); omx_buffer->nAllocLen = GST_BUFFER_SIZE (buf); } else { GST_WARNING_OBJECT (self, "could not pad allocate buffer, using malloc"); omx_buffer->pBuffer = g_malloc (omx_buffer->nAllocLen); } } if (self->share_output_buffer && !omx_buffer->pBuffer) { GST_ERROR_OBJECT (self, "no input buffer to share"); } if (G_UNLIKELY (omx_buffer->nFlags & OMX_BUFFERFLAG_EOS)) { GST_DEBUG_OBJECT (self, "got eos"); gst_pad_push_event (self->srcpad, gst_event_new_eos ()); omx_buffer->nFlags &= ~OMX_BUFFERFLAG_EOS; ret = GST_FLOW_UNEXPECTED; } omx_buffer->nFilledLen = 0; GST_LOG_OBJECT (self, "release_buffer"); g_omx_port_release_buffer (out_port, omx_buffer); } leave: self->last_pad_push_return = ret; if (gomx->omx_error != OMX_ErrorNone) ret = GST_FLOW_ERROR; if (ret != GST_FLOW_OK) { GST_INFO_OBJECT (self, "pause task, reason: %s", gst_flow_get_name (ret)); gst_pad_pause_task (self->srcpad); } GST_LOG_OBJECT (self, "end"); gst_object_unref (self); } static GstFlowReturn pad_chain (GstPad * pad, GstBuffer * buf) { GOmxCore *gomx; GOmxPort *in_port; GstOmxBaseFilter *self; GstFlowReturn ret = GST_FLOW_OK; self = GST_OMX_BASE_FILTER (GST_OBJECT_PARENT (pad)); gomx = self->gomx; GST_LOG_OBJECT (self, "begin"); GST_LOG_OBJECT (self, "gst_buffer: size=%u", GST_BUFFER_SIZE (buf)); GST_LOG_OBJECT (self, "state: %d", gomx->omx_state); if (G_UNLIKELY (gomx->omx_state == OMX_StateLoaded)) { g_mutex_lock (self->ready_lock); GST_INFO_OBJECT (self, "omx: prepare"); /** @todo this should probably go after doing preparations. */ if (self->omx_setup) { self->omx_setup (self); } setup_ports (self); g_omx_core_prepare (self->gomx); if (gomx->omx_state == OMX_StateIdle) { self->ready = TRUE; GST_INFO_OBJECT (self, "start srcpad task"); gst_pad_start_task (self->srcpad, output_loop, self->srcpad); } g_mutex_unlock (self->ready_lock); if (gomx->omx_state != OMX_StateIdle) goto out_flushing; } #ifdef ANDROID if (gomx->settings_changed) { GST_DEBUG_OBJECT (self, "settings changed called from streaming thread... Android"); if (gomx->settings_changed_cb) gomx->settings_changed_cb (gomx); gomx->settings_changed = FALSE; } #endif in_port = self->in_port; if (G_LIKELY (in_port->enabled)) { guint buffer_offset = 0; if (G_UNLIKELY (gomx->omx_state == OMX_StateIdle)) { GST_INFO_OBJECT (self, "omx: play"); g_omx_core_start (gomx); if (gomx->omx_state != OMX_StateExecuting) goto out_flushing; /* send buffer with codec data flag */ /** @todo move to util */ if (self->codec_data) { OMX_BUFFERHEADERTYPE *omx_buffer; GST_LOG_OBJECT (self, "request buffer"); omx_buffer = g_omx_port_request_buffer (in_port); if (G_LIKELY (omx_buffer)) { omx_buffer->nFlags |= 0x00000080; /* codec data flag */ omx_buffer->nFilledLen = GST_BUFFER_SIZE (self->codec_data); memcpy (omx_buffer->pBuffer + omx_buffer->nOffset, GST_BUFFER_DATA (self->codec_data), omx_buffer->nFilledLen); GST_LOG_OBJECT (self, "release_buffer"); g_omx_port_release_buffer (in_port, omx_buffer); } } } if (G_UNLIKELY (gomx->omx_state != OMX_StateExecuting)) { GST_ERROR_OBJECT (self, "Whoa! very wrong"); } while (G_LIKELY (buffer_offset < GST_BUFFER_SIZE (buf))) { OMX_BUFFERHEADERTYPE *omx_buffer; if (self->last_pad_push_return != GST_FLOW_OK || !(gomx->omx_state == OMX_StateExecuting || gomx->omx_state == OMX_StatePause)) { goto out_flushing; } GST_LOG_OBJECT (self, "request buffer"); omx_buffer = g_omx_port_request_buffer (in_port); GST_LOG_OBJECT (self, "omx_buffer: %p", omx_buffer); if (G_LIKELY (omx_buffer)) { log_buffer (self, omx_buffer); if (omx_buffer->nOffset == 0 && self->share_input_buffer) { { GstBuffer *old_buf; old_buf = omx_buffer->pAppPrivate; if (old_buf) { gst_buffer_unref (old_buf); } else if (omx_buffer->pBuffer) { g_free (omx_buffer->pBuffer); } } omx_buffer->pBuffer = GST_BUFFER_DATA (buf); omx_buffer->nAllocLen = GST_BUFFER_SIZE (buf); omx_buffer->nFilledLen = GST_BUFFER_SIZE (buf); omx_buffer->pAppPrivate = buf; } else { omx_buffer->nFilledLen = MIN (GST_BUFFER_SIZE (buf) - buffer_offset, omx_buffer->nAllocLen - omx_buffer->nOffset); memcpy (omx_buffer->pBuffer + omx_buffer->nOffset, GST_BUFFER_DATA (buf) + buffer_offset, omx_buffer->nFilledLen); } if (self->use_timestamps) { GstClockTime timestamp_offset = 0; if (buffer_offset && GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE) { timestamp_offset = gst_util_uint64_scale_int (buffer_offset, GST_BUFFER_DURATION (buf), GST_BUFFER_SIZE (buf)); } omx_buffer->nTimeStamp = gst_util_uint64_scale_int (GST_BUFFER_TIMESTAMP (buf) + timestamp_offset, OMX_TICKS_PER_SECOND, GST_SECOND); } buffer_offset += omx_buffer->nFilledLen; #ifdef ANDROID omx_buffer->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; log_buffer (self, omx_buffer); #endif GST_LOG_OBJECT (self, "release_buffer"); /** @todo untaint buffer */ g_omx_port_release_buffer (in_port, omx_buffer); } else { GST_WARNING_OBJECT (self, "null buffer"); ret = GST_FLOW_WRONG_STATE; goto out_flushing; } } } else { GST_WARNING_OBJECT (self, "done"); ret = GST_FLOW_UNEXPECTED; } if (!self->share_input_buffer) { gst_buffer_unref (buf); } leave: GST_LOG_OBJECT (self, "end"); return ret; /* special conditions */ out_flushing: { const gchar *error_msg = NULL; if (gomx->omx_error) { error_msg = "Error from OpenMAX component"; } else if (gomx->omx_state != OMX_StateExecuting && gomx->omx_state != OMX_StatePause) { error_msg = "OpenMAX component in wrong state"; } if (error_msg) { GST_ELEMENT_ERROR (self, STREAM, FAILED, (NULL), ("%s", error_msg)); ret = GST_FLOW_ERROR; } gst_buffer_unref (buf); goto leave; } }
static GstFlowReturn create (GstBaseSrc * gst_base, guint64 offset, guint length, GstBuffer ** ret_buf) { GOmxCore *gomx; GOmxPort *out_port; GstOmxBaseSrc *self; GstFlowReturn ret = GST_FLOW_OK; self = GST_OMX_BASE_SRC (gst_base); gomx = self->gomx; GST_LOG_OBJECT (self, "begin"); GST_LOG_OBJECT (self, "state: %d", gomx->omx_state); if (gomx->omx_state == OMX_StateLoaded) { GST_INFO_OBJECT (self, "omx: prepare"); setup_ports (self); g_omx_core_prepare (self->gomx); } out_port = self->out_port; while (out_port->enabled) { switch (gomx->omx_state) { case OMX_StateIdle: { GST_INFO_OBJECT (self, "omx: play"); g_omx_core_start (gomx); } break; default: break; } switch (gomx->omx_state) { case OMX_StateExecuting: /* OK */ break; default: GST_ERROR_OBJECT (self, "Whoa! very wrong"); break; } { OMX_BUFFERHEADERTYPE *omx_buffer; GST_LOG_OBJECT (self, "request_buffer"); omx_buffer = g_omx_port_request_buffer (out_port); if (omx_buffer) { GST_DEBUG_OBJECT (self, "omx_buffer: size=%lu, len=%lu, offset=%lu", omx_buffer->nAllocLen, omx_buffer->nFilledLen, omx_buffer->nOffset); if (omx_buffer->nFlags & OMX_BUFFERFLAG_EOS) { GST_INFO_OBJECT (self, "got eos"); g_omx_core_set_done (gomx); break; } if (omx_buffer->nFilledLen > 0) { GstBuffer *buf; if (out_port->enabled) { GstCaps *caps = NULL; caps = gst_pad_get_negotiated_caps (gst_base->srcpad); if (!caps) { /** @todo We shouldn't be doing this. */ GST_WARNING_OBJECT (self, "somebody didn't do his work"); gomx->settings_changed_cb (gomx); } else { GST_LOG_OBJECT (self, "caps already fixed"); gst_caps_unref (caps); } } buf = omx_buffer->pAppPrivate; if (buf && !(omx_buffer->nFlags & OMX_BUFFERFLAG_EOS)) { GST_BUFFER_SIZE (buf) = omx_buffer->nFilledLen; #if 0 if (self->use_timestamps) { GST_BUFFER_TIMESTAMP (buf) = omx_buffer->nTimeStamp * (GST_SECOND / OMX_TICKS_PER_SECOND); } #endif omx_buffer->pAppPrivate = NULL; omx_buffer->pBuffer = NULL; omx_buffer->nFilledLen = 0; *ret_buf = buf; gst_buffer_unref (buf); } else { /* This is only meant for the first OpenMAX buffers, * which need to be pre-allocated. */ /* Also for the very last one. */ gst_pad_alloc_buffer_and_set_caps (gst_base->srcpad, GST_BUFFER_OFFSET_NONE, omx_buffer->nFilledLen, GST_PAD_CAPS (gst_base->srcpad), &buf); if (buf) { GST_WARNING_OBJECT (self, "couldn't zero-copy"); memcpy (GST_BUFFER_DATA (buf), omx_buffer->pBuffer + omx_buffer->nOffset, omx_buffer->nFilledLen); #if 0 if (self->use_timestamps) { GST_BUFFER_TIMESTAMP (buf) = omx_buffer->nTimeStamp * (GST_SECOND / OMX_TICKS_PER_SECOND); } #endif omx_buffer->nFilledLen = 0; g_free (omx_buffer->pBuffer); omx_buffer->pBuffer = NULL; *ret_buf = buf; } else { GST_ERROR_OBJECT (self, "whoa!"); } } if (!omx_buffer->pBuffer) { GstBuffer *new_buf; GstFlowReturn result; GST_LOG_OBJECT (self, "allocate buffer"); result = gst_pad_alloc_buffer_and_set_caps (gst_base->srcpad, GST_BUFFER_OFFSET_NONE, omx_buffer->nAllocLen, GST_PAD_CAPS (gst_base->srcpad), &new_buf); if (result == GST_FLOW_OK) { gst_buffer_ref (new_buf); omx_buffer->pAppPrivate = new_buf; omx_buffer->pBuffer = GST_BUFFER_DATA (new_buf); omx_buffer->nAllocLen = GST_BUFFER_SIZE (new_buf); } else { GST_WARNING_OBJECT (self, "could not allocate buffer"); omx_buffer->pBuffer = g_malloc (omx_buffer->nAllocLen); } } GST_LOG_OBJECT (self, "release_buffer"); g_omx_port_release_buffer (out_port, omx_buffer); break; } else { GST_WARNING_OBJECT (self, "empty buffer"); GST_LOG_OBJECT (self, "release_buffer"); g_omx_port_release_buffer (out_port, omx_buffer); continue; } } else { GST_WARNING_OBJECT (self, "null buffer"); /* ret = GST_FLOW_ERROR; */ break; } } } if (!out_port->enabled) { GST_WARNING_OBJECT (self, "done"); ret = GST_FLOW_UNEXPECTED; } GST_LOG_OBJECT (self, "end"); return ret; }
int main (int argc, char *argv[]) { jack_client_t *client; jack_thread_info_t thread_info; int c; char jackClientName[1024] = ""; int ret = 0; struct stat buf; int i; int longopt_index = 0; extern int optind, opterr; int show_usage = 0; char *optstring = "p:n:c:d:f:b:B:h"; struct option long_options[] = { { "portmatch", 1, 0, 'p' }, { "name", 1, 0, 'n' }, { "config", 1, 0, 'c' }, { "help", 0, 0, 'h' }, { "duration", 1, 0, 'd' }, { "file", 1, 0, 'f' }, { "bitdepth", 1, 0, 'b' }, { "bufsize", 1, 0, 'B' }, { 0, 0, 0, 0 } }; signal(SIGINT, sigHandler); memset (&thread_info, 0, sizeof (thread_info)); thread_info.rb_size = DEFAULT_RB_SIZE; opterr = 0; memset(&g, '\000', sizeof(g)); setServerStatusCallback(&g, serverStatusCallback); setGeneralStatusCallback(&g, generalStatusCallback); setWriteBytesCallback(&g, writeBytesCallback); addBasicEncoderSettings(&g); strcpy(jackClientName, "edcast"); while ((c = getopt_long (argc, argv, optstring, long_options, &longopt_index)) != -1) { switch (c) { case 1: /* getopt signals end of '-' options */ break; case 'p': strcpy(portMatch, optarg); getFirstTwo = 1; break; case 'n': strcpy(jackClientName, optarg); break; case 'c': i = stat (optarg, &buf ); if ( i != 0 ) { printf("Cannot open config file (%s)\n", optarg); exit(1); } setConfigFileName(&g, optarg); readConfigFile(&g, 1); break; case 'h': show_usage++; break; case 'd': thread_info.duration = atoi (optarg); break; case 'f': thread_info.path = optarg; break; case 'b': thread_info.bitdepth = atoi (optarg); break; case 'B': thread_info.rb_size = atoi (optarg); break; default: fprintf (stderr, "error\n"); show_usage++; break; } } if (show_usage || ((optind == argc) && (!getFirstTwo))) { fprintf (stderr, "usage: edcast -c configfile [ -n jack_client_name ] [ -p portmatch ] [ jackport1 [ jackport2 ... ]]\n"); fprintf(stderr, "Where:\n"); fprintf(stderr, "-c : config file that specified encoding settings\n"); fprintf(stderr, "-n : name used to register with jackd\n"); fprintf(stderr, "-p : if specified, edcast will connect to the first two output ports matching this name.\n"); fprintf(stderr, "jackportX : explicitly specify a jack port name\n"); exit (1); } if ((client = jack_client_new (jackClientName)) == 0) { fprintf (stderr, "jack server not running?\n"); exit (1); } thread_info.client = client; if (getFirstTwo) { thread_info.channels = 2; } else { thread_info.channels = argc - optind; } thread_info.can_process = 0; setLogFlags(); setup_edcast_thread (&thread_info); jack_set_process_callback (client, process, &thread_info); jack_on_shutdown (client, jack_shutdown, &thread_info); if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); } setup_ports (thread_info.channels, &argv[optind], &thread_info); run_edcast_thread (&thread_info); jack_client_close (client); jack_ringbuffer_free (rb[0]); jack_ringbuffer_free (rb[1]); exit (0); }
int main(void) { int cnt; setup_ports(); read_config(); setup_timer(); setup_control(); PORTC = DISABLED; setup_uart(9600UL); flags = eeread(FLAGS_START); ph_u = 0; ph_v = 24; ph_w = 12; pwm_u = 0; pwm_v = 0; pwm_w = 0; sei(); cnt = 0; while (1) { register byte i; if ((flags & FLAG_POT) && cnt == 0) read_speed(); cnt++; cnt &= 0x3F; if (flags & FLAG_GO) { int8_t cnt_u, cnt_v, cnt_w; int u_u, u_v, u_w; /* Disable all phases */ PORTC &= ~((1 << EU) | (1 << EV) | (1 << EW)); /* Wait to turn mosfets off */ _delay_loop_2(delay_num * delay_step); /* Switch all bridges to HIGH */ PORTC |= ((1<<UU) | (1<<UV) | (1<<UW)); /* Enable all phases */ PORTC |= ((1<<EU) | (1<<EV) | (1<<EW)); //_delay_loop_2(50); cnt_u = cnt_v = cnt_w = -1; u_u = u_v = u_w = 1; for (i = 0; i < MAX_PWM; i++) { if (i == pwm_u || (i > pwm_u && u_u)) { CLRBIT(PORTC, EU); // DISABLE U u_u = 0; cnt_u = delay_num; } if (i == pwm_v || (i > pwm_v && u_v)) { CLRBIT(PORTC, EV); // DISABLE V u_v = 0; cnt_v = delay_num; } if (i == pwm_w || (i > pwm_w && u_w)) { CLRBIT(PORTC, EW); // DISABLE W u_w = 0; cnt_w = delay_num; } _delay_loop_2(delay_step); if (cnt_u == 0) { CLRBIT(PORTC, UU); // Set U to LOW PORTC |= (1<<EU); cnt_u = -1; } if (cnt_v == 0) { CLRBIT(PORTC, UV); // Set V to LOW PORTC |= (1<<EV); cnt_v = -1; } if (cnt_w == 0) { CLRBIT(PORTC, UW); // Set W to LOW PORTC |= (1<<EW); cnt_w = -1; } if (cnt_u > 0) cnt_u--; if (cnt_v > 0) cnt_v--; if (cnt_w > 0) cnt_w--; } } else { PORTC = DISABLED; _delay_loop_1(250); } } return 0; }
int main (void) { int dummy; //int matrix; //only for test of ledmdrv int i; //int temp_current_val; //temporary //int first_ec=1; //Setup oscillator/ports/pins first setup_oscillator(); setup_ports(); setup_peripheral_pin_select(); setup_interrupt_priorities(); #ifdef USE_DIO setup_dio(); #endif #ifdef USE_CONTROL setup_control(); #endif #ifdef USE_ADC_SPI setup_adc_spi(); #endif #ifdef USE_ADC setup_adc(); initDma0(); // Initialise the DMA controller to buffer ADC data in conversion order #endif #ifdef USE_TIMER3 //setup_timer3(); #endif #ifdef USE_UART setup_uart(); #endif ecat_isr_running = 0; #ifdef USE_ETHERCAT while (!eeprom_loaded()) //Wait until ESC is ready //ToggleHeartbeatLED(); //Success SetHeartbeatLED; //#ifdef ECAT_DMA cfgDma0SpiTx(); cfgDma1SpiRx(); //#endif setup_ethercat(); ClrHeartbeatLED; #endif #if defined PWR_0_2 || defined PWR_0_3 || defined PWR_0_4 || defined PWR_0_5 ClrEnableMotor; #endif setup_interrupt_priorities(); dummy = U1RXREG; while(1){ if (i++%20001==0) { //ToggleHeartbeatLED(); } #if defined USE_ETHERCAT if (!IEC0bits.DMA1IE) { DISABLE_AL_EVENT_INT; step_ethercat(); ENABLE_AL_EVENT_INT; } #endif } }
int main (int argc, char **argv) { jack_client_t *client; jack_thread_info_t thread_info; jack_status_t jstat; int c; memset(&thread_info, 0, sizeof(thread_info)); thread_info.channels = 2; thread_info.delay = 100000; thread_info.format = 0; thread_info.iecmult = 2.0; thread_info.outfd = NULL; thread_info.address = "127.0.0.1"; thread_info.port = 7770; thread_info.message = "/1/fader1"; const char *optstring = "hqpjiomx:d:f:V"; struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "json", no_argument, 0, 'j' }, { "iec268", required_argument, 0, 'i' }, { "file", required_argument, 0, 'f' }, { "delay", required_argument, 0, 'd' }, { "peakhold", required_argument, 0, 'p' }, { "osc", required_argument, 0, 'o' }, { "port", required_argument, 0, 'x' }, { "message", required_argument, 0, 'm' }, { "quiet", no_argument, 0, 'q' }, { "version", no_argument, 0, 'V' }, { 0, 0, 0, 0 } }; int option_index; while ((c = getopt_long(argc, argv, optstring, long_options, &option_index)) != -1) { switch (c) { case 'h': usage(argv[0], 0); break; case 'q': want_quiet = 1; break; case 'i': thread_info.format|=2; thread_info.iecmult = atof(optarg)/100.0; break; case 'j': thread_info.format|=4; break; case 'p': thread_info.format|=8; break; case 'f': if (thread_info.outfd) fclose(thread_info.outfd); thread_info.outfd = fopen(optarg, "w"); break; case 'd': if (atol(optarg) < 0 || atol(optarg) > 60000) fprintf(stderr, "delay: time out of bounds.\n"); else thread_info.delay = 1000*atol(optarg); break; case 'm': thread_info.message = optarg; break; case 'o': thread_info.address = optarg; break; case 'x': thread_info.port = atoi(optarg); break; case 'V': printf ("%s %s\n\n",argv[0], VERSION); printf( "Copyright (C) 2012 Robin Gareus <*****@*****.**>\n" "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n" ); break; default: fprintf(stderr, "invalid argument.\n"); usage(argv[0], 0); break; } } if (!thread_info.outfd) { thread_info.outfd=stdout; thread_info.format|=1; } if (argc <= optind) { fprintf(stderr, "At least one port/audio-channel must be given.\n"); usage(argv[0], 1); } /* set up JACK client */ if ((client = jack_client_open("jackpeak", JackNoStartServer, &jstat)) == 0) { fprintf(stderr, "Can not connect to JACK.\n"); exit(1); } thread_info.client = client; thread_info.can_process = 0; thread_info.channels = argc - optind; jack_set_process_callback(client, process, &thread_info); jack_on_shutdown(client, jack_shutdown, &thread_info); jack_set_buffer_size_callback(client, jack_bufsiz_cb, &thread_info); if (jack_activate(client)) { fprintf(stderr, "cannot activate client"); } setup_ports(thread_info.channels, &argv[optind], &thread_info); /* set up i/o thread */ pthread_create(&thread_info.thread_id, NULL, io_thread, &thread_info); #ifndef _WIN32 signal (SIGHUP, catchsig); #endif thread_info.samplerate = jack_get_sample_rate(thread_info.client); if (!want_quiet) { fprintf(stderr, "%i channel%s, @%iSPS.\naddress: %s:%i\nmessage: %s\n", thread_info.channels, (thread_info.channels>1)?"s":"", thread_info.samplerate, thread_info.address, thread_info.port, thread_info.message ); } /* all systems go - run the i/o thread */ thread_info.can_capture = 1; pthread_join(thread_info.thread_id, NULL); if (thread_info.outfd != stdout) fclose(thread_info.outfd); jack_client_close(client); cleanup(&thread_info); return(0); }
/*------------------------------------------------------------------------------ * main -- Open terminal and launch keypad thread. * Check for button input and respond appropriately *------------------------------------------------------------------------------ */ int main (void) { // int i; int ret; char *emergency="! EMERGENCY !"; char button_read = FALSE; // Local snapshot of Global 'Button' char prev_button = 0; /* error handling - reset LEDs */ atexit(closing_time); signal(SIGINT, closing_time); term_initio(); rs232_open(); setup_ports(); ret = pthread_create( &keypad_thread, NULL, keypad, NULL); while(alive){ button_read = button; if(button_read){ if(prev_button != button_read){ if(blocking){ while(blocking == TRUE && alive){ usleep(SLEEP); } } else{ printf("button: %c\n",button_read); switch(button_read){ case 'A': display_string("Hello. =)",BLOCKING); break; case 'B': move_cursor(LEFT); break; case 'C': display_string("Cancel =(",NOT_BLOCKING); break; case 'D': delete_char(); break; case 'E': display_string(emergency,BLOCKING); break; case 'F': move_cursor(RIGHT); break; case ERROR: break; default: insert_char(button_read); break; } } } } prev_button = button_read; } pthread_join(keypad_thread, NULL); term_exitio(); rs232_close(); return 0; }
int main (void) { int i=0; tmp_debug = 0; //Setup oscillator/ports/pins first setup_oscillator(); setup_ports(); setup_peripheral_pin_select(); setup_interrupt_priorities(); //init_temperature_model(); //Blinking HB LED and Timestamp #ifdef USE_DIO setup_dio(); #endif //ToDo Used? #ifdef USE_TIMER1 setup_timer1(); //do before setup_pwm #endif //ToDo: there was a missing #endif, maybe that's why disabling Timer1 was breaking the code! //Motor control PWM #ifdef USE_PWM //setup_pwm(); #endif //Brushless motor #ifdef USE_BLDC setup_bldc(); #endif //Torque PID and Current PID #ifdef USE_CONTROL setup_control(); #endif //Analog to Digital #ifdef USE_ADC setup_adc(); #endif //Torso external ADC #ifdef USE_ADC_SPI setup_adc_spi(); #endif //Current measurment, control and limitation #ifdef USE_CURRENT setup_current(); #endif //ToDo: Remvove? #ifdef USE_TIMER3 setup_timer3(); #endif //VerteX SPI Encoder #ifdef USE_ENCODER_VERTX setup_vertx(); #endif //Torso motor brake #ifdef USE_BRAKE setup_brake(); #endif //EtherCAT Communication #ifdef USE_ETHERCAT while (!eeprom_loaded()) //Wait until ESC is ready SetHeartbeatLED; setup_ethercat(); ClrHeartbeatLED; #endif setup_interrupt_priorities(); if (RCONbits.WDTO) SetHeartbeatLED; //RCONbits.SWDTEN = 1;//enable watchdog timer if (RCON & 0x03 == 0x03) { RCONbits.BOR = 0; RCONbits.POR = 0; } rcon_reg = RCON; while(1) { if (i++%10001==0) { //ToggleHeartbeatLED(); #if defined USE_ETHERCAT step_ethercat(); #endif } } }
static GstFlowReturn pad_chain (GstPad *pad, GstBuffer *buf) { GOmxCore *gomx; GOmxPort *in_port; GstOmxBaseFilter2 *self; GstFlowReturn ret = GST_FLOW_OK; int i; self = GST_OMX_BASE_FILTER2 (GST_OBJECT_PARENT (pad)); //printf("INput!!\n"); PRINT_BUFFER (self, buf); gomx = self->gomx; GST_LOG_OBJECT (self, "begin: size=%u, state=%d", GST_BUFFER_SIZE (buf), gomx->omx_state); if (G_UNLIKELY (gomx->omx_state == OMX_StateLoaded)) { g_mutex_lock (self->ready_lock); GST_INFO_OBJECT (self, "omx: prepare"); /** @todo this should probably go after doing preparations. */ if (self->omx_setup) { self->omx_setup (self); } setup_input_buffer (self, buf); setup_ports (self); g_omx_core_prepare (self->gomx); if (gomx->omx_state == OMX_StateIdle) { self->ready = TRUE; for (i = 0; i < NUM_OUTPUTS; i++) gst_pad_start_task (self->srcpad[i], output_loop, self->srcpad[i]); } g_mutex_unlock (self->ready_lock); if (gomx->omx_state != OMX_StateIdle) goto out_flushing; } in_port = self->in_port; if (G_LIKELY (in_port->enabled)) { if (G_UNLIKELY (gomx->omx_state == OMX_StateIdle)) { GST_INFO_OBJECT (self, "omx: play"); g_omx_core_start (gomx); if (gomx->omx_state != OMX_StateExecuting) goto out_flushing; /* send buffer with codec data flag */ if (self->codec_data) { GST_BUFFER_FLAG_SET (self->codec_data, GST_BUFFER_FLAG_IN_CAPS); /* just in case */ g_omx_port_send (in_port, self->codec_data); } } if (G_UNLIKELY (gomx->omx_state != OMX_StateExecuting)) { GST_ERROR_OBJECT (self, "Whoa! very wrong"); } while (TRUE) { gint sent; if (self->last_pad_push_return != GST_FLOW_OK || !(gomx->omx_state == OMX_StateExecuting || gomx->omx_state == OMX_StatePause)) { GST_DEBUG_OBJECT (self, "last_pad_push_return=%d", self->last_pad_push_return); goto out_flushing; } if (self->input_fields_separately) { g_omx_port_send_interlaced_fields (in_port, buf, self->second_field_offset); gst_buffer_unref (buf); break; } sent = g_omx_port_send (in_port, buf); if (G_UNLIKELY (sent < 0)) { ret = GST_FLOW_WRONG_STATE; goto out_flushing; } else if (sent < GST_BUFFER_SIZE (buf)) { GstBuffer *subbuf = gst_buffer_create_sub (buf, sent, GST_BUFFER_SIZE (buf) - sent); gst_buffer_unref (buf); buf = subbuf; } else { gst_buffer_unref (buf); break; } } } else { GST_WARNING_OBJECT (self, "done"); ret = GST_FLOW_UNEXPECTED; } leave: GST_LOG_OBJECT (self, "end"); return ret; /* special conditions */ out_flushing: { const gchar *error_msg = NULL; if (gomx->omx_error) { error_msg = "Error from OpenMAX component"; } else if (gomx->omx_state != OMX_StateExecuting && gomx->omx_state != OMX_StatePause) { error_msg = "OpenMAX component in wrong state"; } if (error_msg) { GST_ELEMENT_ERROR (self, STREAM, FAILED, (NULL), (error_msg)); ret = GST_FLOW_ERROR; } gst_buffer_unref (buf); goto leave; } }
main(int argc, char **argv) { if (!kill_old_driver(argc,argv)) return 0; int no_fork=0,i; for (i=1; i<argc; i++) if (!strcmp(argv[i],"-no_fork")) // use this to debug easier no_fork=1; if (!no_fork) // use this for debugging { int child_pid=fork(); if (child_pid) { FILE *fp=fopen(DLOCK_NAME,"wb"); if (!fp) { fprintf(stderr,"Unable to open %s for writing, killing child\n",DLOCK_NAME); kill(child_pid,SIGUSR2); return 0; } fprintf(fp,"%d\n",child_pid); fclose(fp); printf("%d\n",child_pid); // tell parent the sound driver's process number return 0; // exit, child will continue } } fman=new file_manager(argc,argv,&tcpip); int comm_port=DEFAULT_COMM_PORT; int game_port=-1; int debug=0; for (i=1; i<argc-1; i++) if (!strcmp(argv[i],"-port")) { comm_port=atoi(argv[i+1]); if (game_port==-1) game_port=comm_port+1; } else if (!strcmp(argv[i],"-game_port")) game_port=atoi(argv[i+1]); else if (!strcmp(argv[i],"-debug")) debug=1; if (game_port==-1) game_port=DEFAULT_GAME_PORT; // make sure this program was run by the abuse engine if (argc<2 || strcmp(argv[1],"runme")) { fprintf(stderr,"%s is normally run by abuse, running stand-alone file server\n" "Server will be killed by running abuse\n",argv[0]); } else driver=new net_driver(argc,argv,comm_port,game_port,&tcpip); setup_ports(comm_port,game_port); while (1) { tcpip.select_sockets(); if (driver) driver->check_commands(); if (comm_sock->ready_to_read()) { net_address *addr; net_socket *new_sock=comm_sock->accept(addr); if (debug) { if (new_sock) { fprintf(stderr,"accepting new connection from \n"); addr->print(); } else fprintf(stderr,"accept failed\n"); } if (new_sock) { uchar client_type; if (new_sock->read(&client_type,1)!=1) { delete addr; delete new_sock; } else if (client_type==CLIENT_NFS) { delete addr; fman->add_nfs_client(new_sock); } else if (!driver || !driver->add_client(client_type,new_sock,addr)) { delete addr; delete new_sock; } } } fman->process_net(); } }
static GstFlowReturn pad_chain (GstPad *pad, GstBuffer *buf) { GOmxCore *gomx; GOmxPort *in_port; GstOmxBaseFilter21 *self; GstFlowReturn ret = GST_FLOW_OK; int i; static sink_init = 0; int sink_number; static gboolean init_done = FALSE; self = GST_OMX_BASE_FILTER21 (GST_OBJECT_PARENT (pad)); if(strcmp(GST_PAD_NAME(pad), "sink_00") == 0){ sink_number=0; self->sink_camera_timestamp = GST_BUFFER_TIMESTAMP(buf); } else if(strcmp(GST_PAD_NAME(pad), "sink_01") == 0){ sink_number=1; } PRINT_BUFFER (self, buf); gomx = self->gomx; GST_LOG_OBJECT (self, "begin: size=%u, state=%d, sink_number=%d", GST_BUFFER_SIZE (buf), gomx->omx_state, sink_number); /*if (G_LIKELY (gomx->omx_state != OMX_StateExecuting)) { GST_INFO_OBJECT (self, "Begin - Port %d", sink_number); //setup_input_buffer (self, buf, sink_number); //sink_init++; //g_mutex_lock (self->ready_lock); if(init_done == TRUE){ GST_INFO_OBJECT (self, "Init_done"); //g_mutex_unlock(self->ready_lock); } if(init_done == TRUE){ sink_init = 0; init_done = FALSE; } else{ while(sink_init != 2){ usleep(1000); } } }*/ if (G_UNLIKELY (gomx->omx_state == OMX_StateLoaded)) { GST_INFO_OBJECT (self, "omx: prepare"); /** @todo this should probably go after doing preparations. */ if (self->omx_setup) { self->omx_setup (self); } /* enable input port */ for(i=0;i<NUM_INPUTS;i++){ GST_INFO_OBJECT (self,"Enable Port %d",self->in_port[i]->port_index); OMX_SendCommand (gomx->omx_handle, OMX_CommandPortEnable, self->in_port[i]->port_index, NULL); g_sem_down (self->in_port[i]->core->port_sem); } GST_INFO_OBJECT (self,"Enable Port %d",self->out_port->port_index); /* enable output port */ OMX_SendCommand (gomx->omx_handle,OMX_CommandPortEnable, self->out_port->port_index, NULL); g_sem_down (self->out_port->core->port_sem); /* indicate that port is now configured */ setup_ports (self); g_omx_core_prepare (self->gomx); if (gomx->omx_state == OMX_StateIdle) { self->ready = TRUE; //gst_pad_start_task (self->srcpad, output_loop, self->srcpad); } if (gomx->omx_state != OMX_StateIdle) goto out_flushing; GST_INFO_OBJECT (self, "omx: end state Loaded"); } if (G_UNLIKELY (gomx->omx_state == OMX_StateIdle)) { g_omx_core_start (gomx); GST_INFO_OBJECT (self, "Release Port - %d", sink_number); init_done = TRUE; //g_mutex_unlock (self->ready_lock); if (gomx->omx_state != OMX_StateExecuting){ GST_INFO_OBJECT (self, "omx: executing FAILED !"); goto out_flushing; } } if (G_LIKELY (self->in_port[sink_number]->enabled)) { if (G_UNLIKELY (gomx->omx_state != OMX_StateExecuting)) { GST_ERROR_OBJECT (self, "Whoa! very wrong"); } while (TRUE) { gint sent; if (self->last_pad_push_return != GST_FLOW_OK || !(gomx->omx_state == OMX_StateExecuting || gomx->omx_state == OMX_StatePause)) { GST_INFO_OBJECT (self, "last_pad_push_return=%d", self->last_pad_push_return); goto out_flushing; } sent = g_omx_port_send (self->in_port[sink_number], buf); if (G_UNLIKELY (sent < 0)) { ret = GST_FLOW_WRONG_STATE; goto out_flushing; } else if (sent < GST_BUFFER_SIZE (buf)) { GstBuffer *subbuf = gst_buffer_create_sub (buf, sent, GST_BUFFER_SIZE (buf) - sent); gst_buffer_unref (buf); buf = subbuf; } else { gst_buffer_unref (buf); break; } } } else { GST_WARNING_OBJECT (self, "done"); ret = GST_FLOW_UNEXPECTED; } return ret; leave: GST_LOG_OBJECT (self, "end"); return ret; /* special conditions */ out_flushing: { const gchar *error_msg = NULL; if (gomx->omx_error) { error_msg = "Error from OpenMAX component"; } else if (gomx->omx_state != OMX_StateExecuting && gomx->omx_state != OMX_StatePause) { error_msg = "OpenMAX component in wrong state"; } if (error_msg) { GST_ELEMENT_ERROR (self, STREAM, FAILED, (NULL), (error_msg)); ret = GST_FLOW_ERROR; } gst_buffer_unref (buf); goto leave; } }
void setup_term(){ term_initio(); rs232_open(); setup_ports(); }
int main (int argc, char *argv[]) { jack_thread_info_t thread_info; int c; int longopt_index = 0; extern int optind, opterr; int show_usage = 0; char *optstring = "d:f:b:B:h"; struct option long_options[] = { { "help", 0, 0, 'h' }, { "duration", 1, 0, 'd' }, { "file", 1, 0, 'f' }, { "bitdepth", 1, 0, 'b' }, { "bufsize", 1, 0, 'B' }, { 0, 0, 0, 0 } }; memset (&thread_info, 0, sizeof (thread_info)); thread_info.rb_size = DEFAULT_RB_SIZE; opterr = 0; while ((c = getopt_long (argc, argv, optstring, long_options, &longopt_index)) != -1) { switch (c) { case 1: /* getopt signals end of '-' options */ break; case 'h': show_usage++; break; case 'd': thread_info.duration = atoi (optarg); break; case 'f': thread_info.path = optarg; break; case 'b': thread_info.bitdepth = atoi (optarg); break; case 'B': thread_info.rb_size = atoi (optarg); break; default: fprintf (stderr, "error\n"); show_usage++; break; } } if (show_usage || thread_info.path == NULL || optind == argc) { fprintf (stderr, "usage: %s -f filename [ -d second ] [ -b bitdepth ] [ -B bufsize ] port1 [ port2 ... ]\n", argv[0]); exit (1); } if ((client = jack_client_open ("jackrec", JackNullOption, NULL)) == 0) { fprintf (stderr, "JACK server not running?\n"); exit (1); } thread_info.client = client; thread_info.channels = argc - optind; thread_info.can_process = 0; thread_info.sample_rate = jack_get_sample_rate (client); logged_timestamp = 0; setup_disk_thread (&thread_info); jack_set_process_callback (client, process, &thread_info); jack_on_shutdown (client, jack_shutdown, &thread_info); if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); } setup_ports (argc - optind, &argv[optind], &thread_info); /* install a signal handler to properly quits jack client */ #ifndef WIN32 signal(SIGQUIT, signal_handler); signal(SIGHUP, signal_handler); #endif signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); run_disk_thread (&thread_info); jack_client_close (client); jack_ringbuffer_free (rb); exit (0); }
static GstFlowReturn pad_chain (GstPad *pad, GstBuffer *buf) { GOmxCore *gomx; GOmxPort *in_port; GstOmxBaseFilter *self; GstFlowReturn ret = GST_FLOW_OK; self = GST_OMX_BASE_FILTER (GST_OBJECT_PARENT (pad)); gomx = self->gomx; GST_LOG_OBJECT (self, "begin"); GST_LOG_OBJECT (self, "gst_buffer: size=%u", GST_BUFFER_SIZE (buf)); GST_LOG_OBJECT (self, "state: %d", gomx->omx_state); if (G_UNLIKELY (gomx->omx_state == OMX_StateLoaded)) { g_mutex_lock (self->ready_lock); GST_INFO_OBJECT (self, "omx: prepare"); /** @todo this should probably go after doing preparations. */ if (self->omx_setup) { self->omx_setup (self); } setup_ports (self); g_omx_core_prepare (self->gomx); if (gomx->omx_state == OMX_StateIdle) { self->ready = TRUE; gst_pad_start_task (self->srcpad, output_loop, self->srcpad); } g_mutex_unlock (self->ready_lock); if (gomx->omx_state != OMX_StateIdle) goto out_flushing; } in_port = self->in_port; if (G_LIKELY (in_port->enabled)) { guint buffer_offset = 0; if (G_UNLIKELY (gomx->omx_state == OMX_StateIdle)) { GST_INFO_OBJECT (self, "omx: play"); g_omx_core_start (gomx); if (gomx->omx_state != OMX_StateExecuting) goto out_flushing; /* send buffer with codec data flag */ /** @todo move to util */ if (self->codec_data) { OMX_BUFFERHEADERTYPE *omx_buffer; GST_LOG_OBJECT (self, "request buffer"); omx_buffer = g_omx_port_request_buffer (in_port); if (G_LIKELY (omx_buffer)) { omx_buffer->nFlags |= 0x00000080; /* codec data flag */ omx_buffer->nFilledLen = GST_BUFFER_SIZE (self->codec_data); memcpy (omx_buffer->pBuffer + omx_buffer->nOffset, GST_BUFFER_DATA (self->codec_data), omx_buffer->nFilledLen); GST_LOG_OBJECT (self, "release_buffer"); g_omx_port_release_buffer (in_port, omx_buffer); } } } if (G_UNLIKELY (gomx->omx_state != OMX_StateExecuting)) { GST_ERROR_OBJECT (self, "Whoa! very wrong"); } while (G_LIKELY (buffer_offset < GST_BUFFER_SIZE (buf))) { OMX_BUFFERHEADERTYPE *omx_buffer; if (self->last_pad_push_return != GST_FLOW_OK || !(gomx->omx_state == OMX_StateExecuting || gomx->omx_state == OMX_StatePause)) { goto out_flushing; } GST_LOG_OBJECT (self, "request buffer"); omx_buffer = g_omx_port_request_buffer (in_port); GST_LOG_OBJECT (self, "omx_buffer: %p", omx_buffer); if (G_LIKELY (omx_buffer)) { GST_DEBUG_OBJECT (self, "omx_buffer: size=%lu, len=%lu, flags=%lu, offset=%lu, timestamp=%lld", omx_buffer->nAllocLen, omx_buffer->nFilledLen, omx_buffer->nFlags, omx_buffer->nOffset, omx_buffer->nTimeStamp); if (omx_buffer->nOffset == 0 && self->share_input_buffer) { { GstBuffer *old_buf; old_buf = omx_buffer->pAppPrivate; if (old_buf) { gst_buffer_unref (old_buf); } else if (omx_buffer->pBuffer) { g_free (omx_buffer->pBuffer); } } omx_buffer->pBuffer = GST_BUFFER_DATA (buf); omx_buffer->nAllocLen = GST_BUFFER_SIZE (buf); omx_buffer->nFilledLen = GST_BUFFER_SIZE (buf); omx_buffer->pAppPrivate = buf; } else { omx_buffer->nFilledLen = MIN (GST_BUFFER_SIZE (buf) - buffer_offset, omx_buffer->nAllocLen - omx_buffer->nOffset); memcpy (omx_buffer->pBuffer + omx_buffer->nOffset, GST_BUFFER_DATA (buf) + buffer_offset, omx_buffer->nFilledLen); } if (self->use_timestamps) { GstClockTime timestamp_offset = 0; if (buffer_offset && GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE) { timestamp_offset = gst_util_uint64_scale_int (buffer_offset, GST_BUFFER_DURATION (buf), GST_BUFFER_SIZE (buf)); } omx_buffer->nTimeStamp = gst_util_uint64_scale_int (GST_BUFFER_TIMESTAMP (buf) + timestamp_offset, OMX_TICKS_PER_SECOND, GST_SECOND); } buffer_offset += omx_buffer->nFilledLen; GST_LOG_OBJECT (self, "release_buffer"); /** @todo untaint buffer */ g_omx_port_release_buffer (in_port, omx_buffer); } else { GST_WARNING_OBJECT (self, "null buffer"); ret = GST_FLOW_WRONG_STATE; goto out_flushing; } } } else { GST_WARNING_OBJECT (self, "done"); ret = GST_FLOW_UNEXPECTED; } if (!self->share_input_buffer) { gst_buffer_unref (buf); } leave: GST_LOG_OBJECT (self, "end"); return ret; /* special conditions */ out_flushing: { const gchar *error_msg = NULL; if (gomx->omx_error) { error_msg = "Error from OpenMAX component"; } else if (gomx->omx_state != OMX_StateExecuting && gomx->omx_state != OMX_StatePause) { error_msg = "OpenMAX component in wrong state"; } if (error_msg) { GST_ELEMENT_ERROR (self, STREAM, FAILED, (NULL), (error_msg)); ret = GST_FLOW_ERROR; } gst_buffer_unref (buf); goto leave; } }