static void gst_real_audio_dec_probe_modules (GstRealAudioDec * dec) { GstRADecLibrary dummy = { NULL }; if ((dec->valid_atrk = open_library (dec, GST_REAL_AUDIO_DEC_VERSION_ATRK, &dummy))) close_library (dec, &dummy); if ((dec->valid_ra14_4 = open_library (dec, GST_REAL_AUDIO_DEC_VERSION_14_4, &dummy))) close_library (dec, &dummy); if ((dec->valid_ra28_8 = open_library (dec, GST_REAL_AUDIO_DEC_VERSION_28_8, &dummy))) close_library (dec, &dummy); #ifdef HAVE_CPU_X86_64 /* disabled because it does not seem to work on 64 bits */ dec->valid_sipr = FALSE; #else if ((dec->valid_sipr = open_library (dec, GST_REAL_AUDIO_DEC_VERSION_SIPR, &dummy))) close_library (dec, &dummy); #endif if ((dec->valid_cook = open_library (dec, GST_REAL_AUDIO_DEC_VERSION_COOK, &dummy))) close_library (dec, &dummy); }
int main (int argc, char *argv[]) { void * lib = NULL; int (*fun) (); struct compiler * compiler; int rc = EXIT_FAILURE; char prog[] = "int foo () { return 42; }"; compiler = compiler_get_gcc (); if (comp_failed == compile_from_string (compiler, prog, libname)) goto out; if (! (lib = load_library (libname))) goto out; fun = (int (*) ()) get_function (lib, funcname); if (!fun) goto out; printf ("function '%s' from '%s' returned '%d'\n", funcname, libname, fun ()); out: if (lib) if (close_library (lib)) rc = EXIT_SUCCESS; return rc; }
void drew_loader_unref(DrewLoader *ldr) { g_return_if_fail(ldr); if (g_atomic_int_dec_and_test(&ldr->ref_count)) { g_rw_lock_clear(&ldr->lock); for (int i = 0; i < ldr->nlibs; i++) { g_free(ldr->lib[i].name); g_free(ldr->lib[i].path); close_library(ldr->lib[i].handle); } g_free(ldr->lib); for (int i = 0; i < ldr->nplugins; i++) { if (!(ldr->plugin[i].flags & FLAG_PLUGIN_OK)) continue; g_free(ldr->plugin[i].name); g_free(ldr->plugin[i].functbl); g_free(ldr->plugin[i].metadata); } g_free(ldr->plugin); g_free(ldr); } return; }
/** * Load a module and create the driver object. */ static EGLBoolean _eglLoadModule(_EGLModule *mod) { _EGLMain_t mainFunc; lib_handle lib; _EGLDriver *drv; mainFunc = _eglOpenLibrary(mod->Path, &lib); if (!mainFunc) return EGL_FALSE; drv = mainFunc(NULL); if (!drv) { if (lib) close_library(lib); return EGL_FALSE; } if (!drv->Name) { _eglLog(_EGL_WARNING, "Driver loaded from %s has no name", mod->Path); drv->Name = "UNNAMED"; } mod->Handle = (void *) lib; mod->Driver = drv; return EGL_TRUE; }
static GstStateChangeReturn gst_real_audio_dec_change_state (GstElement * element, GstStateChange transition) { GstStateChangeReturn ret; GstRealAudioDec *dec = GST_REAL_AUDIO_DEC (element); switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: gst_real_audio_dec_probe_modules (dec); dec->checked_modules = TRUE; break; default: break; } ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); switch (transition) { case GST_STATE_CHANGE_PAUSED_TO_READY: close_library (dec, &dec->lib); break; case GST_STATE_CHANGE_READY_TO_NULL: dec->checked_modules = FALSE; break; default: break; } return ret; }
/** * Load the named driver. The path and args passed will be * owned by the driver and freed. */ static _EGLDriver * _eglLoadDriver(char *path, char *args) { _EGLMain_t mainFunc; lib_handle lib; _EGLDriver *drv = NULL; mainFunc = _eglOpenLibrary(path, &lib); if (!mainFunc) return NULL; drv = mainFunc(args); if (!drv) { if (lib) close_library(lib); return NULL; } if (!drv->Name) { _eglLog(_EGL_WARNING, "Driver loaded from %s has no name", path); drv->Name = "UNNAMED"; } drv->Path = path; drv->Args = args; drv->LibHandle = lib; return drv; }
static void gst_real_audio_dec_finalize (GObject * object) { GstRealAudioDec *dec = GST_REAL_AUDIO_DEC (object); close_library (dec, &dec->lib); if (dec->real_codecs_path) { g_free (dec->real_codecs_path); dec->real_codecs_path = NULL; } if (dec->racook_names) { g_free (dec->racook_names); dec->racook_names = NULL; } if (dec->raatrk_names) { g_free (dec->raatrk_names); dec->raatrk_names = NULL; } if (dec->ra14_4_names) { g_free (dec->ra14_4_names); dec->ra14_4_names = NULL; } if (dec->ra28_8_names) { g_free (dec->ra28_8_names); dec->ra28_8_names = NULL; } if (dec->rasipr_names) { g_free (dec->rasipr_names); dec->rasipr_names = NULL; } G_OBJECT_CLASS (parent_class)->finalize (object); }
/** * Try to determine which EGL APIs (OpenGL, OpenGL ES, OpenVG, etc) * are supported on the system by looking for standard library names. */ EGLint _eglFindAPIs(void) { EGLint mask = 0x0; lib_handle lib; #if defined(_EGL_PLATFORM_WINDOWS) /* XXX not sure about these names */ const char *es1_libname = "libGLESv1_CM.dll"; const char *es2_libname = "libGLESv2.dll"; const char *gl_libname = "OpenGL32.dll"; const char *vg_libname = "libOpenVG.dll"; #elif defined(_EGL_PLATFORM_X) const char *es1_libname = "libGLESv1_CM.so"; const char *es2_libname = "libGLESv2.so"; const char *gl_libname = "libGL.so"; const char *vg_libname = "libOpenVG.so"; #else /* _EGL_PLATFORM_NO_OS */ const char *es1_libname = NULL; const char *es2_libname = NULL; const char *gl_libname = NULL; const char *vg_libname = NULL; #endif if ((lib = open_library(es1_libname))) { close_library(lib); mask |= EGL_OPENGL_ES_BIT; } if ((lib = open_library(es2_libname))) { close_library(lib); mask |= EGL_OPENGL_ES2_BIT; } if ((lib = open_library(gl_libname))) { close_library(lib); mask |= EGL_OPENGL_BIT; } if ((lib = open_library(vg_libname))) { close_library(lib); mask |= EGL_OPENVG_BIT; } return mask; }
static void lib_dlb_cleanup(void) { int i; /* close the data file(s) */ for (i = 0; i < MAX_LIBS && dlb_libs[i].fdata; i++) close_library(&dlb_libs[i]); }
/** * Open the named driver and find its bootstrap function: _eglMain(). */ static _EGLMain_t _eglOpenLibrary(const char *driverPath, lib_handle *handle) { lib_handle lib; _EGLMain_t mainFunc = NULL; const char *error = "unknown error"; assert(driverPath); _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath); lib = open_library(driverPath); #if defined(_EGL_OS_WINDOWS) /* XXX untested */ if (lib) mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain"); #elif defined(_EGL_OS_UNIX) if (lib) { union { _EGLMain_t func; void *ptr; } tmp = { NULL }; /* direct cast gives a warning when compiled with -pedantic */ tmp.ptr = dlsym(lib, "_eglMain"); mainFunc = tmp.func; if (!mainFunc) error = dlerror(); } else { error = dlerror(); } #endif if (!lib) { _eglLog(_EGL_WARNING, "Could not open driver %s (%s)", driverPath, error); if (!getenv("EGL_DRIVER")) _eglLog(_EGL_WARNING, "The driver can be overridden by setting EGL_DRIVER"); return NULL; } if (!mainFunc) { _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)", driverPath, error); if (lib) close_library(lib); return NULL; } *handle = lib; return mainFunc; }
/** * Unload a module. */ static void _eglUnloadModule(_EGLModule *mod) { /* destroy the driver */ if (mod->Driver && mod->Driver->Unload) mod->Driver->Unload(mod->Driver); if (mod->Handle) close_library(mod->Handle); mod->Driver = NULL; mod->Handle = NULL; }
/** * Open the named driver and find its bootstrap function: _eglMain(). */ static _EGLMain_t _eglOpenLibrary(const char *driverPath, lib_handle *handle) { lib_handle lib; _EGLMain_t mainFunc = NULL; const char *error = "unknown error"; assert(driverPath); _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath); lib = open_library(driverPath); #if defined(_EGL_PLATFORM_WINDOWS) /* XXX untested */ if (lib) mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain"); #elif defined(_EGL_PLATFORM_X) if (lib) { mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain"); if (!mainFunc) error = dlerror(); } else { error = dlerror(); } #else /* _EGL_PLATFORM_NO_OS */ /* must be the default driver name */ if (strcmp(driverPath, DefaultDriverName) == 0) mainFunc = (_EGLMain_t) _eglMain; else error = "not builtin driver"; #endif if (!lib) { _eglLog(_EGL_WARNING, "Could not open driver %s (%s)", driverPath, error); if (!getenv("EGL_DRIVER")) _eglLog(_EGL_WARNING, "The driver can be overridden by setting EGL_DRIVER"); return NULL; } if (!mainFunc) { _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)", driverPath, error); if (lib) close_library(lib); return NULL; } *handle = lib; return mainFunc; }
/* Allocate a library table entry and load the library information from it. If * library is NULL, try to load the current executable instead. */ static int load_library(DrewLoader *ldr, const char *library, const char *path, library_t **libp) { int err = 0; library_t *p, *lib; p = g_realloc(ldr->lib, sizeof(*p) * (ldr->nlibs + 1)); if (!p) return -ENOMEM; if (p != ldr->lib) { // Fix up the lib pointers in the plugins. for (int i = 0; i < ldr->nplugins; i++) ldr->plugin[i].lib = p + (ldr->plugin[i].lib - ldr->lib); } ldr->lib = p; lib = &ldr->lib[ldr->nlibs]; memset(lib, 0, sizeof(*lib)); ldr->nlibs++; if (!library) { err = -DREW_ERR_RESOLUTION; if (!(lib->handle = open_library(NULL))) goto out; lib->name = g_strdup("<internal>"); lib->path = NULL; } else { err = -ENOMEM; if (!(lib->path = g_strdup_printf("%s/%s", path, library))) goto out; // TODO: query this from the library. lib->name = g_strdup(library); err = -DREW_ERR_RESOLUTION; if (!(lib->handle = open_library(lib->path))) goto out; } err = -DREW_ERR_ENUMERATION; if (!(lib->api = get_api(lib->handle))) goto out; err = 0; *libp = lib; out: if (err) { if (lib->handle) close_library(lib->handle); g_free(lib->name); g_free(lib->path); lib->path = NULL; ldr->nlibs--; } return err; }
/* * Open the library file once using stdio. Keep it open, but * keep track of the file position. */ static boolean lib_dlb_init(void) { /* zero out array */ memset((char *)&dlb_libs[0], 0, sizeof (dlb_libs)); /* To open more than one library, add open library calls here. */ if (!open_library(DLBFILE, &dlb_libs[0])) return FALSE; #ifdef DLBFILE2 if (!open_library(DLBFILE2, &dlb_libs[1])) { close_library(&dlb_libs[0]); return FALSE; } #endif return TRUE; }
int main (int argc, char *argv[]) { int arg_index = 1; if (argc < 2) usage (); while (arg_index < argc) { char *arg = argv[arg_index++]; if (strcasecmp (arg, "--prefix") == 0) prefix = argv[arg_index++]; else dump_library (arg); } close_library (); return (0); }
/** * Unload a module. */ static void _eglUnloadModule(_EGLModule *mod) { #if defined(_EGL_OS_UNIX) /* destroy the driver */ if (mod->Driver && mod->Driver->Unload) mod->Driver->Unload(mod->Driver); /* * XXX At this point (atexit), the module might be the last reference to * libEGL. Closing the module might unmap libEGL and give problems. */ #if 0 if (mod->Handle) close_library(mod->Handle); #endif #elif defined(_EGL_OS_WINDOWS) /* XXX Windows unloads DLLs before atexit */ #endif mod->Driver = NULL; mod->Handle = NULL; }
/** * Unload preloaded drivers. */ void _eglUnloadDrivers(void) { EGLint i; for (i = 0; i < _eglGlobal.NumDrivers; i++) { _EGLDriver *drv = _eglGlobal.Drivers[i]; lib_handle handle = drv->LibHandle; if (drv->Path) free((char *) drv->Path); if (drv->Args) free((char *) drv->Args); /* destroy driver */ if (drv->Unload) drv->Unload(drv); if (handle) close_library(handle); _eglGlobal.Drivers[i] = NULL; } _eglGlobal.NumDrivers = 0; }
static gboolean gst_real_audio_dec_setcaps (GstPad * pad, GstCaps * caps) { GstRealAudioDec *dec = GST_REAL_AUDIO_DEC (GST_PAD_PARENT (pad)); GstStructure *s = gst_caps_get_structure (caps, 0); gint version, flavor, channels, rate, leaf_size, packet_size, width, height; guint16 res = 0; RAInit data; gboolean bres; const GValue *v; GstBuffer *buf = NULL; const gchar *name = gst_structure_get_name (s); if (!strcmp (name, "audio/x-sipro")) { version = GST_REAL_AUDIO_DEC_VERSION_SIPR; } else { if (!gst_structure_get_int (s, "raversion", &version)) goto missing_keys; } if (!gst_structure_get_int (s, "flavor", &flavor) || !gst_structure_get_int (s, "channels", &channels) || !gst_structure_get_int (s, "width", &width) || !gst_structure_get_int (s, "rate", &rate) || !gst_structure_get_int (s, "height", &height) || !gst_structure_get_int (s, "leaf_size", &leaf_size) || !gst_structure_get_int (s, "packet_size", &packet_size)) goto missing_keys; if ((v = gst_structure_get_value (s, "codec_data"))) buf = g_value_peek_pointer (v); GST_LOG_OBJECT (dec, "opening code for version %d", version); /* first close existing decoder */ close_library (dec, &dec->lib); if (!open_library (dec, version, &dec->lib)) goto could_not_open; /* we have the module, no initialize with the caps data */ data.samplerate = rate; data.width = width; data.channels = channels; data.quality = 100; data.leaf_size = leaf_size; data.packet_size = packet_size; data.datalen = buf ? GST_BUFFER_SIZE (buf) : 0; data.data = buf ? GST_BUFFER_DATA (buf) : NULL; if ((res = dec->lib.RAInitDecoder (dec->lib.context, &data))) { GST_WARNING_OBJECT (dec, "RAInitDecoder() failed"); goto could_not_initialize; } if (dec->lib.RASetPwd) { dec->lib.RASetPwd (dec->lib.context, dec->pwd ? dec->pwd : DEFAULT_PWD); } if ((res = dec->lib.RASetFlavor (dec->lib.context, flavor))) { GST_WARNING_OBJECT (dec, "RASetFlavor(%d) failed", flavor); goto could_not_initialize; } caps = gst_caps_new_simple ("audio/x-raw-int", "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, width, "depth", G_TYPE_INT, width, "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, "signed", G_TYPE_BOOLEAN, TRUE, NULL); bres = gst_pad_set_caps (GST_PAD (dec->src), caps); gst_caps_unref (caps); if (!bres) goto could_not_set_caps; dec->width = width; dec->height = height; dec->leaf_size = leaf_size; GST_LOG_OBJECT (dec, "opened module"); return TRUE; missing_keys: { GST_DEBUG_OBJECT (dec, "Could not find all necessary keys in structure."); return FALSE; } could_not_open: { GST_DEBUG_OBJECT (dec, "Could not find decoder"); return FALSE; } could_not_initialize: { close_library (dec, &dec->lib); GST_WARNING_OBJECT (dec, "Initialization of REAL driver failed (%i).", res); return FALSE; } could_not_set_caps: { /* should normally not fail */ close_library (dec, &dec->lib); GST_DEBUG_OBJECT (dec, "Could not convince peer to accept caps."); return FALSE; } }
static void mdlTerminate(SimStruct *S) { tCamera* Camera; unsigned int i; if( ssGetSimMode(S) != SS_SIMMODE_NORMAL ) { return; } /* Retrieve and destroy C object */ Camera = (tCamera*)ssGetPWork(S)[0]; num_instances--; if( Camera ) { if( Camera->Handle ) # ifdef LOAD_PVLIB_AT_RUNTIME if( PvLib ) # endif { ss_PvCommandRun(Camera->Handle,"AcquisitionStop"); ss_PvCaptureEnd(Camera->Handle); ss_PvCaptureQueueClear(Camera->Handle); ss_PvCameraClose(Camera->Handle); } if( num_instances == 0 ) { # if defined(_WIN32) || defined(_WIN64) || defined(__LCC__) if( Camera->csec_init ) DeleteCriticalSection( &(Camera->csec) ); if( Camera->event ) CloseHandle( Camera->event ); # else if( Camera->mutex_init ) pthread_mutex_destroy( &(Camera->mutex) ); if( Camera->cond_init ) pthread_cond_destroy( &(Camera->cond) ); # endif } if( Camera->Frames ) { for( i=0; i<Camera->frames_count; i++ ) { if( Camera->Frames[i].ImageBuffer ) free(Camera->Frames[i].ImageBuffer); } free(Camera->Frames); } if( Camera->frames_queue ) free(Camera->frames_queue); free(Camera); ssGetPWork(S)[0] = NULL; } if( num_instances == 0 ) { # ifdef LOAD_PVLIB_AT_RUNTIME if( PvLib ) { ss_PvUnInitialize(); close_library(PvLib); PvLib = NULL; } # else ss_PvUnInitialize(); # endif # if defined(_WIN32) || defined(_WIN64) || defined(__LCC__) WSACleanup(); # endif } }
static gboolean open_library (GstRealAudioDec * dec, gint version, GstRADecLibrary * lib) { const gchar *path, *names; gchar **split_names, **split_path; gint i, j; gpointer ra_close_codec, ra_decode, ra_free_decoder; gpointer ra_open_codec2, ra_init_decoder, ra_set_flavor; gpointer set_dll_access_path = NULL, ra_set_pwd = NULL; gchar *tmppath = NULL; guint16 res = 0; path = dec->real_codecs_path ? dec->real_codecs_path : DEFAULT_REAL_CODECS_PATH; switch (version) { case GST_REAL_AUDIO_DEC_VERSION_COOK: names = dec->racook_names ? dec->racook_names : DEFAULT_RACOOK_NAMES; break; case GST_REAL_AUDIO_DEC_VERSION_ATRK: names = dec->raatrk_names ? dec->raatrk_names : DEFAULT_RAATRK_NAMES; break; case GST_REAL_AUDIO_DEC_VERSION_14_4: names = dec->ra14_4_names ? dec->ra14_4_names : DEFAULT_RA14_4_NAMES; break; case GST_REAL_AUDIO_DEC_VERSION_28_8: names = dec->ra28_8_names ? dec->ra28_8_names : DEFAULT_RA28_8_NAMES; break; case GST_REAL_AUDIO_DEC_VERSION_SIPR: names = dec->rasipr_names ? dec->rasipr_names : DEFAULT_RASIPR_NAMES; break; default: goto unknown_version; } GST_LOG_OBJECT (dec, "splitting paths %s, names %s", path, names); split_path = g_strsplit (path, ":", 0); split_names = g_strsplit (names, ":", 0); for (i = 0; split_path[i]; i++) { for (j = 0; split_names[j]; j++) { gchar *codec = g_strconcat (split_path[i], "/", split_names[j], NULL); GST_LOG_OBJECT (dec, "opening module %s", codec); /* This is racy, but it doesn't matter here; would be nice if GModule * gave us a GError instead of an error string, but it doesn't, so.. */ if (g_file_test (codec, G_FILE_TEST_EXISTS)) { lib->module = g_module_open (codec, G_MODULE_BIND_LAZY); if (lib->module == NULL) { GST_ERROR_OBJECT (dec, "Could not open codec library '%s': %s", codec, g_module_error ()); } } else { GST_DEBUG_OBJECT (dec, "%s does not exist", codec); } g_free (codec); if (lib->module) goto codec_search_done; } } codec_search_done: /* we keep the path for a while to set the dll access path */ g_strfreev (split_names); if (lib->module == NULL) goto could_not_open; GST_LOG_OBJECT (dec, "finding symbols"); if (!g_module_symbol (lib->module, "RACloseCodec", &ra_close_codec) || !g_module_symbol (lib->module, "RADecode", &ra_decode) || !g_module_symbol (lib->module, "RAFreeDecoder", &ra_free_decoder) || !g_module_symbol (lib->module, "RAOpenCodec2", &ra_open_codec2) || !g_module_symbol (lib->module, "RAInitDecoder", &ra_init_decoder) || !g_module_symbol (lib->module, "RASetFlavor", &ra_set_flavor)) { goto could_not_load; } g_module_symbol (lib->module, "RASetPwd", &ra_set_pwd); g_module_symbol (lib->module, "SetDLLAccessPath", &set_dll_access_path); lib->RACloseCodec = (guint16 (*)(gpointer)) ra_close_codec; lib->RADecode = (guint16 (*)(gpointer, guint8 *, guint32, guint8 *, guint32 *, guint32)) ra_decode; lib->RAFreeDecoder = (guint16 (*)(gpointer)) ra_free_decoder; lib->RAOpenCodec2 = (guint16 (*)(gpointer, const gchar *)) ra_open_codec2; lib->RAInitDecoder = (guint16 (*)(gpointer, gpointer)) ra_init_decoder; lib->RASetFlavor = (guint16 (*)(gpointer, guint16)) ra_set_flavor; lib->RASetPwd = (void (*)(gpointer, const gchar *)) ra_set_pwd; lib->SetDLLAccessPath = (void (*)(gchar *)) set_dll_access_path; if (lib->SetDLLAccessPath) lib->SetDLLAccessPath (split_path[i]); tmppath = g_strdup_printf ("%s/", split_path[i]); if ((res = lib->RAOpenCodec2 (&lib->context, tmppath))) { g_free (tmppath); goto could_not_initialize; } g_free (tmppath); /* now we are done with the split paths, so free them */ g_strfreev (split_path); return TRUE; /* ERRORS */ unknown_version: { GST_DEBUG_OBJECT (dec, "Cannot handle version %i.", version); return FALSE; } could_not_open: { g_strfreev (split_path); GST_DEBUG_OBJECT (dec, "Could not find library '%s' in '%s'", names, path); return FALSE; } could_not_load: { g_strfreev (split_path); close_library (dec, lib); GST_DEBUG_OBJECT (dec, "Could not load all symbols: %s", g_module_error ()); return FALSE; } could_not_initialize: { close_library (dec, lib); GST_WARNING_OBJECT (dec, "Initialization of REAL driver failed (%i).", res); return FALSE; } }
static gboolean gst_real_video_dec_setcaps (GstPad * pad, GstCaps * caps) { GstRealVideoDec *dec = GST_REAL_VIDEO_DEC (GST_PAD_PARENT (pad)); GstStructure *s = gst_caps_get_structure (caps, 0); gint version, res, width, height, format, subformat; gint framerate_num, framerate_denom; gchar data[36]; gboolean bres; const GValue *v; if (!gst_structure_get_int (s, "rmversion", &version) || !gst_structure_get_int (s, "width", (gint *) & width) || !gst_structure_get_int (s, "height", (gint *) & height) || !gst_structure_get_int (s, "format", &format) || !gst_structure_get_int (s, "subformat", &subformat) || !gst_structure_get_fraction (s, "framerate", &framerate_num, &framerate_denom)) goto missing_keys; GST_LOG_OBJECT (dec, "Setting version to %d", version); close_library (dec, &dec->lib); if (!open_library (dec, version, &dec->lib)) goto open_failed; /* Initialize REAL driver. */ GST_WRITE_UINT16_LE (data + 0, 11); GST_WRITE_UINT16_LE (data + 2, width); GST_WRITE_UINT16_LE (data + 4, height); GST_WRITE_UINT16_LE (data + 6, 0); GST_WRITE_UINT32_LE (data + 8, 0); GST_WRITE_UINT32_LE (data + 12, subformat); GST_WRITE_UINT32_LE (data + 16, 1); GST_WRITE_UINT32_LE (data + 20, format); if ((res = dec->lib.Init (&data, &dec->lib.context))) goto could_not_initialize; if ((v = gst_structure_get_value (s, "codec_data"))) { GstBuffer *buf; guint32 *msgdata; guint i; guint8 *bufdata; guint bufsize; struct { guint32 type; guint32 msg; gpointer data; guint32 extra[6]; } msg; buf = g_value_peek_pointer (v); bufdata = GST_BUFFER_DATA (buf); bufsize = GST_BUFFER_SIZE (buf); /* skip format and subformat */ bufdata += 8; bufsize -= 8; GST_LOG_OBJECT (dec, "Creating custom message of length %d", bufsize); msgdata = g_new0 (guint32, bufsize + 2); if (!msgdata) goto could_not_allocate; msg.type = 0x24; msg.msg = 1 + ((subformat >> 16) & 7); msg.data = msgdata; for (i = 0; i < 6; i++) msg.extra[i] = 0; msgdata[0] = width; msgdata[1] = height; for (i = 0; i < bufsize; i++) msgdata[i + 2] = 4 * (guint32) bufdata[i]; res = dec->lib.Message (&msg, dec->lib.context); g_free (msgdata); if (res) goto could_not_send_message; }
int main(int argc, char *argv[]) { int i, r; int ap=2; /* argument pointer */ int cp; /* command pointer */ int iseen=0, fseen=0, verbose=0; /* flags */ char action=' '; library lib; if (argc > 0 && argv[0] && *argv[0]) progname = argv[0]; if (argc<2) { usage(); /* doesn't return */ } for (cp=0; argv[1][cp]; cp++){ switch(argv[1][cp]){ default: usage(); /* doesn't return */ case '-': /* silently ignore */ break; case '?': case 'h': verbose_help(); break; case 'I': if (ap == argc) usage(); list_file=argv[ap++]; if (iseen) printf("Warning: multiple I options. Previous ignored.\n"); iseen=1; break; case 'f': if (ap == argc) usage(); library_file=argv[ap++]; if (fseen) printf("Warning: multiple f options. Previous ignored.\n"); fseen=1; break; case 'C': if (ap == argc) usage(); if (chdir(argv[ap++])){ printf("Can't chdir to %s\n",argv[--ap]); xexit(EXIT_FAILURE); } break; case 'v': verbose=1; break; case 't': case 'c': case 'x': if (action != ' '){ printf("Only one of t,x,c may be specified.\n"); usage(); } action=argv[1][cp]; break; } } if (argv[ap] && iseen){ printf("Too many arguments.\n"); xexit(EXIT_FAILURE); } switch(action){ default: printf("Internal error - action.\n"); xexit(EXIT_FAILURE); break; case 't': /* list archive */ if (!open_library(library_file, &lib)) { printf("Can't open dlb file\n"); xexit(EXIT_FAILURE); } for (i = 0; i < lib.nentries; i++) { if (verbose) printf("%-14s %6ld %6ld\n", lib.dir[i].fname, lib.dir[i].foffset, lib.dir[i].fsize); else printf("%s\n", lib.dir[i].fname); } if (verbose) printf("Revision:%ld File count:%ld String size:%ld\n", lib.rev, lib.nentries, lib.strsize); close_library(&lib); xexit(EXIT_SUCCESS); case 'x': { /* extract archive contents */ int f, n; long remainder, total_read; char buf[BUFSIZ]; if (!open_library(library_file, &lib)) { printf("Can't open dlb file\n"); xexit(EXIT_FAILURE); } for (i = 0; i < lib.nentries; i++) { if (argv[ap]) { /* if files are listed, see if current is wanted */ int c; for (c = ap; c < argc; c++) if (!FILENAME_CMP(lib.dir[i].fname, argv[c])) break; if (c == argc) continue; /* skip */ } else if (!FILENAME_CMP(lib.dir[i].fname, DLB_DIRECTORY)) { /* * Don't extract the directory unless the user * specifically asks for it. * * Perhaps we should never extract the directory??? */ continue; } fseek(lib.fdata, lib.dir[i].foffset, SEEK_SET); f = open(lib.dir[i].fname, O_WRONLY|O_TRUNC|O_BINARY|O_CREAT, 0640); if (f < 0) { printf("Can't create '%s'\n", lib.dir[i].fname); xexit(EXIT_FAILURE); } /* read chunks from library and write them out */ total_read = 0; do { remainder = lib.dir[i].fsize - total_read; if (remainder > (long) sizeof(buf)) r = (int) sizeof(buf); else r = remainder; n = fread(buf, 1, r, lib.fdata); if (n != r) { printf("Read Error in '%s'\n", lib.dir[i].fname); xexit(EXIT_FAILURE); } if (write(f, buf, n) != n) { printf("Write Error in '%s'\n", lib.dir[i].fname); xexit(EXIT_FAILURE); } total_read += n; } while (total_read != lib.dir[i].fsize); close(f); if (verbose) printf("x %s\n", lib.dir[i].fname); } close_library(&lib); xexit(EXIT_SUCCESS); } case 'c': /* create archive */ { libdir ld[MAX_DLB_FILES]; char buf[BUFSIZ]; int fd, out, nfiles = 0; long dir_size, slen, flen, fsiz; boolean rewrite_directory = FALSE; /* * Get names from either/both an argv list and a file * list. This does not do any duplicate checking */ /* get file name in argv list */ if (argv[ap]) { for ( ; ap < argc; ap++, nfiles++) { if (nfiles >= MAX_DLB_FILES) { printf("Too many dlb files! Stopping at %d.\n", MAX_DLB_FILES); xexit(EXIT_FAILURE); } ld[nfiles].fname = malloc(strlen(argv[ap]) + 1); strcpy(ld[nfiles].fname, argv[ap]); } } if (iseen) { /* want to do a list file */ FILE *list = fopen(list_file, "r"); if (!list) { printf("Can't open %s\n",list_file); xexit(EXIT_FAILURE); } /* get file names, one per line */ for ( ; fgets(buf, sizeof(buf), list); nfiles++) { if (nfiles >= MAX_DLB_FILES) { printf("Too many dlb files! Stopping at %d.\n", MAX_DLB_FILES); xexit(EXIT_FAILURE); } *(eos(buf)-1) = '\0'; /* strip newline */ ld[nfiles].fname = malloc(strlen(buf) + 1); strcpy(ld[nfiles].fname, buf); } fclose(list); } if (nfiles == 0) { printf("No files to archive\n"); xexit(EXIT_FAILURE); } /* * Get file sizes and name string length. Don't include * the directory information yet. */ for (i = 0, slen = 0, flen = 0; i < nfiles; i++) { fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0); if (fd < 0) { printf("Can't open %s\n", ld[i].fname); xexit(EXIT_FAILURE); } ld[i].fsize = lseek(fd, 0, SEEK_END); ld[i].foffset = flen; slen += strlen(ld[i].fname); /* don't add null (yet) */ flen += ld[i].fsize; close(fd); } /* open output file */ out = open(library_file, O_RDWR|O_TRUNC|O_BINARY|O_CREAT, FCMASK); if (out < 0) { printf("Can't open %s for output\n", library_file); xexit(EXIT_FAILURE); } /* caculate directory size */ dir_size = 40 /* header line (see below) */ + ((nfiles+1)*11) /* handling+file offset+SP+newline */ + slen+strlen(DLB_DIRECTORY); /* file names */ /* write directory */ write_dlb_directory(out, nfiles, ld, slen, dir_size, flen); flen = 0L; /* write each file */ for (i = 0; i < nfiles; i++) { fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0); if (fd < 0) { printf("Can't open input file '%s'\n", ld[i].fname); xexit(EXIT_FAILURE); } if (verbose) printf("%s\n",ld[i].fname); fsiz = 0L; while ((r = read(fd, buf, sizeof buf)) != 0) { if (r == -1) { printf("Read Error in '%s'\n", ld[i].fname); xexit(EXIT_FAILURE); } if (write(out, buf, r) != r) { printf("Write Error in '%s'\n", ld[i].fname); xexit(EXIT_FAILURE); } fsiz += r; } close(fd); if (fsiz != ld[i].fsize) rewrite_directory = TRUE; /* in case directory rewrite is needed */ ld[i].fsize = fsiz; ld[i].foffset = flen; flen += fsiz; } if (rewrite_directory) { if (verbose) printf("(rewriting dlb directory info)\n"); lseek(out, 0, SEEK_SET); /* rewind */ write_dlb_directory(out, nfiles, ld, slen, dir_size, flen); } for (i = 0; i < nfiles; i++) free(ld[i].fname), ld[i].fname = 0; close(out); xexit(EXIT_SUCCESS); } } xexit(EXIT_SUCCESS); /*NOTREACHED*/ return 0; }