void ATVCtrl::ATVC_matv_register_callback(void *cb_param, matv_autoscan_progress_chstate_cb auto_cb, matv_fullscan_progress_cb full_cb, matv_scanfinish_cb finish_cb, matv_audioformat_cb audfmt_cb, matv_shutdown_cb shutdown_cb) { Mutex::Autolock _l(mATVLock); SXLOGD("ATVC_matv_register_callback cb_param=%p", cb_param); SXLOGD("ATVC_matv_register_callback auto_cb=%p, full_cb=%p, finish_cb=%p, audfmt_cb=%p, shutdown_cb=%p", auto_cb, full_cb, finish_cb, audfmt_cb, shutdown_cb); gATVAutoScan_CB = auto_cb; gATVFullScan_CB = full_cb; gATVScanFinish_CB = finish_cb; gATVAudFormat_CB = audfmt_cb; gATVShutdown_CB = shutdown_cb; m_Object = cb_param; const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService(); if (atvcs == NULL) { SXLOGD("ATVC_matv_register_callback atvcs = 0 "); return; } return atvcs->ATVCS_matv_register_callback(); }
// DeathRecipient void ATVCtrl::ATVCtrlClient::binderDied(const wp<IBinder>& who) { SXLOGD("binderDied!"); Mutex::Autolock _l(ATVCtrl::mLock); ATVCtrl::spATVCtrlService.clear(); SXLOGD("ATVCtrlService server died!"); }
int32_t AudioVUnlockDL::SetDownlinkStartTime(int remainMs) { int timeOffset = remainMs < 15 ? 0 : (remainMs-15); if (!StateInputStart()) { return -1; } if (mGetTime == true && mInputStandby == false) { clock_gettime(CLOCK_MONOTONIC, &mNewDLtime); //mNewDLtime.tv_nsec = mNewDLtime.tv_nsec + (int64_t)mStreamOutLatency * 1000 * 1000 / 2 - 20000000; mNewDLtime.tv_nsec = mNewDLtime.tv_nsec + (int64_t)timeOffset * 1000 * 1000; if (mNewDLtime.tv_nsec >= 1000000000) { mNewDLtime.tv_sec += 1; mNewDLtime.tv_nsec -= 1000000000; } SXLOGD("[SetDownlinkStartTime] get DL time: mNewDLtime.tv_sec %d, mNewDLtime.tv_nsec %d, remainMs %d", mNewDLtime.tv_sec, mNewDLtime.tv_nsec, remainMs); mGetTime = false; if (mDLtime.tv_sec != 0) { mInRemaining = mRingBufIn.GetBufDataSz(); mOutRemaining = mRingBufOut.GetBufDataSz(); SXLOGD("[SetDownlinkStartTime] input buf never cleared IN remaining %d, Out remaining %d", mInRemaining, mOutRemaining); } } return 0; }
status_t AudioTrackCenter::addTrack(intptr_t trackId, uint32_t frameCount, uint32_t sampleRate, void* trackPtr, uint32_t afFrameCount, uint32_t afSampleRate) { Mutex::Autolock autoLock(mLock); SXLOGD("%s, trackId:%p, frameCount:%d, sampleRate:%d, trackPtr:%p",__FUNCTION__,(void*)trackId, frameCount, sampleRate, trackPtr); //if (init() != OK) return NO_INIT; mAfSampleRate = afSampleRate; mAfFrameCount = afFrameCount; SXLOGD("mAfSampleRate %d, sampleRate %d, AfFrameCount %d , mAfSampleRate %d, frameCount %d",mAfSampleRate, sampleRate, mAfFrameCount, mAfSampleRate, frameCount ); ssize_t index = mTrackList.indexOfKey(trackId); if (index >= 0) { SXLOGW("trackId: %p has existed!!!", (void*)trackId); //return INVALID_OPERATION; } List<TrackMaps>::iterator it = mTrackMaps.begin(); bool newTrack = true; int64_t framePlayed = 0; while(it != mTrackMaps.end()) { if ((*it).trackPtr == trackPtr ) { ssize_t index = mTrackList.indexOfKey((*it).trackId); if (index >= 0) { SXLOGD("%s, update track info from trackId:%p to trackId:%p", __FUNCTION__, (void*)(*it).trackId, (void*)trackId); struct TrackInfo &info = mTrackList.editValueFor((*it).trackId); framePlayed = info.framePlayed; mTrackList.removeItemsAt(index); TrackMaps *maps = &*it; maps->trackId = trackId; newTrack = false; } break; } ++it; } struct TrackInfo info; info.server = 0; info.frameCount = frameCount; info.framePlayed = framePlayed; info.afFrameCount = mAfSampleRate ? (sampleRate*mAfFrameCount)/mAfSampleRate : frameCount/AUDIOFLINGER_BUFFERCOUNT; info.sampleRate = sampleRate; info.middleServer = 0; info.active = true; info.ts = ALooper::GetNowUs(); mTrackList.add(trackId, info); if (newTrack) { struct TrackMaps maps; maps.trackId = trackId; maps.trackPtr = trackPtr; maps.sinkPtr = NULL; mTrackMaps.push_back(maps); } return OK; }
const sp<IATVCtrlService>& ATVCtrl::get_ATVCtrlService_FM() { SXLOGD("get_ATVCtrlService_FM()"); Mutex::Autolock _l(mLock); if (spATVCtrlService.get() == 0 || spATVCtrlClient_FM == NULL) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder; do { binder = sm->getService(String16("media.ATVCtrlService")); if (binder != 0) { break; } SXLOGW("ATVCtrlService not published, waiting..."); usleep(500000); // 0.5 s } while (true); if (spATVCtrlClient_FM == NULL) { spATVCtrlClient_FM = new ATVCtrlClient(); } else { /* if (gATVErrorCallback){ gATVErrorCallback(NO_ERROR); } */ SXLOGD(" spATVCtrlClient_FM exist "); } binder->linkToDeath(spATVCtrlClient_FM); spATVCtrlService = interface_cast<IATVCtrlService>(binder); spATVCtrlService->registerClient_FM(spATVCtrlClient_FM); SXLOGD(" ATVCtrlService is published, or new spATVCtrlClient_FM "); } if (spATVCtrlService == 0) { SXLOGE("no ATVCtrlService!?"); } return spATVCtrlService; }
void ATVCtrl::notify(int msg, int ext1, int ext2) { sp<MediaPlayerListener> listener = mFMListener; SXLOGD("ATVCtrl::notify"); // this prevents re-entrant calls into client code if (listener.get() != 0) { Mutex::Autolock _l(mNotifyLock); SXLOGD("NOTIFY APP +++,MSG %d", msg); listener->notify(msg, ext1, ext2, NULL); SXLOGD("NOTIFY APP ---,MSG %d", msg); } }
status_t MediaPlayer::getDuration_l(int *msec) { ALOGV("getDuration_l"); bool isValidState = (mCurrentState & (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_STOPPED | MEDIA_PLAYER_PLAYBACK_COMPLETE)); if (mPlayer != 0 && isValidState) { int durationMs; status_t ret = mPlayer->getDuration(&durationMs); #ifdef MTK_AOSP_ENHANCEMENT if(durationMs < 0){ SXLOGD("getDuration:%d < 0 ",durationMs); durationMs = 0; } #endif if (ret != OK) { // Do not enter error state just because no duration was available. durationMs = -1; ret = OK; } if (msec) { *msec = durationMs; } return ret; } ALOGE("Attempt to call getDuration without a valid mediaplayer"); return INVALID_OPERATION; }
int32_t AudioVUnlockRingBuf:: Write(void *buf, uint32_t datasz) { uint32_t leftsz = datasz; char *bufptr = (char *)buf; uint32_t loopCount = 0; int32_t writeAmount = 0; if (buf == NULL) { return -1; } while (leftsz > 0) { int32_t datawritten; datawritten = WriteAdvance(bufptr, leftsz); leftsz -= datawritten; bufptr += datawritten; writeAmount += datawritten; if (leftsz != 0) { // sleep 5ms usleep(1 * 1000); } loopCount ++; if (loopCount == 5 && leftsz != 0) { SXLOGD("[AudioVUnlockRingBuf:: Write] Drop Stream out data! data droped %d , write %d", leftsz, writeAmount); break; } } //SXLOGD("[AudioVUnlockRingBuf:: Write] loopCount %d, %d", loopCount, writeAmount); return writeAmount; }
uint32_t AudioVUnlockRingBuf:: WaitBufData(void) { int32_t leftdata = 0; pthread_mutex_lock(&mBufMutex); if ((mbuf.pWrite == mbuf.pRead)) { if (!mbuf.buffull) { leftdata = 0; } else { leftdata = mbuf.bufLen; } } else { leftdata = (mbuf.pWrite - mbuf.pRead); if (leftdata < 0) { leftdata = mbuf.bufLen + leftdata; } } /*change conditiont to leftdata <=2, since SRC won't work if leftdata <=2*/ //if(leftdata == 0) // wait till buffer filled if (leftdata <= 0) // wait till buffer has 92 ms data. { SXLOGD("[WaitBufData]Buffer empty , wait %d", leftdata); pthread_cond_wait(&mBuf_Cond, &mBufMutex); } pthread_mutex_unlock(&mBufMutex); return (uint32_t)leftdata; }
int32_t AudioVUnlockDL::SetUplinkStartTime(struct timespec uplinkStartTime) { mULtime = uplinkStartTime; SXLOGD("[SetUplinkStartTime] mULtime sec %ld nsec %ld", mULtime.tv_sec, mULtime.tv_nsec); return 0; }
int HeadSetDetect::readStateFromFile() { SXLOGV("readStateFromFile"); int fd = open(HEADSET_STATE_PATH, O_RDONLY, 0); if(fd < 0) { SXLOGD("Fail to open file %s", HEADSET_STATE_PATH); return -1; } char buf[1]; if (read(fd, buf, 1) == -1){ SXLOGD("Can't read %s", HEADSET_STATE_PATH); return -1; } close(fd); return buf[0]; }
int ATVCtrl::ATVC_matv_set_chtable(int ch, matv_ch_entry *entry) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService(); SXLOGD("ATVC_matv_set_chtable ch=%d, entry=%p", ch, entry); if (atvcs == 0) { return PERMISSION_DENIED; } int ret; void *ptr = (void *)entry; int len = sizeof(matv_ch_entry); SXLOGD("ATVC_matv_set_chtable len=%d", len); ret = atvcs->ATVCS_matv_set_chtable(ch, ptr, len); return ret; }
int32_t AudioVUnlockDL:: SetSRC( uint32_t outSR, /* Input, output sampling rate of the conversion */ uint32_t outChannel /* Input, output channel number of the conversion */ ) { if(outSR ==0 ||((outChannel!= 1) && (outChannel!=2)) ) { return -1; } SXLOGD("[SetSRC] mOutputSampleRate %d, mInputSampleRate %d, mInChannel %d, mOutChannel, %d ", (int)outSR, (int)mInputSampleRate, (int)mInChannel, (int)outChannel); pthread_mutex_lock(&mSRCMutex); // check if setting change. if (mOutputSampleRate != outSR || mOutChannel != outChannel) { mOutputSampleRate = outSR; mOutChannel = outChannel; if (mpSrcHdl != NULL) { mpSrcHdl->Close(); delete mpSrcHdl; mpSrcHdl = NULL; } } //set blisrc if (mpSrcHdl == NULL && mOutputSampleRate != 0 && mOutChannel != 0 && mInputSampleRate != 0 && mInChannel != 0) { mpSrcHdl = new MtkAudioSrc(mInputSampleRate, mInChannel, outSR, outChannel, SRC_IN_Q1P15_OUT_Q1P15); mpSrcHdl->Open(); } if (!mpSrcHdl) { SXLOGD("[SetSRC] create SRC handle fail"); pthread_mutex_unlock(&mSRCMutex); return -1; } pthread_mutex_unlock(&mSRCMutex); return 0; }
int32_t AudioVUnlockDL:: GetSRCInputParameter( uint32_t inSR, /* Input, input sampling rate of the conversion */ uint32_t inChannel , /* Input, input channel number of the conversion */ audio_format_t format ) { SXLOGD("[GetSRCInputParameter] mOutputSampleRate %d, mInputSampleRate %d, mInChannel %d, mOutChannel, %d format %d", (int)mOutputSampleRate, (int)inSR, (int)inChannel, (int)mOutChannel,format); if(format != AUDIO_FORMAT_PCM_16_BIT && format != AUDIO_FORMAT_PCM_32_BIT && format != AUDIO_FORMAT_PCM_8_24_BIT) { return -1; } mFormat = format; pthread_mutex_lock(&mSRCMutex); if (mInputSampleRate != inSR || mInChannel != inChannel) { mInputSampleRate = inSR; mInChannel = inChannel; if (mpSrcHdl != NULL) { mpSrcHdl->Close(); delete mpSrcHdl; mpSrcHdl = NULL; } } if (mpSrcHdl == NULL && mOutputSampleRate != 0 && mOutChannel != 0 && mInputSampleRate != 0 && mInChannel != 0) { mpSrcHdl = new MtkAudioSrc(mInputSampleRate, mInChannel, mOutputSampleRate, mOutChannel, SRC_IN_Q1P15_OUT_Q1P15); mpSrcHdl->Open(); } if (!mpSrcHdl) { SXLOGD("[GetSRCInputParameter] create SRC handle fail"); pthread_mutex_unlock(&mSRCMutex); return -1; } pthread_mutex_unlock(&mSRCMutex); return 0; }
int ATVCtrl::ATVC_fm_setListener(sp<MediaPlayerListener> listener) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService_FM(); SXLOGD("ATVC_fm_setListener"); if (atvcs == 0) { SXLOGD("ATVC_fm_setListener error"); return PERMISSION_DENIED; } else { SXLOGD("ATVC_fm_setListener success"); mFMListener = listener; return 1; } }
int ATVCtrl::ATVC_fm_scan(void/*struct fm_scan_parm*/ *s_parm) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService_FM(); struct fm_scan_parm *parm = (struct fm_scan_parm *)s_parm; SXLOGD("ATVC_fm_seek parm=%p", parm); if (atvcs == 0) { return PERMISSION_DENIED; } int ret; void *ptr = (void *)parm; int len = sizeof(struct fm_scan_parm); SXLOGD("ATVC_fm_seek len=%d", len); ret = atvcs->ATVCS_fm_scan(ptr, len); return ret; }
int32_t AudioVUnlockDL:: DoSRC(uint8_t *inbuf, uint32_t *datasz , uint8_t *outbuf, uint32_t *outlength) { uint8_t *inPtr = inbuf ; uint8_t *outPtr = outbuf; uint32_t outbuflen = *outlength; uint32_t dataProduce = 0; uint32_t count = 40; uint32_t dataconsumed = 0; pthread_mutex_lock(&mSRCMutex); if (mpSrcHdl == NULL) { SXLOGD("[DoSRC] SRC not created"); pthread_mutex_unlock(&mSRCMutex); return -1; } while (count) { SXLOGV("count %d ,in offset %d, datasz %d, out offset %d, outlength %d ", count,inPtr - inbuf, *datasz,outPtr - outbuf, *outlength); int consumed_this_time = *datasz; mpSrcHdl->Process((int16_t *)inPtr, datasz, (int16_t *)outPtr, outlength); consumed_this_time -= *datasz; dataconsumed += consumed_this_time; SXLOGV("after count %d , datasz %d, outlength%d ", count, *datasz,*outlength); dataProduce += *outlength; if (*datasz == 0 || *outlength == 0) { break; } else { inPtr = inbuf + dataconsumed; outPtr = outbuf + dataProduce; } // left space in output buffer *outlength = outbuflen - dataProduce; if (*outlength == 0) { break; } count --; } pthread_mutex_unlock(&mSRCMutex); /*if(count == 0 && *datasz !=0 && *outlength != 0) { SXLOGD("[DoSRC] do not finish SRC *datasz %d, &outlength %d", *datasz,*outlength ); //return -1; }*/ *outlength = dataProduce; return dataconsumed; }
void ATVCtrl::ATVC_matv_change_channel(int ch) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService(); SXLOGD("ATVC_matv_change_channel ch=%d", ch); if (atvcs == 0) { return; } atvcs->ATVCS_matv_change_channel(ch); }
void ATVCtrl::ATVC_matv_set_country(int country) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService(); SXLOGD("ATVC_matv_set_country country=%d", country); if (atvcs == 0) { return; } atvcs->ATVCS_matv_set_country(country); }
void ATVCtrl::ATVC_matv_set_tparam(int mode) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService(); SXLOGD("ATVC_matv_set_tparam mode=%d", mode); if (atvcs == 0) { return; } atvcs->ATVCS_matv_set_tparam(mode); }
void ATVCtrl::ATVC_matv_audio_set_format(int val) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService(); SXLOGD("ATVC_matv_audio_set_format val=%d", val); if (atvcs == 0) { return; } atvcs->ATVCS_matv_audio_set_format(val); }
void ATVCtrl::ATVCtrlClient::Shutdown_CB(int source) { Mutex::Autolock _l(mCallbackLock); SXLOGD("ATVCtrl::ATVCtrlClient::Shutdown_CB! m_Object=%p, format=%d", m_Object, source); /*if ( gATVShutdown_CB != NULL) gATVShutdown_CB((void *)m_Object,source);*/ sp<ATVListener> pListener = ATVCtrl::get_ATVListener(); if (pListener.get() != NULL) { pListener->shutdown_cb(source); } }
void ATVCtrl::ATVCtrlClient::AudioFmt_CB(int format) { Mutex::Autolock _l(mCallbackLock); SXLOGD("ATVCtrl::ATVCtrlClient::AudioFmt_CB! m_Object=%p, format=%d", m_Object, format); /*if ( gATVAudFormat_CB != NULL) gATVAudFormat_CB((void *)m_Object,format);*/ sp<ATVListener> pListener = ATVCtrl::get_ATVListener(); if (pListener.get() != NULL) { pListener->audioformat_cb(format); } }
void ATVCtrl::ATVCtrlClient::ScanFinish_CB(int chnum) { Mutex::Autolock _l(mCallbackLock); SXLOGD("ATVCtrl::ATVCtrlClient::ScanFinish_CB! m_Object=%p, chnum=%d", m_Object, chnum); /* if ( gATVScanFinish_CB != NULL) gATVScanFinish_CB((void *)m_Object,chnum);*/ sp<ATVListener> pListener = ATVCtrl::get_ATVListener(); if (pListener.get() != NULL) { pListener->scanfinish_cb(chnum); } }
// IATVCtrlClient ========================================================================== void ATVCtrl::ATVCtrlClient::AutoScan_CB(int precent, int ch, int chnum, void *ptr, int len) { Mutex::Autolock _l(mCallbackLock); SXLOGD("ATVCtrl::ATVCtrlClient::AutoScan_CB! m_Object=%p, precent=%d,ch=%d,chnum=%d,ptr=%p,len=%d", m_Object, precent, ch, chnum, ptr, len); /*if ( gATVAutoScan_CB != NULL) gATVAutoScan_CB((void *)m_Object,precent,ch,chnum, ptr, len);*/ sp<ATVListener> pListener = ATVCtrl::get_ATVListener(); if (pListener.get() != NULL) { pListener->autoscan_progress_chstate_cb(precent, ch, chnum, ptr, len); } }
void ATVCtrl::ATVC_matv_audio_stop() { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService(); SXLOGD("ATVC_matv_audio_stop"); if (atvcs == 0) { return; } atvcs->ATVCS_matv_audio_stop(); }
void ATVCtrl::ATVCtrlClient::FullScan_CB(int precent, int freq, int freq_start, int freq_end) { Mutex::Autolock _l(mCallbackLock); SXLOGD("ATVCtrl::ATVCtrlClient::FullScan_CB! m_Object=%p, precent=%d,freq=%d,freq_start=%d,freq_end=%d", m_Object, precent, freq, freq_start, freq_end); /*if ( gATVFullScan_CB != NULL) gATVFullScan_CB((void *)m_Object,precent,freq,freq_start,freq_end);*/ sp<ATVListener> pListener = ATVCtrl::get_ATVListener(); if (pListener.get() != NULL) { pListener->fullscan_progress_cb(precent, freq, freq_start, freq_end); } }
int32_t AudioVUnlockDL::GetFirstDLTime() { if (!StateInputStart()) { //SXLOGV("[WriteStreamOutToRing] AudioVUnlockDL is not initialized"); return -1; } if (mGetTime == true) { clock_gettime(CLOCK_MONOTONIC, &mNewDLtime); SXLOGD("[GetFirstDLTime] DL time %d, %d", mNewDLtime.tv_sec, mNewDLtime.tv_nsec); mGetTime = false; if (mDLtime.tv_sec != 0) { mInRemaining = mRingBufIn.GetBufDataSz(); mOutRemaining = mRingBufOut.GetBufDataSz(); SXLOGD("[GetFirstDLTime] input buf never cleared IN remaining %d, Out remaining %d", mInRemaining, mOutRemaining); } } return 0; }
int ATVCtrl::ATVC_fm_isRDSsupport(int *val) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService_FM(); SXLOGD("ATVC_fm_isRDSsupport"); if (atvcs == 0) { return PERMISSION_DENIED; } *val = false; return NO_ERROR; }
int ATVCtrl::ATVC_fm_isFMPowerUp(int *val) { Mutex::Autolock _l(mATVLock); const sp<IATVCtrlService>& atvcs = ATVCtrl::get_ATVCtrlService_FM(); SXLOGD("ATVC_fm_isFMPowerUp"); if (atvcs == 0) { return PERMISSION_DENIED; } *val = atvcs->ATVCS_fm_isFMPowerUp(); return NO_ERROR; }