Problem with libvlc_media_new_callbacks

This forum is about all development around libVLC.
Gvv
New Cone
New Cone
Posts: 2
Joined: 09 Aug 2015 12:58

Problem with libvlc_media_new_callbacks

Postby Gvv » 09 Aug 2015 14:07

I'm use libvlc with Delphi XE2.
When I loaded video via libvlc_media_new_path it play fine. Then I'm trying to use libvlc_media_new_callbacks.

Code: Select all

type unsigned_char = Byte; p_unsigned_char = PByte; uint64_t = UInt64; puint64_t = PUInt64; size_t = NativeUInt; ssize_t = NativeInt; PStream = ^TStream; libvlc_media_open_cb = function(opaque: Pointer; var datap: Pointer; sizep: puint64_t): integer; cdecl; libvlc_media_read_cb = function(opaque: Pointer; buf: p_unsigned_char; len: size_t): ssize_t; cdecl; libvlc_media_seek_cb = function(opaque: Pointer; offset: uint64_t): integer; cdecl; libvlc_media_close_cb = function(opaque: Pointer): integer; cdecl; libvlc_media_new_callbacks : function(p_instance : Plibvlc_instance_t; open_cb: libvlc_media_open_cb; read_cb: libvlc_media_read_cb; seek_cb: libvlc_media_seek_cb; close_cb: libvlc_media_close_cb; opaque: Pointer): Plibvlc_media_t; stdcall; var stream: TStream; stream_ptr: Pointer; procedure TVLC.SetMedia(mediaFile: string); begin try // create new vlc instance _vlcInstance := libvlc_new(0, nil); // vlcMedia := libvlc_media_new_path(_vlcInstance, PAnsiChar(AnsiString(mediaFile))); stream := TFileStream.Create(mediaFile, fmOpenRead); stream.Position := 0; stream_ptr := PStream(@stream); vlcMedia := libvlc_media_new_callbacks(_vlcInstance, MediaOpen, MediaRead, nil, MediaClose, stream_ptr); // create new vlc media player _vlcMediaPlayer := libvlc_media_player_new_from_media(vlcMedia); finally libvlc_media_release(vlcMedia); end; end; function MediaOpen(opaque: Pointer; var datap: Pointer; sizep: puint64_t): integer; begin sizep^ := UInt64(106532864); //filesize Result := 0; end; function MediaRead(opaque: Pointer; buf: p_unsigned_char; len: size_t): ssize_t; begin try Result := TStream(opaque^).Read(buf^, len); except on E: Exception do Result := -1; end; function MediaClose(opaque: Pointer): integer; begin FreeAndNil(TStream(opaque1)); end;
And video don't play. I see black screen and sound like fast rewind.

Then I'm trying to do it in C++.
I'm get example of WxWidgets Player from WIKI http://git.videolan.org/?p=vlc.git;a=bl ... k_player.c
Compile with CodeLite and MinGW, the video play fine.
I made some changes:
in open file

Code: Select all

media_file = new ifstream(openFileDialog.GetPath(), ios::in|ios::binary|ios::ate); media_file->seekg(0, media_file->beg); media = libvlc_media_new_callbacks( vlc_inst, media_open_cb, media_read_cb, NULL, media_close_cb, media_file); libvlc_media_player_set_media(media_player, media); play(); libvlc_media_release(media);
and add callback implementation:

Code: Select all

int media_open_cb(void *opaque, void **datap, uint64_t *sizep) { *sizep = 106532864; *datap = opaque; return 0; } ssize_t media_read_cb(void *opaque, unsigned char *buf, size_t len) { ifstream *file = (ifstream *)(opaque); file->read((char *)(buf), len); return file->gcount(); } void media_close_cb(void *opaque) { ifstream *file = (ifstream *)(opaque); file->close(); }
And get the same result as with Delphi XE.
What i'm doing wrong?

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

Re: Problem with libvlc_media_new_callbacks

Postby Rémi Denis-Courmont » 09 Aug 2015 14:28

You forgot the seek callback.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

Gvv
New Cone
New Cone
Posts: 2
Joined: 09 Aug 2015 12:58

Re: Problem with libvlc_media_new_callbacks

Postby Gvv » 09 Aug 2015 14:52

Thank you, implementation of seek callback solved my problem.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 20 guests