Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void GstProducerControl::start(const QUrl &destination)
- {
- emit stateChanged(GstMediaObject::ObjectState::StartingState);
- if (!destination.isValid()) {
- stop(GstMediaObject::ObjectError::InvalidSourceError,
- tr("Invalid destination URL resource"));
- return;
- } else if (destination.scheme() != QLatin1String("udp")) {
- stop(GstMediaObject::ObjectError::InvalidSourceError,
- tr("Invalid destination URL scheme"));
- return;
- }
- m_appsrc = ::gst_element_factory_make("appsrc", nullptr);
- ::g_object_set(G_OBJECT(m_appsrc),
- "stream-type", GST_APP_STREAM_TYPE_STREAM,
- "is-live", true,
- "format", GST_FORMAT_TIME,
- nullptr);
- const auto videoconvert = ::gst_element_factory_make("videoconvert", nullptr);
- const auto encname = detectBestEncoderFactoryName("video/x-h264").toUtf8();
- const auto videoenc = ::gst_element_factory_make(encname.constData(), nullptr);
- if (!videoenc) {
- qCCritical(gstProducerControl) << "Unable to create videoenc element";
- }
- if (encname == "x264enc") {
- ::gst_util_set_object_arg(G_OBJECT(videoenc), "tune", "zerolatency");
- ::g_object_set(G_OBJECT(videoenc),
- "key-int-max", 10,
- nullptr);
- }
- const auto videofilter = ::gst_element_factory_make("capsfilter", nullptr);
- const auto videofiltercaps = ::gst_caps_new_simple(
- "video/x-h264",
- "profile", G_TYPE_STRING, "main",
- nullptr);
- ::g_object_set(G_OBJECT(videofilter),
- "caps", videofiltercaps,
- nullptr);
- const auto pay = ::gst_element_factory_make("rtph264pay", nullptr);
- ::g_object_set(G_OBJECT(pay),
- "config-interval", 1,
- nullptr);
- const auto udpsink = ::gst_element_factory_make("udpsink", nullptr);
- const auto host = destination.host().toLocal8Bit();
- const auto port = destination.port();
- ::g_object_set(G_OBJECT(udpsink),
- "host", host.constData(),
- "port", port,
- nullptr);
- m_pipeline = ::gst_pipeline_new("pipeline");
- const auto bus = ::gst_pipeline_get_bus(GST_PIPELINE(m_pipeline));
- ::gst_bus_set_sync_handler(bus, GstProducerControl::processBusMessage,
- this, nullptr);
- ::gst_object_unref(bus);
- if (!m_appsrc || !videoconvert || !videoenc || !videofilter
- || !pay || !udpsink) {
- qCCritical(gstProducerControl) << "Unable to create one of pipeline element";
- }
- ::gst_bin_add_many(GST_BIN(m_pipeline),
- m_appsrc,
- videoconvert,
- videoenc,
- videofilter,
- pay,
- udpsink,
- nullptr);
- const auto result = ::gst_element_link_many(m_appsrc,
- videoconvert,
- videoenc,
- videofilter,
- pay,
- udpsink,
- nullptr);
- if (!result) {
- qCCritical(gstProducerControl) << "Pipeline linking failed";
- stop(GstMediaObject::ObjectError::ResourceError,
- tr("Unable to link the pipeline"));
- return;
- } else {
- const auto status = ::gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
- if (status == GST_STATE_CHANGE_FAILURE) {
- qCCritical(gstProducerControl) << "Pipeline starting failed";
- stop(GstMediaObject::ObjectError::ResourceError,
- tr("Unable to start pipeline"));
- return;
- } else {
- m_timestamp.start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement