码迷,mamicode.com
首页 > 其他好文 > 详细

vlc源码研究

时间:2018-01-05 22:31:28      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:des   bsp   style   eof   lob   desc   图片   end   log   

有位传说中的大神告诉我,我的p2p打洞打不通是因为,sdp描述信息中的地址不对

 

技术分享图片

 

也就是IN IP4 XXX.XXX.X.XXX这一句

我看到确实是个局域网地址,那么vlc在接收到IN IP4 XXX.XXX.X.XXX的时候到底是如何处理的呢,引起了我极大的好奇

一定要去源码里面找一下

在source insight 里面搜索了一下IN IP

 

技术分享图片

接收肯定是从字符串里面解析东西,不是输入东西

所以估计在

Sap.c (modules\services_discovery):            if (sscanf (sfilter, " incl IN IP%u %*s %255s ", &ipv,
Sap.c (modules\services_discovery):    int res = sscanf (str, "IN IP%u %59[^/]/%u/%u", &fam, host, &n1, &n2);
Sap.c (modules\services_discovery):                if ((sscanf (data, "%63s %"SCNu64" %"SCNu64" IN IP%u %1023s",

sap.c文件里面

static sdp_t *ParseSDP (vlc_object_t *p_obj, const char *psz_sdp)

里面有

switch (expect)
        {
            /* Session description */
            case V:

                break;

            case O:
            {
                expect = S;
                if (cat != o)
                {
                    msg_Dbg (p_obj, "missing SDP originator");
                    goto error;
                }

                if ((sscanf (data, "%63s %"SCNu64" %"SCNu64" IN IP%u %1023s",
                             p_sdp->username, &p_sdp->session_id,
                             &p_sdp->session_version, &p_sdp->orig_ip_version,
                             p_sdp->orig_host) != 5)
                 || ((p_sdp->orig_ip_version != 4)
                  && (p_sdp->orig_ip_version != 6)))
                {
                    msg_Dbg (p_obj, "SDP origin not supported: %s", data);
                    /* Or maybe out-of-range, but this looks suspicious */
                    goto error;
                }
                EnsureUTF8 (p_sdp->orig_host);
                break;
            }

            case S:
            {

                break;
            }

            case I:
            {
  
                    break;
            }

            case U:
                expect = E;
                if (cat == u)
                    break;
            case E:
                expect = E;
                if (cat == e)
                    break;
            case P:
                expect = P;
                if (cat == p)
                    break;
            case C:
                expect = B;
                if (cat == c)
                {
                    if (ParseSDPConnection (data, &glob_addr, &glob_len,
                                            &glob_count))
                    {
                        msg_Dbg (p_obj, "SDP connection infos not supported: "
                                 "%s", data);
                        goto error;
                    }
                    break;
                }

 

所以这段sdp

Owner/Creator, Session Id (o): - 1502808625152723 1502808625152723 IN IP4 192.168.1.146

被解析进了p_sdp->orig_host里面

另一段sdp

Connection Information (c): IN IP4 192.168.1.146

被ParseSDPConnection (data, &glob_addr, &glob_len, &glob_count)处理了,放入了glob_addr里面

再看这一段

            case m:
            media:
            {
                expect = i;
                if (cat != m)
                {
                    msg_Dbg (p_obj, "missing SDP media description");
                    goto error;
                }
                struct sdp_media_t *m;
                m = realloc (p_sdp->mediav, (p_sdp->mediac + 1) * sizeof (*m));
                if (m == NULL)
                    goto error;

                p_sdp->mediav = m;
                m += p_sdp->mediac;
                p_sdp->mediac++;

                memset (m, 0, sizeof (*m));
                memcpy (&m->addr, &glob_addr, m->addrlen = glob_len);
                m->n_addr = glob_count;

最后被放进了p_sdp->mediav->addr 里面

 

所以要追踪p_sdp的动向

static int OpenDemux( vlc_object_t *p_this )
  p_demux->p_sys->p_sdp = p_sdp;

 

vlc源码研究

标签:des   bsp   style   eof   lob   desc   图片   end   log   

原文地址:https://www.cnblogs.com/baldermurphy/p/7367666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!