Exemplo n.º 1
0
    void
    RTMPSession::write(uint8_t* data, size_t size, std::chrono::steady_clock::time_point packetTime, bool isKeyframe)
    {
        if(size > 0) {
            std::shared_ptr<Buffer> buf = std::make_shared<Buffer>(size);
            buf->put(data, size);
            
            m_throughputSession.addBufferSizeSample(m_bufferSize);
            
            increaseBuffer(size);
            if(isKeyframe) {
                m_sentKeyframe = packetTime;
            }
            if(m_bufferSize > kMaxSendbufferSize && isKeyframe) {
                m_clearing = true;
            }
            m_networkQueue.enqueue([=]() {
                size_t tosend = size;
                uint8_t* p ;
                buf->read(&p, size);
                
                while(tosend > 0 && !this->m_ending && (!this->m_clearing || this->m_sentKeyframe == packetTime)) {
                    this->m_clearing = false;
                    size_t sent = m_streamSession->write(p, tosend);
                    p += sent;
                    tosend -= sent;
                    this->m_throughputSession.addSentBytesSample(sent);
                    if( sent == 0 ) {
#ifdef __APPLE__
                        dispatch_semaphore_wait(m_networkWaitSemaphore, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)));
#else
                        std::unique_lock<std::mutex> l(m_networkMutex);
                        m_networkCond.wait_until(l, std::chrono::steady_clock::now() + std::chrono::milliseconds(1000));
                        
                        l.unlock();
#endif
                    }
                }
                this->increaseBuffer(-int64_t(size));
            });
        }
        
    }
Exemplo n.º 2
0
const QCString &KNFile::readLineWnewLine()
{
    filePos = at();
    readBytes = QFile::readLine(dataPtr, buffer.size() - 1);
    if(readBytes != -1)
    {
        while((dataPtr[readBytes - 1] != '\n') && (static_cast<uint>(readBytes + 2) == buffer.size()))  // don't get tricked by files without newline
        {
            at(filePos);
            if(!increaseBuffer() ||
                    (readBytes = QFile::readLine(dataPtr, buffer.size() - 1)) == -1)
            {
                dataPtr[0] = '\0';
                break;
            }
        }
    }
    else dataPtr[0] = '\0';

    return buffer;
}