Somewhat improve error reporting

Original commit message from CVS:
Somewhat improve error reporting
This commit is contained in:
Ronald S. Bultje 2003-06-01 15:13:56 +00:00
parent 401ae2bdee
commit e87e59e1b3
5 changed files with 62 additions and 42 deletions

View file

@ -21,13 +21,59 @@
#include "config.h" #include "config.h"
#endif #endif
#include <string.h>
#include "gstxviddec.h" #include "gstxviddec.h"
#include "gstxvidenc.h" #include "gstxvidenc.h"
gchar *
gst_xvid_error (int errorcode)
{
gchar *error;
switch (errorcode) {
case XVID_ERR_FAIL:
error = "Operation failed";
break;
case XVID_ERR_OK:
error = "No error";
break;
case XVID_ERR_MEMORY:
error = "Memory error";
break;
case XVID_ERR_FORMAT:
error = "Invalid format";
break;
default:
error = "Unknown error";
break;
}
return error;
}
static gboolean static gboolean
plugin_init (GModule *module, plugin_init (GModule *module,
GstPlugin *plugin) GstPlugin *plugin)
{ {
XVID_INIT_PARAM xinit;
gint ret;
/* set up xvid initially (function pointers, CPU flags) */
memset(&xinit, 0, sizeof(XVID_INIT_PARAM));
xinit.cpu_flags = 0;
if ((ret = xvid_init(NULL, 0, &xinit, NULL)) != XVID_ERR_OK) {
g_warning("Faied to initialize XviD: %s (%d)",
gst_xvid_error(ret), ret);
return FALSE;
}
if (xinit.api_version != API_VERSION) {
g_warning("Xvid API version mismatch! %d.%d (that's us) != %d.%d (lib)",
(API_VERSION >> 8) & 0xff, API_VERSION & 0xff,
(xinit.api_version >> 8) & 0xff, xinit.api_version & 0xff);
}
return (gst_xviddec_plugin_init(module, plugin) && return (gst_xviddec_plugin_init(module, plugin) &&
gst_xvidenc_plugin_init(module, plugin)); gst_xvidenc_plugin_init(module, plugin));
} }

View file

@ -120,18 +120,6 @@ static void
gst_xviddec_class_init (GstXvidDecClass *klass) gst_xviddec_class_init (GstXvidDecClass *klass)
{ {
GObjectClass *gobject_class = (GObjectClass *) klass; GObjectClass *gobject_class = (GObjectClass *) klass;
XVID_INIT_PARAM xinit;
/* set up xvid initially (function pointers, CPU flags) */
memset(&xinit, 0, sizeof(xinit));
xinit.cpu_flags = 0;
xvid_init(NULL, 0, &xinit, NULL);
if (xinit.api_version != API_VERSION) {
g_error("Xvid API version mismatch! %d.%d (that's us) != %d.%d (lib)",
(API_VERSION >> 8) & 0xff, API_VERSION & 0xff,
(xinit.api_version >> 8) & 0xff, xinit.api_version & 0xff);
return;
}
parent_class = g_type_class_ref(GST_TYPE_ELEMENT); parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
@ -187,21 +175,10 @@ gst_xviddec_setup (GstXvidDec *xviddec)
if ((ret = xvid_decore(NULL, XVID_DEC_CREATE, if ((ret = xvid_decore(NULL, XVID_DEC_CREATE,
&xdec, NULL)) != XVID_ERR_OK) { &xdec, NULL)) != XVID_ERR_OK) {
char *error; gst_element_error(GST_ELEMENT(xviddec),
switch (ret) { "Setting parameters %dx%d@%d failed: %s (%d)",
case XVID_ERR_MEMORY: xviddec->width, xviddec->height, xviddec->csp,
error = "Memory allocation error"; gst_xvid_error(ret), ret);
break;
case XVID_ERR_FORMAT:
error = "Bad format";
break;
default:
error = "Internal failure";
break;
}
GST_DEBUG(GST_CAT_PLUGIN_INFO,
"Setting parameters %dx%d@%d failed: %s",
xviddec->width, xviddec->height, xviddec->csp, error);
return FALSE; return FALSE;
} }
@ -260,7 +237,8 @@ gst_xviddec_chain (GstPad *pad,
if ((ret = xvid_decore(xviddec->handle, XVID_DEC_DECODE, if ((ret = xvid_decore(xviddec->handle, XVID_DEC_DECODE,
&xframe, NULL))) { &xframe, NULL))) {
gst_element_error(GST_ELEMENT(xviddec), gst_element_error(GST_ELEMENT(xviddec),
"Error decoding xvid frame: %d\n", ret); "Error decoding xvid frame: %s (%d)\n",
gst_xvid_error(ret), ret);
gst_buffer_unref(buf); gst_buffer_unref(buf);
return; return;
} }

View file

@ -65,6 +65,9 @@ GType gst_xviddec_get_type(void);
gboolean gst_xviddec_plugin_init (GModule *module, gboolean gst_xviddec_plugin_init (GModule *module,
GstPlugin *plugin); GstPlugin *plugin);
/* in gstxvid.c */
extern gchar * gst_xvid_error (int errorcode);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View file

@ -131,7 +131,6 @@ gst_xvidenc_get_type(void)
static void static void
gst_xvidenc_class_init (GstXvidEncClass *klass) gst_xvidenc_class_init (GstXvidEncClass *klass)
{ {
XVID_INIT_PARAM xinit;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
GObjectClass *gobject_class; GObjectClass *gobject_class;
@ -140,17 +139,6 @@ gst_xvidenc_class_init (GstXvidEncClass *klass)
parent_class = g_type_class_ref(GST_TYPE_ELEMENT); parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
/* set up xvid initially (function pointers, CPU flags) */
memset(&xinit, 0, sizeof(xinit));
xinit.cpu_flags = 0;
xvid_init(NULL, 0, &xinit, NULL);
if (xinit.api_version != API_VERSION) {
g_error("Xvid API version mismatch! %d.%d (that's us) != %d.%d (lib)",
(API_VERSION >> 8) & 0xff, API_VERSION & 0xff,
(xinit.api_version >> 8) & 0xff, xinit.api_version & 0xff);
return;
}
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BITRATE, g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BITRATE,
g_param_spec_ulong("bitrate","Bitrate", g_param_spec_ulong("bitrate","Bitrate",
"Target video bitrate", "Target video bitrate",
@ -237,7 +225,8 @@ gst_xvidenc_setup (GstXvidEnc *xvidenc)
if ((ret = xvid_encore(NULL, XVID_ENC_CREATE, if ((ret = xvid_encore(NULL, XVID_ENC_CREATE,
&xenc, NULL)) != XVID_ERR_OK) { &xenc, NULL)) != XVID_ERR_OK) {
gst_element_error(GST_ELEMENT(xvidenc), gst_element_error(GST_ELEMENT(xvidenc),
"Error setting up xvid encoder: %d\n", ret); "Error setting up xvid encoder: %s (%d)",
gst_xvid_error(ret), ret);
return FALSE; return FALSE;
} }
@ -291,7 +280,8 @@ gst_xvidenc_chain (GstPad *pad,
if ((ret = xvid_encore(xvidenc->handle, XVID_ENC_ENCODE, if ((ret = xvid_encore(xvidenc->handle, XVID_ENC_ENCODE,
&xframe, NULL)) != XVID_ERR_OK) { &xframe, NULL)) != XVID_ERR_OK) {
gst_element_error(GST_ELEMENT(xvidenc), gst_element_error(GST_ELEMENT(xvidenc),
"Error encoding xvid frame: %d\n", ret); "Error encoding xvid frame: %s (%d)",
gst_xvid_error(ret), ret);
gst_buffer_unref(buf); gst_buffer_unref(buf);
return; return;
} }

View file

@ -74,6 +74,9 @@ GType gst_xvidenc_get_type(void);
gboolean gst_xvidenc_plugin_init (GModule *module, gboolean gst_xvidenc_plugin_init (GModule *module,
GstPlugin *plugin); GstPlugin *plugin);
/* in gstxvid.c */
extern gchar * gst_xvid_error (int errorcode);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */