PVOID runMediaSource()

in source/src/AppRtspSrc.c [973:1025]


PVOID runMediaSource(PVOID args)
{
    STATUS retStatus = STATUS_SUCCESS;
    PRtspSrcContext pRtspSrcContext = (PRtspSrcContext) args;
    PCodecConfiguration pGstConfiguration = NULL;
    /* init GStreamer */
    GstElement* pipeline = NULL;
    GstBus* bus = NULL;
    PVOID mainLoop = NULL;

    CHK(pRtspSrcContext != NULL, STATUS_MEDIA_NULL_ARG);
    pGstConfiguration = &pRtspSrcContext->codecConfiguration;
    pGstConfiguration->codecStatus = STATUS_SUCCESS;
    DLOGI("media source is starting");
    CHK((pipeline = app_gst_pipeline_new("kinesis-rtsp-pipeline")) != NULL, STATUS_MEDIA_MISSING_PIPELINE);
    pGstConfiguration->pipeline = pipeline;
    CHK_STATUS((initGstRtspSrc(pRtspSrcContext, pipeline, FALSE)));
    /* 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);

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

CleanUp:

    /* free resources */
    DLOGD("terminating 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 (mainLoop != NULL) {
        app_g_main_loop_unref(pGstConfiguration->mainLoop);
        pGstConfiguration->mainLoop = NULL;
    }
    return (PVOID)(ULONG_PTR) retStatus;
}