status_t AudioALSALoopbackController::open(const audio_devices_t output_devices, const audio_devices_t input_device)
{
    ALOGD("+%s(), output_devices = 0x%x, input_device = 0x%x", __FUNCTION__, output_devices, input_device);
    AudioAutoTimeoutLock _l(mLock);
    AudioAutoTimeoutLock _l2(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock());

    // DL loopback setting
    memset(&mConfig, 0, sizeof(mConfig));
    mConfig.channels = 2;
    mConfig.rate = 48000;
    mConfig.period_size = 1024;
    mConfig.period_count = 2;
    mConfig.format = PCM_FORMAT_S16_LE;
    mConfig.start_threshold = 0;
    mConfig.stop_threshold = 0;
    mConfig.silence_threshold = 0;
    ALOGD("+%s(), mConfig.rate=%d", __FUNCTION__,mConfig.rate);

    ASSERT(mPcmUL == NULL && mPcmDL == NULL);
    mPcmUL = pcm_open(0, 4, PCM_IN, &mConfig);
    mPcmDL = pcm_open(0, 4, PCM_OUT, &mConfig);
    ASSERT(mPcmUL != NULL && mPcmDL != NULL);
    ALOGV("%s(), mPcmUL = %p, mPcmDL = %p", __FUNCTION__, mPcmUL, mPcmDL);

    pcm_start(mPcmUL);
    pcm_start(mPcmDL);


    mHardwareResourceManager->startInputDevice(input_device);
    mHardwareResourceManager->startOutputDevice(output_devices, mConfig.rate);


    ALOGD("-%s()", __FUNCTION__);
    return NO_ERROR;
}
void AudioHardwareOutput::standbyStatusUpdate(bool isInStandby, bool isMCStream) {

    Mutex::Autolock _l1(mStreamLock);
    bool hdmiAllowed;
    {
        Mutex::Autolock _l2(mSettingsLock);
        hdmiAllowed = mSettings.hdmi.allowed;
    }
    // If there is no HDMI, do nothing
    if (hdmiAllowed && mHDMIConnected) {
        // If a multi-channel stream goes to standy state, we must switch
        // to stereo stream. If MC comes out of standby, we must switch
        // back to MC. No special processing needed for main stream.
        // AudioStreamOut class handles that correctly
        if (isMCStream) {
            uint32_t mcMask;
            uint32_t mainMask;
            if (isInStandby) {
                mainMask = HDMIAudioOutput::classDevMask();
                mcMask = 0;
            } else {
                mainMask = 0;
                mcMask = HDMIAudioOutput::classDevMask();
            }

            if (NULL != mMainOutput)
                mMainOutput->setTgtDevices(mainMask);

            if (NULL != mMCOutput)
                mMCOutput->setTgtDevices(mcMask);
        }
    }
}
status_t AudioHardwareOutput::obtainOutput(const AudioStreamOut& tgtStream,
                                     uint32_t devMask,
                                     sp<AudioOutput>* newOutput) {
    Mutex::Autolock _l1(mOutputLock);

    // Sanity check the device mask passed to us.  There should exactly one bit
    // set, no less, no more.
    if (popcount(devMask) != 1) {
        ALOGW("bad device mask in obtainOutput, %08x", devMask);
        return INVALID_OPERATION;
    }

    // Start by checking to see if the requested output is currently busy.
    AudioOutputList::iterator I;
    for (I = mPhysOutputs.begin(); I != mPhysOutputs.end(); ++I)
        if (devMask & (*I)->devMask())
            return OK; // Yup; its busy.

    // Looks like we don't currently have an output of the requested type.
    // Figure out which type is being requested and try to construct one.
    OutputSettings* S = NULL;
    if (devMask & HDMIAudioOutput::classDevMask()) {
        *newOutput = new HDMIAudioOutput();
        S = &mSettings.hdmi;
    }
    else {
        ALOGW("%s stream out requested output of unknown type %08x",
                tgtStream.getName(), devMask);
        return BAD_VALUE;
    }

    if (*newOutput == NULL)
        return NO_MEMORY;

    status_t res = (*newOutput)->setupForStream(tgtStream);
    if (res != OK) {
        ALOGE("%s setupForStream() returned %d",
              tgtStream.getName(), res);
        *newOutput = NULL;
    } else {
        ALOGI("%s stream out adding %s output.",
                tgtStream.getName(), (*newOutput)->getOutputName());
        mPhysOutputs.push_back(*newOutput);

        {  // Apply current settings
            Mutex::Autolock _l2(mSettingsLock);
            (*newOutput)->setVolume(mSettings.masterVolume);
            (*newOutput)->setMute(mSettings.masterMute);
            (*newOutput)->setExternalDelay_uSec(S->delayCompUsec);
            (*newOutput)->setOutputIsFixed(S->isFixed);
            (*newOutput)->setFixedOutputLevel(S->fixedLvl);
        }
    }

    return res;
}
status_t AudioHardwareOutput::setMasterMute(bool muted)
{
    Mutex::Autolock _l1(mOutputLock);
    Mutex::Autolock _l2(mSettingsLock);

    mSettings.masterMute = muted;

    AudioOutputList::iterator I;
    for (I = mPhysOutputs.begin(); I != mPhysOutputs.end(); ++I)
        (*I)->setMute(mSettings.masterMute);

    return NO_ERROR;
}
status_t AudioHardwareOutput::setMasterVolume(float volume)
{
    Mutex::Autolock _l1(mOutputLock);
    Mutex::Autolock _l2(mSettingsLock);

    mSettings.masterVolume = volume;

    AudioOutputList::iterator I;
    for (I = mPhysOutputs.begin(); I != mPhysOutputs.end(); ++I)
        (*I)->setVolume(mSettings.masterVolume);

    return NO_ERROR;
}
CString GetRemDsc(CWPReminder& rem,BOOL bAddDate=FALSE)
{
	CString sDsc=TrimMessage(rem.szText,30,1);
	if(sDsc==""){
		sDsc=_l2("No description");
	}
	COleDateTime tm(rem.EventTime);
	COleDateTime dtNow=COleDateTime::GetCurrentTime();
	if(bAddDate && (tm.GetDay()!=dtNow.GetDay() || tm.GetMonth()!=dtNow.GetMonth() || tm.GetYear()!=dtNow.GetYear())){
		return Format("%s %s %s",DateFormat(tm,TRUE),TimeFormat(tm),sDsc);
	}else{
		return Format("%s %s",TimeFormat(tm),sDsc);
	}
}
status_t AudioALSACaptureDataProviderTDM::close()
{
    ALOGD("%s()", __FUNCTION__);
    ASSERT(mClientLock.tryLock() != 0); // lock by base class detach

    mEnable = false;
    AudioAutoTimeoutLock _l(mEnableLock);
    AudioAutoTimeoutLock _l2(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock());

    ClosePCMDump();

    pcm_stop(mPcm);
    pcm_close(mPcm);
    mPcm = NULL;

    return NO_ERROR;
}
Exemple #8
0
status_t AudioALSACaptureDataProviderEchoRefExt::close()
{
    ALOGD("%s()", __FUNCTION__);
    ASSERT(mClientLock.tryLock() != 0); // lock by base class detach

    mEnable = false;
    AudioAutoTimeoutLock _l(mEnableLock);
    AudioAutoTimeoutLock _l2(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock());

    ClosePCMDump();

    pcm_stop(mPcm);
    pcm_close(mPcm);
    mPcm = NULL;

    AudioALSASampleRateController *pAudioALSASampleRateController = AudioALSASampleRateController::getInstance();
    pAudioALSASampleRateController->resetScenarioStatus(PLAYBACK_SCENARIO_ECHO_REF_EXT);

    return NO_ERROR;
}
status_t AudioALSALoopbackController::close()
{
    ALOGD("+%s()", __FUNCTION__);
    AudioAutoTimeoutLock _l(mLock);
    AudioAutoTimeoutLock _l2(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock());

    mHardwareResourceManager->stopOutputDevice();

    pcm_stop(mPcmDL);
    pcm_stop(mPcmUL);
    pcm_close(mPcmDL);
    pcm_close(mPcmUL);

    mPcmDL = NULL;
    mPcmUL = NULL;

    mHardwareResourceManager->stopInputDevice(mHardwareResourceManager->getInputDevice());

    ALOGD("-%s()", __FUNCTION__);
    return NO_ERROR;
}
int	WINAPI WKPluginOptionsManager(int iAction, WKOptionsCallbackInterface* pOptionsCallback, DWORD dwParameter)
{
	if(iAction==OM_STARTUP_ADD){
		pOptionsCallback->AddTip("tip1","To add/modify schedule to event/macro/etc expand action`s hotkey and click on 'Add schedule' link",0);
		pOptionsCallback->AddListOption("defView","Default tray calendar view","",_l2("Month")+"\t"+_l2("Week"),0);
		pOptionsCallback->AddBoolOption("AddTrayMenu","Add submenu with reminders into tray menu","",TRUE,0);
		// Дефаулт звук
		// Играть ли звук по умолчанию
		pOptionsCallback->AddBoolOption("Sound","Play sound on scheduled event","",TRUE,0);
		if(szWavFilePath[0]==0){
			WKGetPluginContainer()->GetWKPluginsDirectory(szWavFilePath,MAX_PATH);
			strcat(szWavFilePath,"onevent.wav");
		}
		pOptionsCallback->AddStringOption("Wav","Sound file","",szWavFilePath,1,0);
/*
				pDialog->Option_AddString(hDTF,_l("Time format"),&psk->sODSTimeFormat);
				pDialog->Option_AddString(hDTF,_l("Date format"),&psk->sODSDateFormat);

*/
		pOptionsCallback->AddStringOption("datef","Date format","Used for adding date to clipboard","",1,0);
		//pOptionsCallback->AddBinOption("wndpos");
	}
	if(iAction==OM_STARTUP_ADD || iAction==OM_OPTIONS_SET){
		pOptionsCallback->GetStringOption("Wav",szWavFilePath,sizeof(szWavFilePath));
		pOptionsCallback->GetStringOption("datef",szDateFormat,sizeof(szDateFormat));
		bActSound=pOptionsCallback->GetBoolOption("Sound");
		//pOptionsCallback->GetBinOption("wndpos",&wndRect,sizeof(wndRect));
		bDefViewCalendar=pOptionsCallback->GetListOption("defView");
		bAddTrayMenu=pOptionsCallback->GetBoolOption("AddTrayMenu");
	}
	if(iAction==OM_OPTIONS_GET){
		pOptionsCallback->SetStringOption("datef",szDateFormat);
		pOptionsCallback->SetStringOption("Wav",szWavFilePath);
		pOptionsCallback->SetBoolOption("Sound",bActSound);
		pOptionsCallback->SetBoolOption("AddTrayMenu",bAddTrayMenu);
		pOptionsCallback->SetListOption("defView",bDefViewCalendar);
		//pOptionsCallback->SetBinOption("wndpos",&wndRect,sizeof(wndRect));
	}
	return 1;
}
status_t AudioALSACaptureDataProviderTDM::open()
{
    ALOGD("%s()", __FUNCTION__);
    ASSERT(mClientLock.tryLock() != 0); // lock by base class attach
    AudioAutoTimeoutLock _l(mEnableLock);
    AudioAutoTimeoutLock _l2(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock());

    ASSERT(mEnable == false);

    // config attribute (will used in client SRC/Enh/... later) // TODO(Harvey): query this
    mStreamAttributeSource.audio_format = AUDIO_FORMAT_PCM_16_BIT;
    mStreamAttributeSource.audio_channel_mask = AUDIO_CHANNEL_IN_STEREO;
    mStreamAttributeSource.num_channels = android_audio_legacy::AudioSystem::popCount(mStreamAttributeSource.audio_channel_mask);
    mStreamAttributeSource.sample_rate = 44100;

    OpenPCMDump(LOG_TAG);

    // enable pcm
    ASSERT(mPcm == NULL);
    mPcm = pcm_open(0, 13, PCM_IN, &mConfig);
    //    mPcm = pcm_open(0, 1, PCM_IN, &mConfig);

    ASSERT(mPcm != NULL && pcm_is_ready(mPcm) == true);
    ALOGV("%s(), mPcm = %p", __FUNCTION__, mPcm);

    pcm_start(mPcm);

    // create reading thread
    mEnable = true;
    int ret = pthread_create(&hReadThread, NULL, AudioALSACaptureDataProviderTDM::readThread, (void *)this);
    if (ret != 0)
    {
        ALOGE("%s() create thread fail!!", __FUNCTION__);
        return UNKNOWN_ERROR;
    }

    return NO_ERROR;
}
TensorMechanicsPlasticOrthotropic::TensorMechanicsPlasticOrthotropic(
    const InputParameters & parameters)
  : TensorMechanicsPlasticIsotropicSD(parameters),
    _c1(getParam<std::vector<Real>>("c1")),
    _c2(getParam<std::vector<Real>>("c2"))
{
  _c = 1.0;
  _l1(0, 0, 0, 0) = (_c1[1] + _c1[2]) / 3.0;
  _l1(0, 0, 1, 1) = -_c1[2] / 3.0;
  _l1(0, 0, 2, 2) = -_c1[1] / 3.0;
  _l1(1, 1, 0, 0) = -_c1[2] / 3.0;
  _l1(1, 1, 1, 1) = (_c1[0] + _c1[2]) / 3.0;
  _l1(1, 1, 2, 2) = -_c1[0] / 3.0;
  _l1(2, 2, 0, 0) = -_c1[1] / 3.0;
  _l1(2, 2, 1, 1) = -_c1[0] / 3.0;
  _l1(2, 2, 2, 2) = (_c1[0] + _c1[1]) / 3.0;
  _l1(0, 1, 1, 0) = _c1[5] / 2.0;
  _l1(0, 1, 0, 1) = _c1[5] / 2.0;
  _l1(1, 0, 1, 0) = _c1[5] / 2.0;
  _l1(1, 0, 0, 1) = _c1[5] / 2.0;
  _l1(0, 2, 0, 2) = _c1[4] / 2.0;
  _l1(0, 2, 2, 0) = _c1[4] / 2.0;
  _l1(2, 0, 2, 0) = _c1[4] / 2.0;
  _l1(2, 0, 0, 2) = _c1[4] / 2.0;
  _l1(1, 2, 2, 1) = _c1[3] / 2.0;
  _l1(1, 2, 1, 2) = _c1[3] / 2.0;
  _l1(2, 1, 1, 2) = _c1[3] / 2.0;
  _l1(2, 1, 2, 1) = _c1[3] / 2.0;

  _l2(0, 0, 0, 0) = (_c2[1] + _c2[2]) / 3.0;
  _l2(0, 0, 1, 1) = -_c2[2] / 3.0;
  _l2(0, 0, 2, 2) = -_c2[1] / 3.0;
  _l2(1, 1, 0, 0) = -_c2[2] / 3.0;
  _l2(1, 1, 1, 1) = (_c2[0] + _c2[2]) / 3.0;
  _l2(1, 1, 2, 2) = -_c2[0] / 3.0;
  _l2(2, 2, 0, 0) = -_c2[1] / 3.0;
  _l2(2, 2, 1, 1) = -_c2[0] / 3.0;
  _l2(2, 2, 2, 2) = (_c2[0] + _c2[1]) / 3.0;
  _l2(0, 1, 1, 0) = _c2[5] / 2.0;
  _l2(0, 1, 0, 1) = _c2[5] / 2.0;
  _l2(1, 0, 1, 0) = _c2[5] / 2.0;
  _l2(1, 0, 0, 1) = _c2[5] / 2.0;
  _l2(0, 2, 0, 2) = _c2[4] / 2.0;
  _l2(0, 2, 2, 0) = _c2[4] / 2.0;
  _l2(2, 0, 2, 0) = _c2[4] / 2.0;
  _l2(2, 0, 0, 2) = _c2[4] / 2.0;
  _l2(1, 2, 2, 1) = _c2[3] / 2.0;
  _l2(1, 2, 1, 2) = _c2[3] / 2.0;
  _l2(2, 1, 1, 2) = _c2[3] / 2.0;
  _l2(2, 1, 2, 1) = _c2[3] / 2.0;
}
status_t AudioHardwareOutput::setParameters(const char* kvpairs) {
    AudioParameter param = AudioParameter(String8(kvpairs));
    status_t status = NO_ERROR;
    float floatVal;
    int intVal;
    Settings initial, s;

    {
        // Record the initial state of the settings from inside the lock.  Then
        // leave the lock in order to parse the changes to be made.
        Mutex::Autolock _l(mSettingsLock);
        initial = s = mSettings;
    }

    /***************************************************************
     *                     HDMI Audio Options                      *
     ***************************************************************/
    if (param.getInt(kHDMIAllowedParamKey, intVal) == NO_ERROR) {
        s.hdmi.allowed = (intVal != 0);
        param.remove(kHDMIAllowedParamKey);
    }

    if ((param.getFloat(kHDMIDelayCompParamKey, floatVal) == NO_ERROR) &&
        (floatVal >= 0.0) &&
        (floatVal <= AudioOutput::kMaxDelayCompensationMSec)) {
        uint32_t delay_comp = static_cast<uint32_t>(floatVal * 1000.0);
        s.hdmi.delayCompUsec = delay_comp;
        param.remove(kHDMIDelayCompParamKey);
    }

    if (param.getInt(kFixedHDMIOutputParamKey, intVal) == NO_ERROR) {
        s.hdmi.isFixed = (intVal != 0);
        param.remove(kFixedHDMIOutputParamKey);
    }

    if ((param.getFloat(kFixedHDMIOutputLevelParamKey, floatVal) == NO_ERROR)
        && (floatVal <= 0.0)) {
        s.hdmi.fixedLvl = floatVal;
        param.remove(kFixedHDMIOutputLevelParamKey);
    }

    /***************************************************************
     *                       Other Options                         *
     ***************************************************************/
    if ((param.getFloat(kVideoDelayCompParamKey, floatVal) == NO_ERROR) &&
        (floatVal >= 0.0) &&
        (floatVal <= AudioOutput::kMaxDelayCompensationMSec)) {
        s.videoDelayCompUsec = static_cast<uint32_t>(floatVal * 1000.0);
        param.remove(kVideoDelayCompParamKey);
    }

    if (param.size())
        status = BAD_VALUE;

    // If there was a change made to settings, go ahead and apply it now.
    bool allowedOutputsChanged = false;
    if (memcmp(&initial, &s, sizeof(initial)))  {
        Mutex::Autolock _l1(mOutputLock);
        Mutex::Autolock _l2(mSettingsLock);

        if (memcmp(&initial.hdmi, &s.hdmi, sizeof(initial.hdmi)))
            allowedOutputsChanged = allowedOutputsChanged ||
                applyOutputSettings_l(initial.hdmi, s.hdmi, mSettings.hdmi,
                                      HDMIAudioOutput::classDevMask());

        if (initial.videoDelayCompUsec != s.videoDelayCompUsec)
            mSettings.videoDelayCompUsec = s.videoDelayCompUsec;

        uint32_t tmp = 0;
        if (mSettings.hdmi.allowed && (tmp < mSettings.hdmi.delayCompUsec))
            tmp = mSettings.hdmi.delayCompUsec;
        if (mMaxDelayCompUsec != tmp)
            mMaxDelayCompUsec = tmp;
    }

    if (allowedOutputsChanged) {
        Mutex::Autolock _l(mStreamLock);
        updateTgtDevices_l();
    }

    return status;
}
int WINAPI WKTrayMenuPopup(int iActionType, int& iItemId, HMENU hMenu)
{
	if(!bAddTrayMenu){
		return 0;
	}
	if(iActionType==TM_ADDCUSTOMITEM){
		aRKeys.RemoveAll();
		iIdBeginning=iItemId;
		int iCount=0;
		_SortReminders srp=(_SortReminders)GetProcAddress(hRemin,"SortReminders");
		if(srp){
			(*srp)();
		}
		_GetReminder fp=(_GetReminder)GetProcAddress(hRemin,"GetReminder");
		COleDateTime dtNow=COleDateTime::GetCurrentTime();
		HMENU mn=CreatePopupMenu();
		int iPos=0;
		CString sText;
		char szKey[64]={0};
		sprintf(szKey,"#%i",iCount);
		CWPReminder rem;
		while((*fp)(szKey,rem)){
			COleDateTime tm(rem.EventTime);
			sText=GetRemDsc(rem,TRUE);
			if(sText!="" && abs(tm-dtNow)<=14 && !rem.bDisableRemider){
				AppendMenu(mn,MF_STRING,iItemId,sText);
				aRKeys.SetAtGrow(iPos,rem.szKey);
				iPos++;
			}
			iItemId++;//Увеличиваем на все, даже на пустые!
			iCount++;
			rem.Clear();
			sprintf(szKey,"#%i",iCount);
		}
		//if(iPos>0)//Всегда
		{
			{
				iAddNew=iItemId;
				iItemId++;
				AppendMenu(mn,MF_STRING,iAddNew,_l2("Add new reminder"));
			}
			{
				iShowAll=iItemId;
				iItemId++;
				AppendMenu(mn,MF_STRING,iShowAll,_l2("Show calendar"));
			}
			AppendMenu(hMenu,MF_POPUP|MF_STRING,UINT(mn),_l2("Reminders"));
		}
	}else{
		if(iItemId==iShowAll){
			ShowMainDialog(0);
		}else if(iItemId==iAddNew){
			//WKCallPluginFunction(0,0);
			//CreateRemOnDate(0,COleDateTime::GetCurrentTime(),FALSE);
			CString sSelectedKey=calcNextPrefixedId(DEF_ID);
			char szEvent[128]={0};
			strcpy(szEvent,sSelectedKey);
			WKPluginShowEventX(szEvent,0,COleDateTime::GetCurrentTime(),0);
		}else{
			char szKey[64]={0};
			strcpy(szKey,aRKeys[iItemId-iIdBeginning]);
			WKPluginShowEventX(szKey,0,COleDateTime::GetCurrentTime(),0);
		}
	}
	return 0;
}
int	WINAPI WKPluginShowEventX(char szEvent[128],HWND pParent,COleDateTime dt,BOOL bAskMenu)
{
	static long l=0;
	if(l>0){
		return 0;
	}
	SimpleTracker lc(l);

	CString sEventName=_l2("Scheduled event");
	HINSTANCE hLLHookInst=GetModuleHandle("WP_KeyMaster.wkp");
	_WKIHOTKEYS_GetHotkeyDscByID fpHk=(_WKIHOTKEYS_GetHotkeyDscByID)GetProcAddress(hLLHookInst,"WKIHOTKEYS_GetHotkeyDscByID");
	BOOL bDef=(strcmp(szEvent,DEF_ID)==0);
	if(fpHk){
		char szTitle[256]={0};
		if((*fpHk)(szEvent,szTitle,sizeof(szTitle))){
			sEventName=szTitle;
		}else{
			sEventName=_l2("Attention! Time has come!");
		}
	}
	_GetReminder fp=(_GetReminder)GetProcAddress(hRemin,"GetReminder");
	_IsReminderFamilyPresent fpPr=(_IsReminderFamilyPresent)GetProcAddress(hRemin,"IsReminderFamilyPresent");
	CString sRMKey=szEvent;
	// Возможно нужен выбор?
	CStringArray aTitles;
	CStringArray aKeys;
	if(bDef){
		aTitles.SetAtGrow(0,_l2("Add new reminder"));
		aKeys.SetAtGrow(0,sRMKey);
	}else{
		aTitles.SetAtGrow(0,_l2("Add new schedule"));
		aKeys.SetAtGrow(0,sRMKey);
	}
	CString sSelectedKey="";
	if(bAskMenu){
		int iMaxIndex=0;
		if(fpPr && (*fpPr)(sRMKey,&iMaxIndex)){
			aKeys[0]="";
			for(int i=0;i<=iMaxIndex;i++){
				if(fp){
					CWPReminder rem;
					strcpy(rem.szKey,GetNextPrefixedId(sRMKey,i));
					if((*fp)(rem.szKey,rem)){
						AddMapItems(aKeys,aTitles, rem.szKey, GetRemDsc(rem,TRUE));
					}
				}
			}
		}
		if(aKeys.GetSize()==1){
			sRMKey=aKeys[0];
		}else{
			CMenu menu;
			menu.CreatePopupMenu();
			CPoint pt;
			GetCursorPos(&pt);
			for(int i=0;i<aKeys.GetSize();i++){
				AddMenuString(&menu,WM_USER+i,aTitles[i]);
			}
			AddMenuString(&menu,WM_USER+aKeys.GetSize()+1,_l2("Close menu"));
			int iNum=::TrackPopupMenu(menu.GetSafeHmenu(), TPM_RETURNCMD|TPM_NONOTIFY|TPM_RIGHTBUTTON, pt.x, pt.y, 0, pParent, NULL);
			if(iNum==0 || iNum<WM_USER || iNum>=WM_USER+aKeys.GetSize()){
				return 0;
			}
			sSelectedKey=aKeys[iNum-WM_USER];
			if(sSelectedKey==""){
				sSelectedKey=calcNextPrefixedId(sRMKey);
			}
			sRMKey=sSelectedKey;
		}
	}
	BOOL bNewReminder=0;
	CWPReminder rem;
	memset(&rem,0,sizeof(CWPReminder));
	if(fp && sRMKey!=""){
		strcpy(rem.szKey,sRMKey);
		if(!(*fp)(rem.szKey,rem)){
			// Создаем новый!
			bNewReminder=1;
			//COleDateTime dt=COleDateTime::GetCurrentTime();
			dt=dt+COleDateTimeSpan(0,0,1,0);
			dt.GetAsSystemTime(rem.EventTime);
			rem.bActPopup=bDef;
			rem.bActSound=bActSound;
			rem.bLoopSound=bLoopSound;
			strcpy(rem.szText,sEventName);
			strcpy(rem.szSoundPath,szWavFilePath);
			if(!bDef){
				// Здесь именно оригинальный Id-Event!!!
				strcpy(rem.szReserved,szEvent);
			}
			_PutReminder fp2=(_PutReminder)GetProcAddress(hRemin,"PutReminder");
			if(fp2){
				(*fp2)(rem.szKey,rem);
			}
		}
	}
#ifdef _DEBUG
	WKGetPluginContainer()->ShowAlert(rem.szKey,"opened reminder");
#endif
	_CallModifyReminder fp1=(_CallModifyReminder)GetProcAddress(hRemin,"CallModifyReminder");
	if(fp1){
		int iRes=(*fp1)(rem.szKey,pParent,0);
		if(iRes==IDCANCEL && bNewReminder){
			_RemoveReminder fp3=(_RemoveReminder)GetProcAddress(hRemin,"RemoveReminder");
			if(fp3){
				(*fp3)(rem.szKey);
			}
		}
	}
	return 1;
}
void ClusterGeoIpService::threadMain()
	throw()
{
	char linebuf[65536];
	char buf[65536];
	long n,lineptr;

	while (_run) {
		{
			Mutex::Lock _l(_sOutputLock);

			_sOutputFd = -1;
			_sInputFd = -1;
			_sPid = 0;

			int stdinfds[2] = { 0,0 };  // sub-process's stdin, our output
			int stdoutfds[2] = { 0,0 }; // sub-process's stdout, our input
			::pipe(stdinfds);
			::pipe(stdoutfds);

			long p = (long)::vfork();
			if (p < 0) {
				Thread::sleep(500);
				continue;
			} else if (p == 0) {
				::close(stdinfds[1]);
				::close(stdoutfds[0]);
				::dup2(stdinfds[0],STDIN_FILENO);
				::dup2(stdoutfds[1],STDOUT_FILENO);
				::execl(_pathToExe.c_str(),_pathToExe.c_str(),(const char *)0);
				::exit(1);
			} else {
				::close(stdinfds[0]);
				::close(stdoutfds[1]);
				_sOutputFd = stdinfds[1];
				_sInputFd = stdoutfds[0];
				_sPid = p;
			}
		}

		lineptr = 0;
		while (_run) {
			n = ::read(_sInputFd,buf,sizeof(buf));
			if (n <= 0) {
				if (errno == EINTR)
					continue;
				else break;
			}
			for(long i=0;i<n;++i) {
				if (lineptr > (long)sizeof(linebuf))
					lineptr = 0;
				if ((buf[i] == '\n')||(buf[i] == '\r')) {
					linebuf[lineptr] = (char)0;
					if (lineptr > 0) {
						//fprintf(stderr,"ClusterGeoIpService: >> %s\n",linebuf);
						try {
							std::vector<std::string> result(Utils::split(linebuf,",","",""));
							if ((result.size() >= 7)&&(result[1] == "1")) {
								InetAddress rip(result[0],0);
								if ((rip.ss_family == AF_INET)||(rip.ss_family == AF_INET6)) {
									_CE ce;
									ce.ts = OSUtils::now();
									ce.x = (int)::strtol(result[4].c_str(),(char **)0,10);
									ce.y = (int)::strtol(result[5].c_str(),(char **)0,10);
									ce.z = (int)::strtol(result[6].c_str(),(char **)0,10);
									//fprintf(stderr,"ClusterGeoIpService: %s is at %d,%d,%d\n",rip.toIpString().c_str(),ce.x,ce.y,ce.z);
									{
										Mutex::Lock _l2(_cache_m);
										_cache[rip] = ce;
									}
								}
							}
						} catch ( ... ) {}
					}
					lineptr = 0;
				} else linebuf[lineptr++] = buf[i];
			}
		}

		::close(_sOutputFd);
		::close(_sInputFd);
		::kill(_sPid,SIGTERM);
		Thread::sleep(250);
		::kill(_sPid,SIGKILL);
		::waitpid(_sPid,(int *)0,0);
	}
}
Exemple #17
0
status_t AudioALSACaptureDataProviderEchoRefExt::open()
{
    ALOGD("%s()", __FUNCTION__);
    ASSERT(mClientLock.tryLock() != 0); // lock by base class attach
    AudioAutoTimeoutLock _l(mEnableLock);
    AudioAutoTimeoutLock _l2(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock());

    ASSERT(mEnable == false);

    AudioALSASampleRateController *pAudioALSASampleRateController = AudioALSASampleRateController::getInstance();
    pAudioALSASampleRateController->setScenarioStatus(PLAYBACK_SCENARIO_ECHO_REF_EXT);

    // config attribute (will used in client SRC/Enh/... later) // TODO(Sam): query the mConfig?
    mStreamAttributeSource.audio_format = AUDIO_FORMAT_PCM_16_BIT;
    mStreamAttributeSource.audio_channel_mask = AUDIO_CHANNEL_IN_STEREO;
    mStreamAttributeSource.num_channels = android_audio_legacy::AudioSystem::popCount(mStreamAttributeSource.audio_channel_mask);
    mStreamAttributeSource.sample_rate = AudioALSASampleRateController::getInstance()->getPrimaryStreamOutSampleRate();


    mConfig.channels = mStreamAttributeSource.num_channels;
    mConfig.rate = mStreamAttributeSource.sample_rate;

    // Buffer size: 2048(period_size) * 2(ch) * 2(byte) * 8(period_count) = 64 kb
    mConfig.period_size = 2048;
    mConfig.period_count = 8;
    mConfig.format = PCM_FORMAT_S16_LE;

    mConfig.start_threshold = 0;
    mConfig.stop_threshold = 0;
    mConfig.silence_threshold = 0;


#if 0
    //latency time, set as DataProvider buffer size
    mStreamAttributeSource.latency = (kReadBufferSize * 1000) / (mStreamAttributeSource.num_channels * mStreamAttributeSource.sample_rate *
                                                                 (mStreamAttributeSource.audio_format == AUDIO_FORMAT_PCM_8_BIT ? 1 :    //8  1byte/frame
                                                                  (mStreamAttributeSource.audio_format == AUDIO_FORMAT_PCM_32_BIT ? 4 :   //24bit 3bytes/frame
                                                                   2)));   //default 2bytes/sample
#else
    //latency time, set as hardware buffer size
    mStreamAttributeSource.latency = (mConfig.period_size * mConfig.period_count * 1000) / mConfig.rate;
#endif

    ALOGD("%s(), audio_format = %d, audio_channel_mask=%x, num_channels=%d, sample_rate=%d, latency=%dms", __FUNCTION__,
          mStreamAttributeSource.audio_format, mStreamAttributeSource.audio_channel_mask, mStreamAttributeSource.num_channels, mStreamAttributeSource.sample_rate, mStreamAttributeSource.latency);

    ALOGD("%s(), format = %d, channels=%d, rate=%d", __FUNCTION__,
          mConfig.format, mConfig.channels, mConfig.rate);


#ifdef NXP_SMARTPA_SUPPORT
    MTK_Tfa98xx_EchoReferenceConfigure(1);
#endif

    OpenPCMDump(LOG_TAG);

    // enable pcm
    ASSERT(mPcm == NULL);
    mPcm = pcm_open(0, 16, PCM_IN | PCM_MONOTONIC, &mConfig);
    ASSERT(mPcm != NULL && pcm_is_ready(mPcm) == true);

    pcm_start(mPcm);

    // create reading thread
    mEnable = true;
    int ret = pthread_create(&hReadThread, NULL, AudioALSACaptureDataProviderEchoRefExt::readThread, (void *)this);
    if (ret != 0)
    {
        ALOGE("%s() create thread fail!!", __FUNCTION__);
        return UNKNOWN_ERROR;
    }

    return NO_ERROR;
}