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;
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);
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();
}
What i'm doing wrong?