Commit cc65bba1 authored by Pekka Pessi's avatar Pekka Pessi
Browse files

soa_static.c: cope better if m

darcs-hash:20080512183337-65a35-a0daf350bd553ef6b966fb6dd81170529a931779.gz
parent 145cef6e
......@@ -731,10 +731,11 @@ int soa_sdp_upgrade(soa_session_t *ss,
o_media = su_zalloc(home, (Ns + 1) * (sizeof *o_media));
u_media = su_zalloc(home, (Nu + 1) * (sizeof *u_media));
r_media = su_zalloc(home, (Nr + 1) * (sizeof *r_media));
if (!s_media || !o_media || !u_media || !r_media)
return -1;
um = sdp_media_dup_all(home, user->sdp_media, session);
if (!s_media || !u_media || !r_media || !um)
if (!um && user->sdp_media)
return -1;
u2s = su_alloc(home, (Nu + 1) * sizeof(*u2s));
......@@ -1027,9 +1028,13 @@ int soa_sdp_mode_set(sdp_session_t const *user,
for (j = 0, um = user->sdp_media; j != s2u[i]; um = um->m_next, j++)
assert(um);
if (um == NULL) {
if (dryrun)
return 1;
else
retval = 1;
sm->m_rejected = 1;
sm->m_mode = sdp_inactive;
retval = 1;
sm->m_port = 0;
continue;
}
......@@ -1059,10 +1064,11 @@ int soa_sdp_mode_set(sdp_session_t const *user,
}
}
if (sm->m_mode != (unsigned)(recv_mode | send_mode))
retval = 1;
if (!dryrun) {
if (sm->m_mode != (unsigned)(recv_mode | send_mode)) {
if (dryrun)
return 1;
else
retval = 1;
sm->m_mode = recv_mode | send_mode;
}
}
......@@ -1171,7 +1177,8 @@ static int offer_answer_step(soa_session_t *ss,
*local0 = *local, local = local0;
SU_DEBUG_7(("soa_static(%p, %s): %s\n", (void *)ss, by,
"upgrade with local description"));
soa_sdp_upgrade(ss, tmphome, local, user, NULL, &u2s, &s2u);
if (soa_sdp_upgrade(ss, tmphome, local, user, NULL, &u2s, &s2u) < 0)
goto internal_error;
break;
case generate_answer:
/* Upgrade local SDP based on remote SDP */
......@@ -1183,7 +1190,8 @@ static int offer_answer_step(soa_session_t *ss,
*local0 = *local, local = local0;
SU_DEBUG_7(("soa_static(%p, %s): %s\n", (void *)ss, by,
"upgrade with remote description"));
soa_sdp_upgrade(ss, tmphome, local, user, remote, &u2s, &s2u);
if (soa_sdp_upgrade(ss, tmphome, local, user, remote, &u2s, &s2u) < 0)
goto internal_error;
}
break;
case process_answer:
......
......@@ -1311,6 +1311,159 @@ int test_media_replace(struct context *ctx)
}
int test_media_removal(struct context *ctx)
{
BEGIN();
int n;
soa_session_t *a, *b;
char const *offer = NONE, *answer = NONE;
isize_t offerlen = (isize_t)-1, answerlen = (isize_t)-1;
sdp_session_t const *a_sdp, *b_sdp;
sdp_media_t const *m;
char const a_caps[] =
"v=0\r\n"
"o=left 219498671 2 IN IP4 127.0.0.2\r\n"
"c=IN IP4 127.0.0.2\r\n"
"m=audio 5008 RTP/AVP 0 8\r\n"
;
char const b_caps[] =
"v=0\n"
"m=audio 5004 RTP/AVP 0 8\n"
"a=rtpmap:96 G7231/8000\n"
"a=rtpmap:97 G729/8000\n";
TEST_1(a = soa_create("static", ctx->root, ctx));
TEST_1(b = soa_create("static", ctx->root, ctx));
TEST(soa_set_user_sdp(a, 0, a_caps, strlen(a_caps)), 1);
TEST(soa_set_user_sdp(b, 0, b_caps, strlen(b_caps)), 1);
TEST_1(soa_set_params(b, SOATAG_RTP_MISMATCH(0),
SOATAG_ORDERED_USER(1),
TAG_END()));
n = soa_generate_offer(a, 1, test_completed); TEST(n, 0);
n = soa_get_local_sdp(a, NULL, &offer, &offerlen); TEST(n, 1);
TEST_1(offer != NULL && offer != NONE);
n = soa_set_remote_sdp(b, 0, offer, offerlen); TEST(n, 1);
n = soa_get_local_sdp(b, NULL, &answer, &answerlen); TEST(n, 0);
n = soa_generate_answer(b, test_completed); TEST(n, 0);
n = soa_get_local_sdp(b, &b_sdp, &answer, &answerlen); TEST(n, 1);
TEST_1(answer != NULL && answer != NONE);
n = soa_set_remote_sdp(a, 0, answer, -1); TEST(n, 1);
n = soa_process_answer(a, test_completed); TEST(n, 0);
TEST_1(soa_is_complete(b));
TEST(soa_activate(b, NULL), 0);
TEST_1(soa_is_complete(a));
TEST(soa_activate(a, NULL), 0);
TEST(soa_is_audio_active(a), SOA_ACTIVE_SENDRECV);
TEST(soa_is_remote_audio_active(a), SOA_ACTIVE_SENDRECV);
/* ---------------------------------------------------------------------- */
/* Re-O/A: remove media stream */
TEST(soa_set_user_sdp(b, 0, "v=0", -1), 1);
n = soa_generate_offer(a, 1, test_completed); TEST(n, 0);
n = soa_get_local_sdp(a, &a_sdp, &offer, &offerlen); TEST(n, 1);
TEST_1(offer != NULL && offer != NONE);
n = soa_set_remote_sdp(b, 0, offer, offerlen); TEST(n, 1);
n = soa_generate_answer(b, test_completed); TEST(n, 0);
n = soa_get_local_sdp(b, &b_sdp, &answer, &answerlen); TEST(n, 1);
TEST_1(m = b_sdp->sdp_media); TEST_1(m->m_rejected);
TEST_1(answer != NULL && answer != NONE);
n = soa_set_remote_sdp(a, 0, answer, -1); TEST(n, 1);
n = soa_process_answer(a, test_completed); TEST(n, 0);
n = soa_get_local_sdp(a, &a_sdp, NULL, NULL); TEST(n, 1);
TEST_1(m = a_sdp->sdp_media); TEST_1(m->m_rejected);
TEST_1(soa_is_complete(b));
TEST(soa_activate(b, NULL), 0);
TEST_1(soa_is_complete(a));
TEST(soa_activate(a, NULL), 0);
TEST(soa_is_audio_active(a), SOA_ACTIVE_REJECTED);
TEST(soa_is_remote_audio_active(a), SOA_ACTIVE_REJECTED);
TEST_VOID(soa_terminate(a, NULL));
TEST_VOID(soa_terminate(b, NULL));
TEST_VOID(soa_destroy(a));
TEST_VOID(soa_destroy(b));
/* ---------------------------------------------------------------------- */
TEST_1(a = soa_create("static", ctx->root, ctx));
TEST_1(b = soa_create("static", ctx->root, ctx));
TEST(soa_set_user_sdp(a, 0, a_caps, strlen(a_caps)), 1);
TEST(soa_set_user_sdp(b, 0, b_caps, strlen(b_caps)), 1);
n = soa_generate_offer(a, 1, test_completed); TEST(n, 0);
n = soa_get_local_sdp(a, NULL, &offer, &offerlen); TEST(n, 1);
TEST_1(offer != NULL && offer != NONE);
n = soa_set_remote_sdp(b, 0, offer, offerlen); TEST(n, 1);
n = soa_get_local_sdp(b, NULL, &answer, &answerlen); TEST(n, 0);
n = soa_generate_answer(b, test_completed); TEST(n, 0);
n = soa_get_local_sdp(b, &b_sdp, &answer, &answerlen); TEST(n, 1);
TEST_1(answer != NULL && answer != NONE);
n = soa_set_remote_sdp(a, 0, answer, -1); TEST(n, 1);
n = soa_process_answer(a, test_completed); TEST(n, 0);
TEST_1(soa_is_complete(b));
TEST(soa_activate(b, NULL), 0);
TEST_1(soa_is_complete(a));
TEST(soa_activate(a, NULL), 0);
TEST(soa_is_audio_active(a), SOA_ACTIVE_SENDRECV);
TEST(soa_is_remote_audio_active(a), SOA_ACTIVE_SENDRECV);
/* ---------------------------------------------------------------------- */
/* Re-O/A: offerer remove media stream from user sdp */
TEST(soa_set_user_sdp(a, 0, "v=0", -1), 1);
n = soa_generate_offer(a, 1, test_completed); TEST(n, 0);
n = soa_get_local_sdp(a, &a_sdp, &offer, &offerlen); TEST(n, 1);
TEST_1(m = a_sdp->sdp_media); TEST_1(m->m_rejected);
TEST_1(offer != NULL && offer != NONE);
n = soa_set_remote_sdp(b, 0, offer, offerlen); TEST(n, 1);
n = soa_generate_answer(b, test_completed); TEST(n, 0);
n = soa_get_local_sdp(b, &b_sdp, &answer, &answerlen); TEST(n, 1);
TEST_1(m = b_sdp->sdp_media); TEST_1(m->m_rejected);
TEST_1(answer != NULL && answer != NONE);
n = soa_set_remote_sdp(a, 0, answer, -1); TEST(n, 1);
n = soa_process_answer(a, test_completed); TEST(n, 0);
n = soa_get_local_sdp(a, &a_sdp, NULL, NULL); TEST(n, 1);
TEST_1(m = a_sdp->sdp_media); TEST_1(m->m_rejected);
TEST_1(soa_is_complete(b));
TEST(soa_activate(b, NULL), 0);
TEST_1(soa_is_complete(a));
TEST(soa_activate(a, NULL), 0);
TEST(soa_is_audio_active(a), SOA_ACTIVE_REJECTED);
TEST(soa_is_remote_audio_active(a), SOA_ACTIVE_REJECTED);
TEST_VOID(soa_terminate(a, NULL));
TEST_VOID(soa_terminate(b, NULL));
TEST_VOID(soa_destroy(a));
TEST_VOID(soa_destroy(b));
END();
}
int test_media_reject(struct context *ctx)
{
BEGIN();
......@@ -1482,7 +1635,6 @@ int test_media_replace2(struct context *ctx)
n = soa_get_local_sdp(b, &b_sdp, &offer, &offerlen); TEST(n, 1);
TEST_1(offer != NULL && offer != NONE);
n = soa_set_remote_sdp(a, 0, offer, offerlen); TEST(n, 1);
printf("offer 2:\n%s", offer);
TEST_1(soa_set_params(a, SOATAG_RTP_MISMATCH(0),
SOATAG_USER_SDP_STR(a_caps2),
TAG_END()) > 0);
......@@ -1490,7 +1642,6 @@ int test_media_replace2(struct context *ctx)
n = soa_generate_answer(a, test_completed); TEST(n, 0);
n = soa_get_local_sdp(a, &a_sdp, &answer, &answerlen); TEST(n, 1);
TEST_1(answer != NULL && answer != NONE);
printf("answer 2:\n%s", answer);
n = soa_set_remote_sdp(b, 0, answer, -1); TEST(n, 1);
n = soa_process_answer(b, test_completed); TEST(n, 0);
n = soa_get_local_sdp(b, &b_sdp, NULL, NULL); TEST(n, 1);
......@@ -1730,6 +1881,7 @@ int main(int argc, char *argv[])
retval |= test_static_offer_answer(ctx); SINGLE_FAILURE_CHECK();
retval |= test_codec_selection(ctx); SINGLE_FAILURE_CHECK();
retval |= test_media_replace(ctx); SINGLE_FAILURE_CHECK();
retval |= test_media_removal(ctx); SINGLE_FAILURE_CHECK();
retval |= test_media_reject(ctx); SINGLE_FAILURE_CHECK();
retval |= test_asynch_offer_answer(ctx); SINGLE_FAILURE_CHECK();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment