gnunet_gst_test.c 3.6 KB

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