]> sjero.net Git - linphone/blob - linphone/mediastreamer2/include/mediastreamer2/mediastream.h
e0b971fcec93f92286c958ebf639a6975d8c2000
[linphone] / linphone / mediastreamer2 / include / mediastreamer2 / mediastream.h
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 #include <time.h>
32
33 #if defined(_WIN32_WCE)
34 time_t ms_time (time_t *t);
35 #else
36 #define ms_time time
37 #endif
38
39 typedef enum EchoLimiterType{
40         ELInactive,
41         ELControlMic,
42         ELControlSpeaker
43 } EchoLimiterType;
44
45 struct _AudioStream
46 {
47         MSTicker *ticker;
48         RtpSession *session;
49         MSFilter *soundread;
50         MSFilter *soundwrite;
51         MSFilter *encoder;
52         MSFilter *decoder;
53         MSFilter *rtprecv;
54         MSFilter *rtpsend;
55         MSFilter *dtmfgen;
56         MSFilter *ec;/*echo canceler*/
57         MSFilter *volsend,*volrecv; /*MSVolumes*/
58         MSFilter *read_resampler;
59         MSFilter *write_resampler;
60         MSFilter *equalizer;
61         uint64_t last_packet_count;
62         time_t last_packet_time;
63         EchoLimiterType el_type; /*use echo limiter: two MSVolume, measured input level controlling local output level*/
64         int ec_tail_len; /*milliseconds*/
65         int ec_delay;   /*milliseconds*/
66         int ec_framesize; /* number of fft points */
67         bool_t play_dtmfs;
68         bool_t use_gc;
69         bool_t use_agc;
70         bool_t eq_active;
71         bool_t use_ng;/*noise gate*/
72 };
73
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77
78 typedef struct _AudioStream AudioStream;
79
80 struct _RingStream
81 {
82         MSTicker *ticker;
83         MSFilter *source;
84         MSFilter *sndwrite;
85 };
86
87 typedef struct _RingStream RingStream;
88
89
90
91 /* start a thread that does sampling->encoding->rtp_sending|rtp_receiving->decoding->playing */
92 AudioStream *audio_stream_start (RtpProfile * prof, int locport, const char *remip,
93                                  int remport, int payload_type, int jitt_comp, bool_t echo_cancel);
94
95 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);
96
97 int audio_stream_start_with_files (AudioStream * stream, RtpProfile * prof,
98                                             const char *remip, int remport, int rem_rtcp_port,
99                                             int pt, int jitt_comp,
100                                             const char * infile,  const char * outfile);
101
102 void audio_stream_play(AudioStream *st, const char *name);
103 void audio_stream_record(AudioStream *st, const char *name);
104
105 void audio_stream_set_rtcp_information(AudioStream *st, const char *cname, const char *tool);
106
107 void audio_stream_play_received_dtmfs(AudioStream *st, bool_t yesno);
108
109 /* those two function do the same as audio_stream_start() but in two steps
110 this is useful to make sure that sockets are open before sending an invite;
111 or to start to stream only after receiving an ack.*/
112 AudioStream *audio_stream_new(int locport, bool_t ipv6);
113 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);
114 void audio_stream_set_relay_session_id(AudioStream *stream, const char *relay_session_id);
115 /*returns true if we are still receiving some data from remote end in the last timeout seconds*/
116 bool_t audio_stream_alive(AudioStream * stream, int timeout);
117
118 /*enable echo-limiter dispositve: one MSVolume in input branch controls a MSVolume in the output branch*/
119 void audio_stream_enable_echo_limiter(AudioStream *stream, EchoLimiterType type);
120
121 /*enable gain control, to be done before start() */
122 void audio_stream_enable_gain_control(AudioStream *stream, bool_t val);
123
124 /*enable automatic gain control, to be done before start() */
125 void audio_stream_enable_automatic_gain_control(AudioStream *stream, bool_t val);
126
127 /*to be done before start */
128 void audio_stream_set_echo_canceller_params(AudioStream *st, int tail_len_ms, int delay_ms, int framesize);
129
130 void audio_stream_set_mic_gain(AudioStream *stream, float gain);
131
132 /*enable noise gate, must be done before start()*/
133 void audio_stream_enable_noise_gate(AudioStream *stream, bool_t val);
134
135 /*enable parametric equalizer in the stream that goes to the speaker*/
136 void audio_stream_enable_equalizer(AudioStream *stream, bool_t enabled);
137
138 void audio_stream_equalizer_set_gain(AudioStream *stream, int frequency, float gain, int freq_width);
139
140 /* stop the audio streaming thread and free everything*/
141 void audio_stream_stop (AudioStream * stream);
142
143 RingStream *ring_start (const char * file, int interval, MSSndCard *sndcard);
144 RingStream *ring_start_with_cb(const char * file, int interval, MSSndCard *sndcard, MSFilterNotifyFunc func, void * user_data);
145 void ring_stop (RingStream * stream);
146
147
148 /* send a dtmf */
149 int audio_stream_send_dtmf (AudioStream * stream, char dtmf);
150
151 void audio_stream_set_default_card(int cardindex);
152
153
154 /*****************
155   Video Support
156  *****************/
157
158
159 struct _VideoStream
160 {
161         MSTicker *ticker;
162         RtpSession *session;
163         MSFilter *source;
164         MSFilter *pixconv;
165         MSFilter *sizeconv;
166         MSFilter *tee;
167         MSFilter *output;
168         MSFilter *encoder;
169         MSFilter *decoder;
170         MSFilter *rtprecv;
171         MSFilter *rtpsend;
172         OrtpEvQueue *evq;
173         MSVideoSize sent_vsize;
174         int corner; /*for selfview*/
175         bool_t adapt_bitrate;
176 };
177
178 typedef struct _VideoStream VideoStream;
179
180 VideoStream *video_stream_new(int locport, bool_t use_ipv6);
181 void video_stream_enable_adaptive_bitrate_control(VideoStream *s, bool_t yesno);
182 int video_stream_start(VideoStream * stream, RtpProfile *profile, const char *remip, int remport, int rem_rtcp_port,
183                 int payload, int jitt_comp, MSWebCam *device);
184 void video_stream_set_relay_session_id(VideoStream *stream, const char *relay_session_id);
185 void video_stream_set_rtcp_information(VideoStream *st, const char *cname, const char *tool);
186 /*function to call periodically to handle various events */
187 void video_stream_iterate(VideoStream *stream);
188 void video_stream_send_vfu(VideoStream *stream);
189 void video_stream_stop(VideoStream * stream);
190 void video_stream_set_sent_video_size(VideoStream *stream, MSVideoSize vsize);
191 void video_stream_enable_self_view(VideoStream *stream, bool_t val);
192 unsigned long video_stream_get_native_window_id(VideoStream *stream);
193
194
195 VideoStream * video_preview_start(MSWebCam *device, MSVideoSize vsize);
196 void video_preview_stop(VideoStream *stream);
197
198 int video_stream_recv_only_start(VideoStream * stream, RtpProfile *profile, const char *remip, int remport, int payload, int jitt_comp);
199 int video_stream_send_only_start(VideoStream * stream, RtpProfile *profile, const char *remip, int remport,
200                 int rem_rtcp_port, int payload, int jitt_comp, MSWebCam *device);
201 void video_stream_recv_only_stop(VideoStream *stream);
202 void video_stream_send_only_stop(VideoStream *stream);
203
204
205 bool_t ms_is_ipv6(const char *address);
206
207 #ifdef __cplusplus
208 }
209 #endif
210
211
212 #endif