예제 #1
0
/**
* @brief Save an AVI file.
* @return 0 on success. Otherwise meets fail.
*/
int AlarmAudio_Play(int audMsgQid)
{
	char cmd[280]="";
	int ret=-1,nFree;
	int count=0;
	SysInfo *pSysInfo = pAlarmSysInfo;
	if(pSysInfo == NULL)
		return -1;

	nFree = GetfreememInfo();
	if(nFree <0){
		sleep(1);
		return -1;
	}else{
		DBG("Alarm Audio play check free Memory = %ld Kbyte \n", (long)nFree);
	}

	count=getAudioCount();
	WaitAlarmStatusUpdated();
	while (count > 0){
		if(pSysInfo->lan_config.alarmstatus==0){
			setAudioCount(-1);
			count =0;
			break;
		}
		if(pSysInfo->lan_config.nAlarmAudioPlay) {
			if(pSysInfo->audio_config.samplerate==1) {
				if(pSysInfo->lan_config.nAlarmAudioFile==0)
					sprintf(cmd, "aplay -f U8 alarm_1_16K.wav -r 16000");
				else if(pSysInfo->lan_config.nAlarmAudioFile==1)
					sprintf(cmd, "aplay -f U8 alarm_2_16K.wav -r 16000");
				else
					break;
			}
			else {
				if(pSysInfo->lan_config.nAlarmAudioFile==0)
					sprintf(cmd, "aplay -f U8 alarm_1_8K.wav -r 8000");
				else if(pSysInfo->lan_config.nAlarmAudioFile==1)
					sprintf(cmd, "aplay -f U8 alarm_2_8K.wav -r 8000");
				else
					break;
			}
		}
		NotifyAVServerStart(audMsgQid);
		ret = system(cmd);
		NotifyAVServerEnd(audMsgQid);
		subAudioCount();
		count=getAudioCount();
		DBG("Alarm Audio play check free Memory = %ld Kbyte \n", (long)nFree);
		DBG("AlarmAudio_Play!! count=%d\n",count);
	}

	return ret;
}
예제 #2
0
/**
* @brief Alarm processing thread.
*/
void *ProcAlarmThread(void *arg)
{
	int iCurTime;
	void *status = PROC_SUCESS;
	time_t tCurrentTime;
	struct tm *tmnow;
	AlarmParam_t* pEvironment = (AlarmParam_t*)arg;
	unsigned char enableIn,enableOut=0,trigger;
	LogEntry_t tLog;
	SysInfo *pSysInfo = pAlarmSysInfo;
	DBG("QID: %d\n", pEvironment ->msg_id);
	DBG("From: %d\n", pEvironment ->msg_buf.src);
	DBG("pSysInfo: %p\n", pSysInfo);
	DBG("Index: %d\n", pEvironment ->msg_buf.index);
	if((iCurTime = time(&tCurrentTime)) == -1){
		ERR("Fail on get current time\n");
		status =PROC_FAIL;
		goto ALARM_EXIT;
	}
	tmnow = localtime(&tCurrentTime);
	memcpy(&tLog.time, tmnow, sizeof(struct tm));
	switch(pEvironment->msg_buf.event){
		case ALARM_EVENT_AUDIO_TRIG:
		{
			int alarmDuration;
			DBG("ALARM_EVENT_AUDIO_TRIG \n");
			if((pSysInfo->audio_config.alarmON == 0)||
			   (pSysInfo->lan_config.alarmstatus&FLG_UI_AUDIO)){
				break;
			}
			AddSchedule(AUDIO_SCHEDULE, tmnow, pSysInfo);
			enableOut = (pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.giooutenable);
			trigger=pSysInfo->lan_config.gioouttype;
			alarmDuration=pSysInfo->lan_config.nAlarmDuration;
			if(enableOut==1){
				dm355_gio_write(GIO_ALARMOUT,trigger);
				Set_AlarmDuration(alarmDuration);
			}
			sprintf(tLog.event, "Audio Alarm");
			fSetSysLog(&tLog);
			int count=0;
			count=getAudioCount();
			if ( count > 0){
				setAudioCount(alarmDuration);
				break;
			}
			else
				setAudioCount(alarmDuration);
			AlarmAudio_Play(pEvironment->audMsg_id);
			break;
		}
		case ALARM_EVENT_MOTION_DETECT:
		{
			int alarmDuration;
			DBG("ALARM_EVENT_MOTION_DETECT \n");
			if((pSysInfo->motion_config.motionenable==0)||
			   (pSysInfo->lan_config.alarmstatus&FLG_UI_MOTION)){
				break;
			}
			SetJpegStartSerial(pEvironment->msg_buf.serial);
			AddSchedule(MOTION_SCHEDULE, tmnow, pSysInfo);
			enableOut = (pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.giooutenable);
			trigger=pSysInfo->lan_config.gioouttype;
			alarmDuration=pSysInfo->lan_config.nAlarmDuration;
			if(enableOut==1){
				dm355_gio_write(GIO_ALARMOUT,trigger);
				Set_AlarmDuration(alarmDuration);
			}
			sprintf(tLog.event, "Motion Alarm");
			fSetSysLog(&tLog);
			int count=0;
			count=getAudioCount();
			if ( count > 0){
				setAudioCount(alarmDuration);
				break;
			}
			else
				setAudioCount(alarmDuration);
			AlarmAudio_Play(pEvironment->audMsg_id);
			break;
		}
		case ALARM_EVENT_ALARMRESET_TRIG:
		{
			DBG("ALARM_EVENT_ALARMRESET_TRIG \n");
			ResetSchedule();
			Set_AlarmDuration(0);
			setAudioCount(-1);
			break;
		}
		case ALARM_EVENT_ALARMIN_TRIG:
		{
			int alarmDuration;
			DBG("ALARM_EVENT_ALARMIN_TRIG \n");
			enableIn=(pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.gioinenable);
			alarmDuration=pSysInfo->lan_config.nAlarmDuration;
			/** check if turn gio alarm on   */
			if((enableIn==0)||
			   (pSysInfo->lan_config.alarmstatus&FLG_UI_EXT)){
				break;
			}
			AddSchedule(EXT_SCHEDULE, tmnow, pSysInfo);
			enableOut = (pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.giooutenable);
			trigger=pSysInfo->lan_config.gioouttype;
			if(enableOut==1){
				dm355_gio_write(GIO_ALARMOUT,trigger);
				Set_AlarmDuration(alarmDuration);
			}
			sprintf(tLog.event, "External Alarm");
			fSetSysLog(&tLog);
			int count=0;
			count=getAudioCount();
			if ( count > 0){
				setAudioCount(alarmDuration);
				break;
			}
			else
				setAudioCount(alarmDuration);
			AlarmAudio_Play(pEvironment->audMsg_id);
			break;
		}
		case ALARM_EVENT_ALARMETH_TRIG:
		{
			int alarmDuration;
			DBG("ALARM_EVENT_ALARMETH_TRIG \n");
			alarmDuration=pSysInfo->lan_config.nAlarmDuration;
			/**  check if turn Ethernet alarm on */
			if((pSysInfo->lan_config.lostalarm == 0)||
			   (pSysInfo->lan_config.alarmstatus&FLG_UI_ETH)){
				break;
			}
			AddSchedule(ETH_SCHEDULE, tmnow, pSysInfo);
			enableOut = (pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.giooutenable);
			trigger=pSysInfo->lan_config.gioouttype;
			if(enableOut==1){
				dm355_gio_write(GIO_ALARMOUT,trigger);
				Set_AlarmDuration(alarmDuration);
			}
			sprintf(tLog.event, "Ethernet Alarm");
			fSetSysLog(&tLog);
			int count=0;
			count=getAudioCount();
			if ( count > 0){
				setAudioCount(alarmDuration);
				break;
			}
			else
				setAudioCount(alarmDuration);
			AlarmAudio_Play(pEvironment->audMsg_id);
			break;
		}
		case ALARM_EVENT_SCHEDULE:
		{
			int nflag, bIsAviRun;
			int isFTPAVI,isSDAVI;
			int supportJPG,supportH264,supportH264cif,supportMpeg4,supportMpeg4cif,supportAVI;
			DBG("ALARM_EVENT_SCHEDULE \n");
			isFTPAVI=pSysInfo->ftp_config.ftpfileformat;
			isSDAVI=pSysInfo->sdcard_config.sdfileformat;
			supportJPG = pSysInfo->lan_config.Supportstream1;
			supportMpeg4 = pSysInfo->lan_config.Supportstream2;
			supportMpeg4cif = pSysInfo->lan_config.Supportstream3;
			supportH264 = pSysInfo->lan_config.Supportstream5;
			supportH264cif = pSysInfo->lan_config.Supportstream6;
			supportAVI = supportH264|supportH264cif|supportMpeg4|supportMpeg4cif;
			bIsAviRun = 0;
			sprintf(tLog.event, "Schedule Record");
			nflag =0;
			if(pSysInfo->sdcard_config.sdinsert<=1){
				if(supportAVI&&pSysInfo->sdcard_config.sdrenable&&isSDAVI==0&&
						!gbSD_WriteProtect){
					nflag |= AVI_TO_SD;
					bIsAviRun = 1;
				}
				if(supportAVI&&pSysInfo->ftp_config.rftpenable&&isFTPAVI==0){
					nflag |= AVI_TO_FTP;
					bIsAviRun = 1;
				}
				if(bIsAviRun){
					AviRun(0, nflag);
					SemWait(pEvironment->hAlarmSem);
					gSchAviRun = 1;
					SemRelease(pEvironment->hAlarmSem);
				}
			} else {
				/* AVI no stop case */
				if(supportAVI&&pSysInfo->sdcard_config.sdrenable&&isSDAVI==0&&
						!gbSD_WriteProtect){
					AviRun(1, AVI_TO_SD);
					SemWait(pEvironment->hAlarmSem);
					gSchAviRun = 1;
					SemRelease(pEvironment->hAlarmSem);
				}
			}
			nflag =0;
			if(isSDAVI==1&&pSysInfo->sdcard_config.sdrenable &&
					!gbSD_WriteProtect)
				nflag |= JPG_TO_SD;
			/* Megapixel JPEG mode */
			if(!supportAVI&&pSysInfo->sdcard_config.sdrenable&&!gbSD_WriteProtect)
				nflag |= JPG_TO_SD;
			if(pSysInfo->sdcard_config.sdinsert<=1){
				if(isFTPAVI==1 &&pSysInfo->ftp_config.rftpenable)
					nflag |= JPG_TO_FTP;
				/* Megapixel JPEG mode*/
				if(!supportAVI&&pSysInfo->ftp_config.rftpenable)
					nflag |= JPG_TO_FTP;
				if(nflag){
					JpgRun(nflag, 0 );
					SemWait(pEvironment->hAlarmSem);
					gSchJpgRun = 1;
					SemRelease(pEvironment->hAlarmSem);
				}
			}
			else{
				if(supportJPG&&pSysInfo->ftp_config.rftpenable)
					nflag |= JPG_TO_FTP;
				if(nflag){
					JpgRun(nflag, 1 );
					SemWait(pEvironment->hAlarmSem);
					gSchJpgRun = 1;
					SemRelease(pEvironment->hAlarmSem);
				}
			}
			fSetSysLog(&tLog);
			break;
		}
		case ALARM_EVENT_SCHEDULE_END:
		{
			int isFTPAVI;
			int supportJPG=0,supportH264=0,supportH264cif=0,supportMpeg4=0,supportMpeg4cif=0,supportAVI=0;
			DBG("ALARM_EVENT_SCHEDULE_END\n");
			isFTPAVI=pSysInfo->ftp_config.ftpfileformat;
			isFTPAVI=pSysInfo->ftp_config.ftpfileformat;
			supportJPG = pSysInfo->lan_config.Supportstream1;
			supportMpeg4 = pSysInfo->lan_config.Supportstream2;
			supportMpeg4cif = pSysInfo->lan_config.Supportstream3;
			supportH264 = pSysInfo->lan_config.Supportstream5;
			supportH264cif = pSysInfo->lan_config.Supportstream6;
			supportAVI = supportH264|supportH264cif|supportMpeg4|supportMpeg4cif;
			if(pSysInfo->sdcard_config.sdinsert==3){
				/* AVI no stop case */
				SemWait(pEvironment->hAlarmSem);
				if(!gbSD_WriteProtect && gSchAviRun){
					AviStop();
					gSchAviRun = 0;
				}
				if(gSchJpgRun){
					JpgStop(1);
					gSchJpgRun = 0;
				}
				SemRelease(pEvironment->hAlarmSem);
			} else {
				SemWait(pEvironment->hAlarmSem);
				if(gSchAviRun){
					AviStop();
					gSchAviRun = 0;
				}
				if(gSchJpgRun){
					JpgStop(0);
					gSchJpgRun = 0;
				}
				SemRelease(pEvironment->hAlarmSem);
			}
			break;
		}
		default:
			ERR("Unknown Event\n");
			sprintf(tLog.event, "Unknown Event");
			fSetSysLog(&tLog);
			status = PROC_FAIL;
			break;
	}

ALARM_EXIT:
	free(pEvironment);
	DBG("Free evironment sucess\n");
	pthread_exit(status);
	return status;
}
예제 #3
0
void test_GetAudioCount() {
	int audioCount;
	TEST_ASSERT_EQUAL(RET_CODE_SUCCESS, getAudioCount(&audioCount));
	TEST_ASSERT_TRUE(audioCount  > 0);
}