码迷,mamicode.com
首页 > Windows程序 > 详细

webRTC windows demo1(转)

时间:2016-08-04 13:23:36      阅读:414      评论:0      收藏:0      [点我收藏+]

标签:

    // setup video engine
    char cCameraName[MAX_CAMERA_NAME_LENGTH];
    memset(cCameraName, 0 , MAX_CAMERA_NAME_LENGTH);
    int iRet = RET_SUCCESS;
    CaptureCapability stCurSelectCapbility;

    char cCameraID[MAX_CAMERA_ID_LENGTH];
    memset(cCameraID, 0 , MAX_CAMERA_ID_LENGTH);
    int iCapdeviceCount = 0;
    
    iCapdeviceCount = m_VieCapture->NumberOfCaptureDevices();
    ASSERT(iCapdeviceCount > 0);

    for(int i = 0; i < iCapdeviceCount; i++)
    {
        iRet = m_VieCapture->GetCaptureDevice(i, cCameraName, MAX_CAMERA_NAME_LENGTH, cCameraID, MAX_CAMERA_ID_LENGTH);
        ASSERT(iRet == RET_SUCCESS);
        int iCapbilityCount = 0;
        iCapbilityCount = m_VieCapture->NumberOfCapabilities(cCameraID, MAX_CAMERA_ID_LENGTH);
        ASSERT(iCapbilityCount > 0);
        iRet = m_VieCapture->GetCaptureCapability(cCameraID, MAX_CAMERA_ID_LENGTH, iCapbilityCount - 1, stCurSelectCapbility);
        ASSERT(iRet == RET_SUCCESS);
    }
    int iCaptureId;
    iRet = m_VieCapture->AllocateCaptureDevice(cCameraID, MAX_CAMERA_ID_LENGTH, iCaptureId);
    ASSERT(iRet == RET_SUCCESS);

    iRet = ViECreateWindow(m_CapRenderHwnd, 500,200, 500, 500,_T("Local Render"));
    ASSERT(iRet == RET_SUCCESS);
    
    iRet = ViECreateWindow(m_DecRenderHwnd, 500, 700, 500,500, _T("Remote Render"));
    ASSERT(iRet == RET_SUCCESS);
 
    iRet = m_VieRender->AddRenderer(iCaptureId,(void*)m_CapRenderHwnd, 0, 0.0,0.0,1.0,1.0);
    ASSERT(iRet == RET_SUCCESS);
    
    iRet = m_VieCapture->StartCapture(iCaptureId, stCurSelectCapbility);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VieRender->StartRender(iCaptureId);

    VideoCodec videoCodec;
      
    int numOfVieCodecs = m_VieCodec->NumberOfCodecs();  
    bool bFindVideoCode = false;

    ASSERT(numOfVieCodecs > 0);
    for(int i=0; i<numOfVieCodecs;++i)  
    {  
        if(m_VieCodec->GetCodec(i,videoCodec)!=-1)  
        {  
            if(videoCodec.codecType == kVideoCodecVP8)  
            {
                bFindVideoCode = true;
                break;
            }
        }  
    } 
    ASSERT(bFindVideoCode);

    iRet = m_VieBase->CreateChannel(m_ChannelId);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VieRender->AddRenderer(m_ChannelId,(void*)m_DecRenderHwnd, 0, 0.0,0.0,1.0,1.0);
    ASSERT(iRet == RET_SUCCESS);
    iRet = m_VieRender->StartRender(m_ChannelId);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VieCodec->SetSendCodec(m_ChannelId, videoCodec);
    ASSERT(iRet == RET_SUCCESS);
    iRet = m_VieCodec->SetReceiveCodec(m_ChannelId, videoCodec);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VieCapture->ConnectCaptureDevice(iCaptureId, m_ChannelId);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VieRTP_RTCP->SetRTCPStatus(m_ChannelId, webrtc::kRtcpCompound_RFC4585);
    ASSERT(iRet == RET_SUCCESS);


    iRet = m_VieRTP_RTCP->SetKeyFrameRequestMethod(m_ChannelId, webrtc::kViEKeyFrameRequestPliRtcp);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VieRTP_RTCP->SetTMMBRStatus(m_ChannelId, true);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VieNetwork->SetSendDestination(m_ChannelId, "127.0.0.1", 11111, 11112);
    ASSERT(iRet == RET_SUCCESS);
    iRet = m_VieNetwork->SetLocalReceiver(m_ChannelId, 11111, 11112, "127.0.0.1");

    iRet = m_VieBase->StartSend(m_ChannelId);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VieBase->StartReceive(m_ChannelId);
    ASSERT(iRet == RET_SUCCESS);


    //setup voice engine
    CodecInst voiceCodec;  

    int numOfVoeCodecs = m_VoeCodec->NumOfCodecs();  
    bool bFindAudioCode = false;
    for(int i=0; i<numOfVoeCodecs;++i)  
    {  
        if(m_VoeCodec->GetCodec(i,voiceCodec)!=-1)  
        {  
            if(strncmp(voiceCodec.plname,"ISAC",4)==0)  
            {
                bFindAudioCode = true;
                break;  
            }
        }  
    }  
    ASSERT(bFindAudioCode);
    // define iSAC codec parameters  
    strcpy(voiceCodec.plname, "ISAC");  
    voiceCodec.plfreq   = 16000;    // iSAC宽带模式  
    voiceCodec.pltype   = 103;      // 默认动态负载类型  
    voiceCodec.pacsize  = 480;      // 480kbps,即使用30ms的packet size  
    voiceCodec.channels     = 1;        // 单声道  
    voiceCodec.rate     = -1;       // 信道自适应模式,单位bps 

    int iMaxAEChannelNum = m_VoeBase->MaxNumOfChannels();
    m_AudioChannel = m_VoeBase->CreateChannel();
    ASSERT((m_AudioChannel < iMaxAEChannelNum) && (m_AudioChannel >= 0));
    
    iRet = m_VoeCodec->SetSendCodec(m_AudioChannel, voiceCodec);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VoeRTCP->SetRTCPStatus(m_AudioChannel, true);
    ASSERT(iRet == RET_SUCCESS);
    
    iRet = m_VoeNetwork->SetSourceFilter(m_AudioChannel, 11113, 11114, "127.0.0.1");
    ASSERT(iRet == RET_SUCCESS);
    
    iRet = m_VoeBase->SetSendDestination(m_AudioChannel, 11113, "127.0.0.1", -1, 11114);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VoeBase->SetLocalReceiver(m_AudioChannel, 11113, 11114, "127.0.0.1");
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VoeBase->StartPlayout(m_AudioChannel);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VoeBase->StartReceive(m_AudioChannel);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VoeBase->StartSend(m_AudioChannel);
    ASSERT(iRet == RET_SUCCESS);

    NsModes mode(kNsDefault);//
    iRet = m_VoeApmPtr->SetRxNsStatus(m_AudioChannel, true, mode);
    ASSERT(iRet == RET_SUCCESS);

    AgcModes agcmode(kAgcDefault);
    iRet = m_VoeApmPtr->SetRxAgcStatus(m_AudioChannel, true, agcmode);
    ASSERT(iRet == RET_SUCCESS);

    iRet = m_VoeApmPtr->SetEcStatus(true, kEcAec);
    ASSERT(iRet == RET_SUCCESS);


原文转自 http://www.xuebuyuan.com/1719933.html

webRTC windows demo1(转)

标签:

原文地址:http://www.cnblogs.com/happykoukou/p/5736071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!