void TestParser::initTestCase() { mp_clientSocket = new MockSocket(this); mp_serverSocket = new MockSocket(this); connect(mp_clientSocket, SIGNAL(networkOut(QByteArray)), mp_serverSocket, SLOT(networkIn(QByteArray)), Qt::QueuedConnection); connect(mp_serverSocket, SIGNAL(networkOut(QByteArray)), mp_clientSocket, SLOT(networkIn(QByteArray)), Qt::QueuedConnection); mp_clientParser = new Parser(this, mp_clientSocket); mp_serverParser = new Parser(this, mp_serverSocket); m_clientStreamInitialized = m_serverStreamInitialized = 0; connect(mp_clientParser, SIGNAL(streamInitialized()), this, SLOT(clientStreamInitialized())); connect(mp_serverParser, SIGNAL(streamInitialized()), this, SLOT(serverStreamInitialized())); connect(mp_serverParser, SIGNAL(sigQueryServerInfo(QueryResult)), this, SLOT(serverinfoRequestRecieved(QueryResult))); mp_clientParser->initializeStream(); QCoreApplication::processEvents(); QCOMPARE(m_clientStreamInitialized, 1); QCOMPARE(m_serverStreamInitialized, 1); m_serverName = "Testovaci_server"; m_serverDescription = "Testovaci popis serveru - unicode: čeština podporovaná, esperanto ankaŭ"; }
void VorbisTranscode::processData( const QByteArray& data, bool ) { m_mutex.lock(); m_buffer.append( data ); m_mutex.unlock(); if ( !m_vorbisInit && m_buffer.size() >= OGG_BUFFER ) { ov_callbacks oggCallbacks; oggCallbacks.read_func = vorbis_read; oggCallbacks.close_func = vorbis_close; oggCallbacks.seek_func = vorbis_seek; oggCallbacks.tell_func = vorbis_tell; ov_open_callbacks( this, &m_vorbisFile, 0, 0, oggCallbacks ); m_vorbisInit = true; // Try to determine samplerate vorbis_info* vi = ov_info( &m_vorbisFile, -1 ); qDebug() << "vorbisTranscode( Samplerate:" << vi->rate << "Channels:" << vi->channels << ")"; emit streamInitialized( vi->rate, vi->channels ); } long result = 1; int currentSection = 0; while ( m_buffer.size() >= OGG_BUFFER && result > 0 ) { char tempBuffer[16384]; result = ov_read( &m_vorbisFile, tempBuffer, sizeof( tempBuffer ), 0, 2, 1, ¤tSection ); if ( result > 0 ) { for ( int i = 0; i < ( result / 2 ); i++ ) { m_outBuffer.append( tempBuffer[i * 2] ); m_outBuffer.append( tempBuffer[i * 2 + 1] ); } } } }
void MADTranscode::processData( const QByteArray &buffer, bool finish ) { static audio_dither left_dither, right_dither; int err = 0; m_encodedBuffer.append( buffer ); while ( err == 0 && ( m_encodedBuffer.count() >= MP3_BUFFER || finish ) ) { mad_stream_buffer( &stream, (const unsigned char*)m_encodedBuffer.data(), m_encodedBuffer.count() ); err = mad_frame_decode( &frame, &stream ); if ( stream.next_frame != 0 ) { size_t r = stream.next_frame - stream.buffer; m_encodedBuffer.remove( 0, r ); } if ( err ) { // if ( stream.error != MAD_ERROR_LOSTSYNC ) // qDebug() << "libmad error:" << mad_stream_errorstr( &stream ); if ( !MAD_RECOVERABLE( stream.error ) ) return; err = 0; } else { mad_timer_add( &timer, frame.header.duration ); mad_synth_frame( &synth, &frame ); if ( !m_mpegInitialised ) { long sampleRate = synth.pcm.samplerate; int channels = synth.pcm.channels; qDebug() << "madTranscode( Samplerate:" << sampleRate << "- Channels:" << channels << ")"; m_mpegInitialised = true; emit streamInitialized( sampleRate, channels > 0 ? channels : 2 ); } for ( int i = 0; i < synth.pcm.length; i++ ) { union PCMDATA { short i; unsigned char b[2]; } pcmData; pcmData.i = dither( synth.pcm.samples[0][i], &left_dither ); m_decodedBuffer.append( pcmData.b[0] ); m_decodedBuffer.append( pcmData.b[1] ); if ( synth.pcm.channels == 2 ) { pcmData.i = dither( synth.pcm.samples[1][i], &right_dither ); m_decodedBuffer.append( pcmData.b[0] ); m_decodedBuffer.append( pcmData.b[1] ); } } if ( timer.seconds != last_timer.seconds ) emit timeChanged( timer.seconds ); last_timer = timer; } } }