Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
mediastreamer2
Commits
f12d0e72
Commit
f12d0e72
authored
Sep 30, 2011
by
Pierre-Eric Pelloux-Prayer
Browse files
srtp: add srtp support to mediastreamer
parent
02cc704f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
133 additions
and
2 deletions
+133
-2
include/mediastreamer2/mediastream.h
include/mediastreamer2/mediastream.h
+8
-0
src/audiostream.c
src/audiostream.c
+30
-1
src/mscommon.c
src/mscommon.c
+4
-0
src/videostream.c
src/videostream.c
+30
-0
tests/mediastream.c
tests/mediastream.c
+61
-1
No files found.
include/mediastreamer2/mediastream.h
View file @
f12d0e72
...
...
@@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <ortp/ortp.h>
#include <ortp/event.h>
#include <ortp/zrtp.h>
#include <ortp/srtp.h>
#define PAYLOAD_TYPE_FLAG_CAN_RECV PAYLOAD_TYPE_USER_FLAG_1
...
...
@@ -74,6 +75,7 @@ struct _AudioStream
bool_t
use_rc
;
bool_t
is_beginning
;
OrtpZrtpContext
*
ortpZrtpContext
;
srtp_t
srtp_session
;
};
#ifdef __cplusplus
...
...
@@ -183,6 +185,8 @@ MS2_PUBLIC float audio_stream_get_average_quality_rating(AudioStream *stream);
/* enable ZRTP on the audio 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
);
/*****************
Video Support
...
...
@@ -231,6 +235,7 @@ struct _VideoStream
bool_t
adapt_bitrate
;
int
device_orientation
;
/* warning: meaning of this variable depends on the platform (Android, iOS, ...) */
OrtpZrtpContext
*
ortpZrtpContext
;
srtp_t
srtp_session
;
};
typedef
struct
_VideoStream
VideoStream
;
...
...
@@ -277,6 +282,9 @@ MS2_PUBLIC void video_stream_send_only_stop(VideoStream *vs);
/* enable ZRTP on the video stream using information from the audio stream */
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
);
/**
* Small API to display a local preview window.
...
...
src/audiostream.c
View file @
f12d0e72
...
...
@@ -40,7 +40,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
#endif
#define MAX_RTP_SIZE 1500
...
...
@@ -788,3 +787,33 @@ MS2_PUBLIC float audio_stream_get_average_quality_rating(AudioStream *stream){
void
audio_stream_enable_zrtp
(
AudioStream
*
stream
,
OrtpZrtpParams
*
params
){
stream
->
ortpZrtpContext
=
ortp_zrtp_context_new
(
stream
->
session
,
params
);
}
bool_t
audio_stream_enable_strp
(
AudioStream
*
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: stream=%p key='%s' key='%s'"
,
__FUNCTION__
,
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
;
}
src/mscommon.c
View file @
f12d0e72
...
...
@@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/mscommon.h"
#include "mediastreamer2/msfilter.h"
#include <ortp/srtp.h>
extern
void
__register_ffmpeg_encoders_if_possible
(
void
);
extern
void
ms_ffmpeg_check_init
();
...
...
@@ -644,6 +645,9 @@ void ms_init(){
}
}
#endif
ortp_srtp_init
();
ms_message
(
"ms_init() done"
);
}
...
...
src/videostream.c
View file @
f12d0e72
...
...
@@ -718,3 +718,33 @@ void video_stream_enable_zrtp(VideoStream *vstream, AudioStream *astream, OrtpZr
vstream
->
ortpZrtpContext
=
ortp_zrtp_multistream_new
(
astream
->
ortpZrtpContext
,
vstream
->
session
,
param
);
}
}
bool_t
video_stream_enable_strp
(
VideoStream
*
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: stream=%p key='%s' key='%s'"
,
__FUNCTION__
,
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
;
}
tests/mediastream.c
View file @
f12d0e72
...
...
@@ -51,6 +51,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <jni.h>
#endif
#include <ortp/b64.h>
static
int
cond
=
1
;
...
...
@@ -93,6 +95,9 @@ typedef struct _MediastreamDatas {
int
preview_window_id
;
/* starting values echo canceller */
int
ec_len_ms
,
ec_delay_ms
,
ec_framesize
;
bool_t
enable_srtp
;
char
*
srtp_local_master_key
;
char
*
srtp_remote_master_key
;
AudioStream
*
audio
;
PayloadType
*
pt
;
...
...
@@ -154,6 +159,7 @@ const char *usage="mediastream --local <port> --remote <ip:port> \n"
"[ --zrtp <zid> <secrets file> (enable zrtp) ]
\n
"
"[ --verbose (most verbose messages) ]
\n
"
"[ --video-windows-id <video surface:preview surface>]
\n
"
"[ --srtp <local master_key> <remote master_key> (enable srtp, master key is generated if absent from comand line)
\n
"
;
...
...
@@ -225,6 +231,8 @@ MediastreamDatas* init_default_args() {
args
->
preview_window_id
=
-
1
;
/* starting values echo canceller */
args
->
ec_len_ms
=
args
->
ec_delay_ms
=
args
->
ec_framesize
=
0
;
args
->
enable_srtp
=
FALSE
;
args
->
srtp_local_master_key
=
args
->
srtp_remote_master_key
=
NULL
;
args
->
audio
=
NULL
;
args
->
session
=
NULL
;
...
...
@@ -354,7 +362,19 @@ bool_t parse_args(int argc, char** argv, MediastreamDatas* out) {
}
else
if
(
strcmp
(
argv
[
i
],
"--device-rotation"
)
==
0
)
{
i
++
;
out
->
device_rotation
=
atoi
(
argv
[
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"--help"
)
==
0
){
}
else
if
(
strcmp
(
argv
[
i
],
"--srtp"
)
==
0
)
{
if
(
!
ortp_srtp_supported
())
{
ms_error
(
"ortp srtp support not enabled"
);
return
FALSE
;
}
out
->
enable_srtp
=
TRUE
;
i
++
;
// check if we're being given keys
if
(
i
+
1
<
argc
)
{
out
->
srtp_local_master_key
=
argv
[
i
++
];
out
->
srtp_remote_master_key
=
argv
[
i
++
];
}
}
else
if
(
strcmp
(
argv
[
i
],
"--help"
)
==
0
){
printf
(
"%s"
,
usage
);
return
FALSE
;
}
...
...
@@ -408,6 +428,28 @@ void setup_media_streams(MediastreamDatas* args) {
if
(
args
->
fmtp
!=
NULL
)
payload_type_set_send_fmtp
(
args
->
pt
,
args
->
fmtp
);
if
(
args
->
bitrate
>
0
)
args
->
pt
->
normal_bitrate
=
args
->
bitrate
;
// do we need to generate srtp keys ?
if
(
args
->
enable_srtp
)
{
// default profile require key-length = 30 bytes
// -> input : 40 b64 encoded bytes
if
(
!
args
->
srtp_local_master_key
)
{
uint8_t
tmp
[
30
];
crypto_get_random
(
tmp
,
30
);
args
->
srtp_local_master_key
=
(
char
*
)
malloc
(
41
);
b64_encode
((
const
char
*
)
tmp
,
30
,
args
->
srtp_local_master_key
,
40
);
args
->
srtp_local_master_key
[
40
]
=
'\0'
;
ms_message
(
"Generated local srtp key: '%s'"
,
args
->
srtp_local_master_key
);
}
if
(
!
args
->
srtp_remote_master_key
)
{
uint8_t
tmp
[
30
];
crypto_get_random
(
tmp
,
30
);
args
->
srtp_remote_master_key
=
(
char
*
)
malloc
(
41
);
b64_encode
((
const
char
*
)
tmp
,
30
,
args
->
srtp_remote_master_key
,
40
);
args
->
srtp_remote_master_key
[
40
]
=
'\0'
;
ms_message
(
"Generated remote srtp key: '%s'"
,
args
->
srtp_remote_master_key
);
}
}
if
(
args
->
pt
->
type
!=
PAYLOAD_VIDEO
){
MSSndCardManager
*
manager
=
ms_snd_card_manager_get
();
MSSndCard
*
capt
=
args
->
capture_card
==
NULL
?
ms_snd_card_manager_get_default_capture_card
(
manager
)
:
...
...
@@ -459,6 +501,15 @@ void setup_media_streams(MediastreamDatas* args) {
args
->
session
=
args
->
audio
->
session
;
}
if
(
args
->
enable_srtp
)
{
ms_message
(
"SRTP enabled: %d"
,
audio_stream_enable_strp
(
args
->
audio
,
AES_128_SHA1_80
,
args
->
srtp_local_master_key
,
args
->
srtp_remote_master_key
));
}
}
else
{
#ifdef VIDEO_ENABLED
if
(
args
->
eq
){
...
...
@@ -485,6 +536,15 @@ void setup_media_streams(MediastreamDatas* args) {
args
->
jitter
,
cam
);
args
->
session
=
args
->
video
->
session
;
if
(
args
->
enable_srtp
)
{
ms_message
(
"SRTP enabled: %d"
,
video_stream_enable_strp
(
args
->
video
,
AES_128_SHA1_80
,
args
->
srtp_local_master_key
,
args
->
srtp_remote_master_key
));
}
#else
printf
(
"Error: video support not compiled.
\n
"
);
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment