summaryrefslogtreecommitdiff
path: root/test/qtest.c
blob: e7c2d52186ce57aa6e7777ed5394b21c89168443 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <glib.h>
#include <gst/gst.h>
#include <gst/elements/gstqueue.h>

extern gboolean _gst_plugin_spew;

/* we don't need a lock around the application's state yet, since it's 1
   bit.  as it gets more fleshed in, we'll need a lock so the callbacks
   don't screw around with state unexpectedly */
static gboolean playing = TRUE;

void eof(GstSrc *src) {
  DEBUG("have EOF\n");
  playing = FALSE;
}

int main(int argc,char *argv[]) {
  GstElement *pipeline;
  GstElement *decodethread;
  GstElementFactory *srcfactory;
  GstElement *src;
  GstElementFactory *decodefactory;
  GstElement *decode;
  GstElementFactory *queuefactory;
  GstElement *queue;
  GstElement *playthread;
  GstElementFactory *sinkfactory;
  GstElement *sink;

  gst_init(&argc,&argv);

  /* first create the main pipeline */
  pipeline = gst_pipeline_new("pipeline");

  /* then the decode thread, source, and decoder */
  decodethread = gst_thread_new("decodethread");

  srcfactory = gst_elementfactory_find("asyncdisksrc");
  src = gst_elementfactory_create(srcfactory,"src");
  gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
  gst_bin_add(GST_BIN(decodethread),GST_ELEMENT(src));

  _gst_plugin_spew = TRUE;

  if (argc > 2)
    gst_plugin_load(argv[2]);
  else
    gst_plugin_load_all();
  decodefactory = gst_elementfactory_find("mpg123");
  decode = gst_elementfactory_create(decodefactory,"decode");
  gst_bin_add(GST_BIN(decodethread),GST_ELEMENT(decode));
  gst_element_add_ghost_pad(GST_ELEMENT(decodethread),
                            gst_element_get_pad(decode,"src"));

  gst_pad_connect(gst_element_get_pad(src,"src"),
                  gst_element_get_pad(decode,"sink"));

  /* then the play thread and sink */
  playthread = gst_thread_new("playthread");

  sinkfactory = gst_elementfactory_find("audiosink");
  sink = gst_elementfactory_create(sinkfactory,"sink");
  gst_bin_add(GST_BIN(playthread),GST_ELEMENT(sink));
  gst_element_add_ghost_pad(GST_ELEMENT(playthread),
                            gst_element_get_pad(sink,"sink"));

  /* create the queue */
  queuefactory = gst_elementfactory_find("queue");
  queue = gst_elementfactory_create(queuefactory,"queue");

  /* add threads to the main pipeline */
  gst_bin_add(GST_BIN(pipeline),decodethread);
  gst_bin_add(GST_BIN(pipeline),queue);
  gst_bin_add(GST_BIN(pipeline),playthread);

  gst_pad_connect(gst_element_get_pad(decodethread,"src"),
//                  gst_element_get_pad(queue,"sink"));
//  gst_pad_connect(gst_element_get_pad(queue,"src"),
                  gst_element_get_pad(playthread,"sink"));

  gtk_signal_connect(GTK_OBJECT(src),"eof",
                     GTK_SIGNAL_FUNC(eof),NULL);

  g_print("\nsetting up the decode thread to *NOT* thread\n");
//  gtk_object_set(GTK_OBJECT(decodethread),"create_thread",TRUE,NULL);
  gtk_object_set(GTK_OBJECT(playthread),"create_thread",FALSE,NULL);

  g_print("\neverything's built, setting it up to be runnable\n");
  gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_RUNNING);

  g_print("\nok, runnable, hitting 'play'...\n");
  gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING);

  g_print("\niterating on %p and %p\n",decodethread,playthread);
  while (playing) {
    gst_thread_iterate(GST_THREAD(playthread));
    /* buffers got wedged in the queue, unstick them */
//    while (((GstQueue *)queue)->buffers_queued)
//      gst_connection_push(GST_CONNECTION(queue));
//      gst_thread_iterate(GST_THREAD(playthread));
//    g_print("stuffed and unstuck the queue\n");
//    sleep(1);
  }
}