Example #1
0
static void source_reset(MIXER_SOURCE_T *pSource, int lock) {

  LOG(X_DEBUG("mixer source reset sourceid:%d, lock:%d"), pSource->id, lock);

  pSource->discardedSamplesOffset = 0;

  ringbuf_reset(&pSource->buf, lock);

  if(pSource->pOutput) {

    ringbuf_reset(&pSource->pOutput->buf, 1);

    //
    // Reset the vad output buffer
    //
    if(pSource->pOutput->vad_buffer) {
      pSource->pOutput->priorVadIdx = -1;
      memset(pSource->pOutput->vad_buffer, 0,  pSource->pOutput->vad_bufsz);
    }
  }

}
Example #2
0
static int acd_read(const char *path, char *buf, size_t size, off_t offset,
		      struct fuse_file_info *fi)
{
	size_t len;
        file_ctx * ctx = (file_ctx *) fi->fh;
        pthread_mutex_lock(&ctx->readmutex); //used for async reads - prevents two reads at same time 

        //check if read is backwards.
        
        size_t bufoffset = (ctx->offset-ringbuf_bytes_used(ctx->rb)); //file offset of buffer
        //if buffer is ahead of read || read is ahead of buffer
        if( offset != bufoffset){ //non continuouse read               
                ctx->abort_curl=1;//stop curl callbacks
                ringbuf_reset(ctx->rb); //empty current buffer
                
                pthread_mutex_lock(&ctx->writemutex); //lock the write thread
                fprintf(stderr,"READ Reset: http offset: %u, buffered: %u, read offset: %u\n", ctx->offset, ringbuf_bytes_used(ctx->rb), offset);
                ctx->offset=offset; //set new offset for http reads
                ringbuf_reset(ctx->rb); //empty current buffer
                ctx->abort_curl=0; //allow callbacks
                pthread_mutex_unlock(&ctx->writemutex);
        }
                 
        fprintf(stderr, "READ: %s, size:%u, off:%u\n", path, size, offset);
        size = MIN(size,ctx->filesize-offset); //dont underflow buffer
        
        while( ringbuf_bytes_used(ctx->rb) <  size){
                //fprintf(stderr, ".");//block till we have enough data
                usleep(100);
        }

        //copy accross data
        ringbuf_memcpy_from(buf, ctx->rb, size);
        
        pthread_mutex_unlock(&ctx->readmutex);
	return size;
}
ringbuf_t ringbuf_new(size_t capacity)
{
	ringbuf_t rb = (ringbuf_t)os_zalloc(sizeof(struct ringbuf_t));
	if (rb){
		rb->size = capacity + 1;
		rb->buf = (uint8*)os_zalloc(rb->size);
		if (rb->buf){
			ringbuf_reset(rb);
		}else{
			os_free(rb);
			return NULL;
		}
	}
	return rb;
}
Example #4
0
ringbuf_t
ringbuf_new(size_t capacity)
{
    ringbuf_t rb = malloc(sizeof(struct ringbuf_t));
    if (rb) {

        /* One byte is used for detecting the full condition. */
        rb->size = capacity + 1;
        rb->buf = malloc(rb->size);
        if (rb->buf)
            ringbuf_reset(rb);
        else {
            free(rb);
            return 0;
        }
    }
    return rb;
}
Example #5
0
static int acd_release(const char *path, struct fuse_file_info *fi){
        file_ctx * ctx = (file_ctx *) fi->fh;
        fprintf(stderr, "RELEASE start: %s\n", path);
        
        //Stop htto thread
        ctx->abort_curl=1;//stop curl callbacks
        ctx->thread_done=1;//kill the thread
        ringbuf_reset(ctx->rb); //empty current buffer to force a callback loop
        fprintf(stderr, "RELEASE writemutex: %s\n", path);
        pthread_join(ctx->curlthread, NULL); // wait for thread to end
        
        //Free the memory
        pthread_mutex_destroy(&ctx->writemutex);
        pthread_mutex_destroy(&ctx->readmutex);
        curl_easy_cleanup(ctx->curl); 
        free(ctx->url); //string
        ringbuf_free(&ctx->rb);//ringbuffer
        free(ctx);
        fprintf(stderr, "RELEASE done: %s\n", path);
}
Example #6
0
int ringbuf_init(LOG_CTXT_T *logCtxt,
                 RING_BUF_T *pBuf, 
                 unsigned int sz) {

  if(!pBuf) {
    return -1;
  }

  pBuf->logCtxt = logCtxt;
  pthread_mutex_init(&pBuf->mtx, NULL);

  pBuf->samplesSz = sz;

  if(pBuf->samplesSz > 0 && !(pBuf->buffer = (int16_t *) calloc(sizeof(int16_t), pBuf->samplesSz))) {
    return -1;
  }

  ringbuf_reset(pBuf, 0);

  return 0;
}
Example #7
0
void ringbuf_wipe(struct ringbuf *buf)
{
	memset(buf->data, 0x00, buf->size);
	ringbuf_reset(buf);
}