call xvid_init() only once, and move duplicated code into one place

Original commit message from CVS:
call xvid_init() only once, and move duplicated code into one place
This commit is contained in:
Ronald S. Bultje 2003-07-29 11:59:09 +00:00
parent 0e115bc639
commit 833a8b579b
7 changed files with 73 additions and 39 deletions

2
common

@ -1 +1 @@
Subproject commit d6e219fd076d8f182bd1ee84228b1b85cdb807a6
Subproject commit 8b323f41bfaccb8f30bddfc6ff8bd6a4be04a3e1

View file

@ -26,6 +26,38 @@
#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)
{

36
ext/xvid/gstxvid.h Normal file
View file

@ -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__ */

View 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);

View 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 */

View 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;

View 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 */