~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjmedia/src/pjmedia/port.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* 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: port.c 3893 2011-12-01 10:49:07Z ming $ */
2
 
/*
3
 
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
 
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
 */
20
 
#include <pjmedia/port.h>
21
 
#include <pjmedia/errno.h>
22
 
#include <pj/assert.h>
23
 
#include <pj/log.h>
24
 
#include <pj/pool.h>
25
 
 
26
 
#define THIS_FILE       "port.c"
27
 
 
28
 
 
29
 
/**
30
 
 * This is an auxiliary function to initialize port info for
31
 
 * ports which deal with PCM audio.
32
 
 */
33
 
PJ_DEF(pj_status_t) pjmedia_port_info_init( pjmedia_port_info *info,
34
 
                                            const pj_str_t *name,
35
 
                                            unsigned signature,
36
 
                                            unsigned clock_rate,
37
 
                                            unsigned channel_count,
38
 
                                            unsigned bits_per_sample,
39
 
                                            unsigned samples_per_frame)
40
 
{
41
 
#define USEC_IN_SEC (pj_uint64_t)1000000
42
 
    unsigned frame_time_usec, avg_bps;
43
 
 
44
 
    pj_bzero(info, sizeof(*info));
45
 
 
46
 
    info->signature = signature;
47
 
    info->dir = PJMEDIA_DIR_ENCODING_DECODING;
48
 
    info->name = *name;
49
 
 
50
 
    frame_time_usec = (unsigned)(samples_per_frame * USEC_IN_SEC /
51
 
                                 channel_count / clock_rate);
52
 
    avg_bps = clock_rate * channel_count * bits_per_sample;
53
 
 
54
 
    pjmedia_format_init_audio(&info->fmt, PJMEDIA_FORMAT_L16, clock_rate,
55
 
                              channel_count, bits_per_sample, frame_time_usec,
56
 
                              avg_bps, avg_bps);
57
 
 
58
 
    return PJ_SUCCESS;
59
 
}
60
 
 
61
 
PJ_DEF(pj_status_t) pjmedia_port_info_init2( pjmedia_port_info *info,
62
 
                                             const pj_str_t *name,
63
 
                                             unsigned signature,
64
 
                                             pjmedia_dir dir,
65
 
                                             const pjmedia_format *fmt)
66
 
{
67
 
    pj_bzero(info, sizeof(*info));
68
 
    info->signature = signature;
69
 
    info->dir = dir;
70
 
    info->name = *name;
71
 
 
72
 
    pjmedia_format_copy(&info->fmt, fmt);
73
 
 
74
 
    return PJ_SUCCESS;
75
 
}
76
 
 
77
 
/**
78
 
 * Get a clock source from the port.
79
 
 */
80
 
PJ_DEF(pjmedia_clock_src *) pjmedia_port_get_clock_src( pjmedia_port *port,
81
 
                                                        pjmedia_dir dir )
82
 
{
83
 
    if (port && port->get_clock_src)
84
 
        return port->get_clock_src(port, dir);
85
 
    else
86
 
        return NULL;
87
 
}
88
 
 
89
 
/**
90
 
 * Get a frame from the port (and subsequent downstream ports).
91
 
 */
92
 
PJ_DEF(pj_status_t) pjmedia_port_get_frame( pjmedia_port *port,
93
 
                                            pjmedia_frame *frame )
94
 
{
95
 
    PJ_ASSERT_RETURN(port && frame, PJ_EINVAL);
96
 
 
97
 
    if (port->get_frame)
98
 
        return port->get_frame(port, frame);
99
 
    else {
100
 
        frame->type = PJMEDIA_FRAME_TYPE_NONE;
101
 
        return PJ_EINVALIDOP;
102
 
    }
103
 
}
104
 
 
105
 
 
106
 
/**
107
 
 * Put a frame to the port (and subsequent downstream ports).
108
 
 */
109
 
PJ_DEF(pj_status_t) pjmedia_port_put_frame( pjmedia_port *port,
110
 
                                            pjmedia_frame *frame )
111
 
{
112
 
    PJ_ASSERT_RETURN(port && frame, PJ_EINVAL);
113
 
 
114
 
    if (port->put_frame)
115
 
        return port->put_frame(port, frame);
116
 
    else
117
 
        return PJ_EINVALIDOP;
118
 
}
119
 
 
120
 
/**
121
 
 * Destroy port (and subsequent downstream ports)
122
 
 */
123
 
PJ_DEF(pj_status_t) pjmedia_port_destroy( pjmedia_port *port )
124
 
{
125
 
    pj_status_t status;
126
 
 
127
 
    PJ_ASSERT_RETURN(port, PJ_EINVAL);
128
 
 
129
 
    if (port->on_destroy)
130
 
        status = port->on_destroy(port);
131
 
    else
132
 
        status = PJ_SUCCESS;
133
 
 
134
 
    return status;
135
 
}