void BULKIO_dataShort_In_i::pushPacket(const PortTypes::ShortSequence& data, const BULKIO::PrecisionUTCTime& T, CORBA::Boolean EOS, const char* streamID)
{
    if (queueSem->getMaxValue() == 0) {
        return;
    }    
    BULKIO::StreamSRI tmpH = {1, 0.0, 1.0, 1, 0, 0.0, 0.0, 0, 0, streamID, false, 0};
    bool sriChanged = false;
    bool portBlocking = false;

    RH_SRIMap::iterator currH;
    {
        boost::mutex::scoped_lock lock(sriUpdateLock);

        currH = currentHs.find(std::string(streamID));
        if (currH != currentHs.end()) {
            tmpH = currH->second.first;
            sriChanged = currH->second.second;
            currentHs[streamID] = std::make_pair(currH->second.first, false);
        }
        portBlocking = blocking;
    }

    if(portBlocking) {
        queueSem->incr();
        boost::mutex::scoped_lock lock(dataBufferLock);
        stats.update(data.length(), workQueue.size()/queueSem->getMaxValue(), EOS, streamID, false);
        BULKIO_dataShort_In_i::dataTransfer *tmpIn = new BULKIO_dataShort_In_i::dataTransfer(data, T, EOS, streamID, tmpH, sriChanged, false);
        workQueue.push_back(tmpIn);
        dataAvailable.notify_all();
    } else {
        boost::mutex::scoped_lock lock(dataBufferLock);
        bool flushToReport = false;
        if (workQueue.size() == queueSem->getMaxValue()) { // reached maximum queue depth - flush the queue
            flushToReport = true;
            BULKIO_dataShort_In_i::dataTransfer *tmp;
            while (workQueue.size() != 0) {
                tmp = workQueue.front();
                workQueue.pop_front();
                delete tmp;
            }
        }
        stats.update(data.length(), workQueue.size()/queueSem->getMaxValue(), EOS, streamID, flushToReport);
        BULKIO_dataShort_In_i::dataTransfer *tmpIn = new BULKIO_dataShort_In_i::dataTransfer(data, T, EOS, streamID, tmpH, sriChanged, flushToReport);
        workQueue.push_back(tmpIn);
        dataAvailable.notify_all();
    }
}
Example #2
0
void soundOut_i::pushPacket(const PortTypes::ShortSequence &L, const PortTypes::ShortSequence &R)

{
//    std::cout << "Entering sound pushPacket with insert_idx = " << scp->insert_idx << " and read_idx = " << scp->read_idx << std::endl;

    omni_mutex_lock(scp->playback_mutex);

    for (unsigned int i = 0; i < L.length(); ++i) {

        // Check for buffer full cases and sleep until these is room for data
        //\todo This needs to be refactored
        bool bufferFull(false);
        do {
            bufferFull = false;
            if ((scp->insert_idx == (scp->length - 2)) &&
                    (scp->read_idx == 0)) {
                DEBUG(5, SoundCardPlayBack, "Sound playback overrun.");
                bufferFull = true;
            } else if ((scp->read_idx - scp->insert_idx) == 2) {
                DEBUG(5, SoundCardPlayBack, "Sound playback overrun.");
                bufferFull = true;
            }

            if (bufferFull)
                usleep(100);

        } while (bufferFull);

        // Room to insert a sample
        scp->playback_buffer[scp->insert_idx] = L[i];
        scp->playback_buffer[scp->insert_idx + 1] = R[i];
        scp->insert_idx += 2;
        if (scp->insert_idx >= scp->length)
            scp->insert_idx = 0;
    }

    int len = scp->insert_idx - scp->read_idx;
    if (((len > 0) && (len > (scp->length/4))) ||
            ((len < 0) && (scp->length - scp->insert_idx + scp->read_idx) > scp->length/4))
        scp->data_available.signal();

}