46073ebe3b7a44a87dad7fc0c9b83635194bfe1b
[oweals/gnunet.git] / src / conversation / gnunet_gst_test.c
1 /*
2   This file is part of GNUnet.
3   Copyright (C) 2016 GNUnet e.V.
4
5   GNUnet is free software: you can redistribute it and/or modify it
6   under the terms of the GNU Affero General Public License as published
7   by the Free Software Foundation, either version 3 of the License,
8   or (at your option) any later version.
9
10   GNUnet is distributed in the hope that it will be useful, but
11   WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Affero General Public License for more details.
14  
15   You should have received a copy of the GNU Affero General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 /**
19  * @file conversation/gnunet_gst_test.c
20  * @brief FIXME
21  * @author Hark
22  */
23
24 #include "gnunet_gst_def.h"
25 #include "gnunet_gst.h"
26
27 int
28 main (int argc, char *argv[])
29 {
30   struct GNUNET_gstData *gst;
31   // GstBus *bus;
32   GstElement *gnunetsrc, *gnunetsink, *source, *sink, *encoder, *decoder;
33
34
35
36   // audio_message = GNUNET_malloc (UINT16_MAX);
37   //audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
38
39
40   //GstPipeline *pipeline;
41
42   gst = (GNUNET_gstData*)malloc(sizeof(struct GNUNET_gstData));
43
44   //gst->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
45
46
47   gg_load_configuration(gst);
48 /*
49   gst->audiobackend = JACK;
50   gst->dropsilence = TRUE;
51   gst->usertp = FALSE;
52   */
53   /* Initialize GStreamer */
54   gst_init (&argc, &argv);
55
56   gst->pipeline = GST_PIPELINE(gst_pipeline_new ("gnunet-media-helper"));
57
58 #ifdef IS_SPEAKER
59   int type = SPEAKER;
60   printf("this is the speaker \n");
61 #endif
62 #ifdef IS_MIC
63   int type = MICROPHONE;
64   printf("this is the microphone \n");
65
66 #endif
67   if ( type == SPEAKER)
68   {
69
70     gnunetsrc = GST_ELEMENT(get_app(gst, SOURCE));
71
72     sink = GST_ELEMENT(get_audiobin(gst, SINK));
73     decoder = GST_ELEMENT(get_coder(gst, DECODER));
74     gst_bin_add_many( GST_BIN(gst->pipeline), gnunetsrc, decoder, sink, NULL);
75     gst_element_link_many( gnunetsrc, decoder, sink , NULL);
76
77   }
78   if ( type == MICROPHONE ) {
79
80     source = GST_ELEMENT(get_audiobin(gst, SOURCE));
81
82     encoder = GST_ELEMENT(get_coder(gst, ENCODER));
83
84     gnunetsink = GST_ELEMENT(get_app(gst, SINK));
85
86     gst_bin_add_many( GST_BIN(gst->pipeline), source, encoder, gnunetsink, NULL);
87     gst_element_link_many( source, encoder, gnunetsink , NULL);
88
89
90   }
91   /*
92   gst_bin_add_many( GST_BIN(gst->pipeline), appsource, appsink, source, encoder, decoder, sink, NULL);
93   gst_element_link_many( source, encoder, decoder, sink , NULL);
94 */
95   pl_graph(gst->pipeline);
96   /* Start playing */
97   gst_element_set_state (GST_ELEMENT(gst->pipeline), GST_STATE_PLAYING);
98
99   //pl_graph(gst->pipeline);
100
101   /* Wait until error or EOS */
102   //bus = gst_element_get_bus (GST_ELEMENT(gst->pipeline));
103   //bus_watch_id = gst_bus_add_watch (bus, gnunet_gst_bus_call, pipeline);
104
105   gg_setup_gst_bus(gst);
106 // g_print ("Running...\n");
107
108
109   // start pushing buffers
110  if ( type == MICROPHONE )
111  {
112
113
114     GMainLoop *loop;
115     loop = g_main_loop_new (NULL, FALSE);
116
117      g_main_loop_run (loop);
118
119 /*
120    while ( 1 )
121      {
122          GstFlowReturn flow;
123          flow = on_appsink_new_sample (gst->appsink, gst);
124     }
125 */
126     }
127  if ( type == SPEAKER )
128  {
129    while ( 1 )
130    {
131 //      printf("read.. \n");
132       gnunet_read(gst);
133    }
134  }
135   g_print ("Returned, stopping playback\n");
136
137   // gst_object_unref (bus);
138   gst_element_set_state (GST_ELEMENT(gst->pipeline), GST_STATE_NULL);
139   gst_object_unref (gst->pipeline);
140
141   return 0;
142 }