---
# System prepended metadata

title: PID-1189

---

## To connect to the `notify::caps` signal in GStreamer with a pipeline that uses `nvh264dec`

:::info
GStreamer is a framework for creating streaming media applications. It is a pipeline-based multimedia framework that links together a wide variety of media processing systems to complete complex workflows.  
:::

You can use the `g_signal_connect()` function to connect to the signal . The `notify::caps` signal is emitted when the caps of a pad have changed, which can happen when a new stream is detected or when the caps are renegotiated .

Here's an example of how to connect to the `notify::caps` signal in GStreamer with a pipeline that uses `nvh264dec`:

```c++
#include <gst/gst.h>

static void on_caps_changed(GstElement *element, GParamSpec *pspec, gpointer user_data) {
  // Handle caps changed event here
}

int main(int argc, char *argv[]) {
  GstElement *pipeline, *src, *decoder, *sink;
  GstBus *bus;
  GstMessage *msg;
  GMainLoop *loop;

  /* Initialize GStreamer */
  gst_init(&argc, &argv);
  loop = g_main_loop_new(NULL, FALSE);

  /* Create elements */
  pipeline = gst_pipeline_new("my-pipeline");
  src = gst_element_factory_make("filesrc", "src");
  decoder = gst_element_factory_make("nvh264dec", "decoder");
  sink = gst_element_factory_make("autovideosink", "sink");

  /* Add elements to the pipeline */
  gst_bin_add_many(GST_BIN(pipeline), src, decoder, sink, NULL);

  /* Link elements */
  if (!gst_element_link(src, decoder)) {
    g_error("Failed to link src and decoder");
  }
  if (!gst_element_link(decoder, sink)) {
    g_error("Failed to link decoder and sink");
  }

  /* Connect to the notify::caps signal */
  g_signal_connect(decoder, "notify::caps", G_CALLBACK(on_caps_changed), NULL);

  /* Start playing */
  gst_element_set_state(pipeline, GST_STATE_PLAYING);

  /* Wait for EOS or error */
  bus = gst_element_get_bus(pipeline);
  msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
  if (msg != NULL) {
    gst_message_unref(msg);
  }
  gst_object_unref(bus);
  gst_element_set_state(pipeline, GST_STATE_NULL);
  gst_object_unref(pipeline);

  return 0;
}
```

This program creates a GStreamer pipeline that reads from a file source, decodes the H.264 video using `nvh264dec`, and displays the video using `autovideosink`. It then connects to the `notify::caps` signal of the `nvh264dec` element using `g_signal_connect()`.


When the caps of the `nvh264dec` element change, the `on_caps_changed()` function is called. Finally, the program starts playing the pipeline and waits for the end of the stream or an error message.

