Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OggFlac support #987

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Slim/Formats/FLAC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ sub _addInfoTags {
$tags->{SIZE} = $info->{file_size};
$tags->{SECS} = $info->{song_length_ms} / 1000;
$tags->{OFFSET} = 0; # the header is an important part of the file. don't skip it
$tags->{BITRATE} = sprintf "%d", $info->{bitrate};
$tags->{BITRATE} = sprintf "%d", ($info->{bitrate} || $info->{bitrage_ogg});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a bit of a rage in Ogg? 😁

Don't know whether this typo is needed for compatibility with Audio::Scan?

$tags->{VBR_SCALE} = 1;
$tags->{RATE} = $info->{samplerate};
$tags->{SAMPLESIZE} = $info->{bits_per_sample};
Expand Down Expand Up @@ -920,11 +920,11 @@ so we use this to set the track duaration value.
=cut

sub scanBitrate {
my ( $class, $fh, $url ) = @_;
my ( $class, $fh, $url, $format ) = @_;

seek $fh, 0, 0;

my $s = Audio::Scan->scan_fh( flac => $fh );
my $s = Audio::Scan->scan_fh( $format || 'flac' => $fh );

my $info = $s->{info};

Expand Down
54 changes: 50 additions & 4 deletions Slim/Formats/OggFLAC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,58 @@ package Slim::Formats::OggFLAC;

use base qw(Slim::Formats::FLAC);

sub findFrameBoundaries { 0 }
use Slim::Utils::Log;
use Audio::Scan;

sub scanBitrate{
return (-1, undef);
my $log = logger('scan.scanner');
my $sourcelog = logger('player.source');

=head2 getInitialAudioBlock( $fh, $offset, $time )

Get the OggFlac header. For now, we use a fixed header
that resets MD5 and frame number to 0 upon seeking.
NB: that function is only used when seeking, othersise
the entire file us used untouched.

=cut

sub getInitialAudioBlock {
my ($class, $fh, $track, $time) = @_;

open my $localFh, '<&=', $fh;
my $info = Audio::Scan->find_frame_fh_return_info( ogf => $localFh, 0 );

main::INFOLOG && $sourcelog->is_info && $sourcelog->info('Reading initial audio block of ', length $info->{seek_header});

return $info->{seek_header};
}

=head2 findFrameBoundaries( $fh, $offset, $time )

Seeks to the Ogg block containing the sample at $time.

=cut

sub findFrameBoundaries {
my ( $class, $fh, $offset, $time ) = @_;

return (defined $fh && defined $time) ?
Audio::Scan->find_frame_fh( ogf => $fh, int($time * 1000) ) :
0;
}

=head2 scanBitrate( $fh )

Intended to scan the bitrate of a remote stream, although for FLAC this data
is not accurate, but we can get the duration of the remote file from the header,
so we use this to set the track duaration value.

=cut

sub scanBitrate {
my ( $class, $fh, $url ) = @_;
return $class->SUPER($fh, $url, 'ogf');
}

sub canSeek { 0 }

1;
2 changes: 1 addition & 1 deletion types.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mp4x - - audio
mp3 mp2,mp3 audio/mpeg,audio/mp3,audio/mp3s,audio/x-mpeg,audio/mpeg3,audio/mpg audio
mpc mpc,mp+ audio/x-musepack audio
ogg ogg,oga audio/x-ogg,application/ogg,audio/ogg,application/x-ogg audio
ogf - audio/ogg;codecs=flac audio
ogf ogf audio/ogg;codecs=flac audio
ops opus audio/opus,audio/ogg;codecs=opus audio
pcm pcm audio/L16,audio/x-pcm audio
pdf pdf application/pdf -
Expand Down