void SipClient::Answer() { VideoCapture cap; if (cap.EnumDevices() <= 0) { m_sVideoSendPort.Empty(); // disable video send } super::Answer( WString2String(m_sAudioReceivePort).c_str(), WString2String(m_sAudioSendPort).c_str(), WString2String(m_sVideoReceivePort).c_str(), WString2String(m_sVideoSendPort).c_str() ); }
void SipClient::Dial() { VideoCapture cap; if (cap.EnumDevices() <= 0) { m_sVideoSendPort.Empty(); // disable video send } super::Invite( WString2String(m_sCalleeId).c_str(), WString2String(m_sProxyIp).c_str(), WString2String(m_sProxyPort).c_str(), WString2String(m_sAudioReceivePort).c_str(), WString2String(m_sAudioSendPort).c_str(), WString2String(m_sVideoReceivePort).c_str(), WString2String(m_sVideoSendPort).c_str(), "meeting" ); SPRINTF_S(dbg_str, "Local Audio Port: %s", super::GetAudioReceivePort().c_str()); DEBUG_INFO(dbg_str); }
void SipClient::OnCallStarted() { if ( IsWorking() ) { DEBUG_INFO("SipUADemo::OnCallStarted..."); #ifdef WIN32 WSADATA dat; int iWSRet = WSAStartup(MAKEWORD(2,2),&dat); ASSERT(iWSRet == 0); #endif // WIN32 { VideoCapture cap; if (cap.EnumDevices(false) > 0) m_bCaptureAudio = true; VIDEOSAMPLEINFO vsiLocal; VIDEOFORMATINFO vfiRemote; int nVideoDevices = cap.EnumDevices(); HRESULT hr = E_FAIL; if (nVideoDevices > 0) hr = cap.GetPreviewInfo(nVideoDevices-1, vsiLocal); SPRINTF_S(dbg_str, "Video device detecting: count:%d, HRES:%X" , nVideoDevices , hr); DEBUG_INFO(dbg_str); //if ( cap.EnumDevices() > 0 // && SUCCEEDED(cap.GetPreviewInfo(cap.EnumDevices()-1, vsiLocal)) ) if ( SUCCEEDED(hr) ) { m_bCaptureVideo = true; setVideoSampleInfo(vsiLocal); //TODO: support codecoder selection (for h264, etc.) vfiRemote = VIDEOFORMATINFO( CODEC_FORMAT, H264_WIDTH, H264_HEIGHT, vsiLocal.m_AvgTimePerFrame); setRemoteVideoFormatInfo(vfiRemote); } else { //TODO: support codecoder selection (for h264, etc.) vfiRemote = VIDEOFORMATINFO( CODEC_FORMAT, H264_WIDTH, H264_HEIGHT, FRAMES_PER_SECOND); setRemoteVideoFormatInfo(vfiRemote); } } #ifdef RTP_AUDIO_SENDRECV //Sender { if (m_bCaptureAudio) { SPRINTF_S(dbg_str, "Send Audio to [IP]=%s, [Port]=%s" //", [BasePort]=%s" , GetRemoteAudioIP().c_str() , GetRemoteAudioPort().c_str() //, GetAudioSendPort().c_str() ); DEBUG_INFO(dbg_str); uint16_t portbase,destport; uint32_t destip; std::string ipstr; int status; //ASSERT(GetAudioSendPort().length() > 0); portbase = 6666 + rand() % 6666;//atoi(GetAudioSendPort().c_str()); if (portbase % 2 == 1) portbase += 1; // destination IP address ipstr = GetRemoteAudioIP(); ASSERT(ipstr.length() > 0); destip = inet_addr(ipstr.c_str()); if (destip == INADDR_NONE) { DEBUG_INFO("Bad IP address specified"); DebugBreak(); } // The inet_addr function returns a value in network byte order, but // we need the IP address in host byte order, so we use a call to ntohl destip = ntohl(destip); // destination port ASSERT(GetRemoteAudioPort().length() > 0); destport = atoi(GetRemoteAudioPort().c_str()); // Now, we'll create a RTP session, set the destination, send some // packets and poll for incoming data. RTPUDPv4TransmissionParams transparams; RTPSessionParams sessparams; // IMPORTANT: The local timestamp unit MUST be set, otherwise // RTCP Sender Report info will be calculated wrong // In this case, we'll be sending 10 samples each second, so we'll // put the timestamp unit to (1.0/10.0) //sessparams.SetOwnTimestampUnit(1.0/8000.0); sessparams.SetOwnTimestampUnit(TIMESTAMP_INC_UNIT); //sessparams.SetAcceptOwnPackets(true); transparams.SetPortbase(portbase); m_pAudioSender = std::shared_ptr<AudioSendSession>( new AudioSendSession() ); status = m_pAudioSender->Create(sessparams,&transparams); checkRtpError(status); RTPIPv4Address addr(destip,destport); status = m_pAudioSender->AddDestination(addr); checkRtpError(status); #ifdef ENABLE_AUDIO_AEC ::SetMicQueue(m_pAudioSender->getMicQueue()); ::SetOutQueue(m_pAudioSender->getPackageQueue()); if (::GetUseAEC()) { ::SetRefQueue(m_pAudioSender->getRefQueue()); } else { ::SetRefQueue(NULL); } #endif//ENABLE_AUDIO_AEC m_pAudioSender->Start(); } else { #ifdef ENABLE_AUDIO_AEC if (::GetUseAEC()) { ::SetUseAEC(false); DEBUG_INFO(L"AEC DIS-ABLED: no device for recording."); } ::SetMicQueue(m_pAudioSender->getMicQueue()); ::SetOutQueue(m_pAudioSender->getPackageQueue()); ::SetRefQueue(NULL); #endif//ENABLE_AUDIO_AEC } } //Receiver { SPRINTF_S(dbg_str, "Receive Audio At [BasePort]=%s", GetAudioReceivePort().c_str()); DEBUG_INFO(dbg_str); // Setup receiver session uint16_t portbase; int status; RTPUDPv4TransmissionParams transparams; RTPSessionParams sessparams; portbase = atoi(GetAudioReceivePort().c_str()); //SPRINTF_S(dbg_str, "Port Base: %d", // portbase); //DEBUG_INFO(dbg_str); //TODO: portbase = atoi(GetAudioReceivePort().c_str()); // IMPORTANT: The local timestamp unit MUST be set, otherwise // RTCP Sender Report info will be calculated wrong // In this case, we'll be just use 8000 samples per second. //sessparams.SetOwnTimestampUnit(1.0/8000.0); sessparams.SetOwnTimestampUnit(TIMESTAMP_INC_UNIT); transparams.SetPortbase(portbase); m_pAudioReceiver = std::shared_ptr<AudioReceiveSession>( new AudioReceiveSession() ); status = m_pAudioReceiver->Create(sessparams, &transparams); checkRtpError(status); m_pAudioReceiver->Start(); } #endif//RTP_AUDIO_SENDRECV #ifdef RTP_VIDEO_SENDER //Sender { if (m_bCaptureVideo) { SPRINTF_S(dbg_str, "Send Video to [IP]=%s, [Port]=%s" //", [BasePort]=%s" , GetRemoteVideoIP().c_str() , GetRemoteVideoPort().c_str() //, GetVideoSendPort().c_str() ); DEBUG_INFO(dbg_str); uint16_t portbase,destport; uint32_t destip; std::string ipstr; int status; //TODO: portbase = 8888 + rand() % 8888;//atoi(GetVideoReceivePort().c_str()); if (portbase % 2 == 1) portbase += 1; // destination IP address //ASSERT(GetRemoteIP().length() > 0); //TODO: //ipstr = "127.0.0.1";//GetRemoteIP(); //ipstr = "10.148.206.29"; //ipstr = "10.148.206.93"; ipstr = GetRemoteVideoIP(); destip = inet_addr(ipstr.c_str()); if (destip == INADDR_NONE) { DEBUG_INFO("Bad IP address specified"); DebugBreak(); } // The inet_addr function returns a value in network byte order, but // we need the IP address in host byte order, so we use a call to ntohl destip = ntohl(destip); // destination port //ASSERT(GetRemotePort().length() > 0); //TODO: destport = atoi(GetRemoteVideoPort().c_str()); // Now, we'll create a RTP session, set the destination, send some // packets and poll for incoming data. RTPUDPv4TransmissionParams transparams; RTPSessionParams sessparams; // IMPORTANT: The local timestamp unit MUST be set, otherwise // RTCP Sender Report info will be calculated wrong // In this case, we'll be sending 10 samples each second, so we'll // put the timestamp unit to (1.0/10.0) //sessparams.SetOwnTimestampUnit(1.0/8000.0); sessparams.SetOwnTimestampUnit(TIMESTAMP_INC_UNIT); //sessparams.SetAcceptOwnPackets(true); transparams.SetPortbase(portbase); m_pVideoSender = std::shared_ptr<VideoSendSession>( new VideoSendSession() ); status = m_pVideoSender->Create(sessparams,&transparams); checkRtpError(status); RTPIPv4Address addr(destip,destport); status = m_pVideoSender->AddDestination(addr); checkRtpError(status); //VIDEOSAMPLEINFO vsiLocal; //if ( SUCCEEDED(cap.GetPreviewInfo(cap.EnumDevices()-1, vsiLocal)) ) //{ // setVideoSampleInfo(vsiLocal); // //TODO: support codecoder selection (for h264, etc.) // vfiRemote = VIDEOFORMATINFO( // CODEC_FORMAT, // H264_WIDTH, // H264_HEIGHT, // vsiLocal.m_AvgTimePerFrame); // setRemoteVideoFormatInfo(vfiRemote); ASSERT(m_wndPreview != NULL); m_pVideoSender->SetPreviewWindow(m_wndPreview); m_pVideoSender->Start(); //} } } #endif//RTP_VIDEO_SENDER #ifdef RTP_VIDEO_RECEIVER //Receiver { SPRINTF_S(dbg_str, "Receive Video At [BasePort]=%s" , GetVideoReceivePort().c_str()); DEBUG_INFO(dbg_str); // Setup receiver session uint16_t portbase; int status; RTPUDPv4TransmissionParams transparams; RTPSessionParams sessparams; //TODO: portbase = atoi(GetVideoReceivePort().c_str()); //SPRINTF_S(dbg_str, "Port Base: %d", // portbase); //DEBUG_INFO(dbg_str); // IMPORTANT: The local timestamp unit MUST be set, otherwise // RTCP Sender Report info will be calculated wrong // In this case, we'll be just use 8000 samples per second. //sessparams.SetOwnTimestampUnit(1.0/8000.0); sessparams.SetOwnTimestampUnit(TIMESTAMP_INC_UNIT); transparams.SetPortbase(portbase); m_pVideoReceiver = std::shared_ptr<VideoReceiveSession>( new VideoReceiveSession() ); status = m_pVideoReceiver->Create(sessparams, &transparams); checkRtpError(status); //VideoCapture cap; //if (cap.EnumDevices() > 0 ) //{ // // set remote video format already //} //else //{ // //TODO: support codecoder selection (for h264, etc.) // vfiRemote = VIDEOFORMATINFO( // CODEC_FORMAT, // H264_WIDTH, // H264_HEIGHT, // FRAMES_PER_SECOND); // setRemoteVideoFormatInfo(vfiRemote); //} ASSERT(m_wndRemote != NULL); m_pVideoReceiver->SetRemoteWindow(m_wndRemote); m_pVideoReceiver->Start(); } #endif//RTP_VIDEO_RECEIVER if (this->EnableEvents()) mListener->Callback(SIPUA_CALLSTARTED); DEBUG_INFO("SipUADemo::OnCallStarted DONE"); } }