-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.c~
More file actions
executable file
·109 lines (91 loc) · 3.34 KB
/
send.c~
File metadata and controls
executable file
·109 lines (91 loc) · 3.34 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
#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 <ortp/ortp.h>
#define MAX_RTP_SIZE 1500
struct mstream {
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();
printf("0\n");
RtpSession *session = create_duplex_rtpsession(33333);
printf("1\n");
rtp_session_set_remote_addr(session, "127.0.0.1", 44444);
ms_init();
ms_load_plugins("/home/rudy/plugin");
struct mstream *stream;
stream = (struct mstream *)malloc(sizeof(struct mstream));
MSSndCard *sndcard;
sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(), "PulseAudio: default");
const MSList *list = ms_snd_card_manager_get_list(ms_snd_card_manager_get());
while (list != NULL) {
MSSndCard * card = list->data;
printf("name:%s\n", card->name);
printf("id:%s\n", card->id);
printf("driver:%s\n", card->desc->driver_type);
list = list->next;
}
if(sndcard != NULL)
{
stream->soundread = ms_snd_card_create_reader(sndcard);
}
else
{
stream->soundread=ms_filter_new(MS_FILE_PLAYER_ID);
audio_stream_play(stream, "test.wav");
printf("\n\nread from file\n\n");
}
stream->crypto = ms_filter_new_from_name("Encrypt");
stream->encoder = ms_filter_create_encoder("SPEEX");
stream->rtpsend=ms_filter_new(MS_RTP_SEND_ID);
int sr = 8000;
ms_filter_call_method(stream->soundread,MS_FILTER_SET_SAMPLE_RATE,&sr);
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->rtpsend, 0);
printf("8\n");
stream->ticker = ms_ticker_new();
ms_ticker_set_name(stream->ticker, "recv stream");
ms_ticker_attach(stream->ticker, stream->soundread);
int count = 0;
while (TRUE){
ortp_global_stats_display();
if (session) {
printf("Bandwidth usage: download=%f kbits/sec, upload=%f kbits/sec\n",
rtp_session_compute_recv_bandwidth(session)/1e3,
rtp_session_compute_send_bandwidth(session)/1e3);
}
usleep(500000);
}
ms_exit();
return 0;
}