Multimedia/GStreamer

GStreamer pwg ch 11

Roien 2021. 12. 22.
반응형

 

11.     Building a Test Application

 

plugin test 방법

    Ÿ   plugin GStreamer search 하는 directory에 설치된 경우

        n  gst-launch-1.0

    Ÿ   설치 안 된 경우

        n  GST_PLUGIN_PATH plugin directory를 설정

        n  혹은 --gst-plugin-path를 사용해서 설정

    Ÿ   plugingst-plugin template 기반으로 만들어진 경우

        n  gst-launch-1.0 --gst-plugin-path=$HOME/gst-template/gst-plugin/src/.libs TESTPIPELINE

    Ÿ   더 많은 feature test 하고자 하는 경우

        n  ex. seeking, event, interactivity 

        n  test app 작성이 필요함

 

 

*   gst_init()

    n  처음에 gst_init을 호출하여 GStreamer core library를 초기화 해야함

    n  혹은 gst_init_get_option_group을 호출

        s   GOptionGroup pointer를 리턴

        s   GOption을 사용해서 초기화 수행

 

*   gst_element_factory_make()

    n  element type free-form name을 입력

    n  ex.

        s   identity element

            -       data-to-application transmitter로 동작

            -       data의 점검에 사용됨

        s   fakesink element

            -       data stdout으로 dump

        s   valgrind

            -       memory error check

 

*   linking

    n  linking  filtered caps을 사용

        s   특정 data type element in/out 되도록 함

 

*   running

    n  message listen 해야 함 (from pipeline to app)

        s   error라던가, eos listen

        s   이들에 대한 event들을 pipeline에 추가하여 correct 해야 함

 

*   cleanup

    n  NULL state로 가게되면, element는 할당한 memory cache들을 clean up 해야 함

    n  unref()을 수행

 

 

#include <gst/gst.h>
 
static gboolean
bus_call (GstBus     *bus,
      GstMessage *msg,
      gpointer    data) {
  GMainLoop *loop = data;
 
  switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_EOS:
      g_print ("End-of-stream\n");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_ERROR: {
      gchar *debug = NULL;
      GError *err = NULL;
 
      gst_message_parse_error (msg, &err, &debug);
 
      g_print ("Error: %s\n", err->message);
      g_error_free (err);
 
      if (debug) {
        g_print ("Debug details: %s\n", debug);
        g_free (debug);
      }
 
      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }
 
  return TRUE;
}
 
gint
main (gint   argc,
      gchar *argv[]) {
  GstStateChangeReturn ret;
  GstElement *pipeline, *filesrc, *decoder, *filter, *sink;
  GstElement *convert1, *convert2, *resample;
  GMainLoop *loop;
  GstBus *bus;
  guint watch_id;
 
  /* initialization */
  gst_init (&argc, &argv);
  loop = g_main_loop_new (NULL, FALSE);
  if (argc != 2) {
    g_print ("Usage: %s <mp3 filename>\n", argv[0]);
    return 01;
  }
 
  /* create elements */
  pipeline = gst_pipeline_new ("my_pipeline");
 
  /* watch for messages on the pipeline's bus (note that this will only
   * work like this when a GLib main loop is running) */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  watch_id = gst_bus_add_watch (bus, bus_call, loop);
  gst_object_unref (bus);
 
  filesrc  = gst_element_factory_make ("filesrc", "my_filesource");
  decoder  = gst_element_factory_make ("mad", "my_decoder");
 
  /* putting an audioconvert element here to convert the output of the
   * decoder into a format that my_filter can handle (we are assuming it
   * will handle any sample rate here though) */
  convert1 = gst_element_factory_make ("audioconvert", "audioconvert1");
 
  /* use "identity" here for a filter that does nothing */
  filter   = gst_element_factory_make ("my_filter", "my_filter");
 
  /* there should always be audioconvert and audioresample elements before
   * the audio sink, since the capabilities of the audio sink usually vary
   * depending on the environment (output used, sound card, driver etc.) */
  convert2 = gst_element_factory_make ("audioconvert", "audioconvert2");
  resample = gst_element_factory_make ("audioresample", "audioresample");
  sink     = gst_element_factory_make ("pulsesink", "audiosink");
 
  if (!sink || !decoder) {
    g_print ("Decoder or output could not be found - check your install\n");
    return -1;
  } else if (!convert1 || !convert2 || !resample) {
    g_print ("Could not create audioconvert or audioresample element, "
             "check your installation\n");
    return -1;
  } else if (!filter) {
    g_print ("Your self-written filter could not be found. Make sure it "
             "is installed correctly in $(libdir)/gstreamer-1.0/ or "
             "~/.gstreamer-1.0/plugins/ and that gst-inspect-1.0 lists it. "
             "If it doesn't, check with 'GST_DEBUG=*:2 gst-inspect-1.0' for "
             "the reason why it is not being loaded.");
    return -1;
  }
 
  g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
 
  gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, convert1, filter,
                    convert2, resample, sink, NULL);
 
  /* link everything together */
  if (!gst_element_link_many (filesrc, decoder, convert1, filter, convert2,
                              resample, sink, NULL)) {
    g_print ("Failed to link one or more elements!\n");
    return -1;
  }
 
  /* run */
  ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
  if (ret == GST_STATE_CHANGE_FAILURE) {
    GstMessage *msg;
 
    g_print ("Failed to start up pipeline!\n");
 
    /* check if there is an error message with details on the bus */
    msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
    if (msg) {
      GError *err = NULL;
 
      gst_message_parse_error (msg, &err, NULL);
      g_print ("ERROR: %s\n", err->message);
      g_error_free (err);
      gst_message_unref (msg);
    }
    return -1;
  }
 
  g_main_loop_run (loop);
 
  /* clean up */
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (pipeline);
  g_source_remove (watch_id);
  g_main_loop_unref (loop);
 
  return 0;
}

 

반응형

'Multimedia > GStreamer' 카테고리의 다른 글

GStreamer pwg ch 4~6  (0) 2021.12.22
GStreamer pwg ch 7 ~ 9  (0) 2021.12.22
GStreamer pwg: ch 12  (0) 2021.12.22
GStreamer pwg: ch 13  (0) 2021.12.22
GStreamer pwg: ch. 13 part 1  (0) 2021.12.22

댓글