Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
mediastreamer2
Commits
e003e8c6
Commit
e003e8c6
authored
Jan 07, 2013
by
Ghislain MARY
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factorize media streams code.
parent
22f54d40
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
563 additions
and
542 deletions
+563
-542
include/mediastreamer2/mediastream.h
include/mediastreamer2/mediastream.h
+85
-46
src/Makefile.am
src/Makefile.am
+1
-0
src/audioconference.c
src/audioconference.c
+11
-12
src/audiostream.c
src/audiostream.c
+99
-262
src/mediastream.c
src/mediastream.c
+199
-0
src/private.h
src/private.h
+40
-0
src/videostream.c
src/videostream.c
+113
-207
tests/mediastream.c
tests/mediastream.c
+11
-11
tests/videodisplay.c
tests/videodisplay.c
+4
-4
No files found.
include/mediastreamer2/mediastream.h
View file @
e003e8c6
...
...
@@ -36,9 +36,39 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <ortp/zrtp.h>
#define PAYLOAD_TYPE_FLAG_CAN_RECV PAYLOAD_TYPE_USER_FLAG_1
#define PAYLOAD_TYPE_FLAG_CAN_SEND PAYLOAD_TYPE_USER_FLAG_2
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
enum
StreamType
{
AudioStreamType
,
VideoStreamType
}
StreamType
;
struct
_MediaStream
{
StreamType
type
;
MSTicker
*
ticker
;
RtpSession
*
session
;
OrtpEvQueue
*
evq
;
MSFilter
*
rtprecv
;
MSFilter
*
rtpsend
;
MSFilter
*
encoder
;
MSFilter
*
decoder
;
MSFilter
*
voidsink
;
MSBitrateController
*
rc
;
IceCheckList
*
ice_check_list
;
OrtpZrtpContext
*
zrtp_context
;
srtp_t
srtp_session
;
bool_t
use_rc
;
};
typedef
struct
_MediaStream
MediaStream
;
typedef
enum
EchoLimiterType
{
ELInactive
,
ELControlMic
,
...
...
@@ -47,15 +77,9 @@ typedef enum EchoLimiterType{
struct
_AudioStream
{
MSTicker
*
ticker
;
RtpSession
*
session
;
IceCheckList
*
ice_check_list
;
MediaStream
ms
;
MSFilter
*
soundread
;
MSFilter
*
soundwrite
;
MSFilter
*
encoder
;
MSFilter
*
decoder
;
MSFilter
*
rtprecv
;
MSFilter
*
rtpsend
;
MSFilter
*
dtmfgen
;
MSFilter
*
dtmfgen_rtp
;
MSFilter
*
plc
;
...
...
@@ -65,29 +89,33 @@ struct _AudioStream
MSFilter
*
write_resampler
;
MSFilter
*
equalizer
;
MSFilter
*
dummy
;
MSFilter
*
voidsink
;
uint64_t
last_packet_count
;
time_t
last_packet_time
;
EchoLimiterType
el_type
;
/*use echo limiter: two MSVolume, measured input level controlling local output level*/
OrtpEvQueue
*
evq
;
MSBitrateController
*
rc
;
MSQualityIndicator
*
qi
;
time_t
start_time
;
uint32_t
features
;
bool_t
play_dtmfs
;
bool_t
use_gc
;
bool_t
use_agc
;
bool_t
eq_active
;
bool_t
use_ng
;
/*noise gate*/
bool_t
use_rc
;
bool_t
is_beginning
;
OrtpZrtpContext
*
ortpZrtpContext
;
srtp_t
srtp_session
;
uint32_t
features
;
};
#ifdef __cplusplus
extern
"C"
{
#endif
MS2_PUBLIC
void
media_stream_set_rtcp_information
(
MediaStream
*
stream
,
const
char
*
cname
,
const
char
*
tool
);
MS2_PUBLIC
void
media_stream_get_local_rtp_stats
(
MediaStream
*
stream
,
rtp_stats_t
*
stats
);
MS2_PUBLIC
int
media_stream_set_dscp
(
MediaStream
*
stream
,
int
dscp
);
MS2_PUBLIC
void
media_stream_enable_adaptive_bitrate_control
(
MediaStream
*
stream
,
bool_t
enabled
);
MS2_PUBLIC
void
media_stream_enable_adaptive_jittcomp
(
MediaStream
*
stream
,
bool_t
enabled
);
MS2_PUBLIC
bool_t
media_stream_enable_srtp
(
MediaStream
*
stream
,
enum
ortp_srtp_crypto_suite_t
suite
,
const
char
*
snd_key
,
const
char
*
rcv_key
);
/**
* @addtogroup audio_stream_api
...
...
@@ -154,7 +182,9 @@ MS2_PUBLIC int audio_stream_start_full(AudioStream *stream, RtpProfile *profile,
MS2_PUBLIC
void
audio_stream_play
(
AudioStream
*
st
,
const
char
*
name
);
MS2_PUBLIC
void
audio_stream_record
(
AudioStream
*
st
,
const
char
*
name
);
MS2_PUBLIC
void
audio_stream_set_rtcp_information
(
AudioStream
*
st
,
const
char
*
cname
,
const
char
*
tool
);
MS2_PUBLIC
static
inline
void
audio_stream_set_rtcp_information
(
AudioStream
*
st
,
const
char
*
cname
,
const
char
*
tool
)
{
media_stream_set_rtcp_information
(
&
st
->
ms
,
cname
,
tool
);
}
MS2_PUBLIC
void
audio_stream_play_received_dtmfs
(
AudioStream
*
st
,
bool_t
yesno
);
...
...
@@ -231,11 +261,14 @@ MS2_PUBLIC void audio_stream_enable_automatic_gain_control(AudioStream *stream,
MS2_PUBLIC
void
audio_stream_set_echo_canceller_params
(
AudioStream
*
st
,
int
tail_len_ms
,
int
delay_ms
,
int
framesize
);
/*enable adaptive rate control */
MS2_PUBLIC
void
audio_stream_enable_adaptive_bitrate_control
(
AudioStream
*
st
,
bool_t
enabled
);
MS2_PUBLIC
static
inline
void
audio_stream_enable_adaptive_bitrate_control
(
AudioStream
*
stream
,
bool_t
enabled
)
{
media_stream_enable_adaptive_bitrate_control
(
&
stream
->
ms
,
enabled
);
}
/* Enable adaptive jitter compensation */
MS2_PUBLIC
void
audio_stream_enable_adaptive_jittcomp
(
AudioStream
*
st
,
bool_t
enabled
);
MS2_PUBLIC
static
inline
void
audio_stream_enable_adaptive_jittcomp
(
AudioStream
*
stream
,
bool_t
enabled
)
{
media_stream_enable_adaptive_jittcomp
(
&
stream
->
ms
,
enabled
);
}
MS2_PUBLIC
void
audio_stream_set_mic_gain
(
AudioStream
*
stream
,
float
gain
);
...
...
@@ -264,7 +297,9 @@ MS2_PUBLIC int audio_stream_send_dtmf (AudioStream * stream, char dtmf);
MS2_PUBLIC
void
audio_stream_set_default_card
(
int
cardindex
);
/* retrieve RTP statistics*/
MS2_PUBLIC
void
audio_stream_get_local_rtp_stats
(
AudioStream
*
stream
,
rtp_stats_t
*
stats
);
MS2_PUBLIC
static
inline
void
audio_stream_get_local_rtp_stats
(
AudioStream
*
stream
,
rtp_stats_t
*
stats
)
{
media_stream_get_local_rtp_stats
(
&
stream
->
ms
,
stats
);
}
/* returns a realtime indicator of the stream quality between 0 and 5 */
MS2_PUBLIC
float
audio_stream_get_quality_rating
(
AudioStream
*
stream
);
...
...
@@ -276,9 +311,13 @@ MS2_PUBLIC float audio_stream_get_average_quality_rating(AudioStream *stream);
MS2_PUBLIC
void
audio_stream_enable_zrtp
(
AudioStream
*
stream
,
OrtpZrtpParams
*
params
);
/* enable SRTP on the audio stream */
MS2_PUBLIC
bool_t
audio_stream_enable_strp
(
AudioStream
*
stream
,
enum
ortp_srtp_crypto_suite_t
suite
,
const
char
*
snd_key
,
const
char
*
rcv_key
);
MS2_PUBLIC
static
inline
bool_t
audio_stream_enable_srtp
(
AudioStream
*
stream
,
enum
ortp_srtp_crypto_suite_t
suite
,
const
char
*
snd_key
,
const
char
*
rcv_key
)
{
return
media_stream_enable_srtp
(
&
stream
->
ms
,
suite
,
snd_key
,
rcv_key
);
}
MS2_PUBLIC
int
audio_stream_set_dscp
(
AudioStream
*
stream
,
int
dscp
);
MS2_PUBLIC
static
inline
int
audio_stream_set_dscp
(
AudioStream
*
stream
,
int
dscp
)
{
return
media_stream_set_dscp
(
&
stream
->
ms
,
dscp
);
}
/*****************
Video Support
...
...
@@ -297,23 +336,15 @@ typedef enum _VideoStreamDir{
struct
_VideoStream
{
MSTicker
*
ticker
;
RtpSession
*
session
;
IceCheckList
*
ice_check_list
;
MediaStream
ms
;
MSFilter
*
source
;
MSFilter
*
pixconv
;
MSFilter
*
sizeconv
;
MSFilter
*
tee
;
MSFilter
*
output
;
MSFilter
*
encoder
;
MSFilter
*
decoder
;
MSFilter
*
rtprecv
;
MSFilter
*
rtpsend
;
MSFilter
*
tee2
;
MSFilter
*
jpegwriter
;
MSFilter
*
output2
;
MSFilter
*
voidsink
;
OrtpEvQueue
*
evq
;
MSVideoSize
sent_vsize
;
int
corner
;
/*for selfview*/
VideoStreamRenderCallback
rendercb
;
...
...
@@ -325,14 +356,9 @@ struct _VideoStream
unsigned
long
preview_window_id
;
VideoStreamDir
dir
;
MSWebCam
*
cam
;
bool_t
use_preview_window
;
bool_t
use_rc
;
bool_t
pad
[
2
];
bool_t
display_filter_auto_rotate_enabled
;
int
device_orientation
;
/* warning: meaning of this variable depends on the platform (Android, iOS, ...) */
OrtpZrtpContext
*
ortpZrtpContext
;
srtp_t
srtp_session
;
MSBitrateController
*
rc
;
bool_t
use_preview_window
;
bool_t
display_filter_auto_rotate_enabled
;
bool_t
prepare_ongoing
;
};
...
...
@@ -342,8 +368,12 @@ typedef struct _VideoStream VideoStream;
MS2_PUBLIC
VideoStream
*
video_stream_new
(
int
loc_rtp_port
,
int
loc_rtcp_port
,
bool_t
use_ipv6
);
MS2_PUBLIC
void
video_stream_set_direction
(
VideoStream
*
vs
,
VideoStreamDir
dir
);
MS2_PUBLIC
void
video_stream_enable_adaptive_bitrate_control
(
VideoStream
*
s
,
bool_t
yesno
);
MS2_PUBLIC
void
video_stream_enable_adaptive_jittcomp
(
VideoStream
*
st
,
bool_t
enabled
);
MS2_PUBLIC
static
inline
void
video_stream_enable_adaptive_bitrate_control
(
VideoStream
*
stream
,
bool_t
enabled
)
{
media_stream_enable_adaptive_bitrate_control
(
&
stream
->
ms
,
enabled
);
}
MS2_PUBLIC
static
inline
void
video_stream_enable_adaptive_jittcomp
(
VideoStream
*
stream
,
bool_t
enabled
)
{
media_stream_enable_adaptive_jittcomp
(
&
stream
->
ms
,
enabled
);
}
MS2_PUBLIC
void
video_stream_set_render_callback
(
VideoStream
*
s
,
VideoStreamRenderCallback
cb
,
void
*
user_pointer
);
MS2_PUBLIC
void
video_stream_set_event_callback
(
VideoStream
*
s
,
VideoStreamEventCallback
cb
,
void
*
user_pointer
);
MS2_PUBLIC
void
video_stream_set_display_filter_name
(
VideoStream
*
s
,
const
char
*
fname
);
...
...
@@ -354,7 +384,9 @@ MS2_PUBLIC void video_stream_unprepare_video(VideoStream *stream);
MS2_PUBLIC
void
video_stream_set_relay_session_id
(
VideoStream
*
stream
,
const
char
*
relay_session_id
);
MS2_PUBLIC
void
video_stream_set_rtcp_information
(
VideoStream
*
st
,
const
char
*
cname
,
const
char
*
tool
);
MS2_PUBLIC
static
inline
void
video_stream_set_rtcp_information
(
VideoStream
*
st
,
const
char
*
cname
,
const
char
*
tool
)
{
media_stream_set_rtcp_information
(
&
st
->
ms
,
cname
,
tool
);
}
MS2_PUBLIC
void
video_stream_change_camera
(
VideoStream
*
stream
,
MSWebCam
*
cam
);
/* Calling video_stream_set_sent_video_size() or changing the bitrate value in the used PayloadType during a stream is running does nothing.
The following function allows to take into account new parameters by redrawing the sending graph*/
...
...
@@ -385,14 +417,21 @@ MS2_PUBLIC void video_stream_send_only_stop(VideoStream *vs);
MS2_PUBLIC
void
video_stream_enable_zrtp
(
VideoStream
*
vstream
,
AudioStream
*
astream
,
OrtpZrtpParams
*
param
);
/* enable SRTP on the video stream */
MS2_PUBLIC
bool_t
video_stream_enable_strp
(
VideoStream
*
stream
,
enum
ortp_srtp_crypto_suite_t
suite
,
const
char
*
snd_key
,
const
char
*
rcv_key
);
MS2_PUBLIC
static
inline
bool_t
video_stream_enable_strp
(
VideoStream
*
stream
,
enum
ortp_srtp_crypto_suite_t
suite
,
const
char
*
snd_key
,
const
char
*
rcv_key
)
{
return
media_stream_enable_srtp
(
&
stream
->
ms
,
suite
,
snd_key
,
rcv_key
);
}
/* if enabled, the display filter will internaly rotate the video, according to the device orientation */
MS2_PUBLIC
void
video_stream_enable_display_filter_auto_rotate
(
VideoStream
*
stream
,
bool_t
enable
);
/* retrieve RTP statistics*/
MS2_PUBLIC
void
video_stream_get_local_rtp_stats
(
VideoStream
*
stream
,
rtp_stats_t
*
stats
);
MS2_PUBLIC
static
inline
void
video_stream_get_local_rtp_stats
(
VideoStream
*
stream
,
rtp_stats_t
*
stats
)
{
media_stream_get_local_rtp_stats
(
&
stream
->
ms
,
stats
);
}
MS2_PUBLIC
int
video_stream_set_dscp
(
VideoStream
*
stream
,
int
dscp
);
MS2_PUBLIC
static
inline
int
video_stream_set_dscp
(
VideoStream
*
stream
,
int
dscp
)
{
return
media_stream_set_dscp
(
&
stream
->
ms
,
dscp
);
}
/**
* Small API to display a local preview window.
...
...
src/Makefile.am
View file @
e003e8c6
...
...
@@ -46,6 +46,7 @@ nodist_EXTRA_libmediastreamer_base_la_SOURCES = dummy.cxx
if
ORTP_ENABLED
BUILT_SOURCES
+=
voipdescs.h
libmediastreamer_voip_la_SOURCES
+=
msvoip.c
\
mediastream.c
\
audiostream.c
\
ice.c
\
msrtp.c
\
...
...
src/audioconference.c
View file @
e003e8c6
...
...
@@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/msconference.h"
#include "mediastreamer2/msaudiomixer.h"
#include "private.h"
struct
_MSAudioConference
{
MSTicker
*
ticker
;
...
...
@@ -41,8 +42,6 @@ struct _MSAudioEndpoint{
int
samplerate
;
};
extern
MSTickerPrio
__ms_get_default_prio
(
bool_t
is_video
);
void
ms_audio_endpoint_destroy
(
MSAudioEndpoint
*
ep
);
MSAudioConference
*
ms_audio_conference_new
(
const
MSAudioConferenceParams
*
params
){
...
...
@@ -86,28 +85,28 @@ static void cut_audio_stream_graph(MSAudioEndpoint *ep, bool_t is_remote){
AudioStream
*
st
=
ep
->
st
;
/*stop the audio graph*/
ms_ticker_detach
(
st
->
ticker
,
st
->
soundread
);
if
(
!
st
->
ec
)
ms_ticker_detach
(
st
->
ticker
,
st
->
soundwrite
);
ms_ticker_detach
(
st
->
ms
.
ticker
,
st
->
soundread
);
if
(
!
st
->
ec
)
ms_ticker_detach
(
st
->
ms
.
ticker
,
st
->
soundwrite
);
ep
->
in_cut_point_prev
.
pin
=
0
;
if
(
is_remote
){
/*we would like to keep the volrecv (MSVolume filter) in the graph to measure the output level*/
ep
->
in_cut_point_prev
.
filter
=
st
->
volrecv
;
}
else
{
ep
->
in_cut_point_prev
.
filter
=
st
->
decoder
;
ep
->
in_cut_point_prev
.
filter
=
st
->
ms
.
decoder
;
}
ep
->
in_cut_point
=
just_after
(
ep
->
in_cut_point_prev
.
filter
);
ms_filter_unlink
(
ep
->
in_cut_point_prev
.
filter
,
ep
->
in_cut_point_prev
.
pin
,
ep
->
in_cut_point
.
filter
,
ep
->
in_cut_point
.
pin
);
ep
->
out_cut_point
=
just_before
(
st
->
encoder
);
ms_filter_unlink
(
ep
->
out_cut_point
.
filter
,
ep
->
out_cut_point
.
pin
,
st
->
encoder
,
0
);
ep
->
out_cut_point
=
just_before
(
st
->
ms
.
encoder
);
ms_filter_unlink
(
ep
->
out_cut_point
.
filter
,
ep
->
out_cut_point
.
pin
,
st
->
ms
.
encoder
,
0
);
ms_filter_call_method
(
st
->
rtpsend
,
MS_FILTER_GET_SAMPLE_RATE
,
&
ep
->
samplerate
);
ms_filter_call_method
(
st
->
ms
.
rtpsend
,
MS_FILTER_GET_SAMPLE_RATE
,
&
ep
->
samplerate
);
if
(
is_remote
){
ep
->
mixer_in
.
filter
=
ep
->
in_cut_point_prev
.
filter
;
ep
->
mixer_in
.
pin
=
ep
->
in_cut_point_prev
.
pin
;
ep
->
mixer_out
.
filter
=
st
->
encoder
;
ep
->
mixer_out
.
filter
=
st
->
ms
.
encoder
;
ep
->
mixer_out
.
pin
=
0
;
}
else
{
ep
->
mixer_in
=
ep
->
out_cut_point
;
...
...
@@ -119,10 +118,10 @@ static void cut_audio_stream_graph(MSAudioEndpoint *ep, bool_t is_remote){
static
void
redo_audio_stream_graph
(
MSAudioEndpoint
*
ep
){
AudioStream
*
st
=
ep
->
st
;
ms_filter_link
(
ep
->
in_cut_point_prev
.
filter
,
ep
->
in_cut_point_prev
.
pin
,
ep
->
in_cut_point
.
filter
,
ep
->
in_cut_point
.
pin
);
ms_filter_link
(
ep
->
out_cut_point
.
filter
,
ep
->
out_cut_point
.
pin
,
st
->
encoder
,
0
);
ms_ticker_attach
(
st
->
ticker
,
st
->
soundread
);
ms_filter_link
(
ep
->
out_cut_point
.
filter
,
ep
->
out_cut_point
.
pin
,
st
->
ms
.
encoder
,
0
);
ms_ticker_attach
(
st
->
ms
.
ticker
,
st
->
soundread
);
if
(
!
st
->
ec
)
ms_ticker_attach
(
st
->
ticker
,
st
->
soundwrite
);
ms_ticker_attach
(
st
->
ms
.
ticker
,
st
->
soundwrite
);
}
static
int
find_free_pin
(
MSFilter
*
mixer
){
...
...
src/audiostream.c
View file @
e003e8c6
This diff is collapsed.
Click to expand it.
src/mediastream.c
0 → 100644
View file @
e003e8c6
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006-2013 Belledonne Communications, Grenoble
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.
*/
#ifdef HAVE_CONFIG_H
#include "mediastreamer-config.h"
#endif
#include "mediastreamer2/mediastream.h"
#include "private.h"
#include <ctype.h>
#if defined(_WIN32_WCE)
time_t
ms_time
(
time_t
*
t
)
{
DWORD
timemillis
=
GetTickCount
();
if
(
timemillis
>
0
)
{
if
(
t
!=
NULL
)
*
t
=
timemillis
/
1000
;
}
return
timemillis
/
1000
;
}
#endif
static
void
disable_checksums
(
ortp_socket_t
sock
)
{
#if defined(DISABLE_CHECKSUMS) && defined(SO_NO_CHECK)
int
option
=
1
;
if
(
setsockopt
(
sock
,
SOL_SOCKET
,
SO_NO_CHECK
,
&
option
,
sizeof
(
option
))
==
-
1
)
{
ms_warning
(
"Could not disable udp checksum: %s"
,
strerror
(
errno
));
}
#endif
}
MSTickerPrio
__ms_get_default_prio
(
bool_t
is_video
)
{
const
char
*
penv
;
if
(
is_video
)
{
#ifdef __ios
return
MS_TICKER_PRIO_HIGH
;
#else
return
MS_TICKER_PRIO_NORMAL
;
#endif
}
penv
=
getenv
(
"MS_AUDIO_PRIO"
);
if
(
penv
)
{
if
(
strcasecmp
(
penv
,
"NORMAL"
)
==
0
)
return
MS_TICKER_PRIO_NORMAL
;
if
(
strcasecmp
(
penv
,
"HIGH"
)
==
0
)
return
MS_TICKER_PRIO_HIGH
;
if
(
strcasecmp
(
penv
,
"REALTIME"
)
==
0
)
return
MS_TICKER_PRIO_REALTIME
;
ms_error
(
"Undefined priority %s"
,
penv
);
}
#ifdef __linux
return
MS_TICKER_PRIO_REALTIME
;
#else
return
MS_TICKER_PRIO_HIGH
;
#endif
}
RtpSession
*
create_duplex_rtpsession
(
int
loc_rtp_port
,
int
loc_rtcp_port
,
bool_t
ipv6
)
{
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
,
TRUE
);
rtp_session_set_symmetric_rtp
(
rtpr
,
TRUE
);
rtp_session_set_local_addr
(
rtpr
,
ipv6
?
"::"
:
"0.0.0.0"
,
loc_rtp_port
,
loc_rtcp_port
);
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
);
rtp_session_set_ssrc_changed_threshold
(
rtpr
,
0
);
rtp_session_set_rtcp_report_interval
(
rtpr
,
2500
);
/* At the beginning of the session send more reports. */
disable_checksums
(
rtp_session_get_rtp_socket
(
rtpr
));
return
rtpr
;
}
void
start_ticker
(
MediaStream
*
stream
)
{
MSTickerParams
params
=
{
0
};
char
name
[
16
];
snprintf
(
name
,
sizeof
(
name
)
-
1
,
"%s MSTicker"
,
media_stream_type_str
(
stream
));
name
[
0
]
=
toupper
(
name
[
0
]);
params
.
name
=
name
;
params
.
prio
=
__ms_get_default_prio
((
stream
->
type
==
VideoStreamType
)
?
TRUE
:
FALSE
);
stream
->
ticker
=
ms_ticker_new_with_params
(
&
params
);
}
const
char
*
const
media_stream_type_str
(
MediaStream
*
stream
)
{
switch
(
stream
->
type
)
{
default:
case
AudioStreamType
:
return
"audio"
;
case
VideoStreamType
:
return
"video"
;
}
}
void
media_stream_free
(
MediaStream
*
stream
)
{
if
(
stream
->
zrtp_context
!=
NULL
)
{
ortp_zrtp_context_destroy
(
stream
->
zrtp_context
);
stream
->
zrtp_context
=
NULL
;
}
if
(
stream
->
session
!=
NULL
)
{
rtp_session_unregister_event_queue
(
stream
->
session
,
stream
->
evq
);
rtp_session_destroy
(
stream
->
session
);
}
if
(
stream
->
evq
)
ortp_ev_queue_destroy
(
stream
->
evq
);
if
(
stream
->
rc
!=
NULL
)
ms_bitrate_controller_destroy
(
stream
->
rc
);
if
(
stream
->
rtpsend
!=
NULL
)
ms_filter_destroy
(
stream
->
rtpsend
);
if
(
stream
->
rtprecv
!=
NULL
)
ms_filter_destroy
(
stream
->
rtprecv
);
if
(
stream
->
encoder
!=
NULL
)
ms_filter_destroy
(
stream
->
encoder
);
if
(
stream
->
decoder
!=
NULL
)
ms_filter_destroy
(
stream
->
decoder
);
if
(
stream
->
voidsink
!=
NULL
)
ms_filter_destroy
(
stream
->
voidsink
);
if
(
stream
->
ticker
!=
NULL
)
ms_ticker_destroy
(
stream
->
ticker
);
}
void
media_stream_set_rtcp_information
(
MediaStream
*
stream
,
const
char
*
cname
,
const
char
*
tool
)
{
if
(
stream
->
session
!=
NULL
)
{
rtp_session_set_source_description
(
stream
->
session
,
cname
,
NULL
,
NULL
,
NULL
,
NULL
,
tool
,
NULL
);
}
}
void
media_stream_get_local_rtp_stats
(
MediaStream
*
stream
,
rtp_stats_t
*
lstats
)
{
if
(
stream
->
session
)
{
const
rtp_stats_t
*
stats
=
rtp_session_get_stats
(
stream
->
session
);
memcpy
(
lstats
,
stats
,
sizeof
(
*
stats
));
}
else
memset
(
lstats
,
0
,
sizeof
(
rtp_stats_t
));
}
int
media_stream_set_dscp
(
MediaStream
*
stream
,
int
dscp
)
{
ms_message
(
"Setting DSCP to %i for %s stream."
,
dscp
,
media_stream_type_str
(
stream
));
return
rtp_session_set_dscp
(
stream
->
session
,
dscp
);
}
void
media_stream_enable_adaptive_bitrate_control
(
MediaStream
*
stream
,
bool_t
enabled
)
{
stream
->
use_rc
=
enabled
;
}
void
media_stream_enable_adaptive_jittcomp
(
MediaStream
*
stream
,
bool_t
enabled
)
{
rtp_session_enable_adaptive_jitter_compensation
(
stream
->
session
,
enabled
);
}
bool_t
media_stream_enable_srtp
(
MediaStream
*
stream
,
enum
ortp_srtp_crypto_suite_t
suite
,
const
char
*
snd_key
,
const
char
*
rcv_key
)
{
/* Assign new srtp transport to stream->session with 2 Master Keys. */
RtpTransport
*
rtp_tpt
,
*
rtcp_tpt
;
if
(
!
ortp_srtp_supported
())
{
ms_error
(
"ortp srtp support not enabled"
);
return
FALSE
;
}
ms_message
(
"%s: %s stream snd_key='%s' rcv_key='%s'"
,
__FUNCTION__
,
media_stream_type_str
(
stream
),
snd_key
,
rcv_key
);
stream
->
srtp_session
=
ortp_srtp_create_configure_session
(
suite
,
rtp_session_get_send_ssrc
(
stream
->
session
),
snd_key
,
rcv_key
);
if
(
!
stream
->
srtp_session
)
return
FALSE
;
// TODO: check who will free rtp_tpt ?
srtp_transport_new
(
stream
->
srtp_session
,
&
rtp_tpt
,
&
rtcp_tpt
);
rtp_session_set_transports
(
stream
->
session
,
rtp_tpt
,
rtcp_tpt
);
return
TRUE
;
}
bool_t
ms_is_ipv6
(
const
char
*
remote
)
{
bool_t
ret
=
FALSE
;
#ifdef INET6
struct
addrinfo
hints
,
*
res0
;
int
err
;
memset
(
&
hints
,
0
,
sizeof
(
hints
));
hints
.
ai_family
=
PF_UNSPEC
;
hints
.
ai_socktype
=
SOCK_DGRAM
;
err
=
getaddrinfo
(
remote
,
"8000"
,
&
hints
,
&
res0
);
if
(
err
!=
0
)
{
ms_warning
(
"get_local_addr_for: %s"
,
gai_strerror
(
err
));
return
FALSE
;
}
ret
=
(
res0
->
ai_addr
->
sa_family
==
AF_INET6
);
freeaddrinfo
(
res0
);
#endif
return
ret
;
}
src/private.h
0 → 100644
View file @
e003e8c6
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006-2013 Belledonne Communications, Grenoble
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 PRIVATE_H
#define PRIVATE_H
#include "mediastreamer2/mediastream.h"
#define MAX_RTP_SIZE UDP_MAX_SIZE
MSTickerPrio
__ms_get_default_prio
(
bool_t
is_video
);
RtpSession
*
create_duplex_rtpsession
(
int
loc_rtp_port
,
int
loc_rtcp_port
,
bool_t
ipv6
);
void
start_ticker
(
MediaStream
*
stream
);
const
char
*
const
media_stream_type_str
(
MediaStream
*
stream
);
void
media_stream_free
(
MediaStream
*
stream
);
#endif
/* PRIVATE_H */
src/videostream.c
View file @
e003e8c6
This diff is collapsed.
Click to expand it.
tests/mediastream.c
View file @
e003e8c6
...
...
@@ -606,17 +606,17 @@ void setup_media_streams(MediastreamDatas* args) {
args
->
outfile
==
NULL
?
play
:
NULL
,
args
->
infile
==
NULL
?
capt
:
NULL
,
args
->
infile
!=
NULL
?
FALSE
:
args
->
ec
);
if
(
args
->
ice_local_candidates_nb
||
args
->
ice_remote_candidates_nb
)
{
args
->
audio
->
ice_check_list
=
ice_check_list_new
();
rtp_session_set_pktinfo
(
args
->
audio
->
session
,
TRUE
);
ice_session_add_check_list
(
args
->
ice_session
,
args
->
audio
->
ice_check_list
);
args
->
audio
->
ms
.
ice_check_list
=
ice_check_list_new
();
rtp_session_set_pktinfo
(
args
->
audio
->
ms
.
session
,
TRUE
);
ice_session_add_check_list
(
args
->
ice_session
,
args
->
audio
->
ms
.
ice_check_list
);
}
if
(
args
->
ice_local_candidates_nb
)
{
MediastreamIceCandidate
*
candidate
;
int
c
;
for
(
c
=
0
;
c
<
args
->
ice_local_candidates_nb
;
c
++
){
candidate
=&
args
->
ice_local_candidates
[
c
];
ice_add_local_candidate
(
args
->
audio
->
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
,
1
,
NULL
);
ice_add_local_candidate
(
args
->
audio
->
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
+
1
,
2
,
NULL
);
ice_add_local_candidate
(
args
->
audio
->
ms
.
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
,
1
,
NULL
);
ice_add_local_candidate
(
args
->
audio
->
ms
.
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
+
1
,
2
,
NULL
);
}
}
if
(
args
->
ice_remote_candidates_nb
)
{
...
...
@@ -627,8 +627,8 @@ void setup_media_streams(MediastreamDatas* args) {
candidate
=&
args
->
ice_remote_candidates
[
c
];
memset
(
foundation
,
'\0'
,
sizeof
(
foundation
));
snprintf
(
foundation
,
sizeof
(
foundation
)
-
1
,
"%u"
,
c
+
1
);
ice_add_remote_candidate
(
args
->
audio
->
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
,
1
,
0
,
foundation
,
FALSE
);
ice_add_remote_candidate
(
args
->
audio
->
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
+
1
,
2
,
0
,
foundation
,
FALSE
);
ice_add_remote_candidate
(
args
->
audio
->
ms
.
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
,
1
,
0
,
foundation
,
FALSE
);
ice_add_remote_candidate
(
args
->
audio
->
ms
.
ice_check_list
,
candidate
->
type
,
candidate
->
ip
,
candidate
->
port
+
1
,
2
,
0
,
foundation
,
FALSE
);
}
}
...
...
@@ -665,12 +665,12 @@ void setup_media_streams(MediastreamDatas* args) {
}
#endif
args
->
session
=
args
->
audio
->
session
;
args
->
session
=
args
->
audio
->
ms
.
session
;
}
if
(
args
->
enable_srtp
)
{
ms_message
(
"SRTP enabled: %d"
,
audio_stream_enable_s
t
rp
(
audio_stream_enable_sr
t
p
(