long AudioStream::DataCallback(void* aBuffer, long aFrames) { MonitorAutoLock mon(mMonitor); MOZ_ASSERT(mState != SHUTDOWN, "No data callback after shutdown"); auto writer = AudioBufferWriter( reinterpret_cast<AudioDataValue*>(aBuffer), mOutChannels, aFrames); // FIXME: cubeb_pulse sometimes calls us before cubeb_stream_start() is called. // We don't want to consume audio data until Start() is called by the client. if (mState == INITIALIZED) { NS_WARNING("data callback fires before cubeb_stream_start() is called"); mAudioClock.UpdateFrameHistory(0, aFrames); return writer.WriteZeros(aFrames); } // NOTE: wasapi (others?) can call us back *after* stop()/Shutdown() (mState == SHUTDOWN) // Bug 996162 // callback tells us cubeb succeeded initializing if (mState == STARTED) { mState = RUNNING; } if (mInRate == mOutRate) { GetUnprocessed(writer); } else { GetTimeStretched(writer); } // Always send audible frames first, and silent frames later. // Otherwise it will break the assumption of FrameHistory. if (!mDataSource.Ended()) { mAudioClock.UpdateFrameHistory(aFrames - writer.Available(), writer.Available()); if (writer.Available() > 0) { LOGW("lost %d frames", writer.Available()); writer.WriteZeros(writer.Available()); } } else { // No more new data in the data source. Don't send silent frames so the // cubeb stream can start draining. mAudioClock.UpdateFrameHistory(aFrames - writer.Available(), 0); } WriteDumpFile(mDumpFile, this, aFrames, aBuffer); return aFrames - writer.Available(); }
long AudioStream::DataCallback(void* aBuffer, long aFrames) { MonitorAutoLock mon(mMonitor); MOZ_ASSERT(mState != SHUTDOWN, "No data callback after shutdown"); auto writer = AudioBufferWriter( reinterpret_cast<AudioDataValue*>(aBuffer), mOutChannels, aFrames); if (mPrefillQuirk) { // Don't consume audio data until Start() is called. // Expected only with cubeb winmm backend. if (mState == INITIALIZED) { NS_WARNING("data callback fires before cubeb_stream_start() is called"); mAudioClock.UpdateFrameHistory(0, aFrames); return writer.WriteZeros(aFrames); } } else { MOZ_ASSERT(mState != INITIALIZED); } // NOTE: wasapi (others?) can call us back *after* stop()/Shutdown() (mState == SHUTDOWN) // Bug 996162 if (mAudioClock.GetInputRate() == mAudioClock.GetOutputRate()) { GetUnprocessed(writer); } else { GetTimeStretched(writer); } // Always send audible frames first, and silent frames later. // Otherwise it will break the assumption of FrameHistory. if (!mDataSource.Ended()) { mAudioClock.UpdateFrameHistory(aFrames - writer.Available(), writer.Available()); if (writer.Available() > 0) { LOGW("lost %d frames", writer.Available()); writer.WriteZeros(writer.Available()); } } else { // No more new data in the data source. Don't send silent frames so the // cubeb stream can start draining. mAudioClock.UpdateFrameHistory(aFrames - writer.Available(), 0); } WriteDumpFile(mDumpFile, this, aFrames, aBuffer); return aFrames - writer.Available(); }
/********************************************************************** * TABMAPHeaderBlock::CommitToFile() * * Commit the current state of the binary block to the file to which * it has been previously attached. * * This method makes sure all values are properly set in the header * block buffer and then calls TABRawBinBlock::CommitToFile() to do * the actual writing to disk. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/ int TABMAPHeaderBlock::CommitToFile() { int i, nStatus = 0; if ( m_pabyBuf == NULL || m_nBlockSize != HDR_DATA_BLOCK_SIZE ) { CPLError(CE_Failure, CPLE_AssertionFailed, "TABRawBinBlock::CommitToFile(): Block has not been initialized yet!"); return -1; } /*----------------------------------------------------------------- * Reconstruct header to make sure it is in sync with members variables. *----------------------------------------------------------------*/ GotoByteInBlock(0x000); WriteBytes(HDR_OBJ_LEN_ARRAY_SIZE, gabyObjLenArray); m_nMaxObjLenArrayId = HDR_OBJ_LEN_ARRAY_SIZE-1; GotoByteInBlock(0x100); WriteInt32(HDR_MAGIC_COOKIE); WriteInt16(m_nMAPVersionNumber); WriteInt16(HDR_DATA_BLOCK_SIZE); WriteDouble(m_dCoordsys2DistUnits); WriteInt32(m_nXMin); WriteInt32(m_nYMin); WriteInt32(m_nXMax); WriteInt32(m_nYMax); WriteZeros(16); // ??? WriteInt32(m_nFirstIndexBlock); WriteInt32(m_nFirstGarbageBlock); WriteInt32(m_nFirstToolBlock); WriteInt32(m_numPointObjects); WriteInt32(m_numLineObjects); WriteInt32(m_numRegionObjects); WriteInt32(m_numTextObjects); WriteInt32(m_nMaxCoordBufSize); WriteZeros(14); // ??? WriteByte(m_nDistUnitsCode); WriteByte(m_nMaxSpIndexDepth); WriteByte(m_nCoordPrecision); WriteByte(m_nCoordOriginQuadrant); WriteByte(m_nReflectXAxisCoord); WriteByte(m_nMaxObjLenArrayId); // See gabyObjLenArray[] WriteByte(m_numPenDefs); WriteByte(m_numBrushDefs); WriteByte(m_numSymbolDefs); WriteByte(m_numFontDefs); WriteInt16(m_numMapToolBlocks); WriteZeros(3); // ??? WriteByte(m_sProj.nProjId); WriteByte(m_sProj.nEllipsoidId); WriteByte(m_sProj.nUnitsId); WriteDouble(m_XScale); WriteDouble(m_YScale); WriteDouble(m_XDispl); WriteDouble(m_YDispl); for(i=0; i<6; i++) WriteDouble(m_sProj.adProjParams[i]); WriteDouble(m_sProj.dDatumShiftX); WriteDouble(m_sProj.dDatumShiftY); WriteDouble(m_sProj.dDatumShiftZ); for(i=0; i<5; i++) WriteDouble(m_sProj.adDatumParams[i]); /*----------------------------------------------------------------- * OK, call the base class to write the block to disk. *----------------------------------------------------------------*/ if (nStatus == 0) nStatus = TABRawBinBlock::CommitToFile(); return nStatus; }