mediastream.h 8.43 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/


#ifndef MEDIASTREAM_H
#define MEDIASTREAM_H

smorlat's avatar
smorlat committed
24 25 26 27 28
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msticker.h"
#include "mediastreamer2/mssndcard.h"
#include "mediastreamer2/mswebcam.h"
#include "mediastreamer2/msvideo.h"
aymeric's avatar
aymeric committed
29 30 31
#include "ortp/ortp.h"
#include "ortp/event.h"

32 33


aymeric's avatar
aymeric committed
34

35 36 37
typedef enum EchoLimiterType{
	ELInactive,
	ELControlMic,
38
	ELControlFull
39 40
} EchoLimiterType;

aymeric's avatar
aymeric committed
41 42 43 44 45 46 47 48 49 50 51
struct _AudioStream
{
	MSTicker *ticker;
	RtpSession *session;
	MSFilter *soundread;
	MSFilter *soundwrite;
	MSFilter *encoder;
	MSFilter *decoder;
	MSFilter *rtprecv;
	MSFilter *rtpsend;
	MSFilter *dtmfgen;
52
	MSFilter *dtmfgen_rtp;
aymeric's avatar
aymeric committed
53
	MSFilter *ec;/*echo canceler*/
54
	MSFilter *volsend,*volrecv; /*MSVolumes*/
55 56
	MSFilter *read_resampler;
	MSFilter *write_resampler;
smorlat's avatar
smorlat committed
57
	MSFilter *equalizer;
aymeric's avatar
aymeric committed
58
	uint64_t last_packet_count;
aymeric's avatar
aymeric committed
59
	time_t last_packet_time;
60
	EchoLimiterType el_type; /*use echo limiter: two MSVolume, measured input level controlling local output level*/
61 62 63
	int ec_tail_len; /*milliseconds*/
	int ec_delay;	/*milliseconds*/
	int ec_framesize; /* number of fft points */
64
	OrtpEvQueue *evq;
smorlat's avatar
smorlat committed
65
	bool_t play_dtmfs;
smorlat's avatar
smorlat committed
66
	bool_t use_gc;
67
	bool_t use_agc;
smorlat's avatar
smorlat committed
68
	bool_t eq_active;
69
	bool_t use_ng;/*noise gate*/
aymeric's avatar
aymeric committed
70 71 72 73 74 75 76 77 78 79 80 81
};

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _AudioStream AudioStream;

struct _RingStream
{
	MSTicker *ticker;
	MSFilter *source;
82
	MSFilter *gendtmf;
aymeric's avatar
aymeric committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
	MSFilter *sndwrite;
};

typedef struct _RingStream RingStream;



/* start a thread that does sampling->encoding->rtp_sending|rtp_receiving->decoding->playing */
AudioStream *audio_stream_start (RtpProfile * prof, int locport, const char *remip,
				 int remport, int payload_type, int jitt_comp, bool_t echo_cancel);

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);

int audio_stream_start_with_files (AudioStream * stream, RtpProfile * prof,
					    const char *remip, int remport, int rem_rtcp_port,
					    int pt, int jitt_comp,
					    const char * infile,  const char * outfile);

101 102 103 104
int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char *remip,int remport,
	int rem_rtcp_port, int payload,int jitt_comp, const char *infile, const char *outfile,
	MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec);

aymeric's avatar
aymeric committed
105 106 107 108 109
void audio_stream_play(AudioStream *st, const char *name);
void audio_stream_record(AudioStream *st, const char *name);

void audio_stream_set_rtcp_information(AudioStream *st, const char *cname, const char *tool);

smorlat's avatar
smorlat committed
110 111
void audio_stream_play_received_dtmfs(AudioStream *st, bool_t yesno);

aymeric's avatar
aymeric committed
112
/* those two function do the same as audio_stream_start() but in two steps
Jehan Monnier's avatar
Jehan Monnier committed
113
this is useful to make sure that sockets are open before sending an invite;
aymeric's avatar
aymeric committed
114 115 116 117 118 119 120
or to start to stream only after receiving an ack.*/
AudioStream *audio_stream_new(int locport, bool_t ipv6);
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);
void audio_stream_set_relay_session_id(AudioStream *stream, const char *relay_session_id);
/*returns true if we are still receiving some data from remote end in the last timeout seconds*/
bool_t audio_stream_alive(AudioStream * stream, int timeout);

smorlat's avatar
smorlat committed
121
/*enable echo-limiter dispositve: one MSVolume in input branch controls a MSVolume in the output branch*/
122
void audio_stream_enable_echo_limiter(AudioStream *stream, EchoLimiterType type);
123

smorlat's avatar
smorlat committed
124 125 126
/*enable gain control, to be done before start() */
void audio_stream_enable_gain_control(AudioStream *stream, bool_t val);

127 128 129
/*enable automatic gain control, to be done before start() */
void audio_stream_enable_automatic_gain_control(AudioStream *stream, bool_t val);

130
/*to be done before start */
131
void audio_stream_set_echo_canceller_params(AudioStream *st, int tail_len_ms, int delay_ms, int framesize);
132

smorlat's avatar
smorlat committed
133 134
void audio_stream_set_mic_gain(AudioStream *stream, float gain);

Simon Morlat's avatar
Simon Morlat committed
135 136 137
/* enable/disable rtp stream */ 
void audio_stream_mute_rtp(AudioStream *stream, bool_t val);

138 139 140
/*enable noise gate, must be done before start()*/
void audio_stream_enable_noise_gate(AudioStream *stream, bool_t val);

smorlat's avatar
smorlat committed
141 142 143
/*enable parametric equalizer in the stream that goes to the speaker*/
void audio_stream_enable_equalizer(AudioStream *stream, bool_t enabled);

smorlat's avatar
smorlat committed
144
void audio_stream_equalizer_set_gain(AudioStream *stream, int frequency, float gain, int freq_width);
smorlat's avatar
smorlat committed
145

smorlat's avatar
smorlat committed
146
/* stop the audio streaming thread and free everything*/
aymeric's avatar
aymeric committed
147 148 149 150 151 152 153 154 155 156 157 158
void audio_stream_stop (AudioStream * stream);

RingStream *ring_start (const char * file, int interval, MSSndCard *sndcard);
RingStream *ring_start_with_cb(const char * file, int interval, MSSndCard *sndcard, MSFilterNotifyFunc func, void * user_data);
void ring_stop (RingStream * stream);


/* send a dtmf */
int audio_stream_send_dtmf (AudioStream * stream, char dtmf);

void audio_stream_set_default_card(int cardindex);

Simon Morlat's avatar
Simon Morlat committed
159 160 161
/* retrieve RTP statistics*/
void audio_stream_get_local_rtp_stats(AudioStream *stream, rtp_stats_t *stats);

aymeric's avatar
aymeric committed
162 163 164 165 166

/*****************
  Video Support
 *****************/

167
typedef void (*VideoStreamRenderCallback)(void *user_pointer, const MSPicture *local_view, const MSPicture *remote_view);
aymeric's avatar
aymeric committed
168

169 170 171 172 173 174
typedef enum _VideoStreamDir{
	VideoStreamSendRecv,
	VideoStreamSendOnly,
	VideoStreamRecvOnly
}VideoStreamDir;

aymeric's avatar
aymeric committed
175 176 177 178 179 180
struct _VideoStream
{
	MSTicker *ticker;
	RtpSession *session;
	MSFilter *source;
	MSFilter *pixconv;
181
	MSFilter *sizeconv;
aymeric's avatar
aymeric committed
182 183 184 185 186 187
	MSFilter *tee;
	MSFilter *output;
	MSFilter *encoder;
	MSFilter *decoder;
	MSFilter *rtprecv;
	MSFilter *rtpsend;
188 189
	MSFilter *tee2;
	MSFilter *jpegwriter;
aymeric's avatar
aymeric committed
190
	OrtpEvQueue *evq;
smorlat's avatar
smorlat committed
191
	MSVideoSize sent_vsize;
smorlat's avatar
smorlat committed
192
	int corner; /*for selfview*/
193 194
	VideoStreamRenderCallback rendercb;
	void *render_pointer;
195
	char *display_name;
196
	VideoStreamDir dir;
aymeric's avatar
aymeric committed
197 198 199 200
	bool_t adapt_bitrate;
};

typedef struct _VideoStream VideoStream;
smorlat's avatar
smorlat committed
201

202 203


aymeric's avatar
aymeric committed
204
VideoStream *video_stream_new(int locport, bool_t use_ipv6);
205
void video_stream_set_direction(VideoStream *vs, VideoStreamDir dir);
aymeric's avatar
aymeric committed
206
void video_stream_enable_adaptive_bitrate_control(VideoStream *s, bool_t yesno);
207
void video_stream_set_render_callback(VideoStream *s, VideoStreamRenderCallback cb, void *user_pointer);
208
void video_stream_set_display_filter_name(VideoStream *s, const char *fname);
aymeric's avatar
aymeric committed
209 210
int video_stream_start(VideoStream * stream, RtpProfile *profile, const char *remip, int remport, int rem_rtcp_port,
		int payload, int jitt_comp, MSWebCam *device);
211 212


aymeric's avatar
aymeric committed
213 214
void video_stream_set_relay_session_id(VideoStream *stream, const char *relay_session_id);
void video_stream_set_rtcp_information(VideoStream *st, const char *cname, const char *tool);
215
void video_stream_change_camera(VideoStream *stream, MSWebCam *cam);
aymeric's avatar
aymeric committed
216 217 218
/*function to call periodically to handle various events */
void video_stream_iterate(VideoStream *stream);
void video_stream_send_vfu(VideoStream *stream);
smorlat's avatar
smorlat committed
219 220
void video_stream_stop(VideoStream * stream);
void video_stream_set_sent_video_size(VideoStream *stream, MSVideoSize vsize);
smorlat's avatar
smorlat committed
221
void video_stream_enable_self_view(VideoStream *stream, bool_t val);
222 223
unsigned long video_stream_get_native_window_id(VideoStream *stream);

224 225 226 227 228 229 230
/*provided for compatibility, use video_stream_set_direction() instead */
int video_stream_recv_only_start(VideoStream *videostream, RtpProfile *profile, const char *addr, int port, int used_pt, int jitt_comp);
int video_stream_send_only_start(VideoStream *videostream,
				RtpProfile *profile, const char *addr, int port, int rtcp_port, 
				int used_pt, int  jitt_comp, MSWebCam *device);
void video_stream_recv_only_stop(VideoStream *vs);
void video_stream_send_only_stop(VideoStream *vs);
aymeric's avatar
aymeric committed
231

smorlat's avatar
smorlat committed
232
VideoStream * video_preview_start(MSWebCam *device, MSVideoSize vsize);
aymeric's avatar
aymeric committed
233 234 235 236 237 238 239 240 241 242
void video_preview_stop(VideoStream *stream);

bool_t ms_is_ipv6(const char *address);

#ifdef __cplusplus
}
#endif


#endif