Beispiel #1
0
int AmZRTPSessionState::initSession(AmSession* session) {
  DBG("Initializing ZRTP stream...\n");

  // Allocate zrtp session
  zrtp_status_t status =
    zrtp_session_init( AmZRTP::zrtp_global,
		       &zrtp_profile,
		       ZRTP_SIGNALING_ROLE_UNKNOWN, // fixme
		       &zrtp_session);
  if (zrtp_status_ok != status) {
    // Check error code and debug logs
    return status;
  }

  // Set call-back pointer to our parent structure
  zrtp_session_set_userdata(zrtp_session, session);

  // Attach audio stream
  status = zrtp_stream_attach(zrtp_session, &zrtp_audio);
  if (zrtp_status_ok != status) {
    // Check error code and debug logs
    return status;
  }
  zrtp_stream_set_userdata(zrtp_audio, session);
  return 0;
}
Beispiel #2
0
static int media_alloc(struct menc_media **stp, struct menc_sess *sess,
		       struct rtp_sock *rtp,
		       int proto, void *rtpsock, void *rtcpsock,
		       struct sdp_media *sdpm)
{
	struct menc_media *st;
	zrtp_status_t s;
	int layer = 10; /* above zero */
	int err = 0;
	(void)rtcpsock;

	if (!stp || !sess || proto != IPPROTO_UDP)
		return EINVAL;

	st = *stp;
	if (st)
		goto start;

	st = mem_zalloc(sizeof(*st), media_destructor);
	if (!st)
		return ENOMEM;

	st->sess = sess;
	st->rtpsock = mem_ref(rtpsock);

	err = udp_register_helper(&st->uh, rtpsock, layer,
				  udp_helper_send, udp_helper_recv, st);
	if (err)
		goto out;

	s = zrtp_stream_attach(sess->zrtp_session, &st->zrtp_stream);
	if (s != zrtp_status_ok) {
		warning("zrtp: zrtp_stream_attach failed (status=%d)\n", s);
		err = EPROTO;
		goto out;
	}

	zrtp_stream_set_userdata(st->zrtp_stream, st);

 out:
	if (err) {
		mem_deref(st);
		return err;
	}
	else
		*stp = st;

 start:
	if (sa_isset(sdp_media_raddr(sdpm), SA_ALL)) {
		st->raddr = *sdp_media_raddr(sdpm);

		s = zrtp_stream_start(st->zrtp_stream, rtp_sess_ssrc(rtp));
		if (s != zrtp_status_ok) {
			warning("zrtp: zrtp_stream_start: status = %d\n", s);
		}
	}

	return err;
}
Beispiel #3
0
zrtp_status_t zrtp_test_session_create(zrtp_test_id_t endpoint_id,
									   zrtp_test_session_cfg_t* cfg,
									   zrtp_test_id_t* id) {
	zrtp_status_t s;
	unsigned i;
	zrtp_test_session_t *the_session;
	zrtp_endpoint_t *the_endpoint = zrtp_test_endpoint_by_id(endpoint_id);

	if (!the_endpoint)
		return zrtp_status_fail;

	if (the_endpoint->sessions_count >= K_ZRTP_TEST_MAX_SESSIONS_PER_ENDPOINT)
		return zrtp_status_fail;

	the_session = &the_endpoint->sessions[the_endpoint->sessions_count++];

	zrtp_memset(the_session, 0, sizeof(zrtp_test_session_t));

	zrtp_memcpy(&the_session->cfg, cfg, sizeof(zrtp_test_session_cfg_t));

	the_session->id = g_sessions_counter++;
	the_session->endpoint_id = endpoint_id;

	s = zrtp_session_init(the_endpoint->zrtp,
						  &cfg->zrtp,
						  the_endpoint->zid,
						  cfg->role,
						  &the_session->zrtp);

	if (zrtp_status_ok == s) {

		zrtp_session_set_userdata(the_session->zrtp, &the_session->id);

		for (i=0; i<cfg->streams_count; i++) {
			zrtp_test_stream_t *the_stream = &the_session->streams[i];
			zrtp_memset(the_stream, 0, sizeof(zrtp_test_stream_t));

			the_stream->id = g_streams_counter++;
			the_stream->session_id = the_session->id;
			the_stream->endpoint_id = endpoint_id;

			s = zrtp_stream_attach(the_session->zrtp, &the_stream->zrtp);
			if (zrtp_status_ok == s) {
				zrtp_stream_set_userdata(the_stream->zrtp, &the_stream->id);
				the_session->streams_count++;
			} else {
				break;
			}
		}
	}

	if (zrtp_status_ok == s) {
		*id = the_session->id;
	}

	return s;
}