title: GStreamer IOS : Running audio and video pipeline togethere get a bad access crash
body: <p>I have integrated GStreamer library 1.12.2 version in my ios application that supports audio and video streaming through raspberry pi device . Functionality that has been implemeted is as follows:
  1. Video streaming has to run all time in my application once the application is launched and on main screen.
  2. There are one button one  for receiving audio along with video streaming that shoud run seamlessly
   For which i created two  pipelines one for video and one for audio from raspberry pi device to my ios application.</p>
  
  <p>I have facing a crash as Attempted to dereference garbage pointer when toggling audio i.e play and pause audio or keeping my app still for couple of minutes it gets a crash . </p>
  
  <p>I am attaching some code which i used to create pipeline for video and audio.
  /* for video and audio raspberry pi  to ios app */</p>
  
  <pre><code>-(void) app_function
  {
      GstBus *bus;
      GSource *bus_source;
      GError *error = NULL;
  
      GstBus *bus1;
      GSource *bus_source1;
  
      GST_DEBUG ("Creating pipeline");
  
      /* Create our own GLib Main Context and make it the default one */
      context = g_main_context_new ();
      g_main_context_push_thread_default(context);
  
      // du to app recieve working fine
      audiopipeline = gst_parse_launch("udpsrc port=5001 caps=\"audio/x-raw, rate = 8000, format=S16LE, channels=2\"  !audioconvert ! audioresample ! autoaudiosink sync=false", &amp;error);
      if (error) {
          gchar *message = g_strdup_printf("Unable to build audio pipeline: %s", error-&gt;message);
          g_clear_error (&amp;error);
          [self setUIMessage:message];
          g_free (message);
          return;
      }
      error = NULL;
      pipeline =  gst_parse_launch("udpsrc port=5000 ! application/x-rtp, payload=96 ! rtph264depay ! avdec_h264 ! autovideosink sync=false text-overlay=false", &amp;error);
      if (error) {
          gchar *message = g_strdup_printf("Unable to build video pipeline: %s", error-&gt;message);
          g_clear_error (&amp;error);
          [self setUIMessage:message];
          g_free (message);
          return;
      }
  
      /**************** for video  *****************/
      /* Set the pipeline to READY, so it can already accept a window handle */
      gst_element_set_state(pipeline, GST_STATE_READY);
  
      video_sink = gst_bin_get_by_interface(GST_BIN(pipeline), GST_TYPE_VIDEO_OVERLAY);
      if (!video_sink) {
          GST_ERROR ("Could not retrieve video sink");
          return;
      }
      gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(video_sink), (guintptr) (id) ui_video_view);
  
      /* Instruct the bus to emit signals for each received message, and connect to the interesting signals */
      bus = gst_element_get_bus (pipeline);
      bus_source = gst_bus_create_watch (bus);
      g_source_set_callback (bus_source, (GSourceFunc) gst_bus_async_signal_func, NULL, NULL);
      g_source_attach (bus_source, context);
      g_source_unref (bus_source);
      g_signal_connect (G_OBJECT (bus), "message::error", (GCallback)error_cb, (__bridge void *)self);
      g_signal_connect (G_OBJECT (bus), "message::state-changed", (GCallback)state_changed_cb, (__bridge void *)self);
      gst_object_unref (bus);
  
  
      // for audio
      /**************** for audio **************/
      bus1 = gst_element_get_bus (audiopipeline);
      bus_source1 = gst_bus_create_watch (bus1);
      g_source_set_callback (bus_source1, (GSourceFunc) gst_bus_async_signal_func, NULL, NULL);
      g_source_attach (bus_source1, context);
      g_source_unref (bus_source1);
      g_signal_connect (G_OBJECT (bus1), "message::error", (GCallback)error_cb_audio, (__bridge void *)self);
      g_signal_connect (G_OBJECT (bus1), "message::state-changed", (GCallback)state_changed_cb_audio, (__bridge void *)self);
      gst_object_unref (bus1);
  
      //Create a GLib Main Loop and set it to run 
      GST_DEBUG ("Entering main loop...");
      main_loop = g_main_loop_new (context, FALSE);
      [self check_initialization_complete];
      g_main_loop_run (main_loop);
      GST_DEBUG ("Exited main loop");
      g_main_loop_unref (main_loop);
      main_loop = NULL;
  
  
      // Free resources 
      g_main_context_pop_thread_default(context);
      g_main_context_unref (context);
      gst_element_set_state (pipeline, GST_STATE_NULL);
      gst_object_unref (pipeline);
  
      gst_element_set_state (audiopipeline, GST_STATE_NULL);
      gst_object_unref (audiopipeline);
  
      return;
  }
  </code></pre>