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回调无法调用
相关推荐
老歌老听老掉牙10 分钟前
优化样条曲线拟合参数解决三维建模中的截面连续性问题
c++·opencascade·样条曲线
散峰而望26 分钟前
【算法竞赛】栈和 stack
开发语言·数据结构·c++·算法·leetcode·github·推荐算法
不爱吃糖的程序媛1 小时前
OpenHarmony 通用C/C++三方库 标准化鸿蒙化适配
c语言·c++·harmonyos
fqbqrr1 小时前
2601C++,导出控制
c++
陌路201 小时前
日志系统7--异步日志的实现
c++
程序员Jared1 小时前
C++11—this_thread
c++·this_thread
mjhcsp1 小时前
C++ Manacher 算法:原理、实现与应用全解析
java·c++·算法·manacher 算法
Z1Jxxx2 小时前
0和1的个数
数据结构·c++·算法
朔北之忘 Clancy2 小时前
2020 年 6 月青少年软编等考 C 语言二级真题解析
c语言·开发语言·c++·学习·青少年编程·题解·尺取法
消失的旧时光-19432 小时前
C++ 中的 auto 与 nullptr:不是语法糖,而是类型系统升级
开发语言·c++