/* * * This file is part of bufferpool * * Copyright (C) 2007 by LScube team * See AUTHORS for more details * * bufferpool is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * bufferpool is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with bufferpool; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * */ #include /*! @return the next slot in the buffer and do NOT move current read position. * NULL if buffer is empty * */ BPSlot *bp_getreader(BPConsumer * cons) { BPSlot *last_read; BPSlot *next; bp_lock(cons->buffer); if (bp_shm_refresh(cons->buffer)) { bp_unlock(cons->buffer); return NULL; } last_read = BPtoSlot(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 { bp_unlock(cons->buffer); return NULL; } } else if (last_read && (cons->buffer->slots[last_read->next].slot_seq < next->slot_seq)) next = &cons->buffer->slots[last_read->next]; if (cons->first_rtpseq == -1) cons->first_rtpseq = next->slot_seq; if (cons->first_rtptime == -1) cons->first_rtptime = next->rtp_time; bp_unlock(cons->buffer); return next; }