int Zprintf0(int force, char *buf) { int l; int n; int ret; int msgret; char *str; char junk; str = buf; l = sipx_min(ABSOLUTE_MAX_LOG_MSG_LEN, strlen(buf)); ret = l; if (0 == MpMisc.LogQ) { ret = force ? fwrite(str, 1, ret, stderr) : 0; return ret; } if (force || logging) { if ((ret > MpMisc.logMsgSize) && !intContext()) { taskLock(); } while (l > 0) { n = sipx_min(l, MpMisc.logMsgSize); msgret = msgQSend(MpMisc.LogQ, buf, n, VX_NO_WAIT, MSG_PRI_NORMAL); if (ERROR == msgret) { // int r2 = msgQReceive(MpMisc.LogQ, &junk, 1, VX_NO_WAIT); // osPrintf("discard message; r1=%d, r2=%d, q=0x%X: '%s'\n", // msgret, r2, MpMisc.LogQ, buf); numDiscarded++; msgret = msgQSend(MpMisc.LogQ, buf, n, VX_NO_WAIT, MSG_PRI_NORMAL); } if ((ERROR == msgret) && force) { fwrite(str, 1, ret, stderr); l = 0; } else { l -= n; buf += n; } } if ((ret > MpMisc.logMsgSize) && !intContext()) { taskUnlock(); } } else { ret = 0; } return ret; }
OsStatus MpodBufferRecorder::pushFrame(unsigned int numSamples, const MpAudioSample* samples, MpFrameTime frameTime) { if (!isEnabled()) { return OS_INVALID_STATE; } if (mBufferEnd > mBufferLength) { return OS_FAILED; } unsigned samplesToCopy = sipx_min(numSamples, mBufferLength-mBufferEnd); if (samples != NULL) { memcpy(mpBuffer+mBufferEnd, samples, sizeof(MpAudioSample)*samplesToCopy); } else { memset(mpBuffer+mBufferEnd, 0, sizeof(MpAudioSample)*samplesToCopy); } mBufferEnd += samplesToCopy; return OS_SUCCESS; }
UtlBoolean Url::getFieldParameters(int iMaxReturn, UtlString* pNames, UtlString *pValues, int& iActualReturn) { if(!(mpFieldParameters || parseFieldParameters())) { iActualReturn = 0; } // If the pValue is null, return false and set the actual return to the actual // number of items. else if (pNames == NULL || pValues == NULL) { iActualReturn = mpFieldParameters->entries() ; return FALSE ; } else { iActualReturn = sipx_min(iMaxReturn, ((int)(mpFieldParameters->entries()))) ; for (int i=0; i<iActualReturn; i++) { NameValuePair *pair = (NameValuePair*) mpFieldParameters->at(i) ; pNames[i] = *pair; pValues[i] = pair->getValue() ; } } return (iActualReturn > 0) ; }
void MpodAndroid::audioCallback(int event, void* user, void *info) { //LOGV("MpodAndroid::audioCallback(event=%d)\n", event); RTL_BLOCK("MpodAndroid::audioCallback"); bool lSignal = false; if (event != MpAndroidAudioTrack::EVENT_MORE_DATA) { LOGV("MpodAndroid::audioCallback(event=%d)\n", event); return; } MpAndroidAudioTrack::Buffer *buffer = static_cast<MpAndroidAudioTrack::Buffer *>(info); MpodAndroid *pDriver = static_cast<MpodAndroid *>(user); // Start accessing non-atomic member variables AutoMutex autoLock(pDriver->mLock); int samplesToCopy = sipx_min(buffer->frameCount, pDriver->mSamplesPerFrame-pDriver->mSampleBufferIndex); #ifdef ENABLE_FRAME_TIME_LOGGING LOGV("MpodAndroid::audioCallback() buffer=%p samples=%d size=%d toCopy=%d\n", buffer->i16, buffer->frameCount, buffer->size, samplesToCopy); #endif RTL_EVENT("MpodAndroid::audioCallback_bufsize", samplesToCopy); // Copy data to buffer memcpy(buffer->i16, pDriver->mpSampleBuffer+pDriver->mSampleBufferIndex, samplesToCopy*sizeof(short)); buffer->frameCount = samplesToCopy; buffer->size = samplesToCopy*sizeof(short); pDriver->mSampleBufferIndex += samplesToCopy; #ifdef ENABLE_FILE_LOGGING fwrite(buffer->i16, 1, buffer->frameCount*sizeof(short), sgOutFile); #endif // ENABLE_FILE_LOGGING if (pDriver->mSampleBufferIndex >= pDriver->mSamplesPerFrame) { RTL_BLOCK("MpodAndroid::audioCallback_tick"); if(pDriver->mSampleBufferIndex > pDriver->mSamplesPerFrame) { LOGE("MpodAndroid::audioCallback() sample index (%d) > samples/frame (%d)\n", (int)pDriver->mSampleBufferIndex, (int)pDriver->mSamplesPerFrame); } // Return index to the beginning pDriver->mSampleBufferIndex = 0; // Fire callback. It will call our pushFrame() in turn. #ifdef ENABLE_FRAME_TIME_LOGGING LOGV("MpodAndroid::audioCallback() signal ticker, time %"PRIi64"ns\n", systemTime(SYSTEM_TIME_REALTIME)); #endif pDriver->mpTickerNotification->signal(pDriver->mSamplesPerFrame); // Update frame time. pDriver->mCurFrameTime += pDriver->mSamplesPerFrame; } // Step forward state switch (pDriver->mState) { case DRIVER_STARTING: pDriver->mState = DRIVER_PLAYING; lSignal = true; break; case DRIVER_STOPPING: // pDriver->mState = DRIVER_STOPPED; // break; case DRIVER_STOPPED: LOGV("MpodAndroid::audioCallback() stopping Track\n"); pDriver->mpAudioTrack->stop(); LOGV("MpodAndroid::audioCallback() stopped Track\n"); buffer->size = 0; pDriver->mState = DRIVER_IDLE; lSignal = true; break; default: break; } if (lSignal) { LOGV("MpodAndroid::audioCallback signalling\n"); pDriver->mWaitCbkCond.signal(); LOGV("MpodAndroid::audioCallback signalled\n"); } }
void MpidAndroid::audioCallback(int event, void* user, void *info) { bool lSignal = false; if (event != MpAndroidAudioRecord::EVENT_MORE_DATA) { RTL_BLOCK("MpidAndroid::audioCallback_nondata"); LOGV("MpidAndroid::audioCallback(event=%d)\n", event); return; } RTL_BLOCK("MpidAndroid::audioCallback"); #ifdef ENABLE_FRAME_TIME_LOGGING LOGV("MpidAndroid::audioCallback() time %"PRIi64"ns\n", systemTime(SYSTEM_TIME_REALTIME)); #endif MpAndroidAudioRecord::Buffer *buffer = static_cast<MpAndroidAudioRecord::Buffer *>(info); MpidAndroid *pDriver = static_cast<MpidAndroid *>(user); #ifdef ENABLE_FILE_LOGGING fwrite(buffer->i16, 1, buffer->frameCount*sizeof(short), sgOutFile); #endif // ENABLE_FILE_LOGGING // Start accessing non-atomic member variables AutoMutex autoLock(pDriver->mLock); #ifdef ENABLE_FRAME_TIME_LOGGING LOGV("MpidAndroid::audioCallback() frameCount=%d size=%d state=%d\n", buffer->frameCount, buffer->size, pDriver->mState); #endif // Only process if we're enabled.. if(pDriver->mIsEnabled) { if (buffer->frameCount + pDriver->mBufInternalSamples < pDriver->mSamplesPerFrameInternal) { #ifdef ENABLE_FRAME_TIME_LOGGING LOGV("frameCount=%d mBufInternalSamples=%d (sum=%d) mSamplesPerFrameInternal=%d", buffer->frameCount, pDriver->mBufInternalSamples, buffer->frameCount + pDriver->mBufInternalSamples, pDriver->mSamplesPerFrameInternal); #endif memcpy(pDriver->mpBufInternal+pDriver->mBufInternalSamples, buffer->i16, buffer->frameCount*sizeof(short)); pDriver->mBufInternalSamples += buffer->frameCount; } else { // Copy samples to the temp buffer if needed. MpAudioSample *origSamples; int origSamplesConsumed; if (pDriver->mBufInternalSamples > 0) { origSamplesConsumed = sipx_min(pDriver->mSamplesPerFrameInternal-pDriver->mBufInternalSamples, buffer->frameCount); memcpy(pDriver->mpBufInternal+pDriver->mBufInternalSamples, buffer->i16, origSamplesConsumed*sizeof(short)); pDriver->mBufInternalSamples += origSamplesConsumed; origSamples = pDriver->mpBufInternal; } else { origSamples = buffer->i16; origSamplesConsumed = pDriver->mSamplesPerFrameInternal; } // Resample is needed. MpAudioSample *pushSamples = origSamples; if (pDriver->mpResampler != NULL) { uint32_t samplesProcessed; uint32_t samplesWritten; LOGV("origSamples: %d mSamplesPerFrameInternal: %d samplesProcessed: %d mpResampleBuf: %d mSamplesPerFrame: %d samplesWritten: %d\n", pDriver->mBufInternalSamples, pDriver->mSamplesPerFrameInternal, samplesProcessed, pDriver->mpResampleBuf, pDriver->mSamplesPerFrame, samplesWritten); LOGV("pDriver->mpResampler->getInputRate(): %d pDriver->mpResampler->getOutputRate(): %d\n", pDriver->mpResampler->getInputRate(), pDriver->mpResampler->getOutputRate()); OsStatus status = pDriver->mpResampler->resample(0, pDriver->mpBufInternal, pDriver->mSamplesPerFrameInternal, samplesProcessed, pDriver->mpResampleBuf, pDriver->mSamplesPerFrame, samplesWritten); assert(status == OS_SUCCESS); if(pDriver->mSamplesPerFrameInternal != samplesProcessed || pDriver->mSamplesPerFrame != samplesWritten) { LOGE("mSamplesPerFrameInternal: %d samplesProcessed: %d mSamplesPerFrame: %d samplesWritten: %d\n", pDriver->mSamplesPerFrameInternal, samplesProcessed, pDriver->mSamplesPerFrame, samplesWritten); printf("mSamplesPerFrameInternal: %d samplesProcessed: %d mSamplesPerFrame: %d samplesWritten: %d\n", pDriver->mSamplesPerFrameInternal, samplesProcessed, pDriver->mSamplesPerFrame, samplesWritten); } assert(pDriver->mSamplesPerFrameInternal == samplesProcessed && pDriver->mSamplesPerFrame == samplesWritten); pushSamples = pDriver->mpResampleBuf; } pDriver->mpInputDeviceManager->pushFrame(pDriver->mDeviceId, pDriver->mSamplesPerFrame, pushSamples, pDriver->mCurrentFrameTime); // Copy remaining samples to temp buffer if anything left. pDriver->mBufInternalSamples = sipx_min(buffer->frameCount-origSamplesConsumed, pDriver->mSamplesPerFrameInternal); if (pDriver->mBufInternalSamples > 0) { memcpy(pDriver->mpBufInternal, buffer->i16+origSamplesConsumed, pDriver->mBufInternalSamples*sizeof(short)); if (buffer->frameCount-origSamplesConsumed >= pDriver->mSamplesPerFrameInternal) { LOGW("TOO BIG FRAMES FROM MIC: %d", buffer->frameCount); } } // Ok, we have received and pushed a frame to the manager, // Now we advance the frame time. pDriver->mCurrentFrameTime += (pDriver->mSamplesPerFrame*1000)/pDriver->mSamplesPerSec; } } switch (pDriver->mState) { case DRIVER_STARTING: pDriver->mState = DRIVER_RECORDING; lSignal = true; break; case DRIVER_STOPPING: // pDriver->mState = DRIVER_STOPPED; // break; case DRIVER_STOPPED: pDriver->mpAudioRecord->stop(); buffer->size = 0; pDriver->mState = DRIVER_IDLE; lSignal = true; break; default: break; } if (lSignal) { LOGV("MpidAndroid::audioCallback() signaling condition state=%d\n", pDriver->mState); pDriver->mWaitCbkCond.signal(); } // LOGV("MpidAndroid::audioCallback() done.\n"); }