/* * * 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 #include /* ! Add and return a new consumer reference to the buffer, * @return NULL if an error occurs*/ BPConsumer *bp_ref(BPBuffer * buffer) { BPConsumer *cons; ptrdiff_t i; if (!buffer) return NULL; if ((cons = (BPConsumer *) malloc(sizeof(BPConsumer))) == NULL) return NULL; cons->last_read_pos = -1; // BPtoSlotPtr(buffer, NULL); cons->buffer = buffer; cons->frames = 0; cons->first_rtpseq = -1; cons->first_rtptime = -1; bp_lock(buffer); cons->read_pos = buffer->slots[buffer->control->write_pos].next; cons->last_seq = buffer->slots[buffer->control->write_pos].slot_seq; buffer->control->refs++; bp_unlock(buffer); bp_log(FNC_LOG_DEBUG, "Buffer ref (%d)\n", buffer->control->refs); return cons; }