add attestation API
[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      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 /**
21  * @file conversation/gnunet_gst_test.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   GstElement *gnunetsrc, *gnunetsink, *source, *sink, *encoder, *decoder;
35
36
37   // audio_message = GNUNET_malloc (UINT16_MAX);
38   // audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
39
40
41   // GstPipeline *pipeline;
42
43   gst = (GNUNET_gstData *) malloc (sizeof(struct GNUNET_gstData));
44
45   // gst->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
46
47
48   gg_load_configuration (gst);
49 /*
50    gst->audiobackend = JACK;
51    gst->dropsilence = TRUE;
52    gst->usertp = FALSE;
53  *//* Initialize GStreamer */gst_init (&argc, &argv);
54
55   gst->pipeline = GST_PIPELINE (gst_pipeline_new ("gnunet-media-helper"));
56
57 #ifdef IS_SPEAKER
58   int type = SPEAKER;
59   printf ("this is the speaker \n");
60 #endif
61 #ifdef IS_MIC
62   int type = MICROPHONE;
63   printf ("this is the microphone \n");
64 #endif
65   if (type == SPEAKER)
66   {
67     gnunetsrc = GST_ELEMENT (get_app (gst, SOURCE));
68
69     sink = GST_ELEMENT (get_audiobin (gst, SINK));
70     decoder = GST_ELEMENT (get_coder (gst, DECODER));
71     gst_bin_add_many (GST_BIN (gst->pipeline), gnunetsrc, decoder, sink, NULL);
72     gst_element_link_many (gnunetsrc, decoder, sink, NULL);
73   }
74   if (type == MICROPHONE)
75   {
76     source = GST_ELEMENT (get_audiobin (gst, SOURCE));
77
78     encoder = GST_ELEMENT (get_coder (gst, ENCODER));
79
80     gnunetsink = GST_ELEMENT (get_app (gst, SINK));
81
82     gst_bin_add_many (GST_BIN (gst->pipeline), source, encoder, gnunetsink,
83                       NULL);
84     gst_element_link_many (source, encoder, gnunetsink, NULL);
85   }
86   /*
87      gst_bin_add_many( GST_BIN(gst->pipeline), appsource, appsink, source, encoder, decoder, sink, NULL);
88      gst_element_link_many( source, encoder, decoder, sink , NULL);
89    */
90   pl_graph (gst->pipeline);
91   /* Start playing */
92   gst_element_set_state (GST_ELEMENT (gst->pipeline), GST_STATE_PLAYING);
93
94   // pl_graph(gst->pipeline);
95
96   /* Wait until error or EOS */
97   // bus = gst_element_get_bus (GST_ELEMENT(gst->pipeline));
98   // bus_watch_id = gst_bus_add_watch (bus, gnunet_gst_bus_call, pipeline);
99
100   gg_setup_gst_bus (gst);
101 // g_print ("Running...\n");
102
103
104   // start pushing buffers
105   if (type == MICROPHONE)
106   {
107     GMainLoop *loop;
108     loop = g_main_loop_new (NULL, FALSE);
109
110     g_main_loop_run (loop);
111
112 /*
113    while ( 1 )
114      {
115          GstFlowReturn flow;
116          flow = on_appsink_new_sample (gst->appsink, gst);
117     }
118  */}
119   if (type == SPEAKER)
120   {
121     while (1)
122     {
123 //      printf("read.. \n");
124       gnunet_read (gst);
125     }
126   }
127   g_print ("Returned, stopping playback\n");
128
129   // gst_object_unref (bus);
130   gst_element_set_state (GST_ELEMENT (gst->pipeline), GST_STATE_NULL);
131   gst_object_unref (gst->pipeline);
132
133   return 0;
134 }