SCM ffmpeg_flush(SCM scm_self) { struct ffmpeg_t *self = get_self(scm_self); if (self->video_codec_ctx) avcodec_flush_buffers(self->video_codec_ctx); if (self->audio_codec_ctx) avcodec_flush_buffers(self->audio_codec_ctx); if (self->audio_buffer.buffer) ringbuffer_flush(&self->audio_buffer); return scm_self; }
/** * \brief Process "byte is sent" interrupt * * \param[in] device The pointer to device structure */ static void usart_os_process_byte_sent(struct _usart_async_device *device) { struct usart_os_descriptor *descr = CONTAINER_OF(device, struct usart_os_descriptor, device); /* Flush buffer to remove unexpected data */ ringbuffer_flush(&descr->rx); if (descr->tx_por != descr->tx_buffer_length) { _usart_async_write_byte(&descr->device, descr->tx_buffer[descr->tx_por++]); _usart_async_enable_byte_sent_irq(&descr->device); } else { _usart_async_enable_tx_done_irq(&descr->device); } }
void cereal_rx_flush() { ringbuffer_flush(&cereal_incoming); }
/** * \brief flush usart rx ringbuf */ int32_t usart_os_flush_rx_buffer(struct usart_os_descriptor *const descr) { ASSERT(descr); return ringbuffer_flush(&descr->rx); }
static void*_ringbuffer_consumer_thread(void *arg) { /* * * Note: There are a lot of what might seem like pointless casts in this * function. In args to pthread and semaphore functions. * * These casts are to suppress compiler warnings * about 'discarding the volatile directive'. * */ volatile TTSRENDER_STATE_T *st = (TTSRENDER_STATE_T*)arg; uint8_t *buf = NULL; int bytes_to_send; int rc; while(1) { // wait for ringbuffer data semaphore. this tells us there is data available in the ring buffer sem_wait((sem_t*)&st->ringbuffer_data_sema); pthread_mutex_lock((pthread_mutex_t*)&st->ringbuffer_mutex); while( ! ringbuffer_is_empty(st->ringbuffer)) { // set bytes_to_send to either the OMX IL Client buffer size, or the number of bytes waiting in the ring buffer, whichever is the smaller bytes_to_send = min(st->buffer_size, ringbuffer_used_space(st->ringbuffer)); buf = ilctts_get_buffer((TTSRENDER_STATE_T*)st); while(buf == NULL) { // the free_buffer_cv variable is signalled inside the empty buffer callback pthread_mutex_lock((pthread_mutex_t*)&st->free_buffer_mutex); pthread_cond_wait((pthread_cond_t*)&st->free_buffer_cv, (pthread_mutex_t*)&st->free_buffer_mutex); buf = ilctts_get_buffer((TTSRENDER_STATE_T*)st); pthread_mutex_unlock((pthread_mutex_t*)&st->free_buffer_mutex); }// end while buf == NULL if (st->tts_stop) { ringbuffer_flush(st->ringbuffer); ilctts_flush((TTSRENDER_STATE_T *)st); st->tts_stop = 0; } rc = ringbuffer_read(st->ringbuffer, (void*)buf, bytes_to_send); if (rc == -1) { ERROR("ringbuffer_read returned -1 error code in ilctts_consumer_thread\n", ""); } // try and wait for a minimum latency time (in ms) before sending the next packet ilctts_latency_wait((TTSRENDER_STATE_T *)st); rc = ilctts_send_audio((TTSRENDER_STATE_T*)st, buf, bytes_to_send); if (rc == -1) { ERROR("ilctts_send_audio returned error code -1 in ilctts_consumer_thread\n", ""); } } // end while buffer is not empty pthread_mutex_unlock((pthread_mutex_t*)&st->ringbuffer_mutex); // post ringbuffer semaphore to tell producer thread to go ahead sem_post((sem_t*)&st->ringbuffer_empty_sema); buf = NULL; usleep(1000); } // end while(1) pthread_exit(NULL); } // end _ringbuffer_consumer_thread