/* * * 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 #include /*! @brief Write a new slot in the buffer using the input parameters. * * The function writes a new slot according with input parameters. If the * data belongs to a slot that was previously requested with * bp_getslot then there is not copy of data, just the * parameter setting like a commit of changes done. * @param seq_delta is the difference between sequence number of pkt(slot) and * the expected number. If it's 0, it does mean that the sequence number is * grown by 1. * @return ERR_NOERROR or ERR_ALLOC * */ int bp_write(BPBuffer * buffer, int16_t seq_delta, double timestamp, uint32_t rtp_time, uint8_t marker, uint8_t * data, uint32_t data_size) { BPSlot *slot; // = &buffer->slots[buffer->control->write_pos]; uint64_t curr_seq; // = slot->slot_seq; bp_lock(buffer); if (bp_shm_refresh(buffer)) return ERR_ALLOC; slot = &buffer->slots[buffer->control->write_pos]; curr_seq = slot->slot_seq; if (buffer->slots[slot->next].data == data) { slot = &buffer->slots[slot->next]; } else { if (buffer->slots[slot->next].refs > 0) { if ((slot = bp_addpage(buffer, slot)) == NULL) { bp_unlock(buffer); return ERR_ALLOC; } } else { slot = &buffer->slots[slot->next]; } memcpy(slot->data, data, data_size); } slot->timestamp = timestamp; slot->rtp_time = rtp_time; slot->marker = marker; slot->data_size = data_size; slot->refs = buffer->control->refs; slot->slot_seq = curr_seq + 1; slot->seq_delta = seq_delta + 1; buffer->control->write_pos = BPtoSlotPtr(buffer, slot); bp_dump(NULL, buffer); bp_unlock(buffer); return ERR_NOERROR; }