Webrtcbin create-offer not work

Hello everyone,

I’m trying to establish an SDP connection using webrtcbin in Node.js

When I call create-offer to create an SDP, I always got NULL

I refer to this article: Nirbheek’s Rantings: GStreamer has grown a WebRTC implementation

Min code snippet:

import * as gi from 'node-gtk';

(async () => {
  const Gst = gi.require('Gst');
  gi.startLoop();
  Gst.init(null);

  const pipeline = Gst.parseLaunch(`
    webrtcbin name=src
    src. ! queue ! decodebin ! videoconvert ! autovideosink
    src. ! queue ! decodebin ! audioconvert ! autoaudiosink
  `);

  const webrtcbin = pipeline.getByName('src');

  webrtcbin.on('on-negotiation-needed', () => {
    console.log('🌟 Negotiation needed');
    webrtcbin.emit(
      'create-offer',
      new Gst.Structure('NULL'),
      Gst.Promise.newWithChangeFunc((promise) => {
        promise.wait();
        const reply = promise.getReply();

        console.log('🌟 Sending SDP Offer');
        console.log(reply.toString());

        promise.interrupt();
      }),
    );
  });

  console.log('🚀 Setting pipeline state to PLAYING');
  pipeline.setState(Gst.State.PLAYING);

  await new Promise((resolve) => setTimeout(resolve, 20000));

  console.log('🛑 Setting pipeline state to NULL');
  pipeline.setState(Gst.State.NULL);
})();

Execution Results

🚀 Setting pipeline state to PLAYING
🌟 Negotiation needed
🌟 Sending SDP Offer
0:00:00.045074285 265189     0x33b9e990 WARN               structure gststructure.c:2099:priv_gst_structure_append_to_gstring: No value transform to serialize field 'offer' of type 'GstWebRTCSessionDescription'
application/x-gst-promise, offer=(GstWebRTCSessionDescription)NULL;
🛑 Setting pipeline state to NULL

Why I cannot create SDP offer?

Any insights or suggestions would be greatly appreciated! Thank you in advance. :pray:

In your log an offer has been created. The warning in the log says that the offer value in the structure could not be serialised to string and thus is produced as a NULL. This is not anything wrong and you would be able to retrieve the offer from the promise reply just fine.

1 Like

Yes, you are right.
When I try to reproduce in C
I found one thing
There are two functions in C to get the value in GstStructure
Most examples use gst_structure_get which does not have node-gtk bindings
Structure.getValue in node-gtk is bound to gst_structure_get_value in C

Use gst_structure_get in C to get the value in GstStructure

GstWebRTCSessionDescription* desc = nullptr;
gst_structure_get(reply, "offer", GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &desc, NULL);

Use gst_structure_get_value in C to get the value in GstStructure

const GValue* offer_wrap = gst_structure_get_value(reply, "offer");
const GstWebRTCSessionDescription* offer = g_value_get_boxed(offer_wrap);

Use Structure.getValue with node-gtk to get the value in Gst.Structure

const offer: GObject.Value = reply.getValue('offer');
const desc = offer.getBoxed<GstWebRTC.WebRTCSessionDescription>();

Thank you so much. I lost a lot of hair over this issue over the weekend.