Video chat Qt-based Application using Webrtc

1,007 views
Skip to first unread message

Đỗ Minh Tuấn

unread,
Apr 18, 2019, 2:32:33 AM4/18/19
to discuss-webrtc
Hi,

I am currently building a Qt application for video chat. I have audited the example in peerconnection_client, and followed its coding. However I have a trouble when rendering video. Here is my initialization before calling:


void Backend::initLocalInfo()
{
    m_pcfIface = webrtc::CreatePeerConnectionFactory(
                network_thread.get(), worker_thread.get(), signaling_thread.get(), nullptr,
                webrtc::CreateBuiltinAudioEncoderFactory(),
                webrtc::CreateBuiltinAudioDecoderFactory(),
                webrtc::CreateBuiltinVideoEncoderFactory(),
                webrtc::CreateBuiltinVideoDecoderFactory(),
                nullptr, nullptr);

    if (!m_pcfIface.get()) {
        qDebug() << "Failed to create peer connection factory";
        return;
    }

    webrtc::PeerConnectionInterface::IceServer server;
    webrtc::PeerConnectionInterface::RTCConfiguration config;

    config.sdp_semantics = webrtc::SdpSemantics::kPlanB;
    config.enable_dtls_srtp = true;
    server.uri = "stun:stun.l.google.com:19302";
    config.servers.push_back(server);

    pTestConnObserver = new MyConnectionObserver();
    m_peerConnection = m_pcfIface->CreatePeerConnection(config, nullptr, nullptr, pTestConnObserver);

    if (!m_peerConnection->GetSenders().empty())
        return;

    rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(m_pcfIface->CreateAudioTrack("audio_label", m_pcfIface->CreateAudioSource(cricket::AudioOptions())));

    rtc::scoped_refptr<CaptureTrackSource> video_device = CaptureTrackSource::Create();
    if (video_device) {
        rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(m_pcfIface->CreateVideoTrack("video_label", video_device));

        auto result_or_error = m_peerConnection->AddTrack(video_track, {"stream_id"});
        if (!result_or_error.ok()) {
            qDebug() << "Failed to add video track to PeerConnection: "<< result_or_error.error().message();
        }
        local_renderer_.reset(new VideoRenderer(vc, video_track));                                                      //  <----- CRASHED!!!
    } else {
        qDebug() << "Failed to craete CaptureTrackSource";
    }

}

But it was crashed when I created a new instance VideoRenderer(...), then I went deep down into the function and saw that it was crashed when the class call AddOrUpdateSink(...). Here is my implementation of VideoRenderer():

VideoRenderer::VideoRenderer(QObject *vc, webrtc::VideoTrackInterface* track_to_render):
    width_(0), height_(0), vc(vc), rendered_track_(track_to_render)
{
    rendered_track_->AddOrUpdateSink(this, rtc::VideoSinkWants());
}

VideoRenderer::~VideoRenderer()
{
    rendered_track_->RemoveSink(this);
}

void VideoRenderer::setSize(int width, int height)
{
    mutex_setSize.lock();
    if (width_ == width && height_ == height) {
      return;
    }

    width_ = width;
    height_ = height;
    image_.reset(new uint8_t[width * height * 4]);
    mutex_setSize.unlock();
}

void VideoRenderer::OnFrame(const webrtc::VideoFrame &video_frame)
{
    mutex_onFrame.lock();
    rtc::scoped_refptr<webrtc::I420BufferInterface> buffer(
                video_frame.video_frame_buffer()->ToI420());
    if (video_frame.rotation() != webrtc::kVideoRotation_0) {
        buffer = webrtc::I420Buffer::Rotate(*buffer, video_frame.rotation());
    }
    setSize(buffer->width(), buffer->height());

    libyuv::I420ToABGR(buffer->DataY(), buffer->StrideY(), buffer->DataU(),
                       buffer->StrideU(), buffer->DataV(), buffer->StrideV(),
                       image_.get(), width_ * 4, buffer->width(),
                       buffer->height());
    VideoChat *tmp = static_cast<VideoChat *>(vc);                             // VideoChat is my main window, and it will render based on the data of image
    mutex_onFrame.unlock();
    tmp->StreamVideo();
}


Did I miss some important initialization here? I also attached the screenshot when it was crashed, so please help me

sigsev.png

Hieu than hieu

unread,
Apr 18, 2019, 3:23:51 AM4/18/19
to discuss...@googlegroups.com

Dear Tuấn,
Mình cũng đang phát triển cái này, mình build được server apprtc rồi, liệu chúng ta có thể trao đổi 1 chút không?

P/S Skype của mình: nobjta_9x_tq
Best Regards.

 

Sent from Mail for Windows 10

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/3887adc0-23b4-4f04-a5de-56f17360014d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

sigsev.png
Reply all
Reply to author
Forward
0 new messages