Disconnect, libvlc_event_attach access violation, Delphi

This forum is about all development around libVLC.
Packer
New Cone
New Cone
Posts: 1
Joined: 14 Apr 2011 17:17

Disconnect, libvlc_event_attach access violation, Delphi

Postby Packer » 14 Apr 2011 18:24

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);

ispy
New Cone
New Cone
Posts: 4
Joined: 11 Apr 2011 17:49

Re: Disconnect, libvlc_event_attach access violation, Delphi

Postby ispy » 29 Apr 2011 02:41

I've got the same issue.. anyone??

DsChAeK
Blank Cone
Blank Cone
Posts: 59
Joined: 01 Mar 2008 14:54
VLC version: newest
Operating System: windows

Re: Disconnect, libvlc_event_attach access violation, Delphi

Postby DsChAeK » 01 May 2011 18:34

yep, me too!
I always get an assertion in event.c, line 362.

BobaL
New Cone
New Cone
Posts: 8
Joined: 01 Dec 2009 17:40

Re: Disconnect, libvlc_event_attach access violation, Delphi

Postby BobaL » 02 May 2011 14:21

How do you know the association between C++ declaration and delphi hexadecimal value (libvlc_MediaPlayerMediaChanged = $100)?
* Keep this in sync with src/control/event.c:libvlc_event_type_name(). *)
libvlc_MediaMetaChanged = 0,
...
libvlc_MediaPlayerMediaChanged = $100,
...
libvlc_MediaPlayerStopped,
...
libvlc_MediaPlayerEncounteredError,
...
);

BobaL
New Cone
New Cone
Posts: 8
Joined: 01 Dec 2009 17:40

Re: Disconnect, libvlc_event_attach access violation, Delphi

Postby BobaL » 02 May 2011 14:51

Ok I've found in libvlc_events.h
enum libvlc_event_e {
/* 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_MediaSubItemAdded,
libvlc_MediaDurationChanged,
libvlc_MediaParsedChanged,
libvlc_MediaFreed,
libvlc_MediaStateChanged,

libvlc_MediaPlayerMediaChanged=0x100,
libvlc_MediaPlayerNothingSpecial,
libvlc_MediaPlayerOpening,
libvlc_MediaPlayerBuffering,
libvlc_MediaPlayerPlaying,
libvlc_MediaPlayerPaused,
libvlc_MediaPlayerStopped,
libvlc_MediaPlayerForward,
libvlc_MediaPlayerBackward,
libvlc_MediaPlayerEndReached,
libvlc_MediaPlayerEncounteredError,
libvlc_MediaPlayerTimeChanged,
libvlc_MediaPlayerPositionChanged,
libvlc_MediaPlayerSeekableChanged,
libvlc_MediaPlayerPausableChanged,
libvlc_MediaPlayerTitleChanged,
libvlc_MediaPlayerSnapshotTaken,
libvlc_MediaPlayerLengthChanged,

libvlc_MediaListItemAdded=0x200,
libvlc_MediaListWillAddItem,
libvlc_MediaListItemDeleted,
libvlc_MediaListWillDeleteItem,

libvlc_MediaListViewItemAdded=0x300,
libvlc_MediaListViewWillAddItem,
libvlc_MediaListViewItemDeleted,
libvlc_MediaListViewWillDeleteItem,

libvlc_MediaListPlayerPlayed=0x400,
libvlc_MediaListPlayerNextItemSet,
libvlc_MediaListPlayerStopped,

libvlc_MediaDiscovererStarted=0x500,
libvlc_MediaDiscovererEnded,

libvlc_VlmMediaAdded=0x600,
libvlc_VlmMediaRemoved,
libvlc_VlmMediaChanged,
libvlc_VlmMediaInstanceStarted,
libvlc_VlmMediaInstanceStopped,
libvlc_VlmMediaInstanceStatusInit,
libvlc_VlmMediaInstanceStatusOpening,
libvlc_VlmMediaInstanceStatusPlaying,
libvlc_VlmMediaInstanceStatusPause,
libvlc_VlmMediaInstanceStatusEnd,
libvlc_VlmMediaInstanceStatusError,
};


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 8 guests