[MPlayer-dev-eng] Fwd: [xine-devel] libreal amd64 patch [goetz.waschk at gmail.com]

Roberto Togni r_togni at tiscali.it
Thu Nov 25 20:22:28 CET 2004


Hi

Can somebody with AMD64 have a look at this?
xine real lib loader shoul be the same as MPlayer.

Ciao,
 Roberto



On 2004.11.25 16:02, Götz Waschk wrote:
Hi,

this patch is from MandrakeSoft's AMD64 port maintainer, I'm just the
xine-lib packager. It improves  the usage of real binary codecs on
AMD64. Please take a look at this.

CU, Götz
--
What difference does it make to the dead, the orphans and the
homeless, whether the mad destruction is wrought under the name of
totalitarianism or the holy name of liberty or democracy?
    Mahatma Gandhi (1869 - 1948), "Non-Violence in Peace and War"


--- xine-lib-1-rc5/src/libreal/audio_decoder.c.lib64-real-codecs	 
2004-04-26
13:50:07.000000000 -0400
+++ xine-lib-1-rc5/src/libreal/audio_decoder.c	2004-11-02
12:14:19.930894395 -0500
@@ -32,6 +32,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <dlfcn.h>
+#include <elf.h>

 #define LOG_MODULE "real_audio_decoder"
 #define LOG_VERBOSE
@@ -118,6 +119,49 @@ void __builtin_delete (void *foo) {
   free (foo);
 }

+#ifdef __x86_64__
+/* (gb) quick-n-dirty check to be run natively */
+static int is_x86_64_object_(FILE *f)
+{
+  Elf64_Ehdr *hdr = malloc(sizeof(Elf64_Ehdr));
+  if (hdr == NULL)
+	return 0;
+
+  if (fseek(f, 0, SEEK_SET) != 0) {
+	free(hdr);
+	return 0;
+  }
+
+  if (fread(hdr, sizeof(Elf64_Ehdr), 1, f) != 1) {
+	free(hdr);
+	return 0;
+  }
+
+  if (hdr->e_ident[EI_MAG0] != ELFMAG0 ||
+	  hdr->e_ident[EI_MAG1] != ELFMAG1 ||
+	  hdr->e_ident[EI_MAG2] != ELFMAG2 ||
+	  hdr->e_ident[EI_MAG3] != ELFMAG3) {
+	free(hdr);
+	return 0;
+  }
+
+  return hdr->e_machine == EM_X86_64;
+}
+
+static inline int is_x86_64_object(const char *filename)
+{
+  FILE *f;
+  int ret;
+
+  if ((f = fopen(filename, "r")) == NULL)
+	return 0;
+
+  ret = is_x86_64_object_(f);
+  fclose(f);
+  return ret;
+}
+#endif
+
 static int load_syms_linux (realdec_decoder_t *this, char *codec_name)
{

   cfg_entry_t* entry = this->stream->xine->config->lookup_entry(
@@ -126,6 +170,12 @@ static int load_syms_linux (realdec_deco

   sprintf (path, "%s/%s", entry->str_value, codec_name);

+#ifdef __x86_64__
+  /* check whether it's a real x86-64 library */
+  if (!is_x86_64_object(path))
+	return 0;
+#endif
+
   lprintf ("(audio) opening shared obj '%s'\n", path);

   this->ra_handle = dlopen (path, RTLD_LAZY);
@@ -687,6 +737,12 @@ static void *init_class (xine_t *xine, v
     if (!stat ("/usr/lib/RealPlayer9/users/Real/Codecs/drv3.so.6.0",
&s))
       config->update_string (config, "codec.real_codecs_path",
 			     "/usr/lib/RealPlayer9/users/Real/Codecs");
+    if (!stat ("/usr/lib64/RealPlayer8/Codecs/drv3.so.6.0", &s))
+      config->update_string (config, "codec.real_codecs_path",
+			     "/usr/lib64/RealPlayer8/Codecs");
+    if (!stat ("/usr/lib64/RealPlayer9/users/Real/Codecs/drv3.so.6.0",
&s))
+      config->update_string (config, "codec.real_codecs_path",
+			     "/usr/lib64/RealPlayer9/users/Real/ 
Codecs");
     if (!stat ("/usr/lib/win32/drv3.so.6.0", &s))
       config->update_string (config, "codec.real_codecs_path",
 			     "/usr/lib/win32");
--- xine-lib-1-rc5/src/libreal/xine_decoder.c.lib64-real-codecs	 
2004-05-23
12:12:04.000000000 -0400
+++ xine-lib-1-rc5/src/libreal/xine_decoder.c	2004-11-02
12:14:12.587413056 -0500
@@ -32,6 +32,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <dlfcn.h>
+#include <elf.h>

 #define LOG_MODULE "real_decoder"
 #define LOG_VERBOSE
@@ -103,6 +104,49 @@ void *__builtin_vec_new(uint32_t size);
 void __builtin_vec_delete(void *mem);
 void __pure_virtual(void);

+#ifdef __x86_64__
+/* (gb) quick-n-dirty check to be run natively */
+static int is_x86_64_object_(FILE *f)
+{
+  Elf64_Ehdr *hdr = malloc(sizeof(Elf64_Ehdr));
+  if (hdr == NULL)
+	return 0;
+
+  if (fseek(f, 0, SEEK_SET) != 0) {
+	free(hdr);
+	return 0;
+  }
+
+  if (fread(hdr, sizeof(Elf64_Ehdr), 1, f) != 1) {
+	free(hdr);
+	return 0;
+  }
+
+  if (hdr->e_ident[EI_MAG0] != ELFMAG0 ||
+	  hdr->e_ident[EI_MAG1] != ELFMAG1 ||
+	  hdr->e_ident[EI_MAG2] != ELFMAG2 ||
+	  hdr->e_ident[EI_MAG3] != ELFMAG3) {
+	free(hdr);
+	return 0;
+  }
+
+  return hdr->e_machine == EM_X86_64;
+}
+
+static inline int is_x86_64_object(const char *filename)
+{
+  FILE *f;
+  int ret;
+
+  if ((f = fopen(filename, "r")) == NULL)
+	return 0;
+
+  ret = is_x86_64_object_(f);
+  fclose(f);
+  return ret;
+}
+#endif
+
 /*
  * real codec loader
  */
@@ -115,6 +159,12 @@ static int load_syms_linux (realdec_deco

   sprintf (path, "%s/%s", entry->str_value, codec_name);

+#ifdef __x86_64__
+  /* check whether it's a real x86-64 library */
+  if (!is_x86_64_object(path))
+	return 0;
+#endif
+
   lprintf ("opening shared obj '%s'\n", path);

   this->rv_handle = dlopen (path, RTLD_LAZY);
@@ -566,6 +616,12 @@ static void *init_class (xine_t *xine, v
     if (!stat ("/usr/lib/RealPlayer9/users/Real/Codecs/drv3.so.6.0",
&s))
       config->update_string (config, "codec.real_codecs_path",
 			     "/usr/lib/RealPlayer9/users/Real/Codecs");
+    if (!stat ("/usr/lib64/RealPlayer8/Codecs/drv3.so.6.0", &s))
+      config->update_string (config, "codec.real_codecs_path",
+			     "/usr/lib64/RealPlayer8/Codecs");
+    if (!stat ("/usr/lib64/RealPlayer9/users/Real/Codecs/drv3.so.6.0",
&s))
+      config->update_string (config, "codec.real_codecs_path",
+			     "/usr/lib64/RealPlayer9/users/Real/ 
Codecs");
     if (!stat ("/usr/lib/win32/drv3.so.6.0", &s))
       config->update_string (config, "codec.real_codecs_path",
 			     "/usr/lib/win32");






More information about the MPlayer-dev-eng mailing list