Ejemplo n.º 1
0
void FmodSoundEngine::Update(float dwTimeMilliSecond)
{
	FMOD::Channel **channel = (FMOD::Channel**)this->channel;
	if(ScreenState==SCREEN_GAMEMAIN){
		bool status = false;
		channel[0]->isPlaying(&status);
		if(!status || !channel[0]){	// audio stopped, resume audio in video
			if(m_pAudio)
				m_pAudio->put_Volume(Lin2dB(defaultVolume));
		}else{			// channel 0 is active
			if(m_pAudio)
				m_pAudio->put_Volume(-10000);

			if(pitch_factor!=0)
				SetPitch(pitch_factor,0,true), pitch_factor = 0;

			if(sampleRate_factor!=0)
				SetSampleRate(sampleRate_factor,0,true), sampleRate_factor = 0;

			if(tempo_factor!=0)
				SetTempo(tempo_factor,0,true), tempo_factor = 0;
		}
	}
	system->update();
	for(int i = 0; i < nowChannel; i++)
	{
		if(channel[i]!=NULL)
		{
			float volume;
			result = channel[i]->getVolume(&volume);
			if(volume>volumeDes[i])
			{
				volume -= soundSpd*dwTimeMilliSecond;
				if(volume<volumeDes[i]) volume = volumeDes[i];
			}
			else if(volume<volumeDes[i])
			{
				volume += soundSpd*dwTimeMilliSecond;
				if(volume>volumeDes[i]) volume = volumeDes[i];
			}
			channel[i]->setVolume(volume);
			if(volume==0)
				FreeChannel(i, true);
		}
	}
}
Ejemplo n.º 2
0
void
MediaEngineWebRTCMicrophoneSource::Shutdown()
{
  Super::Shutdown();
  if (mListener) {
    // breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
    mListener->Shutdown();
    // Don't release the webrtc.org pointers yet until the Listener is (async) shutdown
    mListener = nullptr;
  }

  if (mState == kStarted) {
    SourceMediaStream *source;
    bool empty;

    while (1) {
      {
        MonitorAutoLock lock(mMonitor);
        empty = mSources.IsEmpty();
        if (empty) {
          break;
        }
        source = mSources[0];
      }
      Stop(source, kAudioTrack); // XXX change to support multiple tracks
    }
    MOZ_ASSERT(mState == kStopped);
  }

  while (mRegisteredHandles.Length()) {
    MOZ_ASSERT(mState == kAllocated || mState == kStopped);
    Deallocate(nullptr); // XXX Extend concurrent constraints code to mics.
  }

  if (mState != kReleased) {
    FreeChannel();
    MOZ_ASSERT(sChannelsOpen > 0);
    if (--sChannelsOpen == 0) {
      DeInitEngine();
    }
  }

  mAudioInput = nullptr;
}
Ejemplo n.º 3
0
HCHANNEL BassSoundEngine::PlayMusic(int sound_id, CHANNEL Ichannel, bool loop, float volume)
{
	if(Ichannel<0||Ichannel>=maxChannel){
		Ichannel = GetNewChannel();
		if(Ichannel<0)
			return NULL;
	}else
		FreeChannel(Ichannel);
	HSTREAM sound = playMusic[sound_id];
	channel[Ichannel] = sound;

	DWORD hr;
	bool useDSP = false;

	// set position
	float freq;
	if(Ichannel==0)
	{
		hr = BASS_ChannelGetAttribute(sound, BASS_ATTRIB_FREQ, &freq);
		hr = SetPosition(0, sound_id, 0);
		hr = BASS_FX_TempoGetRateRatio(sound);
		if(hr>0)
			useDSP = true;
		music_sampleRate = freq;
	}

	// set volume
	volumeDes[Ichannel] = volume*defaultVolume;
	hr = BASS_ChannelSetAttribute(sound, BASS_ATTRIB_VOL, volumeDes[Ichannel]);

	// start play
	hr = BASS_ChannelPlay(sound, useDSP?FALSE:TRUE);

	// set loop
	if(loop)
		hr = BASS_ChannelFlags(sound, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP);

	if(Ichannel==0)
		Update(0);

	return sound;
}
Ejemplo n.º 4
0
nsresult
MediaEngineWebRTCMicrophoneSource::Deallocate(AllocationHandle* aHandle)
{
  AssertIsOnOwningThread();

  Super::Deallocate(aHandle);

  if (!mRegisteredHandles.Length()) {
    // If empty, no callbacks to deliver data should be occuring
    if (mState != kStopped && mState != kAllocated) {
      return NS_ERROR_FAILURE;
    }

    FreeChannel();
    LOG(("Audio device %d deallocated", mCapIndex));
  } else {
    LOG(("Audio device %d deallocated but still in use", mCapIndex));
  }
  return NS_OK;
}
Ejemplo n.º 5
0
void NetManagerReactor::NetRun()
{
	NetManager::NetRun();

	if(!m_pReactor)
		return;

	m_pReactor->HandleEvents(m_timer, GetEventWaitTime());

	const int32 MAX_SOCKETS = m_ChannelList.GetMaxElement();
	for (int32 i = 0; i < MAX_SOCKETS; ++i)
	{
		NetChannelBase* pChannel = GetChannel(i);
		if(!pChannel)
			continue;

		pChannel->HandleOutput();
		FreeChannel(pChannel);
	}
}
Ejemplo n.º 6
0
bool NetManager::SendPacket(PacketBase& pkt, int32 nSocketID)
{
	bool bSuceed = false;

	NetChannelBase* pChannel = GetChannel( nSocketID );
	if ( pChannel )
	{
		PacketBase* pPkt = DuplicatePacket(pkt);
		if(!pPkt)
			MyLog::error("NetManager::SendPacket failed to DuplicatePacket [%s]", pkt.GetClassName() );
		else
		{
			pPkt->SetSocketID( nSocketID );
			pChannel->AppendPacket( pPkt );
			bSuceed = true;
		}
		FreeChannel(pChannel);
	}

	return bSuceed;
}
Ejemplo n.º 7
0
void NetManager::CloseChannel(int32 nChannel)
{
	NetChannelBase* pChannel = NULL;

	m_mutexChannels.Lock();

	pChannel = m_ChannelList.XGet( nChannel );

	m_ChannelList.remove( nChannel);

	m_mutexChannels.Unlock();

	if( pChannel == NULL || pChannel->GetSocket() == INVALID_SOCKET )
		return;

	if(m_DisconnectCallBack)
		(*m_DisconnectCallBack)(nChannel);

	OnDisconnect(pChannel);
	pChannel->CloseChannel();
	FreeChannel(pChannel);
}
Ejemplo n.º 8
0
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Return Value:
//	1: Fail, 0: Success
///////////////////////////////////////////////////////////////////////////////////////////////////////
int Read_10(unsigned long  lUSB_LUN_Read)
{
	int i;
	unsigned long SCSI_LBA;
	unsigned int SCSI_Transfer_Length;
	unsigned long USB_RW_Buffer_PTR, USB_RW_Buffer_PTR_A,USB_RW_Buffer_PTR_B,USB_RW_Buffer_PTR_Temp;
	int ret,stage;
	unsigned long num;
	unsigned int USBDMA_CHANNEL0, USBDMA_CHANNEL1, USBDMA_CHANNEL2, USBDMA_CHANNEL3;
	str_USB_Lun_Info*  ptr_USB_LUN_Read;

	ptr_USB_LUN_Read = (str_USB_Lun_Info*)lUSB_LUN_Read;
	ulTimeout = 0x4FFFF;
	ret=0x00;
	stage = 0x00;
	Sense_Code = 0;
	R_USB_RW_Busy = 1;

	SCSI_LBA=GetLBA();

	SCSI_Transfer_Length=GetTransLeng();

	USB_RW_Buffer_PTR=GetBufferPointer();
	USB_RW_Buffer_PTR_A=USB_RW_Buffer_PTR;   //add by zhangxh 2006/01/19
	USB_RW_Buffer_PTR_B=USB_RW_Buffer_PTR_A + 256;	

#ifdef OS_vension
	USBDMA_CHANNEL0 = MallocChannel();	 //by zhangxh 2006/01/19
	USBDMA_CHANNEL1 = MallocChannel();	 //by zhangxh 2006/01/19
	USBDMA_CHANNEL2 = MallocChannel();	 //by zhangxh 2006/01/19
	USBDMA_CHANNEL3 = MallocChannel();	 //by zhangxh 2006/01/19
#else
	USBDMA_CHANNEL0 = 0;
	USBDMA_CHANNEL1 = 1;
	USBDMA_CHANNEL2 = 2;
	USBDMA_CHANNEL3 = 3;
#endif

	if(ptr_USB_LUN_Read->unLunType == LunType_SDCardReader)  //SD Card
	{
#ifdef SD_Used	
		if ((SCSI_LBA + SCSI_Transfer_Length)>SDCTotalSector)	//huck
		{
			Sense_Code = 0x1B;  //LOGICAL BLOCK ADDRESS OUT OF RANGE
			ret = 1;
			goto End;
		}

		for(i=0 ; i < SCSI_Transfer_Length ; i++)
		{			

			if (i == 0)

				ret = DrvSDCReadMultiSector_USB((unsigned long)SCSI_LBA+i, (unsigned long)USB_RW_Buffer_PTR_A,USBDMA_CHANNEL0,0);
			else 
				ret = DrvSDCReadMultiSector_USB((unsigned long)SCSI_LBA+i, (unsigned long)USB_RW_Buffer_PTR_A,USBDMA_CHANNEL0,1);

			if (i == SCSI_Transfer_Length-1)
				ret = DrvSDCReadMultiSector_USB((unsigned long)SCSI_LBA+i, (unsigned long)USB_RW_Buffer_PTR_A,USBDMA_CHANNEL0,2);


			if(ret != 0x00)
			{
				DrvSDCReadMultiSector_USB((unsigned long)SCSI_LBA+i, (unsigned long)USB_RW_Buffer_PTR_A,USBDMA_CHANNEL0,4); //4,stop the SDC Only					
				Sense_Code=0x08;
				goto End;
			}			

			if (stage)
			{
				ret = Send_To_USB_DMA_USB(USB_RW_Buffer_PTR_A,USBDMA_CHANNEL1,1);
				for(num=0;num<ulTimeout;num++)
				{
					if(R_USB_Suspend == 1)
						break;
					else
					{
						if ((*P_USBD_EPEvent & 0x0100) != 0)
							ret = 0xffff;
						else
						{
							ret = 0;
							*P_USBD_EPEvent=0x0600;
							break;
						}
					}
				}

				if(num == ulTimeout)
				{
					Sense_Code=0x12;
					ret = 0xffff;
					return ret;					
				}
			}		

			ret = Send_To_USB_DMA_USB(USB_RW_Buffer_PTR_A,USBDMA_CHANNEL1,0);									
			if (ret != 0x00)
			{
				ret = 0xffff;	
				Sense_Code = 0x12; 			
				goto End;
			}

			stage=1;		

			//for last data 
			if (i == SCSI_Transfer_Length-1)
			{
				ret = Send_To_USB_DMA_USB(USB_RW_Buffer_PTR_A,USBDMA_CHANNEL1,1);

				if (ret != 0x00)
				{
					ret = 0xffff;	
					Sense_Code = 0x12; 			
					goto End;
				}

				for(num=0;num<ulTimeout;num++)
				{
					if(R_USB_Suspend == 1)
						break;
					else
					{
						if ((*P_USBD_EPEvent & 0x0100) != 0)
							ret = 0xffff;
						else
						{
							ret = 0;
							*P_USBD_EPEvent=0x0600;
							break;
						}
					}
				}
				if(num == ulTimeout)
				{
					ret = 0xffff;	
					Sense_Code = 0x12; 			
					goto End;
				}

			}
			USB_RW_Buffer_PTR_Temp = USB_RW_Buffer_PTR_B;			
			USB_RW_Buffer_PTR_B = USB_RW_Buffer_PTR_A;
			USB_RW_Buffer_PTR_A = USB_RW_Buffer_PTR_Temp;			

		}//for		

		if(ret != 0x00)
		{			
			CSW_Residue=SCSI_Transfer_Length-i;			
			CSW_Residue=CSW_Residue << 9;	
		}
		else
			CSW_Residue=0;	
#endif
	}	
	else //Nand Drive
	{
#ifdef Nand_Used
		if ((SCSI_LBA + SCSI_Transfer_Length)>ptr_USB_LUN_Read->ulNandSizeSec)	//check read address overflow
		{
			Sense_Code = 0x1B;
			ret = 1;
			goto End;
		}

		if(ptr_USB_LUN_Read->unLunType == LunType_CDROM)	//CDROM, do not modify below CDROM code
		{
			SCSI_LBA ++;						
			SCSI_LBA = SCSI_LBA << 2;						//1 sector = 4 *512
			SCSI_LBA += ptr_USB_LUN_Read->ulNandStartAddr;		
			SCSI_Transfer_Length = SCSI_Transfer_Length << 2; //length *4
		}
		else
			SCSI_LBA += ptr_USB_LUN_Read->ulNandStartAddr;		

		for(i=0 ; i < SCSI_Transfer_Length ; i++)
		{
			ret = _NAND_ReadSector_USB((unsigned long)(SCSI_LBA+i), 1, (unsigned long)USB_RW_Buffer_PTR_A, USBDMA_CHANNEL2);

			if (stage)
			{
				TXToUSB_USB(USB_RW_Buffer_PTR_A, 0x01, USBDMA_CHANNEL1, 0x01);

				ulTimeout = 0x4FFFF;
				while((*P_USBD_EPEvent & 0x0100) != 0)
				{						
					if (!(ulTimeout--))	
					{
						*P_USBD_EPEvent=0x0600;	
						Sense_Code = 0x12; 
						ret = 1;
						goto End;
					}
				}
				*P_USBD_EPEvent=0x0600;
			}

			TXToUSB_USB(USB_RW_Buffer_PTR_A, 0x01, USBDMA_CHANNEL1, 0x00);
			stage=1;

			if (i == SCSI_Transfer_Length-1)
			{
				TXToUSB_USB(USB_RW_Buffer_PTR_A, 0x01, USBDMA_CHANNEL1, 0x01);
				ulTimeout = 0x4FFFF;
				while((*P_USBD_EPEvent & 0x0100) != 0)
				{						
					if (!(ulTimeout--))	
					{
						*P_USBD_EPEvent=0x0600;	
						Sense_Code = 0x12; 
						ret = 1;
						goto End;
					}
				}
				*P_USBD_EPEvent=0x0600;
			}
			USB_RW_Buffer_PTR_Temp = USB_RW_Buffer_PTR_B;			
			USB_RW_Buffer_PTR_B = USB_RW_Buffer_PTR_A;
			USB_RW_Buffer_PTR_A = USB_RW_Buffer_PTR_Temp;
		}		

		CSW_Residue=0x00;
#endif
	}
End:	
#ifdef OS_vension
	FreeChannel(USBDMA_CHANNEL0);
	FreeChannel(USBDMA_CHANNEL1);
	FreeChannel(USBDMA_CHANNEL2);
	FreeChannel(USBDMA_CHANNEL3);		
#endif

	return ret;
}
Ejemplo n.º 9
0
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Return Value:
//	1: Fail, 0: Success
///////////////////////////////////////////////////////////////////////////////////////////////////////
int Write_10(unsigned long	lUSB_LUN_Write)
{
	int j;
	unsigned long SCSI_LBA;
	unsigned int SCSI_Transfer_Length;
	unsigned long USB_RW_Buffer_PTR;
	unsigned long USB_RW_Buffer_PTR_A,USB_RW_Buffer_PTR_B,USB_RW_Buffer_PTR_Temp;
	unsigned int USBDMA_CHANNEL0, USBDMA_CHANNEL1, USBDMA_CHANNEL2, USBDMA_CHANNEL3;
	int ret= 0xffff, stage = 0, *p;
	int ret1=0xffff;
	unsigned int Erro_Flag = 0;
	extern unsigned int *RHM_FlashBuf, RHM_USBreprogBuf_Full;
	unsigned int idx;
	extern unsigned int USBreprogBuf[];
	str_USB_Lun_Info*  ptr_USB_LUN_Write;

	ptr_USB_LUN_Write = (str_USB_Lun_Info*)lUSB_LUN_Write;
	R_USB_RW_Busy = 1;
	Sense_Code = 0x00;
	SCSI_LBA=GetLBA();
	SCSI_Transfer_Length=GetTransLeng();
	USB_RW_Buffer_PTR=GetBufferPointer();

	USB_RW_Buffer_PTR_A=GetBufferPointer();   //add by zhangxh 2006/01/19
	USB_RW_Buffer_PTR_B=USB_RW_Buffer_PTR_A + 256;

#ifdef OS_vension
	USBDMA_CHANNEL0 = MallocChannel();	 //by zhangxh 2006/01/19
	USBDMA_CHANNEL1 = MallocChannel();	 //by zhangxh 2006/01/19
	USBDMA_CHANNEL2 = MallocChannel();	 //by zhangxh 2006/01/19
	USBDMA_CHANNEL3 = MallocChannel();	 //by zhangxh 2006/01/19
#else
	USBDMA_CHANNEL0 = 0;
	USBDMA_CHANNEL1 = 1;
	USBDMA_CHANNEL2 = 2;
	USBDMA_CHANNEL3 = 3;
#endif	

	if(ptr_USB_LUN_Write->unLunType == LunType_SDCardReader)
	{
#ifdef SD_Used	
		if ((SCSI_LBA + SCSI_Transfer_Length)>SDCTotalSector)	//huck	
		{
			Sense_Code = 0x1B; //LOGICAL BLOCK ADDRESS OUT OF RANGE
			ret = 1;
			goto End;			
		}

		for(j=0; j<SCSI_Transfer_Length; j++)
		{							
			//=================================================================================================
			// Enable DMA mode. And using USB 128x8 bytes dual FIFO			
			ret=Receive_From_USB_DMA_USB(USB_RW_Buffer_PTR_B,USBDMA_CHANNEL3);			
			if(ret != 0x00)
			{
				*P_USBD_EPEvntClear=0x0010;
				*P_USBD_EPEvent=0x2000;		// Bulk OUT NACK Reset
				break;
			}

			*P_USBD_EPEvntClear=0x0010;
			*P_USBD_EPEvent=0x2000;		// Bulk OUT NACK Reset

			USB_RW_Buffer_PTR_Temp = USB_RW_Buffer_PTR_B;
			if (j>0 )
			{
				stage = 1;				
			}
			if (!Erro_Flag)
				ret1 = DrvSDCMultiWriteSector_USB((unsigned long)SCSI_LBA+j, (unsigned long)USB_RW_Buffer_PTR_B,(unsigned int)USBDMA_CHANNEL2,stage);			

			if(ret1 != 0x00)
			{
				ret = ret1;
				break;
			}			
			USB_RW_Buffer_PTR_B = USB_RW_Buffer_PTR_A;
			USB_RW_Buffer_PTR_A = USB_RW_Buffer_PTR_Temp;

		}//j

		if((ret1 == 0x00)&&(!Erro_Flag))
			ret1=DrvSDCMultiWriteSector_USB((unsigned long)SCSI_LBA+j, (unsigned long)USB_RW_Buffer_PTR_B,(unsigned int)USBDMA_CHANNEL2,2);		

		if ((ret1 != 0x00)&&(!Erro_Flag))
		{
			DrvSDCMultiWriteSector_USB((unsigned long)SCSI_LBA+j, (unsigned long)USB_RW_Buffer_PTR_B,(unsigned int)USBDMA_CHANNEL2,4);		
			ret = ret1;
		}

		if( (ret != 0x00) || (ret1 != 0x00) )
		{
			CSW_Residue=SCSI_Transfer_Length-j-1;
			CSW_Residue=CSW_Residue << 9;
			Sense_Code=0x10;	   
		}
		else
			CSW_Residue=0;
#endif
	}
	else if(ptr_USB_LUN_Write->unLunType == LunType_NOR) {  //rhm
	
		flash *pflash = (flash *)ptr_USB_LUN_Write->rhmLunData;

		ptr_USB_LUN_Write->ulNandSizeSec = 0xaabbccdd;
		ptr_USB_LUN_Write->ulNandSizeSec = 2048;
	
//		long xx = ptr_USB_LUN_Write->ulNandSizeSec;
//		if ((SCSI_LBA + (SCSI_Transfer_Length*512)) > (ptr_USB_LUN_Write->ulNandSizeSec))	//check address overflow	
//		{
//			Sense_Code = 0x1B;//LOGICAL BLOCK ADDRESS OUT OF RANGE
//			ret = 1;			
//			goto End;
//		}

//		SCSI_LBA += ptr_USB_LUN_Write->ulNandStartAddr;	
		
		//rhm nor erase sector here	
		
		*P_WatchDog_Ctrl = 0;		// disable watchdog

		pflash->pflash = SCSI_LBA;
		pflash->bytesAvail = 0;
//rhm1		pflash->erasesector(pflash);

		for(j=0; j<SCSI_Transfer_Length; j++)
		{				
			//=================================================================================================
			// Enable DMA mode. And using USB 128x8 bytes dual FIFO
			//ret=Receive_From_USB_DMA_USB(USB_RW_Buffer_PTR_B,DMA_CHANNEL2);
//RHM			ret=Receive_From_USB_DMA_USB(USB_RW_Buffer_PTR_B, USBDMA_CHANNEL1);

		    ret=Receive_From_USB_DMA_USB(USB_RW_Buffer_PTR_B, USBDMA_CHANNEL3);

			if (ret != 0x00)
			{
				*P_USBD_EPEvntClear=0x0010;			
				*P_USBD_EPEvent=0x2000;		// Bulk OUT NACK Reset
				break;
			}
			*P_USBD_EPEvntClear=0x0010;			
			*P_USBD_EPEvent=0x2000;		// Bulk OUT NACK Reset

			if (j==0)
				stage = 0;
			else 
				stage = 1;
				
			{
			unsigned short *sp = (unsigned short *)USB_RW_Buffer_PTR_B;
			if(RHM_FlashBuf) {
				for(idx=0; idx<256; idx++) {
					RHM_FlashBuf[(j*256)+idx] = *sp++;
				}
				pflash->bytesAvail += 256;
			}
			}

			USB_RW_Buffer_PTR_Temp = USB_RW_Buffer_PTR_B;
			USB_RW_Buffer_PTR_B = USB_RW_Buffer_PTR_A;
			USB_RW_Buffer_PTR_A = USB_RW_Buffer_PTR_Temp;
		}//j

		if(ret != 0x00)
		{
			CSW_Residue=SCSI_Transfer_Length-j-1;
			CSW_Residue=CSW_Residue << 9;
			Sense_Code=0x10;	//WRITE FAULT
		}
		else {
			CSW_Residue=0;			
			USB_Status =  BULK_IN_NACK;  //TEST			
			RHM_USBreprogBuf_Full = j * 256;
		}
	} // rhm end LunType_NOR
	else { //  rhm LunType_RAM
		
//RHM #ifdef Nand_Used	
		j=0;

		if ((SCSI_LBA + (SCSI_Transfer_Length*512))>ptr_USB_LUN_Write->ulNandSizeSec)	//check address overflow	
		{
			Sense_Code = 0x1B;//LOGICAL BLOCK ADDRESS OUT OF RANGE
			ret = 1;			
			goto End;
		}

		SCSI_LBA += ptr_USB_LUN_Write->ulNandStartAddr;		

		for(j=0; j<SCSI_Transfer_Length; j++)
		{				
			//=================================================================================================
			// Enable DMA mode. And using USB 128x8 bytes dual FIFO
			//ret=Receive_From_USB_DMA_USB(USB_RW_Buffer_PTR_B,DMA_CHANNEL2);
//RHM			ret=Receive_From_USB_DMA_USB(USB_RW_Buffer_PTR_B, USBDMA_CHANNEL1);
		    ret=Receive_From_USB_DMA_USB(USB_RW_Buffer_PTR_B, USBDMA_CHANNEL3);

			if (ret != 0x00)
			{
				*P_USBD_EPEvntClear=0x0010;			
				*P_USBD_EPEvent=0x2000;		// Bulk OUT NACK Reset
				break;
			}
			*P_USBD_EPEvntClear=0x0010;			
			*P_USBD_EPEvent=0x2000;		// Bulk OUT NACK Reset

			if (j==0)
				stage = 0;
			else 
				stage = 1;

//			if (!Erro_Flag)				
//RHM				ret1 = _NAND_WriteSector_USB((unsigned long)SCSI_LBA+j, 1, (unsigned long)USB_RW_Buffer_PTR_B,(unsigned int)USBDMA_CHANNEL0,stage);
					memcpy(SCSI_LBA+(j*256), (unsigned long)USB_RW_Buffer_PTR_B, 256);
//			if (ret1 != 0x00)
//				break;

			USB_RW_Buffer_PTR_Temp = USB_RW_Buffer_PTR_B;
			USB_RW_Buffer_PTR_B = USB_RW_Buffer_PTR_A;
			USB_RW_Buffer_PTR_A = USB_RW_Buffer_PTR_Temp;
		}//j

		if(ret != 0x00)
		{
			CSW_Residue=SCSI_Transfer_Length-j-1;
			CSW_Residue=CSW_Residue << 9;
			Sense_Code=0x10;	//WRITE FAULT
		}
		else
			CSW_Residue=0;
//RHM #endif
	}

End:	
#ifdef OS_vension
	FreeChannel(USBDMA_CHANNEL0);
	FreeChannel(USBDMA_CHANNEL1);
	FreeChannel(USBDMA_CHANNEL2);
	FreeChannel(USBDMA_CHANNEL3);		
#endif

	return ret;	
}
Ejemplo n.º 10
0
nsresult
MediaEngineWebRTCMicrophoneSource::UpdateSingleSource(
    const AllocationHandle* aHandle,
    const NormalizedConstraints& aNetConstraints,
    const MediaEnginePrefs& aPrefs,
    const nsString& aDeviceId,
    const char** aOutBadConstraint)
{
  FlattenedConstraints c(aNetConstraints);

  MediaEnginePrefs prefs = aPrefs;
  prefs.mAecOn = c.mEchoCancellation.Get(prefs.mAecOn);
  prefs.mAgcOn = c.mAutoGainControl.Get(prefs.mAgcOn);
  prefs.mNoiseOn = c.mNoiseSuppression.Get(prefs.mNoiseOn);
  uint32_t maxChannels = 1;
  if (mAudioInput->GetMaxAvailableChannels(maxChannels) != 0) {
    return NS_ERROR_FAILURE;
  }
  // Check channelCount violation
  if (static_cast<int32_t>(maxChannels) < c.mChannelCount.mMin ||
      static_cast<int32_t>(maxChannels) > c.mChannelCount.mMax) {
    *aOutBadConstraint = "channelCount";
    return NS_ERROR_FAILURE;
  }
  // Clamp channelCount to a valid value
  if (prefs.mChannels <= 0) {
    prefs.mChannels = static_cast<int32_t>(maxChannels);
  }
  prefs.mChannels = c.mChannelCount.Get(std::min(prefs.mChannels,
                                        static_cast<int32_t>(maxChannels)));
  // Clamp channelCount to a valid value
  prefs.mChannels = std::max(1, std::min(prefs.mChannels, static_cast<int32_t>(maxChannels)));

  LOG(("Audio config: aec: %d, agc: %d, noise: %d, delay: %d, channels: %d",
      prefs.mAecOn ? prefs.mAec : -1,
      prefs.mAgcOn ? prefs.mAgc : -1,
      prefs.mNoiseOn ? prefs.mNoise : -1,
      prefs.mPlayoutDelay,
      prefs.mChannels));

  mPlayoutDelay = prefs.mPlayoutDelay;

  switch (mState) {
    case kReleased:
      MOZ_ASSERT(aHandle);
      if (sChannelsOpen == 0) {
        if (!InitEngine()) {
          LOG(("Audio engine is not initalized"));
          return NS_ERROR_FAILURE;
        }
      } else {
        // Until we fix (or wallpaper) support for multiple mic input
        // (Bug 1238038) fail allocation for a second device
        return NS_ERROR_FAILURE;
      }
      if (mAudioInput->SetRecordingDevice(mCapIndex)) {
         return NS_ERROR_FAILURE;
      }
      mAudioInput->SetUserChannelCount(prefs.mChannels);
      if (!AllocChannel()) {
        FreeChannel();
        LOG(("Audio device is not initalized"));
        return NS_ERROR_FAILURE;
      }
      LOG(("Audio device %d allocated", mCapIndex));
      {
        // Update with the actual applied channelCount in order
        // to store it in settings.
        uint32_t channelCount = 0;
        mAudioInput->GetChannelCount(channelCount);
        MOZ_ASSERT(channelCount > 0);
        prefs.mChannels = channelCount;
      }
      break;

    case kStarted:
      if (prefs == mLastPrefs) {
        return NS_OK;
      }

      if (prefs.mChannels != mLastPrefs.mChannels) {
        MOZ_ASSERT(mSources.Length() > 0);
        auto& source = mSources.LastElement();
        mAudioInput->SetUserChannelCount(prefs.mChannels);
        // Get validated number of channel
        uint32_t channelCount = 0;
        mAudioInput->GetChannelCount(channelCount);
        MOZ_ASSERT(channelCount > 0 && mLastPrefs.mChannels > 0);
        // Check if new validated channels is the same as previous
        if (static_cast<uint32_t>(mLastPrefs.mChannels) != channelCount
            && !source->OpenNewAudioCallbackDriver(mListener)) {
          return NS_ERROR_FAILURE;
        }
        // Update settings
        prefs.mChannels = channelCount;
      }

      if (MOZ_LOG_TEST(GetMediaManagerLog(), LogLevel::Debug)) {
        MonitorAutoLock lock(mMonitor);
        if (mSources.IsEmpty()) {
          LOG(("Audio device %d reallocated", mCapIndex));
        } else {
          LOG(("Audio device %d allocated shared", mCapIndex));
        }
      }
      break;

    default:
      LOG(("Audio device %d in ignored state %d", mCapIndex, mState));
      break;
  }

  if (sChannelsOpen > 0) {
    int error;

    error = mVoEProcessing->SetEcStatus(prefs.mAecOn, (webrtc::EcModes)prefs.mAec);
    if (error) {
      LOG(("%s Error setting Echo Status: %d ",__FUNCTION__, error));
      // Overhead of capturing all the time is very low (<0.1% of an audio only call)
      if (prefs.mAecOn) {
        error = mVoEProcessing->SetEcMetricsStatus(true);
        if (error) {
          LOG(("%s Error setting Echo Metrics: %d ",__FUNCTION__, error));
        }
      }
    }
    error = mVoEProcessing->SetAgcStatus(prefs.mAgcOn, (webrtc::AgcModes)prefs.mAgc);
    if (error) {
      LOG(("%s Error setting AGC Status: %d ",__FUNCTION__, error));
    }
    error = mVoEProcessing->SetNsStatus(prefs.mNoiseOn, (webrtc::NsModes)prefs.mNoise);
    if (error) {
      LOG(("%s Error setting NoiseSuppression Status: %d ",__FUNCTION__, error));
    }
  }

  mSkipProcessing = !(prefs.mAecOn || prefs.mAgcOn || prefs.mNoiseOn);
  if (mSkipProcessing) {
    mSampleFrequency = MediaEngine::USE_GRAPH_RATE;
    mAudioOutputObserver = nullptr;
  } else {
    // make sure we route a copy of the mixed audio output of this MSG to the
    // AEC
    mAudioOutputObserver = new AudioOutputObserver();
  }
  SetLastPrefs(prefs);
  return NS_OK;
}
Ejemplo n.º 11
0
nsresult
MediaEngineWebRTCMicrophoneSource::UpdateSingleSource(
    const AllocationHandle* aHandle,
    const NormalizedConstraints& aNetConstraints,
    const MediaEnginePrefs& aPrefs,
    const nsString& aDeviceId,
    const char** aOutBadConstraint)
{
  FlattenedConstraints c(aNetConstraints);

  MediaEnginePrefs prefs = aPrefs;
  prefs.mAecOn = c.mEchoCancellation.Get(prefs.mAecOn);
  prefs.mAgcOn = c.mAutoGainControl.Get(prefs.mAgcOn);
  prefs.mNoiseOn = c.mNoiseSuppression.Get(prefs.mNoiseOn);

  LOG(("Audio config: aec: %d, agc: %d, noise: %d, delay: %d",
       prefs.mAecOn ? prefs.mAec : -1,
       prefs.mAgcOn ? prefs.mAgc : -1,
       prefs.mNoiseOn ? prefs.mNoise : -1,
       prefs.mPlayoutDelay));

  mPlayoutDelay = prefs.mPlayoutDelay;

  switch (mState) {
    case kReleased:
      MOZ_ASSERT(aHandle);
      if (sChannelsOpen == 0) {
        if (!InitEngine()) {
          LOG(("Audio engine is not initalized"));
          return NS_ERROR_FAILURE;
        }
      } else {
        // Until we fix (or wallpaper) support for multiple mic input
        // (Bug 1238038) fail allocation for a second device
        return NS_ERROR_FAILURE;
      }
      if (!AllocChannel()) {
        LOG(("Audio device is not initalized"));
        return NS_ERROR_FAILURE;
      }
      if (mAudioInput->SetRecordingDevice(mCapIndex)) {
        FreeChannel();
        return NS_ERROR_FAILURE;
      }
      LOG(("Audio device %d allocated", mCapIndex));
      break;

    case kStarted:
      if (prefs == mLastPrefs) {
        return NS_OK;
      }
      if (MOZ_LOG_TEST(GetMediaManagerLog(), LogLevel::Debug)) {
        MonitorAutoLock lock(mMonitor);
        if (mSources.IsEmpty()) {
          LOG(("Audio device %d reallocated", mCapIndex));
        } else {
          LOG(("Audio device %d allocated shared", mCapIndex));
        }
      }
      break;

    default:
      LOG(("Audio device %d in ignored state %d", mCapIndex, mState));
      break;
  }

  if (sChannelsOpen > 0) {
    int error;

    error = mVoEProcessing->SetEcStatus(prefs.mAecOn, (webrtc::EcModes)prefs.mAec);
    if (error) {
      LOG(("%s Error setting Echo Status: %d ",__FUNCTION__, error));
      // Overhead of capturing all the time is very low (<0.1% of an audio only call)
      if (prefs.mAecOn) {
        error = mVoEProcessing->SetEcMetricsStatus(true);
        if (error) {
          LOG(("%s Error setting Echo Metrics: %d ",__FUNCTION__, error));
        }
      }
    }
    error = mVoEProcessing->SetAgcStatus(prefs.mAgcOn, (webrtc::AgcModes)prefs.mAgc);
    if (error) {
      LOG(("%s Error setting AGC Status: %d ",__FUNCTION__, error));
    }
    error = mVoEProcessing->SetNsStatus(prefs.mNoiseOn, (webrtc::NsModes)prefs.mNoise);
    if (error) {
      LOG(("%s Error setting NoiseSuppression Status: %d ",__FUNCTION__, error));
    }
  }

  mSkipProcessing = !(prefs.mAecOn || prefs.mAgcOn || prefs.mNoiseOn);
  if (mSkipProcessing) {
    mSampleFrequency = MediaEngine::USE_GRAPH_RATE;
  }
  SetLastPrefs(prefs);
  return NS_OK;
}
Ejemplo n.º 12
0
void CDWHCIDevice::ChannelInterruptHandler (unsigned nChannel)
{
	CDWHCITransferStageData *pStageData = m_pStageData[nChannel];
	assert (pStageData != 0);
	CUSBRequest *pURB = pStageData->GetURB ();
	assert (pURB != 0);

	switch (pStageData->GetSubState ())
	{
	case StageSubStateWaitForChannelDisable:
		StartChannel (pStageData);
		return;

	case StageSubStateWaitForTransactionComplete: {
		CleanDataCache ();
		InvalidateDataCache ();
		DataMemBarrier ();

		CDWHCIRegister TransferSize (DWHCI_HOST_CHAN_XFER_SIZ (nChannel));
		TransferSize.Read ();

		CDWHCIRegister ChanInterrupt (DWHCI_HOST_CHAN_INT (nChannel));

		assert (   !pStageData->IsPeriodic ()
			||    DWHCI_HOST_CHAN_XFER_SIZ_PID (TransferSize.Get ())
			   != DWHCI_HOST_CHAN_XFER_SIZ_PID_MDATA);

		pStageData->TransactionComplete (ChanInterrupt.Read (),
			DWHCI_HOST_CHAN_XFER_SIZ_PACKETS (TransferSize.Get ()),
			TransferSize.Get () & DWHCI_HOST_CHAN_XFER_SIZ_BYTES__MASK);
		} break;
	
	default:
		assert (0);
		break;
	}
	
	unsigned nStatus;
	
	switch (pStageData->GetState ())
	{
	case StageStateNoSplitTransfer:
		nStatus = pStageData->GetTransactionStatus ();
		if (nStatus & DWHCI_HOST_CHAN_INT_ERROR_MASK)
		{
			CLogger::Get ()->Write (FromDWHCI, LogError,
						"Transaction failed (status 0x%X)", nStatus);

			pURB->SetStatus (0);
		}
		else if (   (nStatus & (DWHCI_HOST_CHAN_INT_NAK | DWHCI_HOST_CHAN_INT_NYET))
			 && pStageData->IsPeriodic ())
		{
			pStageData->SetState (StageStatePeriodicDelay);

			unsigned nInterval = pURB->GetEndpoint ()->GetInterval ();

			m_pTimer->StartKernelTimer (MSEC2HZ (nInterval), TimerStub, pStageData, this);

			break;
		}
		else
		{
			if (!pStageData->IsStatusStage ())
			{
				pURB->SetResultLen (pStageData->GetResultLen ());
			}

			pURB->SetStatus (1);
		}
		
		DisableChannelInterrupt (nChannel);

		delete pStageData;
		m_pStageData[nChannel] = 0;

		FreeChannel (nChannel);

		pURB->CallCompletionRoutine ();
		break;

	case StageStateStartSplit:
		nStatus = pStageData->GetTransactionStatus ();
		if (   (nStatus & DWHCI_HOST_CHAN_INT_ERROR_MASK)
		    || (nStatus & DWHCI_HOST_CHAN_INT_NAK)
		    || (nStatus & DWHCI_HOST_CHAN_INT_NYET))
		{
			CLogger::Get ()->Write (FromDWHCI, LogError,
						"Transaction failed (status 0x%X)", nStatus);

			pURB->SetStatus (0);

			DisableChannelInterrupt (nChannel);

			delete pStageData;
			m_pStageData[nChannel] = 0;

			FreeChannel (nChannel);

			pURB->CallCompletionRoutine ();
			break;
		}

		pStageData->GetFrameScheduler ()->TransactionComplete (nStatus);

		pStageData->SetState (StageStateCompleteSplit);
		pStageData->SetSplitComplete (TRUE);

		if (!pStageData->GetFrameScheduler ()->CompleteSplit ())
		{
			goto LeaveCompleteSplit;
		}
		
		StartTransaction (pStageData);
		break;
		
	case StageStateCompleteSplit:
		nStatus = pStageData->GetTransactionStatus ();
		if (nStatus & DWHCI_HOST_CHAN_INT_ERROR_MASK)
		{
			CLogger::Get ()->Write (FromDWHCI, LogError,
						"Transaction failed (status 0x%X)", nStatus);

			pURB->SetStatus (0);

			DisableChannelInterrupt (nChannel);

			delete pStageData;
			m_pStageData[nChannel] = 0;

			FreeChannel (nChannel);

			pURB->CallCompletionRoutine ();
			break;
		}
		
		pStageData->GetFrameScheduler ()->TransactionComplete (nStatus);

		if (pStageData->GetFrameScheduler ()->CompleteSplit ())
		{
			StartTransaction (pStageData);
			break;
		}

	LeaveCompleteSplit:
		if (!pStageData->IsStageComplete ())
		{
			if (!pStageData->BeginSplitCycle ())
			{
				pURB->SetStatus (0);

				DisableChannelInterrupt (nChannel);

				delete pStageData;
				m_pStageData[nChannel] = 0;

				FreeChannel (nChannel);

				pURB->CallCompletionRoutine ();
				break;
			}

			if (!pStageData->IsPeriodic ())
			{
				pStageData->SetState (StageStateStartSplit);
				pStageData->SetSplitComplete (FALSE);
				pStageData->GetFrameScheduler ()->StartSplit ();

				StartTransaction (pStageData);
			}
			else
			{
				pStageData->SetState (StageStatePeriodicDelay);

				unsigned nInterval = pURB->GetEndpoint ()->GetInterval ();

				m_pTimer->StartKernelTimer (MSEC2HZ (nInterval),
							    TimerStub, pStageData, this);
			}
			break;
		}

		DisableChannelInterrupt (nChannel);

		if (!pStageData->IsStatusStage ())
		{
			pURB->SetResultLen (pStageData->GetResultLen ());
		}
		pURB->SetStatus (1);

		delete pStageData;
		m_pStageData[nChannel] = 0;

		FreeChannel (nChannel);

		pURB->CallCompletionRoutine ();
		break;

	default:
		assert (0);
		break;
	}
}
Ejemplo n.º 13
0
void PlayField::MessageReceived(void){
	int cnt = GetReceivedCount();
	char *buf = (char*)GetReceivedBuffer();
	for(int n=0; n<cnt; n++){
		switch(GetReceivedCommand(n)){
		case INPUT_DIGITAL_DOWN:{
			if(!buf){
				printf("PlayField::MessageReceived: No buffer!\n");
				break;
			}
			int len = *(int16*)buf;
			buf+=sizeof(int16);
			char *str = new char[len+1];
			for(int n=0; n<len; n++) str[n]=*buf++;
			str[len]='\0';
//			printf("%s down\n",str);

			char *key = &str[1];
			int chan = 0;
			bool done = false;
			do{
				switch(*key++){
				case '0': chan*=10; break;
				case '1': chan*=10; chan+=1; break;
				case '2': chan*=10; chan+=2; break;
				case '3': chan*=10; chan+=3; break;
				case '4': chan*=10; chan+=4; break;
				case '5': chan*=10; chan+=5; break;
				case '6': chan*=10; chan+=6; break;
				case '7': chan*=10; chan+=7; break;
				case '8': chan*=10; chan+=8; break;
				case '9': chan*=10; chan+=9; break;
				default: done=true;
				}
			}while(!done);

if(chan>=channels->GetCount()){
//	printf("PlayField::MessageReceived(): Channel overflow!\n");
	delete str;
	return;
}

//			printf("%s(%d) down\n",key,chan);

			if(!strcmp(key,"!Hook")){
//printf("PlayField: hookof %d\n",chan);
				#ifndef SINGLE_LINE_TEST
				if(GetChannel(chan)) printf("PlayField: Channel allready active (%d)!\n",chan);
				else{
				#endif
					//((Player*)players->GetItem(0))->Logon();
					Player *player = AllocateChannel(chan);
					player->Logon();
				#ifndef SINGLE_LINE_TEST
				}
				#endif
			}
			else if(!strcmp(key,"1")){ if(GetChannel(chan)) ((Player*)GetChannel(chan))->Lock(0); }
			else if(!strcmp(key,"2")){ if(GetChannel(chan)) ((Player*)GetChannel(chan))->Lock(1); }
			else if(!strcmp(key,"3")){ if(GetChannel(chan)) ((Player*)GetChannel(chan))->Lock(2); }
			else if(!strcmp(key,"4")){ if(GetChannel(chan)) ((Player*)GetChannel(chan))->Lock(3); }
			else if(!strcmp(key,"5")){ if(GetChannel(chan)) ((Player*)GetChannel(chan))->Spinn(); }
			if(GetChannel(chan)) ((Player*)GetChannel(chan))->DigitDown(key);

/*
			if(!strcmp(key,"!Hook")) state[chan] = '!';
			if(!strcmp(key,"0"))     state[chan] = '0';
			if(!strcmp(key,"1"))     state[chan] = '1';
			if(!strcmp(key,"2"))     state[chan] = '2';
			if(!strcmp(key,"3"))     state[chan] = '3';
			if(!strcmp(key,"4"))     state[chan] = '4';
			if(!strcmp(key,"5"))     state[chan] = '5';
			if(!strcmp(key,"6"))     state[chan] = '6';
			if(!strcmp(key,"7"))     state[chan] = '7';
			if(!strcmp(key,"8"))     state[chan] = '8';
			if(!strcmp(key,"9"))     state[chan] = '9';
			if(!strcmp(key,"#"))     state[chan] = '#';
			if(!strcmp(key,"*"))     state[chan] = '*';
*/
			delete str;

		}break;
		case INPUT_DIGITAL_UP:{
			if(!buf){
				printf("PlayField::MessageReceived: No buffer!\n");
				break;
			}
			int len = *(int16*)buf;
			buf+=sizeof(int16);
			char *str = new char[len+1];
			for(int n=0; n<len; n++) str[n]=*buf++;
			str[len]='\0';
//			printf("%s up\n",str);

			char *key = &str[1];
			int chan = 0;
			bool done = false;
			do{
				switch(*key++){
				case '0': chan*=10; break;
				case '1': chan*=10; chan+=1; break;
				case '2': chan*=10; chan+=2; break;
				case '3': chan*=10; chan+=3; break;
				case '4': chan*=10; chan+=4; break;
				case '5': chan*=10; chan+=5; break;
				case '6': chan*=10; chan+=6; break;
				case '7': chan*=10; chan+=7; break;
				case '8': chan*=10; chan+=8; break;
				case '9': chan*=10; chan+=9; break;
				default: done=true;
				}
			}while(!done);

if(chan>=channels->GetCount()){
//	printf("PlayField::MessageReceived(): Channel overflow!\n");
	delete str;
	return;
}

//			printf("%s(%d) up\n",key,chan);

//			if(!strcmp(key,"!Hook")) ((Player*)players->GetItem(0))->Logout();
			if(GetChannel(chan)) ((Player*)GetChannel(chan))->DigitUp(key);

			#ifndef SINGLE_LINE_TEST
			if(!strcmp(key,"!Hook")){
//printf("PlayField: hookon %d\n",chan);
				Player *player = GetChannel(chan);
				if(player){
					player->Logout();
					FreeChannel(chan);
				}else printf("PlayField: No player in channel %d!\n",chan);
			}
			#endif

/*
			if(!strcmp(key,"!Hook")) state[chan] = '-';
			else
			if(!strcmp(key,"0"))     state[chan] = '!';
			if(!strcmp(key,"1"))     state[chan] = '!';
			if(!strcmp(key,"2"))     state[chan] = '!';
			if(!strcmp(key,"3"))     state[chan] = '!';
			if(!strcmp(key,"4"))     state[chan] = '!';
			if(!strcmp(key,"5"))     state[chan] = '!';
			if(!strcmp(key,"6"))     state[chan] = '!';
			if(!strcmp(key,"7"))     state[chan] = '!';
			if(!strcmp(key,"8"))     state[chan] = '!';
			if(!strcmp(key,"9"))     state[chan] = '!';
			if(!strcmp(key,"#"))     state[chan] = '!';
			if(!strcmp(key,"*"))     state[chan] = '!';
*/
			delete str;
		}break;
		}
	}
}
Ejemplo n.º 14
0
void BassSoundEngine::StopAllMusic(bool alphaout)
{
	for(int i = 0; i < nowChannel; i++)
		FreeChannel(i, !alphaout);
}
Ejemplo n.º 15
0
void BassSoundEngine::StopMusic(CHANNEL Ichannel, bool alphaout)
{
	FreeChannel(Ichannel, !alphaout);
}
Ejemplo n.º 16
0
/********************************************************************************************
 * OpenChannel
 * purpose : Open an outgoing channel
 * input   : Call           - Call to associate with the channel
 *           MediaType      - Type of media to use for the channel
 *           DataType       - Data type parameter for the channel
 *           MimicChannel   - Pointer of a channel we mimic. NULL if not mimicing
 *           ReplaceChannel - Pointer of a channel we replace. NULL not replacing
 * output  : none
 * return  : TCL_OK on success
 ********************************************************************************************/
int OpenChannel(CallInfo *    Call,
                char *        DataType,
                ChannelInfo * MimicChannel,
                ChannelInfo * ReplaceChannel)
{
    ChannelInfo*       NewChan;
    int                status;

    /* Make sure we're not in an endless loop of mimicing channels */
    if (MimicChannel != NULL)
    {
        HAPPCHAN haSameSession = NULL;
        HCHAN hsSameSession = NULL;
        cmChannelSameSession(MimicChannel->hChan, &haSameSession, &hsSameSession);
        if(haSameSession != NULL) return 0;
    }

    /* Increase the number of channels for this call */
    NewChan = ChannelCreate(NULL, TRUE, FALSE, Call);

    /* Create and open channel */
    status = cmChannelNew(Call->hsCall, (HAPPCHAN) NewChan, (LPHCHAN)&NewChan->hChan);

    if (status >= 0)
    {
        /* See if we're mimicing this channel */
        if (MimicChannel == NULL)
        {
            /* Open an RTP session for this channel */
            if(Call->action == RTP_Replay)
                NewChan->rtpSession = RTP_TestOpen("testChannel");
            if (ReplaceChannel != NULL)
                cmChannelReplace(NewChan->hChan, ReplaceChannel->hChan);
        }
        else
        {
            /* Channel is mimiced */
            NewChan->rtpSession = MimicChannel->rtpSession;
            RTP_TestSetAction(NewChan->rtpSession, Call->action);
            RTP_TestOpenSecondChannel(NewChan->rtpSession);
        }

        /* set RTCP address  and open the channel*/
        if (DataType[0] == 't')
        {
            /* Data channel (Duplex) */
            cmTransportAddress ta={0,0x0e2472c0,(UINT16)1503/*port*/,cmTransportTypeIP};
            cmChannelDuplex(NewChan->hChan);
            cmChannelSetDuplexAddress(NewChan->hChan,ta,1,(char *)"1",FALSE);
        }
        else
            cmChannelSetRTCPAddress(NewChan->hChan, 0,
                (UINT16) (RTP_TestGetLocalPort(NewChan->rtpSession) + 1));
        
        /* set data type */
        strncpy(NewChan->dataType, DataType, sizeof(NewChan->dataType));

        if (MimicChannel)
        {
            if (MimicChannel->dynPayloadType != 0)
                cmChannelSetDynamicRTPPayloadType(NewChan->hChan, MimicChannel->dynPayloadType);

            /* Since this is a mimiced channel, we'll open it in exactly the same manner as the original channel */
            status = cmChannelOpenDynamic(NewChan->hChan, MimicChannel->dataTypeNode, MimicChannel->hChan, NULL, FALSE);
        }
        else
            status = cmChannelOpen(NewChan->hChan, DataType, NULL, NULL, 0);
        
        TclExecute("call:Log %d {ChannelOpen. result=%s}", Call->counter, Status2String(status));
    }
    else
    {
        FreeChannel(NewChan);
        TclExecute("call:Log %d {ChannelNew. result=%s}", Call->counter, Status2String(status));
    }

    /* Add the new channel to the channels list on the main window */
    return DisplayChannelList(Call, NULL);
}
Ejemplo n.º 17
0
/********************************************************************************************
 * cmEvChannelStateChanged
 * purpose : the function that invoked when event ChannelStateChange occurs
 * input   : haChan    - Channel struct of the application
 *         : hsChan    - handle for the channel
 *         : state     - current state of the channel
 *         : stateMode - New state mode. This parameter describes why or how the channel
 *                       enters a new state
 * output  : none
 * return  : negative on error
 ********************************************************************************************/
int RVCALLCONV cmEvChannelStateChanged(IN HAPPCHAN haChan,
                                       IN HCHAN    hsChan,
                                       IN UINT32   state,
                                       IN UINT32   stateMode)
{
    ChannelInfo* CurrentChannel;
    CallInfo* Call;
    int AutoAction;
    int  isDuplex;
    BOOL isOutgoing;

    CurrentChannel = (ChannelInfo *)haChan;
    Call = CurrentChannel->call;

    CurrentChannel->state = (cmChannelState_e)state;

    if (CurrentChannel->scriptChannel == TRUE)
    {
        /* Advanced script handling */
        TclExecute("script:cb {cb:cm:EvChannelStateChanged 0x%p %s %s}",
                   CurrentChannel,
                   CMChannelState2String((cmChannelState_e)state),
                   CMChannelStateMode2String((cmChannelStateMode_e)stateMode));

        if (state == cmChannelStateIdle)
        {
            FreeChannel(CurrentChannel);
            if(Call->numOfChannels >= 0)
                /* Redisplay the list of channels */
                DisplayChannelList(Call, NULL);
        }
        return 0;
    }

    /* get channelid and direction and afterwards searching the channel in the channels array */
    cmChannelGetOrigin(hsChan, &isOutgoing);
    isDuplex = cmChannelIsDuplex(hsChan);

    switch (state)
    {
        case cmChannelStateOffering:
        {
            HCHAN           hsChanSS = NULL;
            HAPPCHAN        haChanSS = NULL;
                
            CurrentChannel->channelId = cmChannelSessionId(hsChan);
            
            cmChannelSameSession(hsChan, &haChanSS, &hsChanSS);
            /* Check to see if this channel has another of the same session, which was not already
              connected to it in cmEvCallNewChannel, and which has an RTP session */
            if((hsChanSS) && (Call->action == RTP_Replay) &&
                (CurrentChannel->rtpSession != ((ChannelInfo *) haChanSS)->rtpSession) &&
                (((ChannelInfo *) haChanSS)->rtpSession >= 0))
            {
                if (CurrentChannel->rtpSession >= 0)
                {
                    /* We've got an open session already - add it as a second channel to that session.
                       This happens when we're the side that initiated the OLC, which never happens for
                       the test application with real media. */
                    RTP_TestClose(CurrentChannel->rtpSession);
                }
                CurrentChannel->rtpSession = ((ChannelInfo *) haChanSS)->rtpSession;
				RTP_TestSetAction(CurrentChannel->rtpSession, Call->action);
                RTP_TestOpenSecondChannel(CurrentChannel->rtpSession);
            }
            
            /* Make sure we open the incoming channel window */
            AutoAction = atoi(TclGetVariable("app(options,autoAccept)"));
            if (AutoAction == 1)
            {
                /* Automatically accept the channel */
                cmChannelSetAddress(CurrentChannel->hChan,0,(UINT16)(RTP_TestGetLocalPort(CurrentChannel->rtpSession)));
                cmChannelSetRTCPAddress(CurrentChannel->hChan,0,(UINT16)(RTP_TestGetLocalPort(CurrentChannel->rtpSession) + 1));
                cmChannelAnswer(CurrentChannel->hChan);

                /* Mimic channel opening if we have to */
                AutoMimic(CurrentChannel);
            }
            else if (atoi(TclGetVariable("app(options,popUp)")) != 0)
            {
                /* Manually open the channel (ask user to accept it) */
                TclExecute("Window open .inchan");
                TclExecute(".inchan.callInfo configure -text {0x%p}",
                           CurrentChannel);
                TclExecute("Call:addWindowToList 0x%p .inchan", Call);

                /* Display channel information inside the listbox */
                DisplayChannelInfo(CurrentChannel, (char *)".inchan.chanInfo.txt");
            }
            break;
        }

        case cmChannelStateConnected:
            {
                /* Update the channel ID now that the channel is connected */
                CurrentChannel->channelId = cmChannelSessionId(hsChan);
                /* terminate the inchan window */
                TclExecute("inchan:terminate {0x%p}", CurrentChannel);

                if (CurrentChannel->isOutgoing)
                {
                    /* todo: Put RTP information here using a timer of 4/5 seconds */
                }
                break;
            }

        case cmChannelStateDisconnected:
            {
                break;
            }

        case cmChannelStateDialtone:
            {
                break;
            }

        case cmChannelStateRingBack:
            {
                break;
            }

        case cmChannelStateIdle:
        {
            /* terminate the dropchan window */
            TclExecute("inchan:terminate {0x%p}", CurrentChannel);
            /* free and close the channel */
            FreeChannel(CurrentChannel);
            break;
        }

        default:
        {
            break;
        }
    }
    /* Redisplay the list of channels */
    DisplayChannelList(Call, NULL);
    return 0;
}
Ejemplo n.º 18
0
void NetManager::ProcNewConnection()
{
	std::deque<NetChannelBase*> tmpQueue;
	
	{
		AUTOLOCK( m_mutexChannels);
		tmpQueue.swap(m_newSocketQueue);
	}

	while (!tmpQueue.empty())
	{
		NetChannelBase* pChannel = tmpQueue.front();
		assert( pChannel);

		int32 nSocketID = AddChannel( pChannel );
		if(nSocketID < 0)
		{
			// channel list is full , can't add another one
			MyLog::warning("NetManager::ProcNewConnection() socket list is full");
			break;
		}

		pChannel->StartChannel();
		OnChannelStart( pChannel );

		if(pChannel->m_bCreateByAccept)
		{
			if(m_AcceptCallBack)
				(*m_AcceptCallBack)(nSocketID);
		}
		else
		{
			if(m_ConnectCallBack)
				(*m_ConnectCallBack)(nSocketID);
		}

		tmpQueue.pop_front();

		if(pChannel->m_hProcNewNotify.IsValid())
			pChannel->m_hProcNewNotify.SetEvent();

		FreeChannel( pChannel );
	}

	// failed process
	while (!tmpQueue.empty())
	{
		NetChannelBase* pChannel = tmpQueue.front();
		tmpQueue.pop_front();
		assert(pChannel);

		if(pChannel->m_hProcNewNotify.IsValid())
		{
			AUTOLOCK(m_mutexChannels);
			m_newSocketQueue.push_back( pChannel );
		}
		else
		{
			SockAddr addr;
			pChannel->GetAddr( addr );
			MyLog::warning("NetManager::ProcNewConnection() drop new socket (%s:%d)", addr.GetIP().c_str(), addr.GetPort());
			FreeChannel(pChannel);
		}
	}
}