ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MPV/MPV.pm
(Generate patch)

Comparing AnyEvent-MPV/MPV.pm (file contents):
Revision 1.11 by root, Mon Mar 20 13:32:52 2023 UTC vs.
Revision 1.13 by root, Mon Mar 20 14:42:40 2023 UTC

218sub OBSID() { 0x10000000000000 } # 2**52 218sub OBSID() { 0x10000000000000 } # 2**52
219 219
220our $JSON = eval { require JSON::XS; JSON::XS:: } 220our $JSON = eval { require JSON::XS; JSON::XS:: }
221 || do { require JSON::PP; JSON::PP:: }; 221 || do { require JSON::PP; JSON::PP:: };
222 222
223our $JSON_CODER = 223our $JSON_ENCODER = $JSON->new->utf8;
224our $JSON_DECODER = $JSON->new->latin1;
224 225
225our $mpv_path; # last mpv path used 226our $mpv_path; # last mpv path used
226our $mpv_optionlist; # output of mpv --list-options 227our $mpv_optionlist; # output of mpv --list-options
227 228
228=item $mpv = AnyEvent::MPV->new (key => value...) 229=item $mpv = AnyEvent::MPV->new (key => value...)
400 while ($buf =~ s/^([^\n]+)\n//) { 401 while ($buf =~ s/^([^\n]+)\n//) {
401 $trace->("mpv>" => "$1"); 402 $trace->("mpv>" => "$1");
402 403
403 if ("{" eq substr $1, 0, 1) { 404 if ("{" eq substr $1, 0, 1) {
404 eval { 405 eval {
405 my $reply = $JSON->new->latin1->decode ($1); 406 my $reply = $JSON_DECODER->decode ($1);
406 407
407 if (defined (my $event = delete $reply->{event})) { 408 if (defined (my $event = delete $reply->{event})) {
408 if ( 409 if (
409 $event eq "client-message" 410 $event eq "client-message"
410 and $reply->{args}[0] eq "AnyEvent::MPV" 411 and $reply->{args}[0] eq "AnyEvent::MPV"
468 $self->{_cmd} = sub { 469 $self->{_cmd} = sub {
469 my $cv = AE::cv; 470 my $cv = AE::cv;
470 471
471 $self->{cmdcv}{++$reqid} = $cv; 472 $self->{cmdcv}{++$reqid} = $cv;
472 473
473 my $cmd = $JSON->new->utf8->encode ({ command => ref $_[0] ? $_[0] : \@_, request_id => $reqid*1 }); 474 my $cmd = $JSON_ENCODER->encode ({ command => ref $_[0] ? $_[0] : \@_, request_id => $reqid*1 });
474 475
475 # (un-)apply escape_binary hack 476 # (un-)apply escape_binary hack
476 $cmd =~ s/\xf4\x8e\x97\x9f(..)/sprintf sprintf "\\x%02x", hex $1/ges; # f48e979f == 10e5df in utf-8 477 $cmd =~ s/\xf4\x8e\x97\x9f(..)/sprintf sprintf "\\x%02x", hex $1/ges; # f48e979f == 10e5df in utf-8
477 478
478 $trace->(">mpv" => $cmd); 479 $trace->(">mpv" => $cmd);
697or mix both approaches as you see fit. 698or mix both approaches as you see fit.
698 699
699=cut 700=cut
700 701
701sub AnyEvent::MPV::Unevent::DESTROY { 702sub AnyEvent::MPV::Unevent::DESTROY {
702 my ($evtcb, $evtid) = @{$_[0]}; 703 my ($evtcb, $event, $evtid) = @{$_[0]};
703 delete $evtcb->{$evtid}; 704 delete $evtcb->{$event}{$evtid};
704} 705}
705 706
706sub register_event { 707sub register_event {
707 my ($self, $event, $cb) = @_; 708 my ($self, $event, $cb) = @_;
708 709
710 711
711 my $evtid = ++$self->{evtid}; 712 my $evtid = ++$self->{evtid};
712 $self->{evtcb}{$event}{$evtid} = $cb; 713 $self->{evtcb}{$event}{$evtid} = $cb;
713 714
714 defined wantarray 715 defined wantarray
715 and bless [$self->{evtcb}, $evtid], AnyEvent::MPV::Unevent:: 716 and bless [$self->{evtcb}, $event, $evtid], AnyEvent::MPV::Unevent::
716} 717}
717 718
718=item [$guard] = $mpv->observe_property ($name => $coderef->($mpv, $name, $value)) 719=item [$guard] = $mpv->observe_property ($name => $coderef->($mpv, $name, $value))
719 720
720=item [$guard] = $mpv->observe_property_string ($name => $coderef->($mpv, $name, $value)) 721=item [$guard] = $mpv->observe_property_string ($name => $coderef->($mpv, $name, $value))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines