Verhalten von GLIB2 C vs. FPC

Antworten
Mathias
Beiträge: 6955
Registriert: Do 2. Jan 2014, 17:21
OS, Lazarus, FPC: Linux (die neusten Trunk)
CPU-Target: 64Bit
Wohnort: Schweiz

Verhalten von GLIB2 C vs. FPC

Beitrag von Mathias »

Ich habe ein kleines natives Programm, welches mit gstreamer eine MP3 lädt und diese mit reduzierten Lautstärke abspielt.
Was ich zuerst noch sagen muss, mit Linux gehen beide Programme einwandfrei.
Ich habe für diesen Zweck ein Programm in C, bei dem die Lautstärke funktioniert. Und eines in FPC, bei dem die Lautstärke NICHT will.
Die Programme sehen fast identisch aus.

Zuerst die C-Version, bei der es funktioniert.

Code: Alles auswählen

// === Linux
// gcc main.c -o main `pkg-config --cflags --libs gstreamer-1.0`

// === Windows
// x86_64-w64-mingw32-gcc  main.c -o main -lgstreamer-1.0-0 -lgobject-2.0-0 -L/home/tux/.wine/drive_c/gstreamer/1.0/msvc_x86_64/bin


#include <stdio.h>

extern void   g_object_set(void * o, char * fpn, ...);

extern void	  gst_init(int *argc, char **argv[]);
extern void * gst_parse_launch(const char * pipeline_description, void ** error);
extern void * gst_bin_get_by_name(void * b, const char * n); 
extern int    gst_element_set_state(void *element, int state);



int main (int argc, char *argv[]) {
  gst_init (&argc, &argv); 

  void * pipeline = gst_parse_launch("filesrc location=test.mp3 ! decodebin ! audioconvert ! audioresample ! volume name=volume ! autoaudiosink", NULL);
  if (!pipeline) {
    printf("pipeline error\n");
  } else {
    printf("pipeline io.\n");
  }

  void * volume = gst_bin_get_by_name(pipeline, "volume");
  if (!volume) {
    printf("volume error\n");
  } else {
    printf("volume io.\n");
  }
  float vol = 0.05;
  g_object_set(volume, "volume", vol, 0);

  gst_element_set_state(pipeline, 4);

  printf("<CTRL+C> = stop\n");
  while (1) {  }
}
Ausgabe:

Code: Alles auswählen

$ wine main.exe 
00dc:err:module:import_dll Library opencore-amrnb-0.dll (which is needed by L"C:\\gstreamer\\1.0\\msvc_x86_64\\lib\\gstreamer-1.0\\gstamrnb.dll") not found
00dc:err:module:import_dll Library opencore-amrnb-0.dll (which is needed by L"C:\\gstreamer\\1.0\\msvc_x86_64\\lib\\gstreamer-1.0\\gstamrnb.dll") not found

(main.exe:216): GStreamer-[1;33mWARNING[0m **: [34m14:09:49.097[0m: Failed to load plugin 'C:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstamrnb.dll': Mod
ul nicht gefunden.
This usually means Windows was unable to find a DLL dependency of the plugin. Please check that PATH is correct.
You can run 'dumpbin -dependents' (provided by the Visual Studio developer prompt) to list the DLL deps of any DLL.
There are also some third-party GUIs to list and debug DLL dependencies recursively.
00dc:err:module:import_dll Library opencore-amrwb-0.dll (which is needed by L"C:\\gstreamer\\1.0\\msvc_x86_64\\lib\\gstreamer-1.0\\gstamrwbdec.dll") not found
00dc:err:module:import_dll Library opencore-amrwb-0.dll (which is needed by L"C:\\gstreamer\\1.0\\msvc_x86_64\\lib\\gstreamer-1.0\\gstamrwbdec.dll") not found

(main.exe:216): GStreamer-[1;33mWARNING[0m **: [34m14:09:49.128[0m: Failed to load plugin 'C:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstamrwbdec.dll': 
Modul nicht gefunden.
This usually means Windows was unable to find a DLL dependency of the plugin. Please check that PATH is correct.
You can run 'dumpbin -dependents' (provided by the Visual Studio developer prompt) to list the DLL deps of any DLL.
There are also some third-party GUIs to list and debug DLL dependencies recursively.
pipeline io.
volume io.
00dc:err:combase:RoGetActivationFactory Failed to find library for L"Windows.ApplicationModel.Core.CoreApplication"
<CTRL+C> = stop
Und die FPC-Version:

Code: Alles auswählen


program project1;

const
  {$IFDEF Linux}
  libgtk4 = 'libgtk-4';
  gstreamerlib = 'libgstreamer-1.0';
  {$ENDIF}

  {$IFDEF Windows}
  libgobject2_0 = 'libgobject-2.0-0.dll';
  gstreamerlib = 'gstreamer-1.0-0.dll';
  {$ENDIF}

  procedure g_object_set(_object: Pointer; first_property_name: PChar); varargs; cdecl; external libgobject2_0;

  procedure gst_init(argc: Plongint; argv: PPPchar); cdecl; external gstreamerlib;
  function gst_parse_launch(pipeline_description: PChar; error: PPointer): Pointer; cdecl; external gstreamerlib;
  function gst_bin_get_by_name(bin: Pointer; Name: PChar): Pointer; cdecl; external gstreamerlib;
  function gst_element_set_state(element: Pointer; state: longint): longint; cdecl; external gstreamerlib;

 var
    pipeline, volume: Pointer;
    vol: single = 0.1;
  begin
    gst_init(@argc, @argv);

    pipeline := gst_parse_launch('filesrc location=test.mp3 ! decodebin ! audioconvert ! audioresample ! volume name=volume ! autoaudiosink', nil);
    if pipeline = nil then begin
      WriteLn('pipeline error');
    end else begin
      WriteLn('pipeline io.');
    end;

    volume := gst_bin_get_by_name(pipeline, 'volume');
    if volume = nil then begin
      WriteLn('volume error');
    end else begin
      WriteLn('volume io.');
    end;

    vol := 0.1;
    g_object_set(volume, 'volume', vol, nil);
    gst_element_set_state(pipeline, 4);
    WriteLn('PLAY');

    repeat
    until False;
end.
Ausgabe:

Code: Alles auswählen

$ wine project1.exe 
00dc:err:module:import_dll Library opencore-amrnb-0.dll (which is needed by L"C:\\gstreamer\\1.0\\msvc_x86_64\\lib\\gstreamer-1.0\\gstamrnb.dll") not found
00dc:err:module:import_dll Library opencore-amrnb-0.dll (which is needed by L"C:\\gstreamer\\1.0\\msvc_x86_64\\lib\\gstreamer-1.0\\gstamrnb.dll") not found

(project1.exe:216): GStreamer-[1;33mWARNING[0m **: [34m14:11:56.079[0m: Failed to load plugin 'C:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstamrnb.dll':
 Modul nicht gefunden.
This usually means Windows was unable to find a DLL dependency of the plugin. Please check that PATH is correct.
You can run 'dumpbin -dependents' (provided by the Visual Studio developer prompt) to list the DLL deps of any DLL.
There are also some third-party GUIs to list and debug DLL dependencies recursively.
00dc:err:module:import_dll Library opencore-amrwb-0.dll (which is needed by L"C:\\gstreamer\\1.0\\msvc_x86_64\\lib\\gstreamer-1.0\\gstamrwbdec.dll") not found
00dc:err:module:import_dll Library opencore-amrwb-0.dll (which is needed by L"C:\\gstreamer\\1.0\\msvc_x86_64\\lib\\gstreamer-1.0\\gstamrwbdec.dll") not found

(project1.exe:216): GStreamer-[1;33mWARNING[0m **: [34m14:11:56.111[0m: Failed to load plugin 'C:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstamrwbdec.dl
l': Modul nicht gefunden.
This usually means Windows was unable to find a DLL dependency of the plugin. Please check that PATH is correct.
You can run 'dumpbin -dependents' (provided by the Visual Studio developer prompt) to list the DLL deps of any DLL.
There are also some third-party GUIs to list and debug DLL dependencies recursively.
pipeline io.
volume io.

(process:216): GLib-[1;35mCRITICAL[0m **: [34m14:11:56.256[0m: g_datalist_id_set_data_full: assertion 'key_id > 0' failed

(process:216): GLib-GObject-[1;35mCRITICAL[0m **: [34m14:11:56.263[0m: g_param_spec_pool_lookup: assertion 'pool != NULL' failed

(process:216): GLib-GObject-[1;35mCRITICAL[0m **: [34m14:11:56.270[0m: g_object_set_is_valid_property: object class '(NULL)' has no property named 'volume'
00dc:err:combase:RoGetActivationFactory Failed to find library for L"Windows.ApplicationModel.Core.CoreApplication"
PLAY
Was mir dabei auffällt das unter Windows die Property für "volume" nicht gesetzt werden kann.
Wieso kann ich die unter Windows nicht setzen ?
Einer eine Idee ?

Ich habe auch schon probiert, die Function "g_object_set" von der GLIB2 Unit welche bei FPC dabei ist. zu nehmen.
Mit Lazarus sehe ich grün
Mit Java und C/C++ sehe ich rot

Mathias
Beiträge: 6955
Registriert: Do 2. Jan 2014, 17:21
OS, Lazarus, FPC: Linux (die neusten Trunk)
CPU-Target: 64Bit
Wohnort: Schweiz

Re: Verhalten von GLIB2 C vs. FPC

Beitrag von Mathias »

Ich habe den Fehler gefunden, als ich es gestern auf meinem Laptop mit wine ausprobierte. Da kam die erwartete Fehlermeldung, das er "libgobject-2.0-0.dll" nicht findet. Da habe ich folgendes korrigiert. Jetzt läuft es wie erwartet.

Code: Alles auswählen

// alt
libgobject2_0 = 'libgobject-2.0-0.dll';
// neu
libgobject2_0 = 'gobject-2.0-0.dll';
Komisch, das mein PC wegen 'libgobject-2.0-0.dll' nicht motzte. Ich vermute wegen lauter bastlerrei hat sich eine ungültige Datei eingeschlichen.
Und beim Win10 in der VB, wurde das Program ohne Kommentar abgebrochen.
Wieso das da keine Meldung wegen fehlender DLL kam, keine Ahnung, ansonsten motzt Windows wegen jedem Furz.
Mit Lazarus sehe ich grün
Mit Java und C/C++ sehe ich rot

Antworten