~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

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

  • Committer: Jackson Doak
  • Date: 2013-07-10 21:04:46 UTC
  • mfrom: (20.1.3 sid)
  • Revision ID: noskcaj@ubuntu.com-20130710210446-y8f587vza807icr9
Properly merged from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: converter.c 4087 2012-04-26 03:39:24Z ming $ */
 
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
    pj_status_t status = PJ_SUCCESS;
 
43
 
 
44
    mgr = PJ_POOL_ALLOC_T(pool, pjmedia_converter_mgr);
 
45
    pj_list_init(&mgr->factory_list);
 
46
 
 
47
    if (!converter_manager_instance)
 
48
        converter_manager_instance = mgr;
 
49
 
 
50
#if PJMEDIA_HAS_LIBSWSCALE && PJMEDIA_HAS_LIBAVUTIL
 
51
    status = pjmedia_libswscale_converter_init(mgr);
 
52
    if (status != PJ_SUCCESS) {
 
53
        PJ_PERROR(4,(THIS_FILE, status,
 
54
                     "Error initializing libswscale converter"));
 
55
    }
 
56
#endif
 
57
 
 
58
    if (p_mgr)
 
59
        *p_mgr = mgr;
 
60
 
 
61
    return PJ_SUCCESS;
 
62
}
 
63
 
 
64
PJ_DEF(pjmedia_converter_mgr*) pjmedia_converter_mgr_instance(void)
 
65
{
 
66
    pj_assert(converter_manager_instance != NULL);
 
67
    return converter_manager_instance;
 
68
}
 
69
 
 
70
PJ_DEF(void) pjmedia_converter_mgr_set_instance(pjmedia_converter_mgr *mgr)
 
71
{
 
72
    converter_manager_instance = mgr;
 
73
}
 
74
 
 
75
PJ_DEF(void) pjmedia_converter_mgr_destroy(pjmedia_converter_mgr *mgr)
 
76
{
 
77
    pjmedia_converter_factory *f;
 
78
 
 
79
    if (!mgr) mgr = pjmedia_converter_mgr_instance();
 
80
 
 
81
    PJ_ASSERT_ON_FAIL(mgr != NULL, return);
 
82
 
 
83
    f = mgr->factory_list.next;
 
84
    while (f != &mgr->factory_list) {
 
85
        pjmedia_converter_factory *next = f->next;
 
86
        pj_list_erase(f);
 
87
        (*f->op->destroy_factory)(f);
 
88
        f = next;
 
89
    }
 
90
 
 
91
    if (converter_manager_instance == mgr)
 
92
        converter_manager_instance = NULL;
 
93
}
 
94
 
 
95
PJ_DEF(pj_status_t)
 
96
pjmedia_converter_mgr_register_factory(pjmedia_converter_mgr *mgr,
 
97
                                       pjmedia_converter_factory *factory)
 
98
{
 
99
    pjmedia_converter_factory *pf;
 
100
 
 
101
    if (!mgr) mgr = pjmedia_converter_mgr_instance();
 
102
 
 
103
    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
 
104
 
 
105
    PJ_ASSERT_RETURN(!pj_list_find_node(&mgr->factory_list, factory),
 
106
                     PJ_EEXISTS);
 
107
 
 
108
    pf = mgr->factory_list.next;
 
109
    while (pf != &mgr->factory_list) {
 
110
        if (pf->priority > factory->priority)
 
111
            break;
 
112
        pf = pf->next;
 
113
    }
 
114
    pj_list_insert_before(pf, factory);
 
115
    return PJ_SUCCESS;
 
116
}
 
117
 
 
118
 
 
119
PJ_DEF(pj_status_t)
 
120
pjmedia_converter_mgr_unregister_factory(pjmedia_converter_mgr *mgr,
 
121
                                         pjmedia_converter_factory *f,
 
122
                                         pj_bool_t destroy)
 
123
{
 
124
    if (!mgr) mgr = pjmedia_converter_mgr_instance();
 
125
 
 
126
    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
 
127
 
 
128
    PJ_ASSERT_RETURN(pj_list_find_node(&mgr->factory_list, f), PJ_ENOTFOUND);
 
129
    pj_list_erase(f);
 
130
    if (destroy)
 
131
        (*f->op->destroy_factory)(f);
 
132
    return PJ_SUCCESS;
 
133
}
 
134
 
 
135
PJ_DEF(pj_status_t) pjmedia_converter_create(pjmedia_converter_mgr *mgr,
 
136
                                              pj_pool_t *pool,
 
137
                                              pjmedia_conversion_param *param,
 
138
                                              pjmedia_converter **p_cv)
 
139
{
 
140
    pjmedia_converter_factory *f;
 
141
    pjmedia_converter *cv = NULL;
 
142
    pj_status_t status = PJ_ENOTFOUND;
 
143
 
 
144
    if (!mgr) mgr = pjmedia_converter_mgr_instance();
 
145
 
 
146
    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
 
147
 
 
148
    *p_cv = NULL;
 
149
 
 
150
    f = mgr->factory_list.next;
 
151
    while (f != &mgr->factory_list) {
 
152
        status = (*f->op->create_converter)(f, pool, param, &cv);
 
153
        if (status == PJ_SUCCESS)
 
154
            break;
 
155
        f = f->next;
 
156
    }
 
157
 
 
158
    if (status != PJ_SUCCESS)
 
159
        return status;
 
160
 
 
161
    *p_cv = cv;
 
162
 
 
163
    return PJ_SUCCESS;
 
164
}
 
165
 
 
166
PJ_DEF(pj_status_t) pjmedia_converter_convert(pjmedia_converter *cv,
 
167
                                               pjmedia_frame *src_frame,
 
168
                                               pjmedia_frame *dst_frame)
 
169
{
 
170
    return (*cv->op->convert)(cv, src_frame, dst_frame);
 
171
}
 
172
 
 
173
PJ_DEF(void) pjmedia_converter_destroy(pjmedia_converter *cv)
 
174
{
 
175
    (*cv->op->destroy)(cv);
 
176
}