A solution or suggestion for either #1 or #2 below would be appreciated.
1) I want to know when a camera (specifically IP POE) has been disconnected. When I detach the camera's network cable, the VLC callback routines (set up with libvlc_video_set_callbacks) continue to send the same frame over and over so that the picture is frozen but my program is unaware. What is a good way to detect disconnection? I thought I'd try events (#2), but that is not working for me.
2) Attempting to attach an event callback, using libvlc_event_attach, results in an access violation. Function, libvlc_media_event_manager, returns a pointer to what appears to be a pointer to its libvlc_event_manager_t struct. Passing the pointer to libvlc_event_attach yields the violation attempting to write to the pointer+24. The error is the same if I pass an event type it doesn't have. What am I doing wrong? The error message is consistent with passing a bogus libvlc_event_manager_t pointer but it looks correct to me.
--- Program debug output ---
vlc version=1.1.9 The Luggage
gMediaPlayer=02C520D0, gLibVlcEventManager=6F59CB76
exception=Access violation at address 77372262 in module 'ntdll.dll'. Write of address 6F59CB8E
--- versions ---
VLC version: 1.1.9 Luggage (worked the same with 1.1.7)
OS: Windows 7, 32-bit and 64-bit
Language: Delphi 7, 32-bit
--- code snippets --- (I'd be glad to post the whole .DPR, .PAS, and .DFM.)
...
libvlc_event_type_t = (
(* Append new event types at the end of a category.
* Do not remove, insert or re-order any entry.
* Keep this in sync with src/control/event.c:libvlc_event_type_name(). *)
libvlc_MediaMetaChanged = 0,
...
libvlc_MediaPlayerMediaChanged = $100,
...
libvlc_MediaPlayerStopped,
...
libvlc_MediaPlayerEncounteredError,
...
);
TlibvlcEventProc = procedure(event:libvlc_event_type_t;data:Pointer); cdecl;
var
Form1: TForm1;
gVlcInstance: PlibvlcInstanceT;
gMedia:PlibvlcMediaT;
gMediaPlayer:PlibvlcMediaPlayerT;
gLibVlcEventManager: Pointer;
gVlcLoadCount: Integer = 0;
gVlcModule: DWord = 0;
libvlc_media_event_manager: function(libvlcMediaPlayer:PlibvlcMediaPlayerT):Pointer cdecl;
libvlc_event_attach: procedure(eventManager: PlibvlcEventManagerT;
eventType: libvlc_event_type_t; //Integer;
eventCB: TlibvlcEventProc;
userData: Pointer); cdecl;
libvlc_event_detach: procedure(eventManager: PlibvlcEventManagerT;
eventType: libvlc_event_type_t;
eventCB: TlibvlcEventProc;
userData: Pointer); cdecl;
implementation
procedure PlayerCB(aEvent:libvlc_event_type_t;aData:Pointer); cdecl;
begin
OutputDebugString(PChar('PlayerCB'));
end;
...
argv[0] := PAnsiChar('--plugin-path=C:\\Prj\\VlcForum');
gVlcInstance := libvlc_new(1,@argv);
OutputDebugString(PChar('vlc version='+String(libvlc_get_version)));
gMedia := libvlc_media_new_path(gVlcInstance,PChar('c:\temp\cool.avi')); //streaming live from camera or reading file has the same result
gMediaPlayer := libvlc_media_player_new_from_media(gMedia);
gLibVlcEventManager := libvlc_media_event_manager(gMediaPlayer);
OutputDebugString(PChar('gMediaPlayer='+format('%-8.8p',[gMediaPlayer])+', gLibVlcEventManager='+format('%-8.8p',[gLibVlcEventManager])));
//=========================== This is where the access violation occurs. ===============================
try
libvlc_event_attach(gLibVlcEventManager, libvlc_MediaPlayerStopped, @PlayerCB, nil);
except on e:exception do
OutputDebugString(Pchar('exception='+e.message));
end;
//Then it goes on to correctly play the AVI.
libvlc_media_player_new_from_media(gMedia);
libvlc_media_player_set_hwnd(gMediaPlayer,panel1.handle);
libvlc_media_player_play(gMediaPlayer);