static PVOID discoverMediaSource()

in source/src/AppRtspSrc.c [783:829]


static PVOID discoverMediaSource(PVOID userData)
{
    STATUS retStatus = STATUS_SUCCESS;
    PRtspSrcContext pRtspSrcContext = (PRtspSrcContext) userData;
    PCodecConfiguration pGstConfiguration = &pRtspSrcContext->codecConfiguration;
    GstElement* pipeline = NULL;
    GstBus* bus = NULL;

    DLOGD("discovering the meida source");
    pGstConfiguration->codecStatus = STATUS_SUCCESS;
    CHK((pipeline = app_gst_pipeline_new("kinesis-rtsp-probe")) != NULL, STATUS_MEDIA_NULL_ARG);
    pGstConfiguration->pipeline = pipeline;

    CHK_STATUS((initGstRtspSrc(pRtspSrcContext, pipeline, TRUE)));

    // Instruct the bus to emit signals for each received message, and connect to the interesting signals
    CHK((bus = app_gst_element_get_bus(pipeline)) != NULL, STATUS_MEDIA_MISSING_BUS);
    app_gst_bus_add_signal_watch(bus);
    app_g_signal_connect(APP_G_OBJECT(bus), GST_SIGNAL_CALLBACK_MSG_ERROR, G_CALLBACK(onMsgErrorFromBus), pRtspSrcContext);
    app_g_signal_connect(APP_G_OBJECT(bus), GST_SIGNAL_CALLBACK_MSG_EOS, G_CALLBACK(onMsgEosFromBus), pRtspSrcContext);

    // start streaming
    CHK(app_gst_element_set_state(pipeline, GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE, STATUS_MEDIA_PLAY);

    pGstConfiguration->mainLoop = app_g_main_loop_new(NULL, FALSE);
    // start running the main loop, and it is blocking call.
    app_g_main_loop_run(pGstConfiguration->mainLoop);

CleanUp:

    /* free resources */
    DLOGD("release the media source");
    if (bus != NULL) {
        app_gst_bus_remove_signal_watch(bus);
        app_gst_object_unref(bus);
    }
    if (pipeline != NULL) {
        app_gst_element_set_state(pipeline, GST_STATE_NULL);
        app_gst_object_unref(pipeline);
        pGstConfiguration->pipeline = NULL;
    }
    if (pGstConfiguration->mainLoop != NULL) {
        app_g_main_loop_unref(pGstConfiguration->mainLoop);
        pGstConfiguration->mainLoop = NULL;
    }
    return (PVOID)(ULONG_PTR) retStatus;
}