Skip to content

Commit 677147c

Browse files
committed
Preserve local sdp's order of media lines in soa_sdp_expand_media(). Add sdp_media_exists() API.
1 parent 0a50b84 commit 677147c

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

libsofia-sip-ua/sdp/sdp.c

+14
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,20 @@ unsigned sdp_media_count_with(sdp_session_t const *sdp,
18451845
return count;
18461846
}
18471847

1848+
/** Find matching media line in SDP. */
1849+
sdp_media_t** sdp_media_exists(sdp_session_t *sdp,
1850+
sdp_media_t const *m0)
1851+
{
1852+
sdp_media_t **m;
1853+
1854+
if (sdp != NULL)
1855+
for (m = &sdp->sdp_media; *m; m = &(*m)->m_next)
1856+
if (sdp_media_match_with(*m, m0))
1857+
return m;
1858+
1859+
return NULL;
1860+
}
1861+
18481862
/** Return true if media uses RTP */
18491863
int sdp_media_uses_rtp(sdp_media_t const *m)
18501864
{

libsofia-sip-ua/sdp/sofia-sip/sdp.h

+3
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ SOFIAPUBFUN unsigned sdp_media_count(sdp_session_t const *sdp,
496496
SOFIAPUBFUN unsigned sdp_media_count_with(sdp_session_t const *sdp,
497497
sdp_media_t const *m0);
498498

499+
SOFIAPUBFUN sdp_media_t** sdp_media_exists(sdp_session_t *sdp,
500+
sdp_media_t const *m0);
501+
499502
/** Return true if media uses RTP */
500503
SOFIAPUBFUN int sdp_media_uses_rtp(sdp_media_t const *m);
501504

libsofia-sip-ua/soa/soa_static.c

+30-11
Original file line numberDiff line numberDiff line change
@@ -301,23 +301,42 @@ sdp_session_t *soa_sdp_expand_media(su_home_t *home,
301301
sdp_session_t const *truncated,
302302
sdp_session_t const *complete)
303303
{
304+
sdp_session_t *tmp_truncated;
304305
sdp_session_t *expanded;
305-
sdp_media_t **m0;
306-
sdp_media_t * const *m1;
306+
sdp_media_t **mE;
307+
sdp_media_t **mT;
308+
sdp_media_t * const *mC;
307309

310+
/* Truncated list that we will be reducing */
311+
tmp_truncated = sdp_session_dup(home, truncated);
312+
/* New resulting list */
308313
expanded = sdp_session_dup(home, truncated);
309314

310315
if (expanded) {
311-
for (m0 = &expanded->sdp_media, m1 = &complete->sdp_media;
312-
*m1;
313-
m1 = &(*m1)->m_next) {
314-
if (!*m0) {
315-
*m0 = soa_sdp_make_rejected_media(home, *m1, expanded, 0);
316-
if (!*m0)
317-
return NULL;
316+
expanded->sdp_media = NULL; /* Empty the list of medias */
317+
mE = &expanded->sdp_media; /* Pointer to the beginning of the new list */
318+
319+
/* Loop through all items in the complete list to preserve complete list's order */
320+
for (mC = &complete->sdp_media; *mC; mC = &(*mC)->m_next) {
321+
/* Find the corresponding media in the truncated list */
322+
if ((mT = sdp_media_exists(tmp_truncated, *mC))) {
323+
/* Copy the corresponding media from the truncated list to the new list */
324+
*mE = sdp_media_dup(home, *mT, expanded);
325+
if (!*mE)
326+
return NULL;
327+
328+
/* Remove corresponding media from the truncated list */
329+
*mT = (*mT)->m_next;
330+
} else {
331+
/* If the corresponding media was not found in the truncated list, add a rejected media */
332+
*mE = soa_sdp_make_rejected_media(home, *mC, expanded, 0);
333+
if (!*mE)
334+
return NULL;
335+
}
336+
337+
/* Prepare pointer of the new list for a new item */
338+
mE = &(*mE)->m_next;
318339
}
319-
m0 = &(*m0)->m_next;
320-
}
321340
}
322341

323342
return expanded;

0 commit comments

Comments
 (0)