-add reverse autoadd; with test
[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
6   it under the terms of the GNU General Public License as published
7   by the Free Software Foundation; either version 3, or (at your
8   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   General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with GNUnet; see the file COPYING.  If not, write to the
17   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18   Boston, MA 02110-1301, USA.
19 */
20 /**
21  * @file conversation/gnunet_gst.c
22  * @brief FIXME
23  * @author Hark
24  */
25
26 #include "gnunet_gst_def.h"
27 #include "gnunet_gst.h"
28
29 int
30 main (int argc, char *argv[])
31 {
32   struct GNUNET_gstData *gst;
33   GstBus *bus;
34   GstMessage *msg;
35   GstElement *gnunetsrc, *gnunetsink, *source, *sink, *encoder, *decoder;
36
37
38
39   // audio_message = GNUNET_malloc (UINT16_MAX);
40   //audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
41
42
43   //GstPipeline *pipeline;
44
45   gst = (GNUNET_gstData*)malloc(sizeof(struct GNUNET_gstData));
46
47   //gst->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
48
49
50   gg_load_configuration(gst);
51 /*
52   gst->audiobackend = JACK;
53   gst->dropsilence = TRUE;
54   gst->usertp = FALSE;
55   */
56   /* Initialize GStreamer */
57   gst_init (&argc, &argv);
58
59   gst->pipeline = GST_PIPELINE(gst_pipeline_new ("gnunet-media-helper"));
60
61 #ifdef IS_SPEAKER
62   int type = SPEAKER;
63   printf("this is the speaker \n");
64 #endif
65 #ifdef IS_MIC
66   int type = MICROPHONE;
67   printf("this is the microphone \n");
68
69 #endif
70   if ( type == SPEAKER)
71   {
72
73     gnunetsrc = GST_ELEMENT(get_app(gst, SOURCE));
74
75     sink = GST_ELEMENT(get_audiobin(gst, SINK));
76     decoder = GST_ELEMENT(get_coder(gst, DECODER));
77     gst_bin_add_many( GST_BIN(gst->pipeline), gnunetsrc, decoder, sink, NULL);
78     gst_element_link_many( gnunetsrc, decoder, sink , NULL);
79
80   }
81   if ( type == MICROPHONE ) {
82
83     source = GST_ELEMENT(get_audiobin(gst, SOURCE));
84
85     encoder = GST_ELEMENT(get_coder(gst, ENCODER));
86
87     gnunetsink = GST_ELEMENT(get_app(gst, SINK));
88
89     gst_bin_add_many( GST_BIN(gst->pipeline), source, encoder, gnunetsink, NULL);
90     gst_element_link_many( source, encoder, gnunetsink , NULL);
91
92
93   }
94   /*
95   gst_bin_add_many( GST_BIN(gst->pipeline), appsource, appsink, source, encoder, decoder, sink, NULL);
96   gst_element_link_many( source, encoder, decoder, sink , NULL);
97 */
98   pl_graph(gst->pipeline);
99   /* Start playing */
100   gst_element_set_state (GST_ELEMENT(gst->pipeline), GST_STATE_PLAYING);
101
102   //pl_graph(gst->pipeline);
103
104   /* Wait until error or EOS */
105   //bus = gst_element_get_bus (GST_ELEMENT(gst->pipeline));
106   //bus_watch_id = gst_bus_add_watch (bus, gnunet_gst_bus_call, pipeline);
107
108   gg_setup_gst_bus(gst);
109 // g_print ("Running...\n");
110
111
112   // start pushing buffers
113  if ( type == MICROPHONE )
114  {
115
116
117     GMainLoop *loop;
118     loop = g_main_loop_new (NULL, FALSE);
119
120      g_main_loop_run (loop);
121
122 /*
123    while ( 1 )
124      {
125          GstFlowReturn flow;
126          flow = on_appsink_new_sample (gst->appsink, gst);
127     }
128 */
129     }
130  if ( type == SPEAKER )
131  {
132    while ( 1 )
133    {
134 //      printf("read.. \n");
135       gnunet_read(gst);
136    }
137  }
138   g_print ("Returned, stopping playback\n");
139
140   gst_object_unref (bus);
141   gst_element_set_state (GST_ELEMENT(gst->pipeline), GST_STATE_NULL);
142   gst_object_unref (gst->pipeline);
143
144   return 0;
145 }