… | |
… | |
218 | sub OBSID() { 0x10000000000000 } # 2**52 |
218 | sub OBSID() { 0x10000000000000 } # 2**52 |
219 | |
219 | |
220 | our $JSON = eval { require JSON::XS; JSON::XS:: } |
220 | our $JSON = eval { require JSON::XS; JSON::XS:: } |
221 | || do { require JSON::PP; JSON::PP:: }; |
221 | || do { require JSON::PP; JSON::PP:: }; |
222 | |
222 | |
223 | our $JSON_CODER = |
223 | our $JSON_ENCODER = $JSON->new->utf8; |
|
|
224 | our $JSON_DECODER = $JSON->new->latin1; |
224 | |
225 | |
225 | our $mpv_path; # last mpv path used |
226 | our $mpv_path; # last mpv path used |
226 | our $mpv_optionlist; # output of mpv --list-options |
227 | our $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); |