1
/* $Id: converter.h 3664 2011-07-19 03:42:28Z nanang $ */
3
* Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
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.
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.
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
19
#ifndef __PJMEDIA_CONVERTER_H__
20
#define __PJMEDIA_CONVERTER_H__
24
* @file pjmedia/converter.h Format conversion utilities
25
* @brief Format conversion utilities
28
#include <pjmedia/frame.h>
29
#include <pjmedia/format.h>
35
* @defgroup PJMEDIA_CONVERTER Format converter
36
* @ingroup PJMEDIA_FRAME_OP
37
* @brief Audio and video converter utilities
44
* This describes conversion parameter. It specifies the source and
45
* destination formats of the conversion.
47
typedef struct pjmedia_conversion_param
49
pjmedia_format src; /**< Source format. */
50
pjmedia_format dst; /**< Destination format. */
51
} pjmedia_conversion_param;
54
/** Forward declaration of factory operation structure */
55
typedef struct pjmedia_converter_factory_op pjmedia_converter_factory_op;
58
* Converter priority guides. Converter priority determines which converter
59
* instance to be used if more than one converters are able to perform the
60
* requested conversion. Converter implementor can use this value to order
61
* the preference based on attributes such as quality or performance. Higher
62
* number indicates higher priority.
64
typedef enum pjmedia_converter_priority_guide
66
/** Lowest priority. */
67
PJMEDIA_CONVERTER_PRIORITY_LOWEST = 0,
69
/** Normal priority. */
70
PJMEDIA_CONVERTER_PRIORITY_NORMAL = 15000,
72
/** Highest priority. */
73
PJMEDIA_CONVERTER_PRIORITY_HIGHEST = 32000
74
} pjmedia_converter_priority_guide;
77
* Converter factory. The converter factory registers a callback function
78
* to create converters.
80
typedef struct pjmedia_converter_factory
83
* Standard list members.
85
PJ_DECL_LIST_MEMBER(struct pjmedia_converter_factory);
93
* Converter priority determines which converter instance to be used if
94
* more than one converters are able to perform the requested conversion.
95
* Converter implementor can use this value to order the preference based
96
* on attributes such as quality or performance. Higher number indicates
97
* higher priority. The pjmedia_converter_priority_guide enumeration shall
98
* be used as the base value to set the priority.
103
* Pointer to factory operation.
105
pjmedia_converter_factory_op *op;
107
} pjmedia_converter_factory;
109
/** Forward declaration for converter operation. */
110
typedef struct pjmedia_converter_op pjmedia_converter_op;
113
* This structure describes a converter instance.
115
typedef struct pjmedia_converter
118
* Pointer to converter operation.
120
pjmedia_converter_op *op;
126
* Converter factory operation.
128
struct pjmedia_converter_factory_op
131
* This function creates a converter with the specified conversion format,
132
* if such format is supported.
134
* @param cf The converter factory.
135
* @param pool Pool to allocate memory from.
136
* @param prm Conversion parameter.
137
* @param p_cv Pointer to hold the created converter instance.
139
* @return PJ_SUCCESS if converter has been created successfully.
141
pj_status_t (*create_converter)(pjmedia_converter_factory *cf,
143
const pjmedia_conversion_param *prm,
144
pjmedia_converter **p_cv);
147
* Destroy the factory.
149
* @param cf The converter factory.
151
void (*destroy_factory)(pjmedia_converter_factory *cf);
155
* Converter operation.
157
struct pjmedia_converter_op
160
* Convert the buffer in the source frame and save the result in the
161
* buffer of the destination frame, according to conversion format that
162
* was specified when the converter was created.
164
* Note that application should use #pjmedia_converter_convert() instead
165
* of calling this function directly.
167
* @param cv The converter instance.
168
* @param src_frame The source frame.
169
* @param dst_frame The destination frame.
171
* @return PJ_SUCCESS if conversion has been performed
174
pj_status_t (*convert)(pjmedia_converter *cv,
175
pjmedia_frame *src_frame,
176
pjmedia_frame *dst_frame);
179
* Destroy the converter instance.
181
* Note that application should use #pjmedia_converter_destroy() instead
182
* of calling this function directly.
184
* @param cv The converter.
186
void (*destroy)(pjmedia_converter *cv);
192
* Opaque data type for conversion manager. Typically, the conversion manager
193
* is a singleton instance, although application may instantiate more than one
194
* instances of this if required.
196
typedef struct pjmedia_converter_mgr pjmedia_converter_mgr;
200
* Create a new conversion manager instance. This will also set the pointer
201
* to the singleton instance if the value is still NULL.
203
* @param pool Pool to allocate memory from.
204
* @param mgr Pointer to hold the created instance of the
205
* conversion manager.
207
* @return PJ_SUCCESS on success or the appropriate error code.
209
PJ_DECL(pj_status_t) pjmedia_converter_mgr_create(pj_pool_t *pool,
210
pjmedia_converter_mgr **mgr);
213
* Get the singleton instance of the conversion manager.
215
* @return The instance.
217
PJ_DECL(pjmedia_converter_mgr*) pjmedia_converter_mgr_instance(void);
220
* Manually assign a specific video manager instance as the singleton
221
* instance. Normally this is not needed if only one instance is ever
222
* going to be created, as the library automatically assign the singleton
225
* @param mgr The instance to be used as the singleton instance.
226
* Application may specify NULL to clear the singleton
227
* singleton instance.
229
PJ_DECL(void) pjmedia_converter_mgr_set_instance(pjmedia_converter_mgr *mgr);
232
* Destroy a converter manager. If the manager happens to be the singleton
233
* instance, the singleton instance will be set to NULL.
235
* @param mgr The converter manager. Specify NULL to use
236
* the singleton instance.
238
PJ_DECL(void) pjmedia_converter_mgr_destroy(pjmedia_converter_mgr *mgr);
241
* Register a converter factory to the converter manager.
243
* @param mgr The converter manager. Specify NULL to use
244
* the singleton instance.
245
* @param f The converter factory to be registered.
247
* @return PJ_SUCCESS on success or the appropriate error code.
250
pjmedia_converter_mgr_register_factory(pjmedia_converter_mgr *mgr,
251
pjmedia_converter_factory *f);
254
* Unregister a previously registered converter factory from the converter
257
* @param mgr The converter manager. Specify NULL to use
258
* the singleton instance.
259
* @param f The converter factory to be unregistered.
260
* @param call_destroy If this is set to non-zero, the \a destroy_factory()
261
* callback of the factory will be called while
262
* unregistering the factory from the manager.
264
* @return PJ_SUCCESS on success or the appropriate error code.
267
pjmedia_converter_mgr_unregister_factory(pjmedia_converter_mgr *mgr,
268
pjmedia_converter_factory *f,
269
pj_bool_t call_destroy);
272
* Create a converter instance to perform the specified format conversion
273
* as specified in \a param.
275
* @param mgr The converter manager. Specify NULL to use
276
* the singleton instance.
277
* @param pool Pool to allocate the memory from.
278
* @param param Conversion parameter.
279
* @param p_cv Pointer to hold the created converter.
281
* @return PJ_SUCCESS if a converter has been created successfully
282
* or the appropriate error code.
284
PJ_DECL(pj_status_t) pjmedia_converter_create(pjmedia_converter_mgr *mgr,
286
pjmedia_conversion_param *param,
287
pjmedia_converter **p_cv);
290
* Convert the buffer in the source frame and save the result in the
291
* buffer of the destination frame, according to conversion format that
292
* was specified when the converter was created.
294
* @param cv The converter instance.
295
* @param src_frame The source frame.
296
* @param dst_frame The destination frame.
298
* @return PJ_SUCCESS if conversion has been performed
301
PJ_DECL(pj_status_t) pjmedia_converter_convert(pjmedia_converter *cv,
302
pjmedia_frame *src_frame,
303
pjmedia_frame *dst_frame);
306
* Destroy the converter.
308
* @param cv The converter instance.
310
PJ_DECL(void) pjmedia_converter_destroy(pjmedia_converter *cv);
320
#endif /* __PJMEDIA_CONVERTER_H__ */