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回调无法调用
相关推荐
Univin1 小时前
C++(10.5)
开发语言·c++·算法
AA陈超1 小时前
虚幻引擎UE5专用服务器游戏开发-33 在上半身播放组合蒙太奇
c++·游戏·ue5·游戏引擎·虚幻
qq_428639612 小时前
虚幻基础:组件间的联动方式
c++·算法·虚幻
怎么没有名字注册了啊2 小时前
C++后台进程
java·c++·算法
slim~3 小时前
CLion实现ini 解析器设计与实现
c++·后端·clion
AA陈超4 小时前
虚幻引擎5 GAS开发俯视角RPG游戏 P05-05 游戏效果委托
c++·游戏·ue5·游戏引擎·虚幻
杨小码不BUG4 小时前
Davor的北极探险资金筹集:数学建模与算法优化(洛谷P4956)
c++·算法·数学建模·信奥赛·csp-j/s
mit6.8244 小时前
10.5 数位dp
c++·算法
初圣魔门首席弟子4 小时前
C++ STL 向量(vector)学习笔记:从基础到实战
c++·笔记·学习
青草地溪水旁5 小时前
Visual Studio Code中launch.json深度解析:C++调试的艺术
c++·vscode·json