-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendrecv.c
More file actions
executable file
·119 lines (92 loc) · 4.03 KB
/
sendrecv.c
File metadata and controls
executable file
·119 lines (92 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <mediastreamer2/mscommon.h>
#include <mediastreamer2/mssndcard.h>
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msticker.h>
#include <mediastreamer2/msrtp.h>
#include <mediastreamer2/mediastream.h>
#include <mediastreamer2/msfileplayer.h>
#include <mediastreamer2/msfilerec.h>
#include <ortp/ortp.h>
#define MAX_RTP_SIZE 1500
struct mstream {
MSFilter *rtprecv;
MSFilter *decrypto;
MSFilter *decoder;
MSFilter *soundwrite;
MSFilter *soundread;
MSFilter *crypto;
MSFilter *encoder;
MSFilter *rtpsend;
MSTicker *ticker;
};
RtpSession *create_duplex_rtpsession(int locport) {
RtpSession *rtpr;
rtpr=rtp_session_new(RTP_SESSION_SENDRECV);
rtp_session_set_recv_buf_size(rtpr, MAX_RTP_SIZE);
rtp_session_set_scheduling_mode(rtpr, 0);
rtp_session_set_blocking_mode(rtpr, 0);
rtp_session_enable_adaptive_jitter_compensation(rtpr, FALSE);
rtp_session_set_symmetric_rtp(rtpr, TRUE);
rtp_session_set_local_addr(rtpr, "0.0.0.0", locport);
rtp_session_signal_connect(rtpr, "timestamp_jump", (RtpCallback)rtp_session_resync, (long)NULL);
rtp_session_signal_connect(rtpr, "ssrc_changed", (RtpCallback)rtp_session_resync, (long)NULL);
return rtpr;
}
int main(int argc, char **argv)
{
ortp_init();
ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
ortp_scheduler_init();
OrtpEvQueue *q = ortp_ev_queue_new();
RtpSession *session = create_duplex_rtpsession(11111);
rtp_session_set_remote_addr(session, "127.0.0.1", 11111);
ms_init();
ms_load_plugins("/home/rudy/plugin");
struct mstream *stream;
stream = (struct mstream *)malloc(sizeof(struct mstream));
MSSndCard *sndcard1, *sndcard2;
const MSList *list = ms_snd_card_manager_get_list(ms_snd_card_manager_get());
MSSndCard * card;
sndcard1 = ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
sndcard2 = ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
int sr = 8000;
int chan=1;
char *testfile1 = "rec.wav";
char *testfile2 = "test.wav";
stream->rtprecv = ms_filter_new(MS_RTP_RECV_ID);
stream->decrypto = ms_filter_new_from_name("Decrypt");
stream->decoder = ms_filter_create_decoder("SPEEX");
stream->soundwrite = ms_filter_new( MS_FILE_REC_ID);
stream->soundread = ms_filter_new(MS_FILE_PLAYER_ID);
stream->crypto = ms_filter_new_from_name("Encrypt");
stream->encoder = ms_filter_create_encoder("SPEEX");
stream->rtpsend=ms_filter_new(MS_RTP_SEND_ID);
ms_filter_call_method(stream->soundwrite,MS_FILE_REC_OPEN,testfile1);
ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_SAMPLE_RATE,&sr);
ms_filter_call_method_noarg(stream->soundwrite,MS_FILE_REC_START);
ms_filter_call_method(stream->decoder,MS_FILTER_SET_SAMPLE_RATE,&sr);
ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_NCHANNELS, &chan);
ms_filter_call_method(stream->rtprecv, MS_RTP_RECV_SET_SESSION, session);
ms_filter_call_method(stream->soundread,MS_FILE_PLAYER_OPEN,testfile2);
ms_filter_call_method(stream->encoder,MS_FILTER_SET_SAMPLE_RATE,&sr);
ms_filter_call_method(stream->rtpsend, MS_RTP_SEND_SET_SESSION, session);
ms_filter_link(stream->soundread, 0, stream->encoder, 0);
ms_filter_link(stream->encoder, 0, stream->crypto, 0);
ms_filter_link(stream->crypto, 0, stream->decrypto, 0);
printf("\t\t1\n\n");
ms_filter_link(stream->decrypto, 0, stream->decoder, 0);
ms_filter_link(stream->decoder, 0, stream->soundwrite, 0);
printf("\t\t2\n\n");
stream->ticker = ms_ticker_new();
ms_filter_call_method_noarg(stream->soundread,MS_FILE_PLAYER_START);
ms_ticker_set_name(stream->ticker, "recv stream");
ms_ticker_attach(stream->ticker, stream->soundread);
usleep(10000000);
ms_filter_call_method_noarg(stream->soundwrite,MS_FILE_REC_STOP);
ms_filter_call_method_noarg(stream->soundwrite,MS_FILE_REC_CLOSE);
ms_exit();
return 0;
}