2 * codecs interface 2007 Tomas Kukosa
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <wsutil/wslog.h>
17 #include <wsutil/plugins.h>
21 static plugins_t
*libwscodecs_plugins
;
24 static GSList
*codecs_plugins
;
28 codecs_register_plugin(const codecs_plugin
*plug
)
30 codecs_plugins
= g_slist_prepend(codecs_plugins
, (codecs_plugin
*)plug
);
32 #else /* HAVE_PLUGINS */
34 codecs_register_plugin(const codecs_plugin
*plug _U_
)
36 ws_warning("codecs_register_plugin: built without support for binary plugins");
38 #endif /* HAVE_PLUGINS */
41 call_plugin_register_codec_module(void * data
, void * user_data _U_
)
43 codecs_plugin
*plug
= (codecs_plugin
*)data
;
45 if (plug
->register_codec_module
) {
46 plug
->register_codec_module();
52 * For all codec plugins, call their register routines.
58 libwscodecs_plugins
= plugins_init(WS_PLUGIN_CODEC
);
60 g_slist_foreach(codecs_plugins
, call_plugin_register_codec_module
, NULL
);
66 g_slist_free(codecs_plugins
);
67 codecs_plugins
= NULL
;
69 plugins_cleanup(libwscodecs_plugins
);
70 libwscodecs_plugins
= NULL
;
77 codec_init_fn init_fn
;
78 codec_release_fn release_fn
;
79 codec_get_channels_fn channels_fn
;
80 codec_get_frequency_fn frequency_fn
;
81 codec_decode_fn decode_fn
;
85 * List of registered codecs.
87 static GHashTable
*registered_codecs
;
90 /* Find a registered codec by name. */
92 find_codec(const char *name
)
95 char *key
= g_ascii_strup(name
, -1);
97 ret
= (registered_codecs
) ? (codec_handle_t
)g_hash_table_lookup(registered_codecs
, key
) : NULL
;
102 /* Register a codec by name. */
104 register_codec(const char *name
, codec_init_fn init_fn
, codec_release_fn release_fn
,
105 codec_get_channels_fn channels_fn
, codec_get_frequency_fn frequency_fn
,
106 codec_decode_fn decode_fn
)
108 struct codec_handle
*handle
;
111 /* Create our hash table if it doesn't already exist */
112 if (registered_codecs
== NULL
)
113 registered_codecs
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
115 /* RFC 4855 3. Mapping to SDP Parameters "Note that the payload format
116 * (encoding) names... are commonly shown in upper case. These names
117 * are case-insensitive in both places."
119 key
= g_ascii_strup(name
, -1);
121 /* Make sure the registration is unique */
122 if (g_hash_table_lookup(registered_codecs
, key
) != NULL
) {
124 return false; /* report an error, or have our caller do it? */
127 handle
= g_new(struct codec_handle
, 1);
129 handle
->init_fn
= init_fn
;
130 handle
->release_fn
= release_fn
;
131 handle
->channels_fn
= channels_fn
;
132 handle
->frequency_fn
= frequency_fn
;
133 handle
->decode_fn
= decode_fn
;
135 g_hash_table_insert(registered_codecs
, (void *)key
, (void *) handle
);
139 /* Deregister a codec by name. */
141 deregister_codec(const char *name
)
144 if (registered_codecs
) {
145 char *key
= g_ascii_strup(name
, -1);
147 ret
= g_hash_table_remove(registered_codecs
, key
);
153 void *codec_init(codec_handle_t codec
, codec_context_t
*context
)
155 if (!codec
) return NULL
;
156 return (codec
->init_fn
)(context
);
159 void codec_release(codec_handle_t codec
, codec_context_t
*context
)
162 (codec
->release_fn
)(context
);
165 unsigned codec_get_channels(codec_handle_t codec
, codec_context_t
*context
)
167 if (!codec
) return 0;
168 return (codec
->channels_fn
)(context
);
171 unsigned codec_get_frequency(codec_handle_t codec
, codec_context_t
*context
)
173 if (!codec
) return 0;
174 return (codec
->frequency_fn
)(context
);
177 size_t codec_decode(codec_handle_t codec
, codec_context_t
*context
, const void *input
, size_t inputSizeBytes
, void *output
, size_t *outputSizeBytes
)
179 if (!codec
) return 0;
180 return (codec
->decode_fn
)(context
, input
, inputSizeBytes
, output
, outputSizeBytes
);
184 * Editor modelines - https://www.wireshark.org/tools/modelines.html
189 * indent-tabs-mode: nil
192 * vi: set shiftwidth=4 tabstop=8 expandtab:
193 * :indentSize=4:tabSize=8:noTabs=true: