GST-RTSP-Server + GST Pipelines (not in string/launch sintax)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

GST-RTSP-Server + GST Pipelines (not in string/launch sintax)

Mariano Koremblum
Hi Everyone, I am trying to combine the "basic GST hand-made pipelines" with
gst-rtsp-server. I have to say that I am new in GST, just started using it
two weeks ago, and now I am struggling with this "advanced" problem.

The real struggle is, I need to have individual access to each element of
the pipelines for handling its properties and callbacks. I know this is
possible if the pipeline is handmade element by element and the linking then
and all that stuff. Probably it is also possible using the good old
gst_parse_launch() and then somehow scavenging the pipeline. Doesn't really
mater. Once I have the pipeline and all the handling methods for them and
its elements, I need to attach this pipelines to the gst-rtsp-server
somehow. The problem when I use the gst_rtsp_media_factory_set_launch() is
that I lose all this capabilities of handling individually each element of
each pipeline.

I have run into some similar questions but weren't very clarifying or maybe
is it that I am not really used to this library yet.

If someone can help me, I promise to somehow make a good simple example for
future generations that may have the same problem and upload it for
everyone.

Thanks in advance to you all :)



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: GST-RTSP-Server + GST Pipelines (not in string/launch sintax)

Michael Gruner
Hi Mariano

What you can do is subclass GstRTSPMediaFactory and implement the “create_pipeline” virtual method. The default implementation is to create an empty pipeline and have the media “take” it. Here’s the relevant code:

https://github.com/GStreamer/gst-rtsp-server/blob/5d8abd9bfd3bbf8ae31b0c8970bf1338dc56a593/gst/rtsp-server/rtsp-media-factory.c#L1736

In your implementation, besides doing this, you’d save a reference to this pipeline, which will be eventually filled with the required elements. Later on, you can grab references to these elements by using gst_bin_get_by_name. You may want to attach to the “prepared” signal to be notified when the pipeline is ready to be used.

Hope it helps!

Michael
www.ridgerun.com

> On May 15, 2020, at 12:59 PM, Mariano Koremblum <[hidden email]> wrote:
>
> Hi Everyone, I am trying to combine the "basic GST hand-made pipelines" with
> gst-rtsp-server. I have to say that I am new in GST, just started using it
> two weeks ago, and now I am struggling with this "advanced" problem.
>
> The real struggle is, I need to have individual access to each element of
> the pipelines for handling its properties and callbacks. I know this is
> possible if the pipeline is handmade element by element and the linking then
> and all that stuff. Probably it is also possible using the good old
> gst_parse_launch() and then somehow scavenging the pipeline. Doesn't really
> mater. Once I have the pipeline and all the handling methods for them and
> its elements, I need to attach this pipelines to the gst-rtsp-server
> somehow. The problem when I use the gst_rtsp_media_factory_set_launch() is
> that I lose all this capabilities of handling individually each element of
> each pipeline.
>
> I have run into some similar questions but weren't very clarifying or maybe
> is it that I am not really used to this library yet.
>
> If someone can help me, I promise to somehow make a good simple example for
> future generations that may have the same problem and upload it for
> everyone.
>
> Thanks in advance to you all :)
>
>
>
> --
> Sent from: http://gstreamer-devel.966125.n4.nabble.com/
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: GST-RTSP-Server + GST Pipelines (not in string/launch sintax)

Mariano Koremblum
This post was updated on .
Hi Michael! Thanks a lot, It helped me to solve the issue :). Later on I will
post the solution. Now I have another inconvenient. I can create "manually"
the pipelines by overriding this function, but now I want to have control of
the pipeline's bus, but can never catch the signals... Some of the code:

int main(void)
{
    GstRTSPMediaFactory *push = NULL;
    GstRTSPMediaFactory *pull = NULL;
    GstRTSPMountPoints *mounts = NULL;
    GstRTSPServer *server = NULL;

    int serviceID = -1;

    gst_init(NULL, NULL);

    push = g_object_new(TEST_TYPE_RTSP_MEDIA_FACTORY, NULL);
    pull = g_object_new(TEST_TYPE_RTSP_MEDIA_FACTORY, NULL);

    context = g_main_context_default();
    loop = g_main_loop_new(context, FALSE);

    server = gst_rtsp_server_new();

    gst_rtsp_server_set_address(server, IP);
    gst_rtsp_server_set_service(server, PORT);

    mounts = gst_rtsp_server_get_mount_points(server);

    gst_rtsp_media_factory_set_shared(push, TRUE);
    gst_rtsp_mount_points_add_factory(mounts, PLAY_MOUNT_POINT, push);

    gst_rtsp_media_factory_set_transport_mode(pull,
GST_RTSP_TRANSPORT_MODE_RECORD);
    gst_rtsp_media_factory_set_shared(pull, TRUE);
    gst_rtsp_mount_points_add_factory(mounts, RECORD_MOUNT_POINT, pull);

    serviceID = gst_rtsp_server_attach(server,
g_main_loop_get_context(loop));

    g_object_unref(mounts);

    g_main_loop_run(loop);

    return 0;
}

/*

.
.
.

*/

static GstElement *
custom_create_element(GstRTSPMediaFactory *factory, const GstRTSPUrl *url)
{
    pipe = (strPipeline *)malloc(sizeof(strPipeline));

    /* + + + + + Elements Linking and result checking + + + + + */
    pipe->pipeline = gst_pipeline_new("pipeline");               // Creates
Pipeline
    .
    .
    // MANY SUCCESSFULLY ELEMENTS CREATION, BIN ADDING AND LINKING
    .
    .

    pipe->bus = gst_pipeline_get_bus(GST_PIPELINE(pipe->pipeline));
    gst_bus_add_signal_watch_full (pipe->bus, G_PRIORITY_HIGH);
    g_signal_connect (pipe->bus, "message::error",(GCallback)
handle_bus, NULL);
    g_signal_connect (pipe->bus, "message::warning",(GCallback)
handle_bus, NULL);
    g_signal_connect (pipe->bus, "message::eos",(GCallback)
handle_bus, NULL);
    g_signal_connect (pipe->bus, "message::state-changed",(GCallback)
handle_bus, NULL);
}




/*

.
.
.

*/

static void
handle_bus_messages (GstBus * bus, GstMessage * message, GstPipeline *
pipeline)
{
    g_print("Just HI!\n\n");
}

/* +++++++++++++++++++  END OF CODE  +++++++++++++++++++++ */

This "custom_create_element" is asynchronously called when a client connects
to the server and is handled by gst/rtsp... the using of
"g_main_loop_get_context" was just an experiment, I get the same result just
using "NULL"...

So, the legend "Just HI!" never shows, and I can not think in any other
solution. Does anyone have any idea how to do it? The pipeline and server
works fine both, just can't access the bus' messages.



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: GST-RTSP-Server + GST Pipelines (not in string/launch sintax)

Mariano Koremblum
This post was updated on .
I have found out that the RTSP server automatically handles the bus... You
can see it here, in the function "gst_rtsp_media_prepare":

https://github.com/alessandrod/gst-rtsp-server/blob/master/gst/rtsp-server/rtsp-media.c

It uses a function "bus_message" that then calls the
"default_handle_message" function. This last one can be overridden, so I did
then the following:

#define TEST_TYPE_RTSP_MEDIA (test_rtsp_media_get_type())

typedef struct TestRTSPMediaClass    TestRTSPMediaClass;
typedef struct TestRTSPMedia         TestRTSPMedia;

struct TestRTSPMediaClass
{
    GstRTSPMediaClass parent;
};

struct TestRTSPMedia
{
    GstRTSPMedia parent;
};

static gboolean custom_handle_message (GstRTSPMedia * media, GstMessage *
message);

G_DEFINE_TYPE(TestRTSPMedia, test_rtsp_media, GST_TYPE_RTSP_MEDIA);

static void
test_rtsp_media_class_init(TestRTSPMediaClass *test_klass)
{
    GstRTSPMediaClass *klass = (GstRTSPMediaClass *)(test_klass);
    klass->handle_message = custom_handle_message;
}

static void
test_rtsp_media_init(TestRTSPMedia *media)
{
}

The thing now is that I am not really sure which and how to set an object as
"TEST_TYPE_RTSP_MEDIA" as I did before with the factory (myFactory =
g_object_new(TEST_TYPE_RTSP_MEDIA_FACTORY, NULL)) in order to get the bus
handler function overriden but keeping the things working as before.

Another thing I tried doing was to remove the watcher an then add the one I
wanted (on the factory signal "media-configure") but couldn't do it, mainly
because it uses a "source" to attach the signal and I am not really sure how
to get it, I always ran into messages like:

GStreamer-CRITICAL **: 18:45:25.964: gst_element_get_bus: assertion
'GST_IS_ELEMENT (element)' failed

GStreamer-CRITICAL **: 18:45:25.964: gst_bus_remove_watch: assertion
'GST_IS_BUS (bus)' failed

or

GStreamer-CRITICAL **: 18:53:19.372: gst_bus_create_watch: assertion
'bus->priv->poll != NULL' failed

GLib-CRITICAL **: 18:53:19.372: g_source_set_callback: assertion 'source !=
NULL' failed

or

(gst_rtsp_override.bin:9525): GLib-CRITICAL **: 18:52:12.500: Source ID 2 was not found when attempting to remove it

And never gets the watcher removed since I watched the debug logs and there
is always some entries on the "default_handle_message".

Sorry for the long post! I would really appreciate any help you can provide
me! Thanks a lot in advance! :)




--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel