Changeset 60db87243c9426e59557d0f0f2e30276cc2f9c94

Show
Ignore:
Timestamp:
01/05/07 19:14:14 (1 year ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1178039654 +0000
git-parent:

[7681a9b5d1df0cbcaa5914cc33bb40fee8276a36]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1178039654 +0000
Message:

Add helper for SDP media description formatting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/stream_output/sdp.c

    re8ff31e r60db872  
    2525 
    2626#include <string.h> 
     27#include <stdarg.h> 
     28#include <stdio.h> 
     29#include <assert.h> 
    2730#include <vlc_network.h> 
    2831#include <vlc_charset.h> 
     
    109112    if (!IsSDPString (name) || !IsSDPString (description) 
    110113     || !IsSDPString (url) || !IsSDPString (email) || !IsSDPString (phone) 
    111      || (AddressToSDP ((struct sockaddr *)orig, origlen, machine) == NULL) 
    112      || (AddressToSDP ((struct sockaddr *)addr, addrlen, conn) == NULL)) 
     114     || (AddressToSDP (orig, origlen, machine) == NULL) 
     115     || (AddressToSDP (addr, addrlen, conn) == NULL)) 
    113116        return NULL; 
    114117 
     
    150153} 
    151154 
     155 
     156char *MakeSDPMedia (const char *type, int dport, const char *protocol, 
     157                    unsigned pt, const char *rtpmap, const char *fmtpfmt, ...) 
     158{ 
     159    char *sdp_media = NULL; 
     160 
     161    /* Some default values */ 
     162    if (type == NULL) 
     163        type = "video"; 
     164    if (dport == 0) 
     165        dport = 9; 
     166    if (protocol == NULL) 
     167        protocol = "RTP/AVP"; 
     168    assert (pt < 128u); 
     169 
     170    /* RTP payload type map */ 
     171    char sdp_rtpmap[rtpmap ? (sizeof ("a=rtpmap:123 *\r\n") + strlen (rtpmap)) : 1]; 
     172    if (rtpmap != NULL) 
     173        sprintf (sdp_rtpmap, "a=rtpmap:%u %s\r\n", pt, rtpmap); 
     174    else 
     175        *sdp_rtpmap = '\0'; 
     176 
     177    /* Format parameters */ 
     178    char *fmtp = NULL; 
     179    if (fmtpfmt != NULL) 
     180    { 
     181        va_list ap; 
     182 
     183        va_start (ap, fmtpfmt); 
     184        if (vasprintf (&fmtp, fmtpfmt, ap) == -1) 
     185            fmtpfmt = NULL; 
     186        va_end (ap); 
     187 
     188        if (fmtp == NULL) 
     189            return NULL; 
     190    } 
     191 
     192    char sdp_fmtp[fmtp ? (sizeof ("a=fmtp:123 *\r\n") + strlen (fmtp)) : 1]; 
     193    if (fmtp != NULL) 
     194    { 
     195        sprintf (sdp_fmtp, "a=fmtp:%u %s\r\n", pt, fmtp); 
     196        free (fmtp); 
     197    } 
     198    else 
     199        *sdp_fmtp = '\0'; 
     200 
     201    if (asprintf (&sdp_media, "m=%s %u %s %d\r\n" "%s" "%s", 
     202                  type, dport, protocol, pt, 
     203                  sdp_rtpmap, sdp_fmtp) == -1) 
     204        return NULL; 
     205 
     206    return sdp_media; 
     207} 
  • src/stream_output/stream_output.h

    r7681a9b r60db872  
    117117                const struct sockaddr *orig, socklen_t origlen, 
    118118                const struct sockaddr *addr, socklen_t addrlen); 
     119char *MakeSDPMedia (const char *type, int dport, const char *protocol, 
     120                    unsigned pt, const char *rtpmap, const char *fmtp, ...); 
    119121