~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/pjmedia/src/pjmedia/stream_common.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: stream_common.c 3664 2011-07-19 03:42:28Z nanang $ */
 
2
/* 
 
3
 * Copyright (C) 2011 Teluu Inc. (http://www.teluu.com)
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 
18
 */
 
19
#include <pjmedia/stream_common.h>
 
20
#include <pj/log.h>
 
21
 
 
22
#define THIS_FILE       "stream_common.c"
 
23
 
 
24
/*
 
25
 * Parse fmtp for specified format/payload type.
 
26
 */
 
27
PJ_DEF(pj_status_t) pjmedia_stream_info_parse_fmtp( pj_pool_t *pool,
 
28
                                                    const pjmedia_sdp_media *m,
 
29
                                                    unsigned pt,
 
30
                                                    pjmedia_codec_fmtp *fmtp)
 
31
{
 
32
    const pjmedia_sdp_attr *attr;
 
33
    pjmedia_sdp_fmtp sdp_fmtp;
 
34
    char *p, *p_end, fmt_buf[8];
 
35
    pj_str_t fmt;
 
36
    pj_status_t status;
 
37
 
 
38
    pj_assert(m && fmtp);
 
39
 
 
40
    pj_bzero(fmtp, sizeof(pjmedia_codec_fmtp));
 
41
 
 
42
    /* Get "fmtp" attribute for the format */
 
43
    pj_ansi_sprintf(fmt_buf, "%d", pt);
 
44
    fmt = pj_str(fmt_buf);
 
45
    attr = pjmedia_sdp_media_find_attr2(m, "fmtp", &fmt);
 
46
    if (attr == NULL)
 
47
        return PJ_SUCCESS;
 
48
 
 
49
    /* Parse "fmtp" attribute */
 
50
    status = pjmedia_sdp_attr_get_fmtp(attr, &sdp_fmtp);
 
51
    if (status != PJ_SUCCESS)
 
52
        return status;
 
53
 
 
54
    /* Prepare parsing */
 
55
    p = sdp_fmtp.fmt_param.ptr;
 
56
    p_end = p + sdp_fmtp.fmt_param.slen;
 
57
 
 
58
    /* Parse */
 
59
    while (p < p_end) {
 
60
        char *token, *start, *end;
 
61
 
 
62
        if (fmtp->cnt >= PJMEDIA_CODEC_MAX_FMTP_CNT) {
 
63
            PJ_LOG(4,(THIS_FILE,
 
64
                      "Warning: fmtp parameter count exceeds "
 
65
                      "PJMEDIA_CODEC_MAX_FMTP_CNT"));
 
66
            return PJ_SUCCESS;
 
67
        }
 
68
 
 
69
        /* Skip whitespaces */
 
70
        while (p < p_end && (*p == ' ' || *p == '\t')) ++p;
 
71
        if (p == p_end)
 
72
            break;
 
73
 
 
74
        /* Get token */
 
75
        start = p;
 
76
        while (p < p_end && *p != ';' && *p != '=') ++p;
 
77
        end = p - 1;
 
78
 
 
79
        /* Right trim */
 
80
        while (end >= start && (*end == ' '  || *end == '\t' || 
 
81
                                *end == '\r' || *end == '\n' ))
 
82
            --end;
 
83
 
 
84
        /* Forward a char after trimming */
 
85
        ++end;
 
86
 
 
87
        /* Store token */
 
88
        if (end > start) {
 
89
            if (pool) {
 
90
                token = (char*)pj_pool_alloc(pool, end - start);
 
91
                pj_ansi_strncpy(token, start, end - start);
 
92
            } else {
 
93
                token = start;
 
94
            }
 
95
            if (*p == '=')
 
96
                /* Got param name */
 
97
                pj_strset(&fmtp->param[fmtp->cnt].name, token, end - start);
 
98
            else
 
99
                /* Got param value */
 
100
                pj_strset(&fmtp->param[fmtp->cnt++].val, token, end - start);
 
101
        } else if (*p != '=') {
 
102
            ++fmtp->cnt;
 
103
        }
 
104
 
 
105
        /* Next */
 
106
        ++p;
 
107
    }
 
108
 
 
109
    return PJ_SUCCESS;
 
110
}
 
111