call xvid_init() only once, and move duplicated code into one place
authorRonald S. Bultje <rbultje@ronald.bitfreak.net>
Tue, 29 Jul 2003 11:59:09 +0000 (11:59 +0000)
committerRonald S. Bultje <rbultje@ronald.bitfreak.net>
Tue, 29 Jul 2003 11:59:09 +0000 (11:59 +0000)
Original commit message from CVS:
call xvid_init() only once, and move duplicated code into one place

common
ext/xvid/gstxvid.c
ext/xvid/gstxvid.h [new file with mode: 0644]
ext/xvid/gstxviddec.c
ext/xvid/gstxviddec.h
ext/xvid/gstxvidenc.c
ext/xvid/gstxvidenc.h

diff --git a/common b/common
index d6e219f..8b323f4 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit d6e219fd076d8f182bd1ee84228b1b85cdb807a6
+Subproject commit 8b323f41bfaccb8f30bddfc6ff8bd6a4be04a3e1
index fb7d06f..8496a9d 100644 (file)
 #include "gstxviddec.h"
 #include "gstxvidenc.h"
 
+gboolean
+gst_xvid_init (void)
+{
+  XVID_INIT_PARAM xinit;
+  gint ret;
+  static gboolean is_init = FALSE;
+
+  /* only init once */
+  if (is_init == TRUE) {
+    return TRUE;
+  }
+
+  /* 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("Failed 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 FALSE;
+  }
+
+  is_init = TRUE;
+  return TRUE;
+}
+
 gchar *
 gst_xvid_error (int errorcode)
 {
diff --git a/ext/xvid/gstxvid.h b/ext/xvid/gstxvid.h
new file mode 100644 (file)
index 0000000..6e444f5
--- /dev/null
@@ -0,0 +1,36 @@
+/* GStreamer xvid decoder plugin
+ * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_XVID_H__
+#define __GST_XVID_H__
+
+#include <gst/gst.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+extern gchar * gst_xvid_error (int errorcode);
+extern gboolean        gst_xvid_init  (void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __GST_XVID_H__ */
index a5888da..50e72a3 100644 (file)
@@ -135,23 +135,8 @@ static void
 gst_xviddec_class_init (GstXvidDecClass *klass)
 {
   GObjectClass *gobject_class = (GObjectClass *) klass;
-  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("Failed to initialize XviD: %s (%d)",
-             gst_xvid_error(ret), ret);
-    return;
-  }
-  
-  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);
-  }
+
+  gst_xvid_init();
 
   parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
 
index 6a08b2b..d174334 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <gst/gst.h>
 #include <xvid.h>
+#include "gstxvid.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -66,9 +67,6 @@ GType gst_xviddec_get_type(void);
 gboolean gst_xviddec_plugin_init (GModule   *module,
                                   GstPlugin *plugin);
 
-/* in gstxvid.c */
-extern gchar * gst_xvid_error (int errorcode);
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index eb27b8f..b217b65 100644 (file)
@@ -147,23 +147,8 @@ gst_xvidenc_class_init (GstXvidEncClass *klass)
 {
   GstElementClass *gstelement_class;
   GObjectClass *gobject_class;
-  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("Failed to initialize XviD: %s (%d)",
-             gst_xvid_error(ret), ret);
-    return;
-  }
-  
-  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);
-  }
+
+  gst_xvid_init();
 
   gobject_class = (GObjectClass *) klass;
   gstelement_class = (GstElementClass *) klass;
index 224487d..02028d8 100644 (file)
@@ -21,6 +21,7 @@
 #define __GST_XVIDENC_H__
 
 #include <gst/gst.h>
+#include "gstxvid.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -75,9 +76,6 @@ GType gst_xvidenc_get_type(void);
 gboolean gst_xvidenc_plugin_init (GModule   *module,
                                   GstPlugin *plugin);
 
-/* in gstxvid.c */
-extern gchar * gst_xvid_error (int errorcode);
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */