Main Page   Modules   Compound List   File List   Compound Members   File Members  

xlv_plugin_mgr.h

Go to the documentation of this file.
00001 /*
00002  * xlv_plugin_mgr.h
00003  *
00004  * Copyright (C) 2001 Guilhem Lavaux
00005  *
00006  * This file is part of XLV, a free middleware audio-video stream coder/decoder.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * XLV is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 
00029 #ifndef _XLV_PLUGIN_MGR_H
00030 #define _XLV_PLUGIN_MGR_H
00031 
00032 #include <glib.h>
00033 
00034 #define xlv_fourcc(a,b,c,d) ( ((guint32)(a)) | ((guint32)(b)) << 8 | ((guint32)(c)) << 16 | ((guint32)(d)) << 24)
00035 
00052 #define XLV_STREAM_OK           0
00053 
00054 #define XLV_STREAM_EOF          1
00055 
00056 #define XLV_STREAM_ERRIO        2
00057 
00058 #define XLV_STREAM_UNSUPPORTED  3
00059 
00060 #define XLV_STREAM_INVAL        4
00061 
00062 #define XLV_STREAM_NOMEM        5
00063 
00071 #define XLV_PLUGIN_NONE           0
00072 
00073 #define XLV_PLUGIN_AUDIO_RENDERER 1
00074 
00075 #define XLV_PLUGIN_VIDEO_RENDERER 2
00076 
00077 #define XLV_PLUGIN_AUDIO_CODEC    3
00078 
00079 #define XLV_PLUGIN_VIDEO_CODEC    4
00080 
00081 #define XLV_PLUGIN_INPUT_STREAM   5
00082 
00083 #define XLV_PLUGIN_SYSTEM         6
00084 
00085 #define XLV_PLUGIN_SYSENC         7
00086 
00087 #define XLV_PLUGIN_GLUE           8
00088 /* @} */
00089 
00095 #define XLV_PLUGIN_GET_CAPS         0
00096 
00102 #define XLV_PLUGIN_GET_OPTIONS_LIST 1
00103 
00109 #define XLV_PLUGIN_GET_OPTION       2
00110 
00116 #define XLV_PLUGIN_SET_OPTION       3
00117 
00120 #define XLV_PLUGIN_OPTION_UINT8       0
00121 
00123 #define XLV_PLUGIN_OPTION_UINT16      1
00124 
00126 #define XLV_PLUGIN_OPTION_UINT32      2
00127 
00129 #define XLV_PLUGIN_OPTION_STRING      3
00130 
00134 #define XLV_PLUGIN_OPTION_CHOOSEONE    4
00135 
00139 #define XLV_PLUGIN_OPTION_CHOOSEMULTI  5
00140 
00144 #define XLV_PLUGIN_OPTION_GROUP       6
00145 
00147 #define XLV_PLUGIN_OPTION_BOOL        7
00148 
00153 typedef struct _XLV_PluginGetOption {
00155     const gchar *m_option_name;
00157     guint8 m_option_type;
00158     guint16 m_option_id;
00159 
00160     /* @brief This is a subtree: it is needed if this option is a container */
00161     struct _XLV_PluginOptionsList *m_option_subtree;
00162 } XLV_PluginGetOption;
00163 
00165 typedef struct _XLV_PluginOption {
00167     guint16 m_option_id;
00169     union {
00170         guint8 u8;
00171         guint16 u16;
00172         guint32 u32;
00173         gchar *string;
00174     } data;
00175 } XLV_PluginOption;
00176 
00178 typedef struct _XLV_PluginOptionsList {
00179     guint16 m_options_len;
00180     XLV_PluginGetOption *m_options;
00181 } XLV_PluginOptionsList;
00182 
00193 #define XLV_STREAM_RESET           10
00194 
00198 #define XLV_STREAM_SEEK            11
00199 
00202 #define XLV_STREAM_SKIP            12
00203 
00206 #define XLV_STREAM_TELL            13
00207 
00209 #define XLV_STREAM_SIZE            14
00210 
00212 #define XLV_STREAM_ENABLE_CACHE    15
00213 
00215 #define XLV_STREAM_DISABLE_CACHE   16
00216 
00223 typedef struct _XLV_Data {
00225     gpointer m_data;
00227     guint32 m_length;
00229     gboolean m_flags;
00230 } XLV_Data;
00231 
00236 #define XLV_DATA_UNKNOWN   0x0000
00237 
00238 #define XLV_DATA_KEY_FRAME 0x0001
00239 
00240 #define XLV_DATA_TIMESTAMP 0x0002
00241 
00242 #define XLV_DATA_NO_DATA   0x0004
00243 
00244 #define XLV_DATA_NULL_DATA 0x0008
00245 
00253 #define XLV_PLUGIN_PREALLOC_CAPABLE 0x01
00254 
00255 #define XLV_PLUGIN_WRITABLE         0x02
00256 
00257 #define XLV_PLUGIN_READABLE         0x04
00258 
00259 #define XLV_PLUGIN_DECODER          0x08
00260 
00261 #define XLV_PLUGIN_ENCODER          0x10
00262 
00263 #define XLV_PLUGIN_CONFIGURABLE     0x20
00264 
00265 #define XLV_PLUGIN_SEEKABLE         0x40
00266 
00267 #define XLV_PLUGIN_CODEC_CONFIG     0x80
00268 
00270 /* Adaptor specific */
00271 #define XLV_ADAPTOR_SET_REQUIRED   500
00272 
00279 #define XLV_READ_ONLY  0
00280 
00281 #define XLV_WRITE_ONLY 1
00282 
00283 #define XLV_RDWR       2
00284 
00291 typedef struct _XLV_GUID {
00292         guint32 m_v1;
00293         guint16 m_v2;
00294         guint16 m_v3;
00295         guint8 m_v4[8];
00296 } XLV_GUID;
00297 
00298 #define XLV_NULL_GUID {0, 0, 0, {0,0,0,0, 0,0,0,0}}
00299 
00303 typedef struct _XLV_Stream XLV_Stream;
00304 
00305 #ifdef XLV_INTERNAL 
00306 
00308 struct _XLV_PluginMgr {
00309     GList *m_plugins;
00310     GList *m_modules;
00311     guint m_last_id;
00312     gboolean m_can_load;
00313     GList *m_paths;
00314     GAllocator *m_allocator;
00315     GHashTable *m_namehash;
00316 };
00317 #endif
00318 
00322 typedef struct _XLV_PluginMgr XLV_PluginMgr;
00323 
00324 /* Plugin structures/descriptions */
00325 
00333 typedef struct _XLV_PluginStream XLV_PluginStream;
00334 
00337 struct _XLV_PluginStream {
00338     guint m_error;
00339     guint8 m_mode;
00340 };
00341 
00344 typedef struct _XLV_Plugin XLV_Plugin;
00345 typedef struct _XLV_Module XLV_Module;
00346 
00347 typedef XLV_PluginStream *(*XLV_OpenPlugin) (XLV_Stream * in_stream,
00348                                              gpointer plugdata);
00349 typedef XLV_PluginStream *(*XLV_OpenStream) (const gchar * name, guint mode,
00350                                              gpointer plugdata);
00351 typedef void (*XLV_ClosePlugin) (XLV_PluginStream * stream);
00352 typedef gint (*XLV_Ioctl) (XLV_PluginStream * stream, guint cmd,
00353                            gpointer param);
00354 typedef guint32 (*XLV_ReadData) (XLV_PluginStream * stream, gpointer data,
00355                                  guint32 len);
00356 typedef guint32 (*XLV_WriteData) (XLV_PluginStream * stream, gpointer data,
00357                                   guint32 len);
00358 typedef void (*XLV_ReleasePlugin) (XLV_Plugin * plug);
00359 
00360 typedef gboolean (*XLV_PluginInitializer) (XLV_PluginMgr * mgr,
00361                                            XLV_Module * module);
00362 
00365 struct _XLV_Plugin {
00366     const gchar *m_name;
00367     const gchar *m_idname;
00368     guint16 m_version;
00369     guint16 m_type;
00370     gpointer m_plugdata;
00371 
00372     XLV_OpenPlugin f_open;
00373     XLV_OpenStream f_openStream;
00374     XLV_ClosePlugin f_close;
00375     XLV_Ioctl f_ioctl;
00376     XLV_ReadData f_readData;
00377     XLV_WriteData f_writeData;
00378     XLV_ReleasePlugin f_release;
00379 
00380     guint16 m_interface_release;
00381 
00382     XLV_GUID m_plugin_guid;
00383 
00384     XLV_PluginMgr *m_manager;
00385     guint16 m_refcounter;
00386 };
00387 
00388 
00391 struct _XLV_Stream {
00392     XLV_Plugin *m_plugin;
00393     XLV_PluginStream *m_stream;
00394 };
00395 
00396 typedef struct _XLV_StreamBuilder {
00397     guint8 m_id;
00398     XLV_Stream *m_stream;
00399 } XLV_StreamBuilder;
00400 
00401 #ifdef XLV_INTERNAL
00402 #include <gmodule.h>
00403 
00404 struct _XLV_Module {
00405     GModule *m_module;
00406     gchar *m_module_name;
00407     gchar *m_module_path;
00408     GList *m_plugins;
00409     XLV_PluginMgr *m_plugin_mgr;
00410     GList *m_depends;
00411 
00412     guint16 m_opened_plugins;
00413     gboolean m_loaded:1;
00414     gboolean m_recall:1;
00415 };
00416 
00417 typedef struct _XLV_PluginInternal {
00418     XLV_Plugin m_plugin_desc;
00419     guint m_id;
00420     XLV_Module *m_module;
00421     GList *m_depends_on;
00422     gboolean m_valid:1;
00423     gboolean m_free_idname:1;
00424     gboolean m_pre_valid:1;
00425     gboolean m_unload_locked:1;
00426 } XLV_PluginInternal;
00427 #endif
00428 
00429 #define XLV_CLOSE(s) ((s)->m_plugin->f_close((s)->m_stream))
00430 #define XLV_IOCTL(s, cmd, len) ( ((s)->m_plugin->f_ioctl != NULL) ? ((s)->m_plugin->f_ioctl((s)->m_stream, cmd, len)) : -1 )
00431 #define XLV_READ(s, b, len)  xlv_read((s), (b), (len))
00432 #define XLV_WRITE(s, b, len) xlv_write((s), (b), (len))
00433 
00434 #define xlv_plugin_add(mgr, plug) xlv_plugin_package_add(mgr, NULL, plug)
00435 
00436 /* Interfaces */
00437 
00438 #ifdef __cplusplus
00439 extern "C" {
00440 #endif
00441 
00444     XLV_PluginMgr *xlv_plugin_mgr_new ();
00447     void xlv_plugin_mgr_cleanup (XLV_PluginMgr * mgr);
00448 
00454     void xlv_plugin_add_path (XLV_PluginMgr * mgr, const gchar * path);
00467     void xlv_plugin_load_all (XLV_PluginMgr * mgr, gboolean with_registered);
00468 
00478     gint xlv_plugin_load (XLV_PluginMgr * mgr, const gchar * name);
00479 
00490     gboolean xlv_plugin_load_registered (XLV_Plugin * plugin);
00491 
00499     void xlv_plugin_invalidate (XLV_Plugin * plugin);
00500 
00510     gboolean xlv_plugin_unregister (XLV_Plugin * plugin);
00511 
00523     gint xlv_plugin_package_add (XLV_PluginMgr * mgr, XLV_Module * module,
00524                                  XLV_Plugin * plugin);
00525 
00528     gint xlv_plugin_add_module (XLV_PluginMgr * mgr, const gchar * module,
00529                                 const gchar * idname, guint32 plugin_type);
00530 
00531 
00539     gboolean xlv_plugin_add_dep (XLV_Plugin * plugin, XLV_Plugin * dep);
00540 
00548     gboolean xlv_plugin_add_named_dep (XLV_Plugin * plugin, const gchar *dep);
00549 
00557     guint xlv_get_number_of_plugins (XLV_PluginMgr * mgr);
00558 
00566     XLV_Plugin *xlv_plugin_get_from_id (XLV_PluginMgr * mgr, guint id);
00567 
00575     XLV_Plugin *xlv_plugin_get_from_idname (XLV_PluginMgr * mgr,
00576                                             const gchar * idname);
00577 
00585     XLV_Plugin *xlv_plugin_get_from_guid (XLV_PluginMgr * mgr, XLV_GUID *guid);
00586 
00593     GList *xlv_plugin_iterate (XLV_PluginMgr * mgr);
00594 
00598     void xlv_plugin_set_unused (XLV_Plugin * plugin);
00599 
00604     gboolean xlv_plugin_is_loaded (XLV_Plugin * plugin);
00605 
00606 
00607 #ifdef __cplusplus
00608 }
00609 #endif
00610 
00632 static inline XLV_Stream *
00633 xlv_open (XLV_Plugin * plug, XLV_Stream * in)
00634 {
00635     XLV_PluginStream *ps;
00636     XLV_Stream *s;
00637 
00638     g_assert (plug != NULL);
00639 
00640     if (!plug->f_open) {
00641         if (!xlv_plugin_load_registered (plug))
00642             return (XLV_Stream *) NULL;
00643         if (!plug->f_open)
00644             return (XLV_Stream *) NULL;
00645     }
00646 
00647     ps = plug->f_open (in, plug->m_plugdata);
00648     if (!ps)
00649         return (XLV_Stream *) NULL;
00650     s = g_new (XLV_Stream, 1);
00651     s->m_plugin = plug;
00652     plug->m_refcounter++;
00653     s->m_stream = ps;
00654     return s;
00655 }
00656 
00657 static inline XLV_Stream *
00658 xlv_open_stream (XLV_Plugin * plug, const gchar * name, guint mode)
00659 {
00660     XLV_PluginStream *ps;
00661     XLV_Stream *s;
00662 
00663     g_assert (plug != NULL);
00664 
00665     if (!plug->f_openStream) {
00666         if (!xlv_plugin_load_registered (plug))
00667             return (XLV_Stream *) NULL;
00668         if (!plug->f_openStream)
00669             return (XLV_Stream *) NULL;
00670     }
00671 
00672     ps = plug->f_openStream (name, mode, plug->m_plugdata);
00673     if (!ps)
00674         return (XLV_Stream *) NULL;
00675     s = g_new (XLV_Stream, 1);
00676     s->m_plugin = plug;
00677     plug->m_refcounter++;
00678     s->m_stream = ps;
00679     return s;
00680 }
00681 
00682 static inline void
00683 xlv_close (XLV_Stream * s)
00684 {
00685     g_assert (s != NULL);
00686     g_assert (s->m_plugin->m_refcounter != 0);
00687 
00688     s->m_plugin->m_refcounter--;
00689 
00690     if (s->m_plugin->f_close)
00691         s->m_plugin->f_close (s->m_stream);
00692 
00693     if (s->m_plugin->m_manager && s->m_plugin->m_refcounter == 0)
00694         xlv_plugin_set_unused (s->m_plugin);
00695 
00696     g_free (s);
00697 }
00698 
00699 static inline guint32
00700 xlv_read (XLV_Stream * s, gpointer data, guint32 len)
00701 {
00702     g_assert (s != NULL);
00703 
00704     if (s->m_plugin->f_readData)
00705         return s->m_plugin->f_readData (s->m_stream, data, len);
00706     else
00707         return 0;
00708 }
00709 
00710 static inline guint32
00711 xlv_write (XLV_Stream * s, gpointer data, guint32 len)
00712 {
00713     g_assert(s != NULL);
00714     
00715     if (s->m_plugin->f_writeData)
00716             return (s->m_plugin->f_writeData(s->m_stream, data, len));
00717     else
00718             return 0;
00719 }
00720 
00721 #endif

Generated on Mon Jul 1 19:39:06 2002 for XLV by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002