Do something less catastrophic than crashing if the same name is used in

two codec registrations.

svn path=/trunk/; revision=53711
This commit is contained in:
Guy Harris 2013-12-02 08:51:46 +00:00
parent 0cc1545d05
commit 40b60cbf55
2 changed files with 6 additions and 6 deletions

View File

@ -119,19 +119,18 @@ find_codec(const char *name)
}
/* Register a codec by name. */
void
gboolean
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) {
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);
if (g_hash_table_lookup(registered_codecs, name) != NULL)
return FALSE; /* report an error, or have our caller do it? */
handle = (struct codec_handle *)g_malloc(sizeof (struct codec_handle));
handle->name = name;
@ -140,6 +139,7 @@ register_codec(const char *name, codec_init_fn init_fn, codec_release_fn release
handle->decode_fn = decode_fn;
g_hash_table_insert(registered_codecs, (gpointer)name, (gpointer) handle);
return TRUE;
}
void *codec_init(codec_handle_t codec)

View File

@ -46,7 +46,7 @@ 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 gboolean 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);