GStreamer concepts 에서 추가적으로 설명한 개념

이상문·2021년 8월 19일
0

gstreamer

목록 보기
3/5

gstreamer의 기본 구성 블럭

원소 생성

/* Create the elements */
  source = gst_element_factory_make ("videotestsrc", "source");
  sink = gst_element_factory_make ("autovideosink", "sink");

첫번째 인자는 원소의 타입.
두번째 인자는 원소의 이름.
videotestsrc 는 비디오 패턴을 만들어내는 소스.
autovideosink 는 이미지를 받아서 윈도우 상에 표시해주는 싱크. 가장 적합한 것으로 자동 선택해준다.

파이프라인 생성

  /* Create the empty pipeline */
  pipeline = gst_pipeline_new ("test-pipeline");

파이프라인 조립

  /* Build the pipeline */
  gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
  if (gst_element_link (source, sink) != TRUE) {
    g_printerr ("Elements could not be linked.\n");
    gst_object_unref (pipeline);
    return -1;
  }

pipeline은 bin의 한 종류. 다른 원소를 담을 수 있는 원소.
gst_bin_add_many 는 가변 인자를 받으며, NULL이 나타날 때까지 원소를 추가.
실제 연결 작업은 gst_element_link 을 통해서 한다.
bin에 원소를 추가한 다음에 원소들을 연결해야 한다.

properties

모든 원소는 GObject의 한 종류이며, property를 읽어오거나(g_object_get) 설정(g_object_set)할 수 있다.

  /* Modify the source's properties */
  g_object_set (source, "pattern", 0, NULL);

videotestsrc 는 pattern이라는 property를 가지고 있으며, 값에 따라 패턴을 변경할 수 있다.
GstVideoTestSrcPattern
링크를 통해서 들어가보면 0~25까지 값을 지정할 수 있다.

에러 검사

  /* Start playing */
  ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
  if (ret == GST_STATE_CHANGE_FAILURE) {
    g_printerr ("Unable to set the pipeline to the playing state.\n");
    gst_object_unref (pipeline);
    return -1;
  }

GstMessage

GstMessage 는 어떤 정보라도 전달할 수 있도록 다양한 값들을 담을 수 있다.

 /* Wait until error or EOS */
  bus = gst_element_get_bus (pipeline);
  msg =
      gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
      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);
        break;
      case GST_MESSAGE_EOS:
        g_print ("End-Of-Stream reached.\n");
        break;
      default:
        /* We should not reach here because we only asked for ERRORs and EOS */
        g_printerr ("Unexpected message received.\n");
        break;
    }
    gst_message_unref (msg);
  }

GST_MESSAGE_TYPE 을 통해서 GST_MESSAGE_ERROR 타입임을 알게 되면, gst_message_parse_error 을 통해서 에러에 대한 자세한 내용을 알아낼 수 있다.

GStremer 버스

원소에 의해서 발생되는 GstMessage 는 버스를 통해 전달된다. 미디어의 실제 스트리밍은 애플리케이션 스레드가 아닌 다른 스레드에서 실행된다.

profile
프로그래밍을 좋아하는 평범한 개발자입니다.

0개의 댓글