webrtc c++ native 获取local sdp流程

webrtc c++ native 获取local sdp流程

一、初始化线程

复制代码
    rtc::WinsockInitializer winsock_init;
    rtc::Win32SocketServer w32_ss;
    rtc::Win32Thread w32_thread(&w32_ss);
    rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);

二、创建peer_connection_factory

复制代码
    peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
        nullptr /* network_thread */, nullptr /* worker_thread */,
        nullptr /* signaling_thread */, nullptr /* default_adm */,
        webrtc::CreateBuiltinAudioEncoderFactory(),
        webrtc::CreateBuiltinAudioDecoderFactory(),
        webrtc::CreateBuiltinVideoEncoderFactory(),
        webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
        nullptr /* audio_processing */);

三、创建peer_connection

复制代码
    peer_connection_ = peer_connection_factory_->CreatePeerConnection(
        config, nullptr, nullptr, this);

四、创建audio track并add进入peer_connection

复制代码
    rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
        peer_connection_factory_->CreateAudioTrack(
            kAudioLabel, peer_connection_factory_->CreateAudioSource(
                cricket::AudioOptions())));

    auto result_or_error = peer_connection_->AddTrack(audio_track, { kStreamId });

五、创建video track并add进入peer_connection

复制代码
rtc::scoped_refptr<CapturerTrackSource> video_device = CapturerTrackSource::Create();
        rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track_(
            peer_connection_factory_->CreateVideoTrack(kVideoLabel, video_device));
        result_or_error = peer_connection_->AddTrack(video_track_, { kStreamId });

六、创建offer

复制代码
    peer_connection_->CreateOffer(
        conductor, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());

七、获取sdp

复制代码
    void OnSuccess(webrtc::SessionDescriptionInterface* desc) override {
        printf("xxxxxxxxxxxxxxxxxxxxxxx\n");
        std::string sdp;
        desc->ToString(&sdp);
    }

八、常见问题

  1. 初始化线程最好放到main函数(主线程中),否则OnSuccess回调无法调用
相关推荐
StudyWinter20 小时前
【c++】thread总结
开发语言·c++·算法
@小白鸽20 小时前
匿名函数lambda
c++·匿名函数
饕餮怪程序猿20 小时前
贪心算法经典应用:活动选择问题(C++实现)
c++·算法·贪心算法
暗然而日章20 小时前
C++基础:Stanford CS106L学习笔记 15 RAII&智能指针&构建C++工程
c++·笔记·学习
YYDS31420 小时前
次小生成树
c++·算法·深度优先·图论·lca最近公共祖先·次小生成树
xu_yule20 小时前
算法基础(区间DP)
数据结构·c++·算法·动态规划·区间dp
biter down20 小时前
C++ 交换排序算法:从基础冒泡到高效快排
c++·算法·排序算法
落羽的落羽20 小时前
【C++】深入浅出“图”——图的遍历与最小生成树算法
linux·服务器·c++·人工智能·算法·机器学习·深度优先
txp玩Linux20 小时前
rk3568上webrtc处理稳态噪声实践
算法·webrtc
Dream it possible!21 小时前
牛客周赛 Round 123_C_小红出对 (哈希表+哈希集合)
c++·哈希算法·散列表