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回调无法调用
相关推荐
wuminyu4 小时前
Kafka中sendfile与mmap实现机制解析
java·linux·c语言·jvm·c++
无小道9 小时前
C++——列表初始化
c++·列表初始化
blueSatchel9 小时前
c++action 编写(ros-humble)
c++·ros2
老赵的博客11 小时前
c++面试之从虚函数表到Rtti一次性讲清楚
c++·qt
傲世仙尊12 小时前
System V 进程间通信详解:共享内存、消息队列与信号量(CSDN博客)
linux·开发语言·c++
cvby12 小时前
C++11
开发语言·c++
6Hzlia12 小时前
【Classic 150 刷题计划】 LeetCode 26. 删除有序数组中的重复项 | C++ 快慢双指针经典模板
c++·算法·leetcode
夜不会漫长13 小时前
C++:类和对象(2)
java·javascript·c++
无小道13 小时前
C++ 中 `explicit` 关键字详解:彻底理解隐式类型转换
c++·explicit
蒸蒸yyyyzwd14 小时前
cpp 选手秋招学习笔记 day34
c++·八股