I am working on Pause and Play Feature on a videopipeline. I am facing issue after pausing the video and playing i am unable to stream the captured video to display

#include <gst/gst.h>
#include
#include <stdio.h>
#ifdef APPLE
#include <TargetConditionals.h>
#endif

using namespace std;

struct CustomData
{

GstElement *source;
GstElement *pipeline;
GstElement *sink;
GstElement *convertor;
GMainLoop *loop;

gboolean playing;

};

/* Process keyboard input */
static gboolean handle_keyboard (GIOChannel * source, GIOCondition cond, CustomData * data)
{
gchar *str = NULL;

if (g_io_channel_read_line (source, &str, NULL, NULL, NULL) != G_IO_STATUS_NORMAL)
{
return TRUE;
}

switch (g_ascii_tolower (str[0]))
{
case ‘p’:
data->playing = !data->playing;
gst_element_set_state (data->pipeline,data->playing ? GST_STATE_PLAYING : GST_STATE_PAUSED);
g_print (“Setting state to %s\n”, data->playing ? “PLAYING” : “PAUSE”);
break;
case ‘q’:
g_main_loop_quit (data->loop);
break;
default:
break;
}

g_free (str);

return TRUE;
}

int main(int arg, char *argv)
{

CustomData data{};
cout << “GStreammer Intiated” << endl;

GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
gboolean terminate = FALSE;
GIOChannel *io_stdin;

gst_init(&arg, &argv);

/* Print usage map */
g_print (“USAGE: Choose one of the following options, then press enter:\n”
" ‘P’ to toggle between PAUSE and PLAY\n"
" ‘Q’ to quit\n");

data.source = gst_element_factory_make(“autovideosrc”,“source”);
data.convertor = gst_element_factory_make(“videoconvert”,“csp”);
data.sink = gst_element_factory_make(“autovideosink”, “sink”);

data.pipeline = gst_pipeline_new(“gstreamer-pipeline”);

if (!data.pipeline || !data.source || !data.convertor || !data.sink)
{
g_printerr(“Not elements could be created\n”);
}

gst_bin_add_many(GST_BIN(data.pipeline), data.source, data.convertor , data.sink, NULL);

if (!gst_element_link_many(data.source, data.convertor, data.sink,NULL))
{
g_printerr(“Elements could not be linked”);
gst_object_unref(data.pipeline);
return -1;
}

/* Add a keyboard watch so we get notified of keystrokes */
#ifdef G_OS_WIN32
io_stdin = g_io_channel_win32_new_fd (fileno (stdin));
#else
io_stdin = g_io_channel_unix_new (fileno (stdin));
#endif
g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc) handle_keyboard, &data);

/* Start playing */
ret = gst_element_set_state(data.pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE)
{
g_printerr(“unable to set the pipeline to playing state”);
gst_object_unref(data.pipeline);
return -1;
}

data.playing = TRUE;

/* Create a GLib Main Loop and set it to run */
data.loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (data.loop);

/* Listen to the bus */
bus = gst_element_get_bus (data.pipeline);

msg = gst_bus_timed_pop_filtered (bus, 100 * GST_MSECOND, static_cast(GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS));

/* Parse message */
if (msg != NULL)
{
GError *err;
gchar *debug_info;

  switch (GST_MESSAGE_TYPE (msg)) 
  {
    case GST_MESSAGE_ERROR:
      gst_message_parse_error (msg, &err, &debug_info);
      g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
      g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
      g_clear_error (&err);
      g_free (debug_info);
      terminate = TRUE;
      break;
    case GST_MESSAGE_EOS:
      g_print ("End-Of-Stream reached.\n");
      terminate = TRUE;
      break;
    case GST_MESSAGE_STATE_CHANGED:
      /* We are only interested in state-changed messages from the pipeline */
      if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data.pipeline)) {
        GstState old_state, new_state, pending_state;
        gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
        g_print ("Pipeline state changed from %s to %s:\n",
            gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));
      }
      break;
    default:
      /* We should not reach here */
      g_printerr ("Unexpected message received.\n");
      break;
  }
  gst_message_unref (msg);

}

/* Free resources */
g_main_loop_unref (data.loop);
g_print(“GMainLoop has been unreferenced and resources freed.\n”);
gst_object_unref (bus);
g_io_channel_unref (io_stdin);
gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
gst_object_unref (data.pipeline);
return 0;
}