| 1 | /* |
|---|
| 2 | mediastreamer2 library - modular sound and video processing and streaming |
|---|
| 3 | Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org) |
|---|
| 4 | |
|---|
| 5 | This program is free software; you can redistribute it and/or |
|---|
| 6 | modify it under the terms of the GNU General Public License |
|---|
| 7 | as published by the Free Software Foundation; either version 2 |
|---|
| 8 | of the License, or (at your option) any later version. |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with this program; if not, write to the Free Software |
|---|
| 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #ifndef MEDIASTREAM_H |
|---|
| 22 | #define MEDIASTREAM_H |
|---|
| 23 | |
|---|
| 24 | #include <mediastreamer2/msfilter.h> |
|---|
| 25 | #include <mediastreamer2/msticker.h> |
|---|
| 26 | #include <mediastreamer2/mssndcard.h> |
|---|
| 27 | #include <mediastreamer2/mswebcam.h> |
|---|
| 28 | #include <mediastreamer2/msvideo.h> |
|---|
| 29 | #include <ortp/ortp.h> |
|---|
| 30 | #include <ortp/event.h> |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | typedef enum EchoLimiterType{ |
|---|
| 34 | ELInactive, |
|---|
| 35 | ELControlMic, |
|---|
| 36 | ELControlFull |
|---|
| 37 | } EchoLimiterType; |
|---|
| 38 | |
|---|
| 39 | struct _AudioStream |
|---|
| 40 | { |
|---|
| 41 | MSTicker *ticker; |
|---|
| 42 | RtpSession *session; |
|---|
| 43 | MSFilter *soundread; |
|---|
| 44 | MSFilter *soundwrite; |
|---|
| 45 | MSFilter *encoder; |
|---|
| 46 | MSFilter *decoder; |
|---|
| 47 | MSFilter *rtprecv; |
|---|
| 48 | MSFilter *rtpsend; |
|---|
| 49 | MSFilter *dtmfgen; |
|---|
| 50 | MSFilter *dtmfgen_rtp; |
|---|
| 51 | MSFilter *ec;/*echo canceler*/ |
|---|
| 52 | MSFilter *volsend,*volrecv; /*MSVolumes*/ |
|---|
| 53 | MSFilter *read_resampler; |
|---|
| 54 | MSFilter *write_resampler; |
|---|
| 55 | MSFilter *equalizer; |
|---|
| 56 | uint64_t last_packet_count; |
|---|
| 57 | time_t last_packet_time; |
|---|
| 58 | EchoLimiterType el_type; /*use echo limiter: two MSVolume, measured input level controlling local output level*/ |
|---|
| 59 | OrtpEvQueue *evq; |
|---|
| 60 | bool_t play_dtmfs; |
|---|
| 61 | bool_t use_gc; |
|---|
| 62 | bool_t use_agc; |
|---|
| 63 | bool_t eq_active; |
|---|
| 64 | bool_t use_ng;/*noise gate*/ |
|---|
| 65 | }; |
|---|
| 66 | |
|---|
| 67 | #ifdef __cplusplus |
|---|
| 68 | extern "C" { |
|---|
| 69 | #endif |
|---|
| 70 | |
|---|
| 71 | typedef struct _AudioStream AudioStream; |
|---|
| 72 | |
|---|
| 73 | struct _RingStream |
|---|
| 74 | { |
|---|
| 75 | MSTicker *ticker; |
|---|
| 76 | MSFilter *source; |
|---|
| 77 | MSFilter *gendtmf; |
|---|
| 78 | MSFilter *write_resampler; |
|---|
| 79 | MSFilter *sndwrite; |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | typedef struct _RingStream RingStream; |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | /* start a thread that does sampling->encoding->rtp_sending|rtp_receiving->decoding->playing */ |
|---|
| 87 | MS2_PUBLIC AudioStream *audio_stream_start (RtpProfile * prof, int locport, const char *remip, |
|---|
| 88 | int remport, int payload_type, int jitt_comp, bool_t echo_cancel); |
|---|
| 89 | |
|---|
| 90 | MS2_PUBLIC AudioStream *audio_stream_start_with_sndcards(RtpProfile * prof, int locport, const char *remip4, int remport, int payload_type, int jitt_comp, MSSndCard *playcard, MSSndCard *captcard, bool_t echocancel); |
|---|
| 91 | |
|---|
| 92 | MS2_PUBLIC int audio_stream_start_with_files (AudioStream * stream, RtpProfile * prof, |
|---|
| 93 | const char *remip, int remport, int rem_rtcp_port, |
|---|
| 94 | int pt, int jitt_comp, |
|---|
| 95 | const char * infile, const char * outfile); |
|---|
| 96 | |
|---|
| 97 | MS2_PUBLIC int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char *remip,int remport, |
|---|
| 98 | int rem_rtcp_port, int payload,int jitt_comp, const char *infile, const char *outfile, |
|---|
| 99 | MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec); |
|---|
| 100 | |
|---|
| 101 | MS2_PUBLIC void audio_stream_play(AudioStream *st, const char *name); |
|---|
| 102 | MS2_PUBLIC void audio_stream_record(AudioStream *st, const char *name); |
|---|
| 103 | |
|---|
| 104 | MS2_PUBLIC void audio_stream_set_rtcp_information(AudioStream *st, const char *cname, const char *tool); |
|---|
| 105 | |
|---|
| 106 | MS2_PUBLIC void audio_stream_play_received_dtmfs(AudioStream *st, bool_t yesno); |
|---|
| 107 | |
|---|
| 108 | /* those two function do the same as audio_stream_start() but in two steps |
|---|
| 109 | this is useful to make sure that sockets are open before sending an invite; |
|---|
| 110 | or to start to stream only after receiving an ack.*/ |
|---|
| 111 | MS2_PUBLIC AudioStream *audio_stream_new(int locport, bool_t ipv6); |
|---|
| 112 | MS2_PUBLIC int audio_stream_start_now(AudioStream * stream, RtpProfile * prof, const char *remip, int remport, int rem_rtcp_port, int payload_type, int jitt_comp,MSSndCard *playcard, MSSndCard *captcard, bool_t echo_cancel); |
|---|
| 113 | MS2_PUBLIC void audio_stream_set_relay_session_id(AudioStream *stream, const char *relay_session_id); |
|---|
| 114 | /*returns true if we are still receiving some data from remote end in the last timeout seconds*/ |
|---|
| 115 | MS2_PUBLIC bool_t audio_stream_alive(AudioStream * stream, int timeout); |
|---|
| 116 | |
|---|
| 117 | /*enable echo-limiter dispositve: one MSVolume in input branch controls a MSVolume in the output branch*/ |
|---|
| 118 | MS2_PUBLIC void audio_stream_enable_echo_limiter(AudioStream *stream, EchoLimiterType type); |
|---|
| 119 | |
|---|
| 120 | /*enable gain control, to be done before start() */ |
|---|
| 121 | MS2_PUBLIC void audio_stream_enable_gain_control(AudioStream *stream, bool_t val); |
|---|
| 122 | |
|---|
| 123 | /*enable automatic gain control, to be done before start() */ |
|---|
| 124 | MS2_PUBLIC void audio_stream_enable_automatic_gain_control(AudioStream *stream, bool_t val); |
|---|
| 125 | |
|---|
| 126 | /*to be done before start */ |
|---|
| 127 | MS2_PUBLIC void audio_stream_set_echo_canceller_params(AudioStream *st, int tail_len_ms, int delay_ms, int framesize); |
|---|
| 128 | |
|---|
| 129 | MS2_PUBLIC void audio_stream_set_mic_gain(AudioStream *stream, float gain); |
|---|
| 130 | |
|---|
| 131 | /* enable/disable rtp stream */ |
|---|
| 132 | MS2_PUBLIC void audio_stream_mute_rtp(AudioStream *stream, bool_t val); |
|---|
| 133 | |
|---|
| 134 | /*enable noise gate, must be done before start()*/ |
|---|
| 135 | MS2_PUBLIC void audio_stream_enable_noise_gate(AudioStream *stream, bool_t val); |
|---|
| 136 | |
|---|
| 137 | /*enable parametric equalizer in the stream that goes to the speaker*/ |
|---|
| 138 | MS2_PUBLIC void audio_stream_enable_equalizer(AudioStream *stream, bool_t enabled); |
|---|
| 139 | |
|---|
| 140 | MS2_PUBLIC void audio_stream_equalizer_set_gain(AudioStream *stream, int frequency, float gain, int freq_width); |
|---|
| 141 | |
|---|
| 142 | /* stop the audio streaming thread and free everything*/ |
|---|
| 143 | MS2_PUBLIC void audio_stream_stop (AudioStream * stream); |
|---|
| 144 | |
|---|
| 145 | MS2_PUBLIC RingStream *ring_start (const char * file, int interval, MSSndCard *sndcard); |
|---|
| 146 | MS2_PUBLIC RingStream *ring_start_with_cb(const char * file, int interval, MSSndCard *sndcard, MSFilterNotifyFunc func, void * user_data); |
|---|
| 147 | MS2_PUBLIC void ring_stop (RingStream * stream); |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | /* send a dtmf */ |
|---|
| 151 | MS2_PUBLIC int audio_stream_send_dtmf (AudioStream * stream, char dtmf); |
|---|
| 152 | |
|---|
| 153 | MS2_PUBLIC void audio_stream_set_default_card(int cardindex); |
|---|
| 154 | |
|---|
| 155 | /* retrieve RTP statistics*/ |
|---|
| 156 | MS2_PUBLIC void audio_stream_get_local_rtp_stats(AudioStream *stream, rtp_stats_t *stats); |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | /***************** |
|---|
| 160 | Video Support |
|---|
| 161 | *****************/ |
|---|
| 162 | |
|---|
| 163 | typedef void (*VideoStreamRenderCallback)(void *user_pointer, const MSPicture *local_view, const MSPicture *remote_view); |
|---|
| 164 | typedef void (*VideoStreamEventCallback)(void *user_pointer, const MSFilter *f, const unsigned int event_id, const void *args); |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | typedef enum _VideoStreamDir{ |
|---|
| 169 | VideoStreamSendRecv, |
|---|
| 170 | VideoStreamSendOnly, |
|---|
| 171 | VideoStreamRecvOnly |
|---|
| 172 | }VideoStreamDir; |
|---|
| 173 | |
|---|
| 174 | struct _VideoStream |
|---|
| 175 | { |
|---|
| 176 | MSTicker *ticker; |
|---|
| 177 | RtpSession *session; |
|---|
| 178 | MSFilter *source; |
|---|
| 179 | MSFilter *pixconv; |
|---|
| 180 | MSFilter *sizeconv; |
|---|
| 181 | MSFilter *tee; |
|---|
| 182 | MSFilter *output; |
|---|
| 183 | MSFilter *encoder; |
|---|
| 184 | MSFilter *decoder; |
|---|
| 185 | MSFilter *rtprecv; |
|---|
| 186 | MSFilter *rtpsend; |
|---|
| 187 | MSFilter *tee2; |
|---|
| 188 | MSFilter *jpegwriter; |
|---|
| 189 | MSFilter *output2; |
|---|
| 190 | OrtpEvQueue *evq; |
|---|
| 191 | MSVideoSize sent_vsize; |
|---|
| 192 | int corner; /*for selfview*/ |
|---|
| 193 | VideoStreamRenderCallback rendercb; |
|---|
| 194 | void *render_pointer; |
|---|
| 195 | VideoStreamEventCallback eventcb; |
|---|
| 196 | void *event_pointer; |
|---|
| 197 | char *display_name; |
|---|
| 198 | unsigned long window_id; |
|---|
| 199 | unsigned long preview_window_id; |
|---|
| 200 | VideoStreamDir dir; |
|---|
| 201 | MSWebCam *cam; |
|---|
| 202 | bool_t use_preview_window; |
|---|
| 203 | bool_t adapt_bitrate; |
|---|
| 204 | }; |
|---|
| 205 | |
|---|
| 206 | typedef struct _VideoStream VideoStream; |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | MS2_PUBLIC VideoStream *video_stream_new(int locport, bool_t use_ipv6); |
|---|
| 211 | MS2_PUBLIC void video_stream_set_direction(VideoStream *vs, VideoStreamDir dir); |
|---|
| 212 | MS2_PUBLIC void video_stream_enable_adaptive_bitrate_control(VideoStream *s, bool_t yesno); |
|---|
| 213 | MS2_PUBLIC void video_stream_set_render_callback(VideoStream *s, VideoStreamRenderCallback cb, void *user_pointer); |
|---|
| 214 | MS2_PUBLIC void video_stream_set_event_callback(VideoStream *s, VideoStreamEventCallback cb, void *user_pointer); |
|---|
| 215 | MS2_PUBLIC void video_stream_set_display_filter_name(VideoStream *s, const char *fname); |
|---|
| 216 | MS2_PUBLIC int video_stream_start(VideoStream * stream, RtpProfile *profile, const char *remip, int remport, int rem_rtcp_port, |
|---|
| 217 | int payload, int jitt_comp, MSWebCam *device); |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | MS2_PUBLIC void video_stream_set_relay_session_id(VideoStream *stream, const char *relay_session_id); |
|---|
| 221 | MS2_PUBLIC void video_stream_set_rtcp_information(VideoStream *st, const char *cname, const char *tool); |
|---|
| 222 | MS2_PUBLIC void video_stream_change_camera(VideoStream *stream, MSWebCam *cam); |
|---|
| 223 | /* Calling video_stream_set_sent_video_size() or changing the bitrate value in the used PayloadType during a stream is running does nothing. |
|---|
| 224 | The following function allows to take into account new parameters by redrawing the sending graph*/ |
|---|
| 225 | MS2_PUBLIC void video_stream_update_video_params(VideoStream *stream); |
|---|
| 226 | /*function to call periodically to handle various events */ |
|---|
| 227 | MS2_PUBLIC void video_stream_iterate(VideoStream *stream); |
|---|
| 228 | MS2_PUBLIC void video_stream_send_vfu(VideoStream *stream); |
|---|
| 229 | MS2_PUBLIC void video_stream_stop(VideoStream * stream); |
|---|
| 230 | MS2_PUBLIC void video_stream_set_sent_video_size(VideoStream *stream, MSVideoSize vsize); |
|---|
| 231 | MS2_PUBLIC void video_stream_enable_self_view(VideoStream *stream, bool_t val); |
|---|
| 232 | MS2_PUBLIC unsigned long video_stream_get_native_window_id(VideoStream *stream); |
|---|
| 233 | MS2_PUBLIC void video_stream_set_native_window_id(VideoStream *stream, unsigned long id); |
|---|
| 234 | MS2_PUBLIC void video_stream_set_native_preview_window_id(VideoStream *stream, unsigned long id); |
|---|
| 235 | MS2_PUBLIC unsigned long video_stream_get_native_preview_window_id(VideoStream *stream); |
|---|
| 236 | MS2_PUBLIC void video_stream_use_preview_video_window(VideoStream *stream, bool_t yesno); |
|---|
| 237 | |
|---|
| 238 | /*provided for compatibility, use video_stream_set_direction() instead */ |
|---|
| 239 | MS2_PUBLIC int video_stream_recv_only_start(VideoStream *videostream, RtpProfile *profile, const char *addr, int port, int used_pt, int jitt_comp); |
|---|
| 240 | MS2_PUBLIC int video_stream_send_only_start(VideoStream *videostream, |
|---|
| 241 | RtpProfile *profile, const char *addr, int port, int rtcp_port, |
|---|
| 242 | int used_pt, int jitt_comp, MSWebCam *device); |
|---|
| 243 | MS2_PUBLIC void video_stream_recv_only_stop(VideoStream *vs); |
|---|
| 244 | MS2_PUBLIC void video_stream_send_only_stop(VideoStream *vs); |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | /** |
|---|
| 248 | * Small API to display a local preview window. |
|---|
| 249 | **/ |
|---|
| 250 | |
|---|
| 251 | typedef VideoStream VideoPreview; |
|---|
| 252 | |
|---|
| 253 | MS2_PUBLIC VideoPreview * video_preview_new(); |
|---|
| 254 | #define video_preview_set_size(p,s) video_stream_set_sent_video_size(p,s) |
|---|
| 255 | #define video_preview_set_display_filter_name(p,dt) video_stream_set_display_filter_name(p,dt) |
|---|
| 256 | #define video_preview_set_native_window_id(p,id) video_stream_set_native_preview_window_id (p,id) |
|---|
| 257 | #define video_preview_get_native_window_id(p) video_stream_get_native_preview_window_id (p) |
|---|
| 258 | MS2_PUBLIC void video_preview_start(VideoPreview *stream, MSWebCam *device); |
|---|
| 259 | MS2_PUBLIC void video_preview_stop(VideoPreview *stream); |
|---|
| 260 | |
|---|
| 261 | MS2_PUBLIC bool_t ms_is_ipv6(const char *address); |
|---|
| 262 | |
|---|
| 263 | #ifdef __cplusplus |
|---|
| 264 | } |
|---|
| 265 | #endif |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | #endif |
|---|