how to define chroma (fourcc) without knowing videorect

This forum is about all development around libVLC.
fpascal
Blank Cone
Blank Cone
Posts: 10
Joined: 28 Jun 2010 22:54

how to define chroma (fourcc) without knowing videorect

Postby fpascal » 03 Feb 2014 23:12

Hello,

i've a liddle Problem: How can I define the chroma without knowing the videorect? If I use libvlc_video_get_width before ore direct after libvlc_media_player_play it always returns 0 and if i use it after libvlc_media_player_play, it doesn't change anything. If I use -1 for width and hight I get a black window.

Thanks

Actual Code:

Code: Select all

unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, vlc; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Image1: TImage; Timer1: TTimer; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Timer1StartTimer(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { private declarations } public { public declarations } end; function lock(data, pixels: Pointer):Pointer; cdecl; function unlock(data, id, pixels: Pointer):Pointer; cdecl; var Form1: TForm1; VLCctx:tVLCcontext; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var w,h:Integer; begin // create new vlc media from file vlcMedia := libvlc_media_new_path(vlcInstance, '*********************************'); // create new vlc media player vlcMediaPlayer := libvlc_media_player_new_from_media(vlcMedia); // now no need the vlc media, free it libvlc_media_release(vlcMedia); //libvlc_video_set_callbacks(vlcMediaPlayer, @lock, @unlock, nil, @VLCctx); libvlc_video_set_callbacks(vlcMediaPlayer, @lock, nil, nil, @VLCctx); //ShowMessage(IntToStr(libvlc_video_get_width(vlcMediaPlayer))); w:=320; h:=240; //libvlc_video_set_format(vlcMediaPlayer,'RGBA',w,h,w*4); libvlc_video_set_format(vlcMediaPlayer,'RGBA',w,h,w*4); // play media libvlc_media_player_play(vlcMediaPlayer); Timer1.Enabled:=true; end; procedure TForm1.FormCreate(Sender: TObject); begin CreateVLCPlayer(); end; procedure TForm1.Timer1StartTimer(Sender: TObject); begin end; procedure TForm1.Timer1Timer(Sender: TObject); var ix,iy,c:integer; begin for ix:=0 to 320 do for iy:=0 to 240 do begin {c:= VLCctx.vlcpixels[ix*4+0+iy*320*4]; c:=c+VLCctx.vlcpixels[ix*4+1+iy*320*4]*256; c:=c+VLCctx.vlcpixels[ix*4+2+iy*320*4]*256*256; } c:= VLCctx.vlcpixels[ix*4+0+iy*320*4]; c:=c+VLCctx.vlcpixels[ix*4+1+iy*320*4]*256; c:=c+VLCctx.vlcpixels[ix*4+2+iy*320*4]*256*256; Image1.Canvas.Pixels[ix,iy]:=TColor(c); end; end; function lock(data, pixels: Pointer):Pointer; cdecl; var w,h:Integer; begin w:=libvlc_video_get_width(vlcMediaPlayer); h:=libvlc_video_get_height(vlcMediaPlayer); Setlength(VLCctx.vlcpixels,w*h*4); libvlc_video_set_format(vlcMediaPlayer,'RGBA',w,h,w*4); Pointer(pixels^) := @(VLCctx.vlcpixels[0]); Result:=nil; end; function unlock(data, id, pixels: Pointer):Pointer; cdecl; begin //noch leer end; end.
vlc.pas:

Code: Select all

unit vlc; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Dialogs{$IFDEF WINDOWS}, Windows{$ENDIF}; type plibvlc_instance_t = type Pointer; plibvlc_media_player_t = type Pointer; plibvlc_media_t = type Pointer; tVLC_lock = function(data, pixels: Pointer):Pointer; cdecl; tVLC_unlock = function(data, id, pixels: Pointer):Pointer; cdecl; pVLC_lock = ^tVLC_lock; pVLC_unlock = ^tVLC_unlock; TRGBTripleArray = array of TRGBTriple; pRGBTripleArray = ^TRGBTripleArray; tVLCcontext = record VLCpixels:array of byte; //VLCpixels:tRGBTripleArray end; var libvlc_media_new_path : function(p_instance : Plibvlc_instance_t; path : PAnsiChar) : Plibvlc_media_t; cdecl; libvlc_media_new_location : function(p_instance : plibvlc_instance_t; psz_mrl : PAnsiChar) : Plibvlc_media_t; cdecl; libvlc_media_player_new_from_media : function(p_media : Plibvlc_media_t) : Plibvlc_media_player_t; cdecl; libvlc_media_player_set_hwnd : procedure(p_media_player : Plibvlc_media_player_t; drawable : Pointer); cdecl; libvlc_media_player_play : procedure(p_media_player : Plibvlc_media_player_t); cdecl; libvlc_media_player_stop : procedure(p_media_player : Plibvlc_media_player_t); cdecl; libvlc_media_player_release : procedure(p_media_player : Plibvlc_media_player_t); cdecl; libvlc_media_player_is_playing : function(p_media_player : Plibvlc_media_player_t) : Integer; cdecl; libvlc_media_release : procedure(p_media : Plibvlc_media_t); cdecl; libvlc_new : function(argc : Integer; argv : PAnsiChar) : Plibvlc_instance_t; cdecl; libvlc_release : procedure(p_instance : Plibvlc_instance_t); cdecl; libvlc_video_set_callbacks : procedure(p_media_player : Plibvlc_media_player_t; lock : tVLC_lock; unlock: tVLC_unlock; display, opaque: Pointer); cdecl; // libvlc_video_set_callbacks : procedure(p_media_player : Plibvlc_media_player_t; lock, unlock: Pointer; display, opaque: Pointer); cdecl; libvlc_video_get_width : function(p_media_player : Plibvlc_media_player_t) : Integer; cdecl; libvlc_video_get_height : function(p_media_player : Plibvlc_media_player_t) : Integer; cdecl; libvlc_video_get_size : function(p_media_player : Plibvlc_media_player_t; num:Integer; px, py:Pointer) : Integer; cdecl; libvlc_video_set_format : procedure(p_media_player : Plibvlc_media_player_t; chroma:String; width, height, pitch: Integer) cdecl; vlcLib: integer; vlcInstance: plibvlc_instance_t; vlcMedia: plibvlc_media_t; vlcMediaPlayer: plibvlc_media_player_t; procedure CreateVLCPlayer; implementation // ----------------------------------------------------------------------------- // Read registry to get VLC installation path // ----------------------------------------------------------------------------- function GetVLCLibPath: String; begin if DirectoryExists('C:\Program Files (x86)\VideoLAN\VLC') then result:='C:\Program Files (x86)\VideoLAN\VLC'; if DirectoryExists('C:\Program Files\VideoLAN\VLC') then result:='C:\Program Files\VideoLAN\VLC'; end; // ----------------------------------------------------------------------------- // Load libvlc library into memory // ----------------------------------------------------------------------------- function LoadVLCLibrary(APath: string): integer; begin Result := LoadLibrary(PChar(APath + '\libvlccore.dll')); //if not FileExists(PChar(APath + '\libvlc.dll')) then ShowMessage('ah'); Result := LoadLibrary(PChar(APath + '\libvlc.dll')); //ShowMessage(PChar(APath + '\libvlc.dll') + ' :' + IntToStr(Result)); end; // ----------------------------------------------------------------------------- function GetVLCProcAddress(vlcHandle: integer; var addr: Pointer; procName: string; failedList: TStringList): integer; begin addr := GetProcAddress(vlcHandle, PChar(procName)); if Assigned(addr) then Result := 0 else begin if Assigned(failedList) then failedList.Add(procName); Result := -1; end; end; // ----------------------------------------------------------------------------- // Get address of libvlc functions // ----------------------------------------------------------------------------- function LoadVLCFunctions(vlcHandle: integer; failedList: TStringList): Boolean; begin GetVLCProcAddress(vlcHandle, pointer(libvlc_new), 'libvlc_new', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_new_location), 'libvlc_media_new_location', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_player_new_from_media), 'libvlc_media_player_new_from_media', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_release), 'libvlc_media_release', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_player_set_hwnd), 'libvlc_media_player_set_hwnd', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_player_play), 'libvlc_media_player_play', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_player_stop), 'libvlc_media_player_stop', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_player_release), 'libvlc_media_player_release', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_release), 'libvlc_release', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_player_is_playing), 'libvlc_media_player_is_playing', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_media_new_path), 'libvlc_media_new_path', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_video_set_callbacks), 'libvlc_video_set_callbacks', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_video_get_width), 'libvlc_video_get_width', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_video_get_height), 'libvlc_video_get_height', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_video_get_size), 'libvlc_video_get_size', failedList); GetVLCProcAddress(vlcHandle, pointer(libvlc_video_set_format), 'libvlc_video_set_format', failedList); // if all functions loaded, result is an empty list, otherwise result is a list of functions failed Result := failedList.Count = 0; end; procedure CreateVLCPlayer; var sL: TStringList; begin // load vlc library vlclib := LoadVLCLibrary(GetVLCLibPath()); if vlclib = 0 then begin Showmessage('Load vlc library failed'); Exit; end; // sL will contains list of functions fail to load sL := TStringList.Create; if not LoadVLCFunctions(vlclib, sL) then begin Showmessage('Some functions failed to load : ' + #13#10 + sL.Text); FreeLibrary(vlclib); sL.Free; Exit; end; sL.Free; vlcInstance := libvlc_new(0, nil); end; end.

Rémi Denis-Courmont
Developer
Developer
Posts: 15272
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: how to define chroma (fourcc) without knowing videorect

Postby Rémi Denis-Courmont » 04 Feb 2014 17:50

Use libvlc_video_set_format_callbacks() instead of libvlc_video_set_format().
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

fpascal
Blank Cone
Blank Cone
Posts: 10
Joined: 28 Jun 2010 22:54

Re: how to define chroma (fourcc) without knowing videorect

Postby fpascal » 07 Feb 2014 23:42

Thank you.

OK, i've replaced libvlc_video_set_format by libvlc_video_set_format_callbacks. Now I've defined the following

Code: Select all

function setupfc(data:Pointer; chroma:pAnsiChar; width, height, pitches, lines: Pointer):Pointer; cdecl; begin chroma:='RGBA'; //no influence //Integer(width^):=320; //any difference to the original size leads to a black picture //Integer(height^):=240; //any difference to the original size leads to a black picture Integer(pitches^):=Integer(width^)*4; //it works Integer(lines^):=Integer(height^); //no influence //Integer(result^):=1; end;
But i've the problems described in the comments.

Any idea, what's wrong?

Thanks

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: how to define chroma (fourcc) without knowing videorect

Postby Jean-Baptiste Kempf » 11 Feb 2014 17:53

look in the logs.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

fpascal
Blank Cone
Blank Cone
Posts: 10
Joined: 28 Jun 2010 22:54

Re: how to define chroma (fourcc) without knowing videorect

Postby fpascal » 14 Mar 2014 15:54

ich hatte längere Zeit keine Zeit das Thema weiter zu verfolgen. Nun möche ich mich noch einmal dem Thema widmen.

Sehe ich das richtig, dass das schreiben der Log-Datei erst mittels libvlc_log_set_file und libvlc_set_log_verbosity aktiviert werden muss?

Wenn ja, wie nutze ich libvlc_log_set_file in Pascal. Einenen File-Stream, wie er von C mittels open(name,modus=default) geöffnet wird gibte es meines Wissens in dieser Form nicht. Gibt es also eine Möglichkeit z.B. mittels AssignFile oder TFileStream? Oder wie ist das schreiben der Datei sonst handhabbar?

Ich löse immer eine Schutzverletzung (SIGSEGV) aus, wenn ich libvlc_log_set_file folgendermaßen definiere:

Code: Select all

libvlc_log_set_file : procedure(p_media_player : Plibvlc_media_player_t; var FileStream:TextFile) cdecl;
und dann folgenderweise nutze

Code: Select all

AssignFile(f, 'xxxxxxx\libvlc.log'); Rewrite(f); libvlc_log_set_file(vlcMediaPlayer,f);
Ist das FileHandle, dass AssignFile zurück gibt vom Typ her ein anderes, als open() in C zurück gibt? Eine Variable des Typs file of * lässt sich jedenfalls nicht in einen LongWord konvertieren (und das gibt ja open() zurück).

Vielen Dank im Voraus

fpascal
Blank Cone
Blank Cone
Posts: 10
Joined: 28 Jun 2010 22:54

Re: how to define chroma (fourcc) without knowing videorect

Postby fpascal » 16 Mar 2014 14:03

I'm sorry about my reply in German (it was caused by the fact, that i sometimes don't notice the change between German - my native language - and English). I realized it today and will to translate it now:

Last weeks I had not enough time to continue in this topic. Now I want to continue there.

Is the assumtion right, that you have to activate the saving of a log by using libvlc_log_set_file and libvlc_set_log_verbosity?

If it's right, i've the question how to use libvlc_log_set_file in Pascal. I don't know a file-stream like the function open(name,modus=default) offers in C. So whats's the right way in Pascal? Is there any way for example using the function AssignFile() or the class TFileStream? I thing the file handle of AssignFile() is different to open(): a variable of the typs "file of *" is not convertable to LongWord the type is returned by open(). So the following code results in a segmentation fault (SIGSEGV):

I've defined libvlc_log_set_file like this:

Code: Select all

libvlc_log_set_file : procedure(p_media_player : Plibvlc_media_player_t; var FileStream:TextFile) cdecl;
and used like this:

Code: Select all

AssignFile(f, 'xxxxxxx\libvlc.log'); Rewrite(f); libvlc_log_set_file(vlcMediaPlayer,f);
Thank you in advance.

Rémi Denis-Courmont
Developer
Developer
Posts: 15272
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: how to define chroma (fourcc) without knowing videorect

Postby Rémi Denis-Courmont » 16 Mar 2014 14:17

This forum is not exactly the best place for question on Pascal to C mapping.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

fpascal
Blank Cone
Blank Cone
Posts: 10
Joined: 28 Jun 2010 22:54

Re: how to define chroma (fourcc) without knowing videorect

Postby fpascal » 17 Mar 2014 09:49

Hello,

I've searched for more Information about the right file handling. Now im shure, that a solution with TFileStream.Handle / FileOpen is correct. But I still have a segmentation fault: 77BF22D2 f00fba3000 lock btrl $0x0,(%eax)

The actual source is:

Code: Select all

LogStream:=FileOpen('xxxxxxxxxxxxxxxxxxx\libvlc.log',fmOpenReadWrite); libvlc_set_log_verbosity(vlcInstance, 2); libvlc_log_set_file(vlcInstance,LogStream);
Edit: The same error occures using libvlc_log_set with an empty procedure (same address,...).

Normal wirting is possible. The problem might be a double locking of the file via a spinlock (lock btrl - Assembler).

Any Idea how to solve this problem?

Thank you in advance.

Info: the actual VLC-Mediaplyer (2.1.3) is installed

fpascal
Blank Cone
Blank Cone
Posts: 10
Joined: 28 Jun 2010 22:54

Re: how to define chroma (fourcc) without knowing videorect

Postby fpascal » 17 Mar 2014 16:26

Back to the main problem:

now I've read out the values of the setup-procedure (libvlc_video_setup_cb) of libvlc_video_set_format_callbacks.

Code: Select all

procedure libvlc_video_format(var opaque : Pointer; chroma : PAnsiChar; var width : LongWord; var height : LongWord; var pitches : LongWord; var lines : LongWord); cdecl;
There are 3 errors:
  • chroma has a random value (1 to 4 Chars)
  • pitches and lines always have the value 0
The values of width and hight are correct. It's irrelevant wether the function libvlc_video_set_format(libvlc_media_player,'RGBA',320,240,320*4); is used before. There seams to be a bug in the libvlc or in the definition of the setup-procedure.

Can someone help me to fix the bug?

fpascal
Blank Cone
Blank Cone
Posts: 10
Joined: 28 Jun 2010 22:54

Re: how to define chroma (fourcc) without knowing videorect

Postby fpascal » 18 Mar 2014 01:14

I've found a workauround:

Code: Select all

libvlc_dynamic_dll_init_with_path('C:\Program Files (x86)\VideoLAN\VLC'); libvlc_instance := libvlc_new(0, nil); libvlc_media := libvlc_media_new_path(libvlc_instance, 'xxxxxxxxxxxxxxxxxxxxxxxx'); libvlc_media_parse(libvlc_media); libvlc_media_get_tracks_info(libvlc_media,libvlc_media_track_info); ...


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 23 guests