Пример #1
0
qint64 QAudioInterfaceBuffer::bytesAvailable()
{
    m_mutex.lock();
    int count = writeCounter() - readCounter();
    m_mutex.unlock();
    if (count >= 0)
        return count;
    return 0;
}
Пример #2
0
/*------------------------------------------------------------------------------*/
void GRConnection::sendGRPacket(wxUint32 command, wxUint32 payloadLength, wxUint8 *payload)
{
	GR_PACKET_HEADER header;
	wxUint32 len = 0;
	wxUint8 *packet;
	wxUint8 counterByte;
	bool writeCounterByte = false;

	header.command = htonl(command);

	writeCounterByte = writeCounter(command);
	
	if(writeCounterByte == false) header.payloadLength = htonl(payloadLength);
	else header.payloadLength = htonl(payloadLength+1);	
	

	//Check if we should append packet counter byte
	if(writeCounterByte == false) len = sizeof(header)+payloadLength;
	else len = sizeof(header)+payloadLength + sizeof(wxUint8);


	packet = new wxUint8[len];

	memcpy(packet, &header, sizeof(header));
	memcpy(packet+sizeof(header), payload, payloadLength);

	//append packet counter byte
	if(writeCounterByte == true) 
	{
		counterByte = getPacketCounterByte(command, payloadLength);
		memcpy(packet+sizeof(header)+payloadLength, (wxUint8*)&counterByte, sizeof(wxUint8));
	}
		
	GRLogger::getInstance()->log(GRLogger::LOG_INFO, wxT("Sent Data"));
	GRLogger::getInstance()->logData(packet, len);

	if(socket->IsConnected())
		socket->Write(packet, len);

	delete[] packet;
}
Пример #3
0
qint64 QAudioInterfaceBuffer::writeData(const char *data, qint64 len)
{
    if (m_size <= 0 || len <= 0) {
        return 0;
    }

    m_mutex.lock();
    int count = len;
    const char *pdata = data;
    int increment = 0;

#if QT_DEBUG_SOUNDBACKEND
    qDebug() << QThread::currentThreadId() << (quint64)m_elapsed.elapsed() <<
                "wr:" << len << "+" << (writeCounter() - readCounter());
#endif
    while (count > 0) {
        bool wrap = (m_writePos + count) >= m_size;
        if (wrap) {
            int block = m_size - m_writePos;
            memcpy(m_buffer + m_writePos, pdata, block);
            increment = block;
            count -= block;
            pdata += block;
            m_writeWrap++;
            m_writePos = 0;
        } else {
            memcpy(m_buffer + m_writePos, pdata, count);
            increment = count;
            count -= count;
            pdata += count;
            m_writePos = (m_writePos + increment) % m_size;
        }
    }

    m_mutex.unlock();
    return len;
}
int incrementFile()
{
	return writeCounter(addOneTotInt(readCounter()));
}