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

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/pjmedia/src/pjmedia/converter.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: converter.c 4412 2013-03-05 03:12:32Z riza $ */
 
2
/*
 
3
 * Copyright (C) 2010-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/converter.h>
 
20
#include <pj/assert.h>
 
21
#include <pj/errno.h>
 
22
 
 
23
#define THIS_FILE       "converter.c"
 
24
 
 
25
struct pjmedia_converter_mgr
 
26
{
 
27
    pjmedia_converter_factory  factory_list;
 
28
};
 
29
 
 
30
static pjmedia_converter_mgr *converter_manager_instance;
 
31
 
 
32
#if PJMEDIA_HAS_LIBSWSCALE && PJMEDIA_HAS_LIBAVUTIL
 
33
PJ_DECL(pj_status_t)
 
34
pjmedia_libswscale_converter_init(pjmedia_converter_mgr *mgr);
 
35
#endif
 
36
 
 
37
 
 
38
PJ_DEF(pj_status_t) pjmedia_converter_mgr_create(pj_pool_t *pool,
 
39
                                                 pjmedia_converter_mgr **p_mgr)
 
40
{
 
41
    pjmedia_converter_mgr *mgr;
 
42
#if PJMEDIA_HAS_LIBSWSCALE && PJMEDIA_HAS_LIBAVUTIL
 
43
    pj_status_t status = PJ_SUCCESS;
 
44
#endif
 
45
 
 
46
    mgr = PJ_POOL_ALLOC_T(pool, pjmedia_converter_mgr);
 
47
    pj_list_init(&mgr->factory_list);
 
48
 
 
49
    if (!converter_manager_instance)
 
50
        converter_manager_instance = mgr;
 
51
 
 
52
#if PJMEDIA_HAS_LIBSWSCALE && PJMEDIA_HAS_LIBAVUTIL
 
53
    status = pjmedia_libswscale_converter_init(mgr);
 
54
    if (status != PJ_SUCCESS) {
 
55
        PJ_PERROR(4,(THIS_FILE, status,
 
56
                     "Error initializing libswscale converter"));
 
57
    }
 
58
#endif
 
59
 
 
60
    if (p_mgr)
 
61
        *p_mgr = mgr;
 
62
 
 
63
    return PJ_SUCCESS;
 
64
}
 
65
 
 
66
PJ_DEF(pjmedia_converter_mgr*) pjmedia_converter_mgr_instance(void)
 
67
{
 
68
    pj_assert(converter_manager_instance != NULL);
 
69
    return converter_manager_instance;
 
70
}
 
71
 
 
72
PJ_DEF(void) pjmedia_converter_mgr_set_instance(pjmedia_converter_mgr *mgr)
 
73
{
 
74
    converter_manager_instance = mgr;
 
75
}
 
76
 
 
77
PJ_DEF(void) pjmedia_converter_mgr_destroy(pjmedia_converter_mgr *mgr)
 
78
{
 
79
    pjmedia_converter_factory *f;
 
80
 
 
81
    if (!mgr) mgr = pjmedia_converter_mgr_instance();
 
82
 
 
83
    PJ_ASSERT_ON_FAIL(mgr != NULL, return);
 
84
 
 
85
    f = mgr->factory_list.next;
 
86
    while (f != &mgr->factory_list) {
 
87
        pjmedia_converter_factory *next = f->next;
 
88
        pj_list_erase(f);
 
89
        (*f->op->destroy_factory)(f);
 
90
        f = next;
 
91
    }
 
92
 
 
93
    if (converter_manager_instance == mgr)
 
94
        converter_manager_instance = NULL;
 
95
}
 
96
 
 
97
PJ_DEF(pj_status_t)
 
98
pjmedia_converter_mgr_register_factory(pjmedia_converter_mgr *mgr,
 
99
                                       pjmedia_converter_factory *factory)
 
100
{
 
101
    pjmedia_converter_factory *pf;
 
102
 
 
103
    if (!mgr) mgr = pjmedia_converter_mgr_instance();
 
104
 
 
105
    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
 
106
 
 
107
    PJ_ASSERT_RETURN(!pj_list_find_node(&mgr->factory_list, factory),
 
108
                     PJ_EEXISTS);
 
109
 
 
110
    pf = mgr->factory_list.next;
 
111
    while (pf != &mgr->factory_list) {
 
112
        if (pf->priority > factory->priority)
 
113
            break;
 
114
        pf = pf->next;
 
115
    }
 
116
    pj_list_insert_before(pf, factory);
 
117
    return PJ_SUCCESS;
 
118
}
 
119
 
 
120
 
 
121
PJ_DEF(pj_status_t)
 
122
pjmedia_converter_mgr_unregister_factory(pjmedia_converter_mgr *mgr,
 
123
                                         pjmedia_converter_factory *f,
 
124
                                         pj_bool_t destroy)
 
125
{
 
126
    if (!mgr) mgr = pjmedia_converter_mgr_instance();
 
127
 
 
128
    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
 
129
 
 
130
    PJ_ASSERT_RETURN(pj_list_find_node(&mgr->factory_list, f), PJ_ENOTFOUND);
 
131
    pj_list_erase(f);
 
132
    if (destroy)
 
133
        (*f->op->destroy_factory)(f);
 
134
    return PJ_SUCCESS;
 
135
}
 
136
 
 
137
PJ_DEF(pj_status_t) pjmedia_converter_create(pjmedia_converter_mgr *mgr,
 
138
                                              pj_pool_t *pool,
 
139
                                              pjmedia_conversion_param *param,
 
140
                                              pjmedia_converter **p_cv)
 
141
{
 
142
    pjmedia_converter_factory *f;
 
143
    pjmedia_converter *cv = NULL;
 
144
    pj_status_t status = PJ_ENOTFOUND;
 
145
 
 
146
    if (!mgr) mgr = pjmedia_converter_mgr_instance();
 
147
 
 
148
    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
 
149
 
 
150
    *p_cv = NULL;
 
151
 
 
152
    f = mgr->factory_list.next;
 
153
    while (f != &mgr->factory_list) {
 
154
        status = (*f->op->create_converter)(f, pool, param, &cv);
 
155
        if (status == PJ_SUCCESS)
 
156
            break;
 
157
        f = f->next;
 
158
    }
 
159
 
 
160
    if (status != PJ_SUCCESS)
 
161
        return status;
 
162
 
 
163
    *p_cv = cv;
 
164
 
 
165
    return PJ_SUCCESS;
 
166
}
 
167
 
 
168
PJ_DEF(pj_status_t) pjmedia_converter_convert(pjmedia_converter *cv,
 
169
                                               pjmedia_frame *src_frame,
 
170
                                               pjmedia_frame *dst_frame)
 
171
{
 
172
    return (*cv->op->convert)(cv, src_frame, dst_frame);
 
173
}
 
174
 
 
175
PJ_DEF(void) pjmedia_converter_destroy(pjmedia_converter *cv)
 
176
{
 
177
    (*cv->op->destroy)(cv);
 
178
}
 
179
 
 
180