Bläddra i källkod

* Fix bug ID #30762

git-svn-id: trunk@34866 -
michael 8 år sedan
förälder
incheckning
ab566789a8
3 ändrade filer med 44 tillägg och 7 borttagningar
  1. 2 0
      packages/libvlc/example/testvlc.pp
  2. 8 2
      packages/libvlc/example/tvlc.pp
  3. 34 5
      packages/libvlc/src/libvlc.pp

+ 2 - 0
packages/libvlc/example/testvlc.pp

@@ -15,6 +15,8 @@ begin
   // This is needed, or loading the VLC libraries will fail with a SIGFPE
   setexceptionmask([exInvalidOp, exDenormalized, exZeroDivide,
                      exOverflow, exUnderflow, exPrecision]);
+  With TVLCLibrary.Create(Nil) do
+    Initialize;
   P:=TVLCMediaPlayer.Create(Nil);
   if ParamCount=1 then
     With P do

+ 8 - 2
packages/libvlc/example/tvlc.pp

@@ -1,7 +1,12 @@
+{$IFDEF UNIX}
 {$linklib pthread}
+{$ENDIF}
+{$mode objfpc}
+{$H+}
+
 program tvlc;
 
-uses cthreads, libvlc, math;
+uses  {$ifdef unix}cthreads,{$endif}libvlc, math;
 
 Var
   Args: Array[0..3] of pchar;
@@ -11,8 +16,9 @@ begin
   // This is needed, or loading the VLC libraries will fail with a SIGFPE
   setexceptionmask([exInvalidOp, exDenormalized, exZeroDivide,
                      exOverflow, exUnderflow, exPrecision]);
-  LoadLibVLC('libvlc.so.5',False);
+  LoadLibVLC(libname,False);
   args[0] := PAnsiChar('libvlc.so.5');
+  Args[1] := PansiChar(ParamStr(1));
   args[2] := NIL;
   FHandle := libvlc_new(1, @args);
 end.

+ 34 - 5
packages/libvlc/src/libvlc.pp

@@ -633,6 +633,9 @@ uses
 
 var
   hlib : tlibhandle;
+  {$IFDEF WINDOWS}
+  hclib : tlibhandle;
+  {$ENDIF}
   LibRefCount : Integer;
 
 procedure Freelibvlc;
@@ -643,6 +646,11 @@ begin
   if LibRefCount>0 then
     exit;
   FreeLibrary(hlib);
+  hlib:=NilHandle;
+{$IFDEF WINDOWS}
+  FreeLibrary(hclib);
+  hclib:=NilHandle;
+{$ENDIF}
   libvlc_errmsg:=nil;
   libvlc_clearerr:=nil;
   libvlc_printerr:=nil;
@@ -932,7 +940,28 @@ Procedure Loadlibvlc(lib : AnsiString; CheckProcNames : Boolean = False);
     raise Exception.CreateFmt('Could not load library "%s"',[FN]);
     {$endif}
   end;
-  
+
+  Function TryLoadLib(ALib : String) : TLibHandle;
+  // On Windows, the vlccore lib must be loaded first.
+  // If it is not in the PATH then this will fail when specifying an arbitrary path.
+  // So we load it explicitly from the same directory first
+  {$IFDEF WINDOWS}
+  Var
+    ADir : String;
+  {$endif}
+
+  begin
+    {$IFDEF WINDOWS}
+    Result:=NilHandle;
+    ADir:=ExtractFilePath(ALib);
+    if ADir<>'' then
+      ADir:=IncludeTrailingPathDelimiter(ADir);
+    hclib:=LoadLibrary(ADir+corelibname);
+    if (HCLib<>Nilhandle) then
+    {$ENDIF}
+      Result:=LoadLibrary(ALib);
+  end;
+
 
 {$IFDEF WINDOWS}  
 Var
@@ -945,21 +974,21 @@ begin
     Inc(LibRefCount);
     Exit;
     end;
-  hlib:=LoadLibrary(lib);
-{$IFDEF WINDOWS}  
+  hlib:=TryLoadLib(lib);
+{$IFDEF WINDOWS}
   // MVC: This automatism is highly questionable; The end user should in fact determine the library.
   if (hlib=NilHandle) then
     begin
     D:=ExtractFilePath(lib);
     // Try default name in same directiory.
-    hlib:=LoadLibrary(d+corelibname);
+    hlib:=TryLoadLib(d+libname);
     if (hLib=NilHandle) and (d='') then
       begin
       // No directory specified, try default name in installation directory.
       if (DefaultlibPath='') then
         DefaultLibPath:=GetVLCLibPath;
       if (DefaultLibPath<>'') then
-        hLib:=LoadLibrary(IncludeTrailingPathDelimiter(DefaultlibPath)+corelibname);
+        hLib:=TryLoadLib(IncludeTrailingPathDelimiter(DefaultlibPath)+libname);
       end;  
     end;  
 {$endif}