double OMSbuff_nextts(OMSConsumer *cons) { OMSSlot *last_read; OMSSlot *next; OMSbuff_lock(cons->buffer); OMSbuff_shm_refresh(cons->buffer); last_read = OMStoSlot(cons->buffer, cons->last_read_pos); next = &cons->buffer->slots[cons->read_pos]; if ( !next->refs || (next->slot_seq < cons->last_seq) ) { // added some slots? if ( last_read && cons->buffer->slots[last_read->next].refs && (cons->buffer->slots[last_read->next].slot_seq > cons->last_seq) ) next = &cons->buffer->slots[last_read->next]; else { OMSbuff_unlock(cons->buffer); return -1; } } else if (last_read && ( cons->buffer->slots[last_read->next].slot_seq < next->slot_seq ) ) next = &cons->buffer->slots[last_read->next]; OMSbuff_unlock(cons->buffer); return next->timestamp; }
/*! Check if buffer is empty for a given consumer. * * Checks in this function are taken from <tt>OMSbuff_read()</tt> and not * optimized * * \param Consumer to be checked. * \return 1 if buffer is empty, 0 if not. * \return -1 on error. * * \see OMSbuff_read * */ int OMSbuff_isempty(OMSConsumer * cons) { OMSSlot *last_read; OMSSlot *next; OMSbuff_lock(cons->buffer); OMSbuff_shm_refresh(cons->buffer); last_read = OMStoSlot(cons->buffer, cons->last_read_pos); next = &cons->buffer->slots[cons->read_pos]; if (!next->refs || (next->slot_seq < cons->last_seq)) { // added some slots? if (last_read && cons->buffer->slots[last_read->next].refs && (cons->buffer->slots[last_read->next].slot_seq > cons->last_seq)) RETURN(0); else RETURN(1); } else if (last_read && (cons->buffer->slots[last_read->next].slot_seq < next->slot_seq)) RETURN(0); OMSbuff_unlock(cons->buffer); return 0; }
/* ! Add and return a new consumer reference to the buffer, * \return NULL if an error occurs*/ OMSConsumer *OMSbuff_ref(OMSBuffer *buffer) { OMSConsumer *cons; ptrdiff_t i; if (!buffer) return NULL; if ((cons = (OMSConsumer *)malloc(sizeof(OMSConsumer))) == NULL ) return NULL; cons->last_read_pos = -1;// OMStoSlotPtr(buffer, NULL); cons->buffer = buffer; cons->frames=0; cons->firstts = -1; OMSbuff_lock(buffer); // cons->read_pos = buffer->slots[buffer->control->write_pos].next; // cons->last_seq = buffer->slots[buffer->control->write_pos].slot_seq; cons->read_pos = buffer->control->valid_read_pos; // buffer->slots[buffer->control->valid_read_pos].next; cons->last_seq = 0; // buffer->slots[buffer->control->valid_read_pos].slot_seq; if (buffer->slots[cons->read_pos].slot_seq) { for (i=cons->read_pos; i!=buffer->control->write_pos; i=buffer->slots[i].next) buffer->slots[i].refs++; buffer->slots[i].refs++; } printf("ref at position %d (write_pos @ %d)\n", cons->read_pos, buffer->control->write_pos); buffer->control->refs++; // if ( msync(buffer->control, sizeof(OMSControl), MS_SYNC) ) // printf("*** control msync error\n"); OMSbuff_unlock(buffer); fnc_log(FNC_LOG_DEBUG, "Buffer ref (%d)\n", buffer->control->refs); return cons; }