void PacketBuffer::onPut(const Packet &p) { if (m_mode == BufferTime) { m_value1 = qint64(p.pts*1000.0); // FIXME: what if no pts m_value0 = qint64(queue[0].pts*1000.0); // must compute here because it is reset to 0 if take from empty //if (isBuffering()) // qDebug("+buffering progress: %.1f%%=%.1f/%.1f~%.1fs %d-%d", bufferProgress()*100.0, (qreal)buffered()/1000.0, (qreal)bufferValue()/1000.0, qreal(bufferValue())*bufferMax()/1000.0, m_value1, m_value0); } else if (m_mode == BufferBytes) { m_value1 += p.data.size(); } else { m_value1++; } if (!m_buffering) return; if (checkEnough()) { m_buffering = false; } if (!m_buffering) { //buffering=>buffered m_history = ring<BufferInfo>(kAvgSize); return; } BufferInfo bi; bi.bytes = p.data.size(); if (!m_history.empty()) bi.bytes += m_history.back().bytes; bi.v = m_value1; bi.t = QDateTime::currentMSecsSinceEpoch(); m_history.push_back(bi); }
void PacketBuffer::onPut(const Packet &p) { if (m_mode == BufferTime) { m_value1 = int(p.pts*1000.0); // FIXME: what if no pts m_value0 = int(queue[0].pts*1000.0); // must compute here because it is reset to 0 if take from empty //if (isBuffering()) // qDebug("+buffering progress: %.1f%%=%.1f/%.1f~%.1fs %d-%d", bufferProgress()*100.0, (qreal)buffered()/1000.0, (qreal)bufferValue()/1000.0, qreal(bufferValue())*bufferMax()/1000.0, m_value1, m_value0); } else if (m_mode == BufferBytes) { m_value1 += p.data.size(); } else { m_value1++; } // TODO: compute buffer speed (and auto set the best bufferValue) if (!m_buffering) return; if (checkEnough()) { m_buffering = false; } }