diff options
author | Tomas Kukosa <tomas.kukosa@siemens.com> | 2007-10-25 09:38:15 +0000 |
---|---|---|
committer | Tomas Kukosa <tomas.kukosa@siemens.com> | 2007-10-25 09:38:15 +0000 |
commit | 136de3920c4f703e9d7aeb5f6d3b6484a2bc6479 (patch) | |
tree | b55286be4fe6da2b8556a21a18dea5b3563ed374 /epan | |
parent | 821106256bf98c026652181dbdf9480abf080f6a (diff) |
new codec table for registering codecs by name
new codec plugin type
search registered codecs in rtp player
fix memory leak in rtp player
svn path=/trunk/; revision=23270
Diffstat (limited to 'epan')
-rw-r--r-- | epan/Makefile.common | 2 | ||||
-rw-r--r-- | epan/codecs.c | 91 | ||||
-rw-r--r-- | epan/codecs.h | 43 | ||||
-rw-r--r-- | epan/libwireshark.def | 5 | ||||
-rw-r--r-- | epan/plugins.c | 39 | ||||
-rw-r--r-- | epan/plugins.h | 2 |
6 files changed, 178 insertions, 4 deletions
diff --git a/epan/Makefile.common b/epan/Makefile.common index ebfaac6e18..3cbeff93cc 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -35,6 +35,7 @@ LIBWIRESHARK_SRC = \ camel-persistentdata.c \ charsets.c \ circuit.c \ + codecs.c \ column.c \ column-utils.c \ conversation.c \ @@ -145,6 +146,7 @@ LIBWIRESHARK_INCLUDES = \ charsets.h \ chdlctypes.h \ circuit.h \ + codecs.h \ column.h \ column_info.h \ column-utils.h \ diff --git a/epan/codecs.c b/epan/codecs.c new file mode 100644 index 0000000000..28c53d7b62 --- /dev/null +++ b/epan/codecs.c @@ -0,0 +1,91 @@ +/* codecs.c + * codecs interface 2007 Tomas Kukosa + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <epan/codecs.h> + +struct codec_handle { + const char *name; + codec_init_fn init_fn; + codec_release_fn release_fn; + codec_decode_fn decode_fn; +}; + +/* + * List of registered codecs. + */ +static GHashTable *registered_codecs = NULL; + + +/* Find a registered codec by name. */ +codec_handle_t +find_codec(const char *name) +{ + return (registered_codecs) ? g_hash_table_lookup(registered_codecs, name) : NULL; +} + +/* Register a codec by name. */ +void +register_codec(const char *name, codec_init_fn init_fn, codec_release_fn release_fn, codec_decode_fn decode_fn) +{ + struct codec_handle *handle; + + /* Create our hash table if it doesn't already exist */ + if (registered_codecs == NULL) { + registered_codecs = g_hash_table_new(g_str_hash, g_str_equal); + g_assert(registered_codecs != NULL); + } + + /* Make sure the registration is unique */ + g_assert(g_hash_table_lookup(registered_codecs, name) == NULL); + + handle = g_malloc(sizeof (struct codec_handle)); + handle->name = name; + handle->init_fn = init_fn; + handle->release_fn = release_fn; + handle->decode_fn = decode_fn; + + g_hash_table_insert(registered_codecs, (gpointer)name, (gpointer) handle); +} + +void *codec_init(codec_handle_t codec) +{ + if (!codec) return NULL; + return (codec->init_fn)(); +} + +void codec_release(codec_handle_t codec, void *context) +{ + if (!codec) return; + (codec->release_fn)(context); +} + +int codec_decode(codec_handle_t codec, void *context, const void *input, int inputSizeBytes, void *output, int *outputSizeBytes) +{ + if (!codec) return 0; + return (codec->decode_fn)(context, input, inputSizeBytes, output, outputSizeBytes); +} diff --git a/epan/codecs.h b/epan/codecs.h new file mode 100644 index 0000000000..de5d02c1be --- /dev/null +++ b/epan/codecs.h @@ -0,0 +1,43 @@ +/* codecs.h + * codecs interface 2007 Tomas Kukosa + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _CODECS_H_ +#define _CODECS_H_ + +#include "epan/epan.h" + +struct codec_handle; +typedef struct codec_handle *codec_handle_t; + +typedef void *(*codec_init_fn)(void); +typedef void (*codec_release_fn)(void *context); +typedef int (*codec_decode_fn)(void *context, const void *input, int inputSizeBytes, void *output, int *outputSizeBytes); + +extern void register_codec(const char *name, codec_init_fn init_fn, codec_release_fn release_fn, codec_decode_fn decode_fn); +extern codec_handle_t find_codec(const char *name); +extern void *codec_init(codec_handle_t codec); +extern void codec_release(codec_handle_t codec, void *context); +extern int codec_decode(codec_handle_t codec, void *context, const void *input, int inputSizeBytes, void *output, int *outputSizeBytes); + +#endif diff --git a/epan/libwireshark.def b/epan/libwireshark.def index e304183ef9..22047e49f4 100644 --- a/epan/libwireshark.def +++ b/epan/libwireshark.def @@ -66,6 +66,9 @@ circuit_add_proto_data circuit_get_proto_data circuit_new cleanup_dissection +codec_init +codec_decode +codec_release col_add_fstr col_add_str col_append_fstr @@ -318,6 +321,7 @@ file_write_error_message files_identical filesystem_opt find_circuit +find_codec find_conversation find_dissector find_dissector_table @@ -693,6 +697,7 @@ register_all_protocol_handoffs register_all_wiretap_modules register_ber_oid_syntax register_ber_syntax_dissector +register_codec register_count register_dissector register_dissector_filter diff --git a/epan/plugins.c b/epan/plugins.c index 6594afd3b9..68031b5be2 100644 --- a/epan/plugins.c +++ b/epan/plugins.c @@ -69,7 +69,8 @@ static int add_plugin(void *handle, gchar *name, gchar *version, void (*register_protoinfo)(void), void (*reg_handoff)(void), void (*register_tap_listener)(void), - void (*register_wtap_module)(void)) + void (*register_wtap_module)(void), + void (*register_codec_module)(void)) { plugin *new_plug, *pt_plug; @@ -108,6 +109,7 @@ add_plugin(void *handle, gchar *name, gchar *version, new_plug->reg_handoff = reg_handoff; new_plug->register_tap_listener = register_tap_listener; new_plug->register_wtap_module = register_wtap_module; + new_plug->register_codec_module = register_codec_module; new_plug->next = NULL; return 0; @@ -145,6 +147,7 @@ plugins_scan_dir(const char *dirname) void (*reg_handoff)(void); void (*register_tap_listener)(void); void (*register_wtap_module)(void); + void (*register_codec_module)(void); gchar *dot; int cr; @@ -310,18 +313,29 @@ plugins_scan_dir(const char *dirname) register_wtap_module = NULL; } + /* + * Do we have a register_codec_module routine? + */ + if (g_module_symbol(handle, "register_codec_module", &gp)) + { + register_codec_module = gp; + } else { + register_codec_module = NULL; + } + /* * Does this dissector do anything useful? */ if (register_protoinfo == NULL && register_tap_listener == NULL && - register_wtap_module == NULL ) + register_wtap_module == NULL && + register_codec_module == NULL ) { /* * No. */ report_failure("The plugin '%s' has neither a register routine, " - "a register_tap_listener or a register_wtap_module routine", + "a register_tap_listener or a register_wtap_module or a register_codec_module routine", name); g_module_close(handle); continue; @@ -332,7 +346,7 @@ plugins_scan_dir(const char *dirname) */ if ((cr = add_plugin(handle, g_strdup(name), version, register_protoinfo, reg_handoff, - register_tap_listener,register_wtap_module))) + register_tap_listener,register_wtap_module,register_codec_module))) { if (cr == EEXIST) fprintf(stderr, "The plugin %s, version %s\n" @@ -432,6 +446,7 @@ init_plugins(void) } } register_all_wiretap_modules(); + register_all_codecs(); } void @@ -507,4 +522,20 @@ register_all_wiretap_modules(void) (pt_plug->register_wtap_module)(); } } + +void +register_all_codecs(void) +{ + plugin *pt_plug; + + /* + * For all plugins with register_wtap_module routines, call the + * routines. + */ + for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next) + { + if (pt_plug->register_codec_module) + (pt_plug->register_codec_module)(); + } +} #endif diff --git a/epan/plugins.h b/epan/plugins.h index c6a43ab2c9..961cb1c024 100644 --- a/epan/plugins.h +++ b/epan/plugins.h @@ -38,6 +38,7 @@ typedef struct _plugin { void (*reg_handoff)(void); /* routine to call to register dissector handoff */ void (*register_tap_listener)(void); /* routine to call to register tap listener */ void (*register_wtap_module)(void); /* routine to call to register a wiretap module */ + void (*register_codec_module)(void); /* routine to call to register a codec */ struct _plugin *next; /* forward link */ } plugin; @@ -48,6 +49,7 @@ extern void register_all_plugin_registrations(void); extern void register_all_plugin_handoffs(void); extern void register_all_plugin_tap_listeners(void); extern void register_all_wiretap_modules(void); +extern void register_all_codecs(void); /* get the personal plugin dir */ /* Return value is g_malloced so the caller should g_free() it. */ |