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回调无法调用
相关推荐
QuantumStack44 分钟前
【C++ 真题】B2037 奇偶数判断
数据结构·c++·算法
结衣结衣.2 小时前
C++ 类和对象的初步介绍
java·开发语言·数据结构·c++·笔记·学习·算法
学习使我变快乐2 小时前
C++:静态成员
开发语言·c++
心怀花木2 小时前
【C++】多态
c++·多态
风清扬_jd2 小时前
Chromium 添加书签功能浅析c++
c++·chrome
吃椰子不吐壳2 小时前
c++类与对象二
c++
天天讯通3 小时前
网页WebRTC电话和软电话哪个好用?
webrtc
弱冠少年3 小时前
WebRTC入门
webrtc
zaim14 小时前
计算机的错误计算(一百一十四)
java·c++·python·rust·go·c·多项式
学习使我变快乐4 小时前
C++:const成员
开发语言·c++