Ok, I found https://www.perlmonks.org/?node_id=867652 and without studying the thread in depth, I tried the following and it seems to work so far:
first ein deleteted
#define PERL_NO_GET_CONTEXT in the beginning of my Simple.xs file.
then I created a set_ctx function
void set_ctx()
{
dTHX;
mine = Perl_get_context;
}
(...)
MODULE = MPV::Simple PACKAGE = MPV::Simple
(...)
void
_set_context(ctx)
MPV::Simple ctx
CODE:
set_ctx();
and called it in the constructor in Simple.pm
sub new {
my ($class) = shift;
my $obj = $class->xs_create();
bless $obj;
$obj->_set_context();
return $obj;
}
Last I set Perl_Context in callp instead of dTHX:
void callp( SV* data)
{
//dTHX;
PERL_SET_CONTEXT(mine);
{
dMY_CXT;
dSP;
ENTER; SAVETMPS;
PUSHMARK(SP);
PUTBACK;
perl_call_sv(MY_CXT.callback,G_DISCARD|G_NOARGS);
SPAGAIN;
PUTBACK;FREETMPS;LEAVE;
}
}
Does that make any sense? Or is it ugly and bad? To be honest, I don't really understand the linked thread :-) And I am a little bit worried because of deleting PERL_NO_GET_CONTEXT..
I have to do further tests, whether the binding now works as expected..
Max
UPDATE:
Unfortunately this doesn't work, too. Sometimes it seems to work and the video is shown. But in other cases there is again the segfault or the thread is closed too early.