Skip to content

Commit

Permalink
flac & socks fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe44 committed Apr 4, 2021
1 parent 359cd3a commit 907a6af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
17 changes: 15 additions & 2 deletions Slim/Formats/FLAC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,8 @@ sub parseStream {
my ( $class, $dataref, $args, $length ) = @_;

$args->{_scanbuf} .= $$dataref;
return -1 if length $args->{_scanbuf} < 32*1024;
my $buflen = length $args->{_scanbuf};
return -1 if $buflen < 32*1024;

my $fh = File::Temp->new( DIR => Slim::Utils::Misc::getTempDir);
$fh->write($args->{_scanbuf});
Expand All @@ -954,7 +955,19 @@ sub parseStream {
return undef unless $info->{samplerate};

$info->{fh} = $fh;
$info->{avg_bitrate} = int(8*1000 * ($length - $info->{audio_offset}) / $info->{song_length_ms}) if $info->{song_length_ms} && $length;

# Audio::Scan tries to guess total_sample which is in FLAC header. When codec does not know, it sets it
# to 0 and then Audio::Scan seeks to eof and read sample numbers from there which is incorrect here. So we
# assume that in best cases, FLAC has a compression ratio of 8 and use that as a limit.
my $maxSamples = ($buflen - $info->{audio_offset}) / ($info->{channels} * $info->{bits_per_sample} / 8) * 8;

if ($maxSamples < 0 || $info->{total_samples} < $maxSamples) {
$log->warn("Can't estimate track duration (got $info->{song_length_ms} ms)");
$info->{song_length_ms} = 0;
$info->{total_samples} = 0;
} elsif ($length) {
$info->{avg_bitrate} = int(8*1000 * ($length - $info->{audio_offset}) / $info->{song_length_ms});
}

return $info;
}
Expand Down
3 changes: 1 addition & 2 deletions Slim/Networking/Async/Socket/HTTPSSocks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sub new {
# change PeerAddr to proxy with no handshake (no deepcopy needed)
my %params = %args;
$params{PeerAddr} = $args{ProxyAddr};
$params{PeerPort} = $args{ProxyPort};
$params{PeerPort} = $args{ProxyPort} || 1080;
$params{SSL_StartHandshake} => 0;

# and connect parent's class to it
Expand All @@ -24,7 +24,6 @@ sub new {
$params{AuthType} = $args{Username} ? 'userpass' : 'none';
$params{ConnectAddr} = $args{PeerAddr} || $args{Host};
$params{ConnectPort} = $args{PeerPort};
$params{ProxyPort} = $args{ProxyPort} || 1080;
$params{Blocking} => 1;

# and initiate negotiation (we'll become IO::Socket::Socks)
Expand Down
3 changes: 1 addition & 2 deletions Slim/Networking/Async/Socket/HTTPSocks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sub new {
# change PeerAddr to proxy (no deepcopy needed)
my %params = %args;
$params{PeerAddr} = $args{ProxyAddr};
$params{PeerPort} = $args{ProxyPort};
$params{PeerPort} = $args{ProxyPort} | 1080;
$params{Blocking} => 1;

# and connect parent's class to it (better block)
Expand All @@ -24,7 +24,6 @@ sub new {
$params{AuthType} = $args{Username} ? 'userpass' : 'none';
$params{ConnectAddr} = $args{PeerAddr} || $args{Host};
$params{ConnectPort} = $args{PeerPort};
$params{ProxyPort} = $args{ProxyPort} || 1080;

# and initiate negotiation (we'll become IO::Socket::Socks)
$sock = IO::Socket::Socks->start_SOCKS($sock, %params) || return;
Expand Down

0 comments on commit 907a6af

Please sign in to comment.