messenger-gtk

Gtk+3 graphical user interfaces for GNUnet Messenger
Log | Files | Refs | Submodules | README | LICENSE

discourse.h (6153B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2024 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  * @author Tobias Frisch
     22  * @file discourse.h
     23  */
     24 
     25 #ifndef DISCOURSE_H_
     26 #define DISCOURSE_H_
     27 
     28 #include "application.h"
     29 
     30 #include <glib-2.0/glib.h>
     31 #include <gnunet/gnunet_chat_lib.h>
     32 #include <gtk-3.0/gtk/gtk.h>
     33 #include <pthread.h>
     34 
     35 /**
     36  * Returns the discourse id for a typical voice chat.
     37  *
     38  * @return Voice chat discourse id
     39  */
     40 const struct GNUNET_CHAT_DiscourseId*
     41 get_voice_discourse_id();
     42 
     43 /**
     44  * Returns the discourse id for a typical video chat.
     45  *
     46  * @return Video chat discourse id
     47  */
     48 const struct GNUNET_CHAT_DiscourseId*
     49 get_video_discourse_id();
     50 
     51 typedef enum MESSENGER_DiscourseControl {
     52   MESSENGER_DISCOURSE_CTRL_MICROPHONE = 1,
     53   MESSENGER_DISCOURSE_CTRL_SPEAKERS = 2,
     54   MESSENGER_DISCOURSE_CTRL_WEBCAM = 3,
     55   MESSENGER_DISCOURSE_CTRL_SCREEN_CAPTURE = 4,
     56 
     57   MESSENGER_DISCOURSE_CTRL_UNKNOWN = 0
     58 } MESSENGER_DiscourseControl;
     59 
     60 typedef struct MESSENGER_DiscourseInfo
     61 {
     62   struct GNUNET_CHAT_Discourse *discourse;
     63 
     64   GstElement *audio_record_pipeline;
     65   GstElement *audio_record_sink;
     66 
     67   GstElement *video_record_pipeline;
     68   GstElement *video_record_source;
     69   GstElement *video_record_sink;
     70   GstElement *video_heartbeat_source;
     71 
     72   GstElement *audio_mix_pipeline;
     73   GstElement *audio_mix_element;
     74   GstElement *audio_volume_element;
     75 
     76   pthread_mutex_t mutex;
     77   guint heartbeat;
     78   
     79   GList *subscriptions;
     80 } MESSENGER_DiscourseInfo;
     81 
     82 typedef struct MESSENGER_DiscourseSubscriptionInfo
     83 {
     84   MESSENGER_DiscourseInfo *discourse;
     85   struct GNUNET_CHAT_Contact *contact;
     86 
     87   GstElement *audio_stream_source;
     88   GstElement *audio_jitter_buffer;
     89   GstElement *audio_depay;
     90   GstElement *audio_converter;
     91 
     92   GstElement *video_stream_pipeline;
     93   GstElement *video_stream_source;
     94   GstElement *video_stream_sink;
     95 
     96   GstPad *audio_mix_pad;
     97   GList *buffers; 
     98 
     99   uint64_t position;
    100   uint64_t last_timestamp;
    101 
    102   pthread_mutex_t mutex;
    103 
    104   GDateTime *end_datetime;
    105 } MESSENGER_DiscourseSubscriptionInfo;
    106 
    107 /**
    108  * Creates a discourse information struct to potentially
    109  * update all GUI appearances of a specific discourse at
    110  * once.
    111  *
    112  * @param discourse Chat discourse
    113  * @return #GNUNET_YES on info creation, otherwise #GNUNET_NO
    114  */
    115 enum GNUNET_GenericReturnValue
    116 discourse_create_info(struct GNUNET_CHAT_Discourse *discourse);
    117 
    118 /**
    119  * Destroys and frees resources allocated for a given
    120  * discourse information struct.
    121  *
    122  * @param discourse Chat discourse
    123  */
    124 void
    125 discourse_destroy_info(struct GNUNET_CHAT_Discourse *discourse);
    126 
    127 /**
    128  * Updates the connected UI elements for a given
    129  * discourse and its subscriptions depending on the 
    130  * current state.
    131  *
    132  * @param discourse Chat discourse
    133  */
    134 void
    135 discourse_update_subscriptions(struct GNUNET_CHAT_Discourse *discourse);
    136 
    137 /**
    138  * Pushes a data message of a given discourse to
    139  * update UI elements or output regarding its content.
    140  *
    141  * @param discourse Chat discourse
    142  * @param message Chat message
    143  */
    144 void
    145 discourse_stream_message(struct GNUNET_CHAT_Discourse *discourse,
    146                          const struct GNUNET_CHAT_Message *message);
    147 
    148 /**
    149  * Returns whether a given discourse should have controls
    150  * regarding a given type of input/output.
    151  *
    152  * @param discourse Chat discourse
    153  * @return #TRUE if there should be controls, otherwise #FALSE
    154  */
    155 bool
    156 discourse_has_controls(struct GNUNET_CHAT_Discourse *discourse,
    157                        MESSENGER_DiscourseControl control);
    158 
    159 /**
    160  * Sets the volume for speakers of a given discourse.
    161  *
    162  * @param discourse Chat discourse
    163  * @param volume Speakers volume
    164  */
    165 void
    166 discourse_set_volume(struct GNUNET_CHAT_Discourse *discourse,
    167                      double volume);
    168 
    169 /**
    170  * Returns the volume for speakers of a given discourse.
    171  *
    172  * @param discourse Chat discourse
    173  * @return Speakers volume
    174  */
    175 double
    176 discourse_get_volume(struct GNUNET_CHAT_Discourse *discourse);
    177 
    178 /**
    179  * Mutes/Unmutes the microphone of a given discourse.
    180  *
    181  * @param discourse Chat discourse
    182  * @param mute Mute flag
    183  */
    184 void
    185 discourse_set_mute(struct GNUNET_CHAT_Discourse *discourse,
    186                    bool mute);
    187 
    188 /**
    189  * Returns whether the microphone of a given discourse
    190  * is muted or not.
    191  *
    192  * @param discourse Chat discourse
    193  * @return #TRUE if muted, #FALSE otherwise
    194  */
    195 bool
    196 discourse_is_mute(const struct GNUNET_CHAT_Discourse *discourse);
    197 
    198 /**
    199  * Sets the capture target of a given discourse by name.
    200  *
    201  * @param discourse Chat discourse
    202  * @param name Target name
    203  */
    204 void
    205 discourse_set_target(struct GNUNET_CHAT_Discourse *discourse,
    206                      const char *name);
    207 
    208 /**
    209  * Links/Unlinks a widget from the video pipeline of a discourse
    210  * for a given chat contact to a selected container as
    211  * child.
    212  *
    213  * @param discourse Chat discourse
    214  * @param contact Chat contact
    215  * @param container Container
    216  * @param linked Linking flag
    217  * @return #TRUE if successful, #FALSE otherwise
    218  */
    219 gboolean
    220 discourse_link_widget(const struct GNUNET_CHAT_Discourse *discourse,
    221                       const struct GNUNET_CHAT_Contact *contact,
    222                       GtkContainer *container);
    223 
    224 /**
    225  * Returns whether the data stream of a selected chat contact in 
    226  * a given discourse is active or not.
    227  *
    228  * @param discourse Chat discourse
    229  * @param contact Chat contact
    230  * @return #TRUE if active, #FALSE otherwise
    231  */
    232 gboolean
    233 discourse_is_active(const struct GNUNET_CHAT_Discourse *discourse,
    234                     const struct GNUNET_CHAT_Contact *contact);
    235 
    236 #endif /* DISCOURSE_H_ */