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.12 by root, Mon Mar 20 13:44:40 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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines