Exemplo n.º 1
0
/* Init the video interface. Start GStreamer and create all the elements. */
int video_init(int flags)
{
	GstElement *dec, *vqueue, *vconv, *vscale, *aqueue, *aconv, *ascale;

	if (!gst_init_check(NULL, NULL)) return VIDEO_ERROR;

	status = 0;
	status_mutex = g_mutex_new();
	video_width = video_height = 0;
	apeer = NULL;
	audio_disabled = flags & VIDEO_INIT_NOAUDIO;

	/* Main pipeline */
	pipeline = gst_thread_new("pipeline");
	g_signal_connect(pipeline, "eos", G_CALLBACK (cb_eos), NULL);
	g_signal_connect(pipeline, "error", G_CALLBACK (cb_error), NULL);
	g_signal_connect(pipeline, "state-change", G_CALLBACK (cb_state_change), NULL);
	src = gst_element_factory_make("filesrc", "src");
	dec = gst_element_factory_make("decodebin", "dec");
	g_signal_connect (dec, "new-decoded-pad", G_CALLBACK(cb_new_pad), NULL);
	if (!gst_element_link_many(src, dec, NULL)) return VIDEO_ERROR;
	gst_bin_add_many(GST_BIN(pipeline), src, dec, NULL);

	/* Video thread */
	vthread = gst_thread_new("vthread");
	vqueue = gst_element_factory_make("queue", "vqueue");
	vqueuesink = gst_element_get_pad(vqueue, "sink");
	vconv = gst_element_factory_make("ffmpegcolorspace", "vconv");
	vscale = gst_element_factory_make("videoscale", "vscale");
	vdrop = gst_element_factory_make("videodrop", "vdrop");
	xvsink = gst_element_factory_make("xvimagesink", "xvsink");
	gst_bin_add_many(GST_BIN(vthread), vqueue, vconv, vscale, vdrop, xvsink, NULL);
	if (!gst_element_link_many(vqueue, vconv, vscale, vdrop, xvsink, NULL)) 
		return VIDEO_ERROR;
	gst_object_ref(GST_OBJECT(vthread));

	/* Audio thread */
	if (audio_disabled) return VIDEO_OK;

	athread = gst_thread_new("athread");
	aqueue = gst_element_factory_make("queue", "aqueue");
	aqueuesink = gst_element_get_pad(aqueue, "sink");
	aconv = gst_element_factory_make("audioconvert", "aconv");
	ascale = gst_element_factory_make ("audioscale", "ascale");
	asink = gst_element_factory_make ("alsasink", "asink");
	gst_bin_add_many (GST_BIN (athread), aqueue, aconv, ascale, asink, NULL);
	if (!gst_element_link_many (aqueue, aconv, ascale, asink, NULL))
		return VIDEO_ERROR;
	gst_object_ref(GST_OBJECT(athread));

	return VIDEO_OK;
}
Exemplo n.º 2
0
static GstElement *
create_thread_ghostpads (void)
{
  GstElement *thread;
  GstElement *element1, *element2;

  thread = gst_thread_new ("testthread");
  element1 = gst_element_new ();
  gst_element_set_name (element1, "test1");
  gst_element_add_pad (element1,
      gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate),
          "src1"));
  gst_bin_add (GST_BIN (thread), element1);
  element2 = gst_element_new ();
  gst_element_set_name (element2, "test2");
  gst_element_add_pad (element1,
      gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate),
          "sink1"));
  gst_bin_add (GST_BIN (thread), element2);
  gst_element_link (element1, "src1", element2, "sink1");
  gst_element_add_ghost_pad (thread, gst_element_get_pad (element2, "sink1"),
      "sink1");

  return thread;
}
Exemplo n.º 3
0
static void
add_remove_test4 (void)
{
  GstElement *thread, *thread2;
  GstElement *element;

  thread = gst_thread_new ("testthread");
  element = gst_element_new ();
  gst_element_set_name (element, "test1");
  g_assert (GST_OBJECT_FLOATING (element));
  gst_bin_add (GST_BIN (thread), element);
  g_assert (!GST_OBJECT_FLOATING (element));

  thread2 = create_thread ();
  g_assert (GST_OBJECT_FLOATING (thread2));
  gst_bin_add (GST_BIN (thread), thread2);
  g_assert (!GST_OBJECT_FLOATING (thread2));

  gst_object_unref (thread2);
  g_assert (gst_bin_get_by_name (GST_BIN (thread), "testthread") == NULL);
  gst_object_unref (element);
  g_assert (gst_bin_get_by_name (GST_BIN (thread), "test1") == NULL);

  gst_object_unref (thread);
}
Exemplo n.º 4
0
int
main (int argc, char *argv[])
{
  GstElement *filesrc, *osssink;
  GstElement *pipeline;
  GstElement *thread;

  gst_init (&argc, &argv);

  if (argc != 2) {
    g_print ("usage: %s <filename>\n", argv[0]);
    exit (-1);
  }

  /* create a new thread to hold the elements */
  thread = gst_thread_new ("thread");
  g_assert (thread != NULL);

  /* create a new bin to hold the elements */
  pipeline = gst_pipeline_new ("pipeline");
  g_assert (pipeline != NULL);

  /* create a disk reader */
  filesrc = gst_element_factory_make ("filesrc", "disk_source");
  g_assert (filesrc != NULL);
  g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
  g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread);

  /* and an audio sink */
  osssink = gst_element_factory_make ("osssink", "play_audio");
  g_assert (osssink != NULL);

  /* add objects to the main pipeline */
  /*
     gst_pipeline_add_src(GST_PIPELINE(pipeline), filesrc);
     gst_pipeline_add_sink(GST_PIPELINE(pipeline), osssink);

     if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) {
     g_print("unable to handle stream\n");
     exit(-1);
     }
   */

  /*gst_bin_remove(GST_BIN(pipeline), filesrc); */

  /*gst_bin_add(GST_BIN(thread), filesrc); */
  gst_bin_add (GST_BIN (thread), GST_ELEMENT (pipeline));

  /* make it ready */
  gst_element_set_state (GST_ELEMENT (thread), GST_STATE_READY);
  /* start playing */
  gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING);

  loop = g_main_loop_new (NULL, FALSE);

  gst_object_unref (thread);

  exit (0);
}
Exemplo n.º 5
0
static void
add_remove_test1 (void)
{
  GstElement *thread;
  GstElement *element;

  thread = gst_thread_new ("testthread");
  element = gst_element_new ();
  gst_element_set_name (element, "test1");
  g_assert (GST_OBJECT_FLOATING (element));
  gst_bin_add (GST_BIN (thread), element);
  g_assert (!GST_OBJECT_FLOATING (element));
  gst_bin_remove (GST_BIN (thread), element);

  gst_object_unref (thread);
}
Exemplo n.º 6
0
static GstElement *
create_thread (void)
{
  GstElement *thread;
  GstElement *element;

  thread = gst_thread_new ("testthread");
  element = gst_element_new ();
  gst_element_set_name (element, "test1");
  gst_bin_add (GST_BIN (thread), element);
  element = gst_element_new ();
  gst_element_set_name (element, "test2");
  gst_bin_add (GST_BIN (thread), element);

  return thread;
}
Exemplo n.º 7
0
int
main (int argc, char *argv[])
{
  /*int i, j; */
  /*gboolean done; */

  /*char buffer[20]; */

  /*output_channel_t *channel_out; */

  GstElement *audiosrc;

  gst_init (&argc, &argv);
/*
  if (argc == 1)
  {
    g_print("usage: %s <filename1> <filename2> <...>\n", argv[0]);
    exit(-1);
  }*/

  /* set up input channel and main bin */

  g_print ("creating main bin\n");
  /* create cutter */
  cutter = gst_element_factory_make ("cutter", "cutter");

  g_object_set (G_OBJECT (cutter),
      "threshold_dB", -40.0, "runlength", 0.5, "prelength", 1.0, NULL);

  /* create an audio src */
  if (!(audiosrc = gst_element_factory_make ("osssrc", "audio_src")))
    g_error ("Could not create 'osssrc' element !\n");

  /* set params */

  g_object_set (G_OBJECT (audiosrc), "frequency", 44100,
      "channels", 1, "format", 16, NULL);

  if (!(encoder = gst_element_factory_make ("passthrough", "encoder")))
    g_error ("Could not create 'passthrough' element !\n");

  if (!(filesink = gst_element_factory_make ("afsink", "disk_sink")))
    g_error ("Could not create 'afsink' element !\n");

  g_object_set (G_OBJECT (filesink), "location", "/dev/null", NULL);

  thread = gst_thread_new ("thread");
  g_assert (thread != NULL);

  /* create main bin */
  main_bin = gst_pipeline_new ("bin");
  g_assert (main_bin != NULL);

  queue = gst_element_factory_make ("queue", "queue");
  g_assert (queue);

  /* add elements to bin */
  gst_bin_add (GST_BIN (main_bin), audiosrc);
  gst_bin_add (GST_BIN (thread), queue);

  gst_bin_add_many (GST_BIN (thread), cutter, encoder, filesink, NULL);

  gst_element_link_many (audiosrc, queue, cutter, encoder, filesink, NULL);
  gst_bin_add (GST_BIN (main_bin), thread);

  /* set signal handlers */
  g_print ("setting signal handlers\n");
  g_signal_connect (G_OBJECT (cutter), "cut_start",
      (GCallback) cut_start_signal, NULL);
  g_signal_connect (G_OBJECT (cutter), "cut_stop",
      (GCallback) cut_stop_signal, NULL);

  /* start playing */
  g_print ("setting to play\n");
  gst_element_set_state (main_bin, GST_STATE_PLAYING);
/*
  g_print ("setting thread to play\n");
  gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING);
*/
  while (playing) {
/*      g_print ("> "); */
    gst_bin_iterate (GST_BIN (main_bin));
/*      g_print (" <"); */
    if (cut_start_signalled) {
      g_print ("\nDEBUG: main: cut_start_signalled true !\n");
      cut_start (cutter);
      cut_start_signalled = FALSE;
    }
    if (cut_stop_signalled) {
      g_print ("\nDEBUG: main: cut_stop_signalled true !\n");
      cut_stop (cutter);
      cut_stop_signalled = FALSE;
    }
  }
  g_print ("we're done iterating.\n");
  /* stop the bin */

  gst_element_set_state (main_bin, GST_STATE_NULL);

  gst_object_unref (filesink);
  gst_object_unref (main_bin);

  exit (0);
}
Exemplo n.º 8
0
int
main (int argc, char *argv[])
{
  GstElement *filesrc, *osssink, *queue, *queue2, *parse, *decode;
  GstElement *bin;
  GstElement *thread, *thread2;

  gst_init (&argc, &argv);

  if (argc != 2) {
    g_print ("usage: %s <filename>\n", argv[0]);
    exit (-1);
  }

  /* create a new thread to hold the elements */
  thread = gst_thread_new ("thread");
  g_assert (thread != NULL);
  thread2 = gst_thread_new ("thread2");
  g_assert (thread2 != NULL);

  /* create a new bin to hold the elements */
  bin = gst_bin_new ("bin");
  g_assert (bin != NULL);

  /* create a disk reader */
  filesrc = gst_element_factory_make ("filesrc", "disk_source");
  g_assert (filesrc != NULL);
  g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
  g_signal_connect (G_OBJECT (filesrc), "eos", G_CALLBACK (eos), thread);

  queue = gst_element_factory_make ("queue", "queue");
  queue2 = gst_element_factory_make ("queue", "queue2");

  /* and an audio sink */
  osssink = gst_element_factory_make ("osssink", "play_audio");
  g_assert (osssink != NULL);

  parse = gst_element_factory_make ("mp3parse", "parse");
  decode = gst_element_factory_make ("mpg123", "decode");

  /* add objects to the main bin */
  gst_bin_add (GST_BIN (bin), filesrc);
  gst_bin_add (GST_BIN (bin), queue);

  gst_bin_add (GST_BIN (thread), parse);
  gst_bin_add (GST_BIN (thread), decode);
  gst_bin_add (GST_BIN (thread), queue2);

  gst_bin_add (GST_BIN (thread2), osssink);

  gst_element_link_many (filesrc, queue, parse, decode, queue2, osssink, NULL);

  gst_bin_add (GST_BIN (bin), thread);
  gst_bin_add (GST_BIN (bin), thread2);

  /* make it ready */
  gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
  /* start playing */
  gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);

  playing = TRUE;

  while (playing) {
    gst_bin_iterate (GST_BIN (bin));
  }

  gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);

  exit (0);
}
Exemplo n.º 9
0
int
main (int argc, gchar * argv[])
{
  GstElement *thread, *element;
  long usage1;
  gint i, iters;

  gst_init (&argc, &argv);

  if (argc == 2)
    iters = atoi (argv[1]);
  else
    iters = ITERS;

  g_print ("starting test\n");
  usage1 = vmsize ();

  thread = gst_thread_new ("somethread");
  gst_object_unref (thread);
  g_print ("create/unref new thread %ld\n", vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    thread = gst_thread_new ("somethread");
    gst_object_unref (thread);
  }
  g_print ("create/unref %d threads %ld\n", iters, vmsize () - usage1);

  thread = gst_thread_new ("somethread");
  g_assert (GST_OBJECT_FLOATING (thread));
  gst_object_ref (thread);
  gst_object_sink (GST_OBJECT (thread));
  g_assert (!GST_OBJECT_FLOATING (thread));
  gst_object_unref (thread);
  g_print ("create/ref/sink/unref new thread %ld\n", vmsize () - usage1);


  for (i = 0; i < iters; i++) {
    thread = gst_thread_new ("somethread");
    gst_object_ref (thread);
    gst_object_sink (GST_OBJECT (thread));
    gst_object_unref (thread);
  }
  g_print ("create/ref/sink/unref %d threads %ld\n", iters, vmsize () - usage1);

  thread = gst_thread_new ("somethread");
  g_assert (!GST_OBJECT_DESTROYED (thread));
  gst_object_unref (thread);
  g_assert (GST_OBJECT_DESTROYED (thread));
  gst_object_unref (thread);
  g_print ("create/destroy/unref new thread %ld\n", vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    thread = gst_thread_new ("somethread");
    gst_object_unref (thread);
    gst_object_unref (thread);
  }
  g_print ("create/destroy/unref %d thread %ld\n", iters, vmsize () - usage1);

  thread = gst_thread_new ("somethread");
  gst_object_ref (thread);
  gst_object_unref (thread);
  gst_object_unref (thread);
  g_print ("create/ref/unref/unref new thread %ld\n", vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    thread = gst_thread_new ("somethread");
    gst_object_ref (thread);
    gst_object_unref (thread);
    gst_object_unref (thread);
  }
  g_print ("create/ref/unref/unref %d thread %ld\n", iters, vmsize () - usage1);

  thread = gst_thread_new ("somethread");
  gst_object_ref (thread);
  gst_object_unref (thread);
  gst_object_unref (thread);
  gst_object_unref (thread);
  g_print ("craete/ref/destroy/unref/unref new thread %ld\n",
      vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    thread = gst_thread_new ("somethread");
    gst_object_ref (thread);
    gst_object_unref (thread);
    gst_object_unref (thread);
    gst_object_unref (thread);
  }
  g_print ("craete/ref/destroy/unref/unref %d threads %ld\n", iters,
      vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    thread = gst_thread_new ("somethread");
    gst_object_ref (thread);
    gst_element_set_name (thread, "testing123");
    gst_object_unref (thread);
    gst_element_set_name (thread, "testing123");
    gst_object_unref (thread);
    gst_object_unref (thread);
  }
  g_print ("craete/ref/destroy/unref/unref %d threads with name %ld\n", iters,
      vmsize () - usage1);

  thread = gst_thread_new ("somethread");
  for (i = 0; i < iters; i++) {
    gst_element_set_name (thread, "testing");
  }
  gst_object_unref (thread);
  g_print ("set name %d times %ld\n", iters, vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    thread = gst_thread_new ("somethread");
    element = gst_element_new ();
    gst_element_set_name (element, "test1");
    gst_bin_add (GST_BIN (thread), element);
    gst_object_unref (thread);
  }
  g_print ("create/unref %d thread with one element %ld\n", iters,
      vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    thread = create_thread ();
    gst_object_unref (thread);
  }
  g_print ("create/unref %d thread with children %ld\n", iters,
      vmsize () - usage1);

  for (i = 0; i < iters / 2; i++) {
    thread = create_thread_ghostpads ();
    gst_object_unref (thread);
  }
  g_print ("create/unref %d thread with children and ghostpads %ld\n",
      iters / 2, vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    add_remove_test1 ();
  }
  g_print ("add/remove test1 %d in thread %ld\n", iters, vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    add_remove_test2 ();
  }
  g_print ("add/remove test2 %d in thread %ld\n", iters, vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    add_remove_test3 ();
  }
  g_print ("add/destroy/remove test3 %d in thread %ld\n", iters,
      vmsize () - usage1);

  for (i = 0; i < iters; i++) {
    add_remove_test4 ();
  }
  g_print ("add/destroy/remove test4 %d in thread %ld\n", iters,
      vmsize () - usage1);

  g_print ("leaked: %ld\n", vmsize () - usage1);

  return (vmsize () - usage1 ? -1 : 0);
}