[vlc-commits] sap: remove demux sub-module

Rémi Denis-Courmont git at videolan.org
Wed Apr 22 21:29:27 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Apr 22 21:47:26 2020 +0300| [03d120cb80bd0d9bb551066c947f4e22b456fa26] | committer: Rémi Denis-Courmont

sap: remove demux sub-module

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=03d120cb80bd0d9bb551066c947f4e22b456fa26
---

 modules/services_discovery/sap.c | 335 +--------------------------------------
 1 file changed, 1 insertion(+), 334 deletions(-)

diff --git a/modules/services_discovery/sap.c b/modules/services_discovery/sap.c
index b06ad2d2f5..f161dac988 100644
--- a/modules/services_discovery/sap.c
+++ b/modules/services_discovery/sap.c
@@ -77,180 +77,6 @@
 #define SAP_V4_LINK_ADDRESS     "224.0.0.255"
 #define ADD_SESSION 1
 
-static bool IsWellKnownPayload (int type)
-{
-    switch (type)
-    {   /* Should be in sync with modules/demux/rtp.c */
-        case  0: /* PCMU/8000 */
-        case  3:
-        case  8: /* PCMA/8000 */
-        case 10: /* L16/44100/2 */
-        case 11: /* L16/44100 */
-        case 12:
-        case 14: /* MPA/90000 */
-        case 32: /* MPV/90000 */
-        case 33: /* MP2/90000 */
-            return true;
-   }
-   return false;
-}
-
-/* Compute URI */
-static char *ParseConnection(vlc_object_t *p_obj, const struct vlc_sdp *p_sdp,
-                             unsigned *rtcp_port)
-{
-    const struct vlc_sdp_media *m = p_sdp->media;
-    char *uri;
-
-    if (m == NULL)
-    {
-        msg_Dbg (p_obj, "Ignoring SDP with no media");
-        return NULL;
-    }
-
-    const struct vlc_sdp_conn *c = vlc_sdp_media_conn(m);
-
-    if (m->next != NULL || c == NULL || c->next != NULL || m->port_count != 1)
-    {
-        msg_Dbg (p_obj, "Multiple media ports not supported -> live555");
-        return NULL;
-    }
-
-    char host[1026];
-    unsigned port = m->port;
-
-    if (strchr(c->addr, ':') != NULL)
-        snprintf(host, sizeof (host), "[%s]", c->addr);
-    else
-        snprintf(host, sizeof (host), "%s", c->addr);
-
-    /* Parse m= field */
-    const char *sdp_proto = m->proto;
-    const char *subtype = m->format;
-
-    /* FIXME: check for multiple payload types in RTP/AVP case.
-     * FIXME: check for "mpeg" subtype in raw udp case. */
-    if (strcasecmp(sdp_proto, "udp") != 0
-     && !IsWellKnownPayload(atoi(subtype)))
-        return NULL;
-
-    /* RTP protocol, nul, VLC shortcut, nul, flags byte as follow:
-     * 0x1: Connection-Oriented media. */
-    static const char proto_match[] =
-        "udp\0"             "udp\0\0"
-        "RTP/AVP\0"         "rtp\0\0"
-        "UDPLite/RTP/AVP\0" "udplite\0\0"
-        "DCCP/RTP/AVP\0"    "dccp\0\1"
-        "TCP/RTP/AVP\0"     "rtptcp\0\1"
-        "\0";
-
-    const char *vlc_proto = NULL;
-    uint8_t flags = 0;
-    for (const char *proto = proto_match; *proto;)
-    {
-        if (strcasecmp (proto, sdp_proto) == 0)
-        {
-            vlc_proto = proto + strlen (proto) + 1;
-            flags = vlc_proto[strlen (vlc_proto) + 1];
-            break;
-        }
-        proto += strlen (proto) + 1;
-        proto += strlen (proto) + 2;
-    }
-
-    if (vlc_proto == NULL)
-    {
-        msg_Dbg (p_obj, "unknown SDP media protocol: %s", sdp_proto);
-        return NULL;
-    }
-
-    if (!strcmp (vlc_proto, "udp")
-     || vlc_sdp_media_attr_present(m, "rtcp-mux"))
-        *rtcp_port = 0;
-    else
-    {
-        const char *rtcp = vlc_sdp_media_attr_value(m, "rtcp");
-        if (rtcp)
-            *rtcp_port = atoi(rtcp);
-        else
-        if (port & 1) /* odd port -> RTCP; next even port -> RTP */
-            *rtcp_port = port++;
-        else /* even port -> RTP; next odd port -> RTCP */
-            *rtcp_port = port + 1;
-    }
-
-    if (flags & 1)
-    {
-        /* Connection-oriented media */
-        const char *setup = vlc_sdp_media_attr_value(m, "setup");
-        if (setup == NULL)
-            setup = vlc_sdp_attr_value(p_sdp, "setup");
-        if (setup == NULL)
-            setup = "active"; /* default value */
-
-        if (strcmp (setup, "actpass") && strcmp (setup, "passive"))
-        {
-            msg_Dbg (p_obj, "unsupported COMEDIA mode: %s", setup);
-            return NULL;
-        }
-
-        if (asprintf(&uri, "%s://%s:%d", vlc_proto, host, port) == -1)
-            return NULL;
-    }
-    else
-    {
-        /* Non-connected (normally multicast) media */
-        char psz_source[258] = "";
-        const char *sfilter = vlc_sdp_media_attr_value(m, "source-filter");
-        if (sfilter == NULL)
-            sfilter = vlc_sdp_attr_value(p_sdp, "source-filter");
-        if (sfilter != NULL)
-        {
-            char psz_source_ip[256];
-            unsigned ipv;
-
-            if (sscanf (sfilter, " incl IN IP%u %*s %255s ", &ipv,
-                        psz_source_ip) == 2)
-            {
-                /* According to RFC4570, FQDNs can be used for source-filters,
-                 * but -seriously- this is impractical */
-                switch (ipv)
-                {
-#ifdef AF_INET6
-                    case 6:
-                    {
-                        struct in6_addr addr;
-                        if ((inet_pton (AF_INET6, psz_source_ip, &addr) > 0)
-                        && (inet_ntop (AF_INET6, &addr, psz_source + 1,
-                                        sizeof (psz_source) - 2) != NULL))
-                        {
-                            psz_source[0] = '[';
-                            psz_source[strlen (psz_source)] = ']';
-                        }
-                        break;
-                    }
-#endif
-                    case 4:
-                    {
-                        struct in_addr addr;
-                        if ((inet_pton (AF_INET, psz_source_ip, &addr) > 0)
-                        && (inet_ntop (AF_INET, &addr, psz_source,
-                                        sizeof (psz_source)) == NULL))
-                            *psz_source = '\0';
-                        break;
-                    }
-                }
-            }
-        }
-
-        if (asprintf(&uri, "%s://%s@%s:%i", vlc_proto, psz_source,
-                     host, port) == -1)
-            return NULL;
-    }
-
-    return uri;
-}
-
 static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i_len )
 {
 #ifdef HAVE_ZLIB_H
@@ -299,158 +125,6 @@ static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i
 #endif
 }
 
-typedef struct
-{
-    struct vlc_sdp *p_sdp;
-    /* "computed" URI */
-    char *uri;
-    unsigned rtcp_port;
-} demux_sys_t;
-
-/**********************************************************************
- * Demux: reads and demuxes data packets
- * Return -1 if error, 0 if EOF, 1 else
- **********************************************************************/
-static int Demux( demux_t *p_demux )
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-    struct vlc_sdp *p_sdp = p_sys->p_sdp;
-    input_item_t *p_parent_input = p_demux->p_input_item;
-
-    if( !p_parent_input )
-    {
-        msg_Err( p_demux, "parent input could not be found" );
-        return VLC_EGENERIC;
-    }
-
-    input_item_SetURI(p_parent_input, p_sys->uri);
-    input_item_SetName(p_parent_input, p_sdp->name);
-    if( p_sys->rtcp_port )
-    {
-        char *rtcp;
-        if( asprintf( &rtcp, ":rtcp-port=%u", p_sys->rtcp_port ) != -1 )
-        {
-            input_item_AddOption( p_parent_input, rtcp, VLC_INPUT_OPTION_TRUSTED );
-            free( rtcp );
-        }
-    }
-
-    vlc_mutex_lock( &p_parent_input->lock );
-
-    p_parent_input->i_type = ITEM_TYPE_STREAM;
-    p_parent_input->b_net = true;
-
-    vlc_mutex_unlock( &p_parent_input->lock );
-    return VLC_SUCCESS;
-}
-
-static int Control( demux_t *p_demux, int i_query, va_list args )
-{
-    VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
-    return VLC_EGENERIC;
-}
-
-/*****************************************************************************
- * OpenDemux: initialize and create stuff
- *****************************************************************************/
-static int OpenDemux( vlc_object_t *p_this )
-{
-    demux_t *p_demux = (demux_t *)p_this;
-    const uint8_t *p_peek;
-    char *psz_sdp = NULL;
-    struct vlc_sdp *p_sdp = NULL;
-    int errval = VLC_EGENERIC;
-    size_t i_len;
-
-    if( !var_CreateGetBool( p_demux, "sap-parse" ) )
-    {
-        /* We want livedotcom module to parse this SDP file */
-        return VLC_EGENERIC;
-    }
-
-    assert( p_demux->s ); /* this is NOT an access_demux */
-
-    /* Probe for SDP */
-    if( vlc_stream_Peek( p_demux->s, &p_peek, 7 ) < 7 )
-        return VLC_EGENERIC;
-
-    if( memcmp( p_peek, "v=0\r\no=", 7 ) && memcmp( p_peek, "v=0\no=", 6 ) )
-        return VLC_EGENERIC;
-
-    /* Gather the complete sdp file */
-    for( i_len = 0, psz_sdp = NULL; i_len < 65536; )
-    {
-        const int i_read_max = 1024;
-        char *psz_sdp_new = realloc( psz_sdp, i_len + i_read_max + 1 );
-        size_t i_read;
-        if( psz_sdp_new == NULL )
-        {
-            errval = VLC_ENOMEM;
-            goto error;
-        }
-        psz_sdp = psz_sdp_new;
-
-        i_read = vlc_stream_Read( p_demux->s, &psz_sdp[i_len], i_read_max );
-        if( (int)i_read < 0 )
-        {
-            msg_Err( p_demux, "cannot read SDP" );
-            goto error;
-        }
-        i_len += i_read;
-
-        psz_sdp[i_len] = '\0';
-
-        if( (int)i_read < i_read_max )
-            break; // EOF
-    }
-
-    p_sdp = vlc_sdp_parse(psz_sdp, i_len);
-
-    if( !p_sdp )
-    {
-        msg_Warn( p_demux, "invalid SDP");
-        goto error;
-    }
-
-    unsigned rtcp_port;
-    char *uri = ParseConnection(VLC_OBJECT(p_demux), p_sdp, &rtcp_port);
-    if (uri == NULL)
-        goto error;
-
-    demux_sys_t *p_sys = malloc( sizeof(*p_sys) );
-    if( unlikely(p_sys == NULL) )
-        goto error;
-    p_sys->p_sdp = p_sdp;
-    p_sys->uri = uri;
-    p_sys->rtcp_port = rtcp_port;
-    p_demux->p_sys = p_sys;
-    p_demux->pf_control = Control;
-    p_demux->pf_demux = Demux;
-
-    FREENULL( psz_sdp );
-    return VLC_SUCCESS;
-
-error:
-    FREENULL( psz_sdp );
-    if (p_sdp != NULL)
-        vlc_sdp_free(p_sdp);
-    return errval;
-}
-
-/*****************************************************************************
- * CloseDemux: Close the demuxer
- *****************************************************************************/
-static void CloseDemux( vlc_object_t *p_this )
-{
-    demux_t *p_demux = (demux_t *)p_this;
-    demux_sys_t *sys = p_demux->p_sys;
-
-    if( sys->p_sdp )
-        vlc_sdp_free(sys->p_sdp);
-    free(sys->uri);
-    free( sys );
-}
-
 typedef struct sap_announce_t
 {
     vlc_tick_t i_last;
@@ -973,8 +647,7 @@ vlc_module_begin()
     add_obsolete_bool("sap-ipv6") /* since 2.0.0 */
     add_integer("sap-timeout", 1800,
                 SAP_TIMEOUT_TEXT, SAP_TIMEOUT_LONGTEXT, true)
-    add_bool("sap-parse", true,
-             SAP_PARSE_TEXT,SAP_PARSE_LONGTEXT, true)
+    add_obsolete_bool("sap-parse") /* since 4.0.0 */
     add_obsolete_bool("sap-strict") /* since 4.0.0 */
     add_obsolete_bool("sap-timeshift") /* Redundant since 1.0.0 */
 
@@ -982,10 +655,4 @@ vlc_module_begin()
     set_callbacks(Open, Close)
 
     VLC_SD_PROBE_SUBMODULE
-
-    add_submodule()
-        set_description(N_("SDP Descriptions parser"))
-        add_shortcut("sdp")
-        set_capability("demux", 51)
-        set_callbacks(OpenDemux, CloseDemux)
 vlc_module_end()



More information about the vlc-commits mailing list