Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
stsaz committed Mar 1, 2025
1 parent 26b7782 commit 98d01ee
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 49 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ Features and notes by platform:
> Important: ALAC decoder is disabled by default in phiola/Android because of potential security issues (see https://github.com/macosforge/alac).
See also: [phiola Architecture](doc/arch/arch.md).


## Install

Expand Down
6 changes: 4 additions & 2 deletions src/acodec/aac-dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ static int aac_decode(void *ctx, phi_track *t)
a->state = R_CACHE_DATA;

} else {
dbglog(t, "decoded %u samples @%U"
, out.len / phi_af_size(&a->aac.fmt), apos);
const fdkaac_info *inf = &a->aac.info;
dbglog(t, "decoded %u samples @%U aot:%u rate:%u chan:%u br:%u"
, out.len / phi_af_size(&a->aac.fmt), apos
, inf->aot, inf->rate, inf->channels, inf->bitrate);
}

switch (a->state) {
Expand Down
2 changes: 1 addition & 1 deletion src/acodec/alib3-bridge/flac-dec-if.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
2015, Simon Zolin */

#pragma once
#include <avpack/flac-fmt.h>
#include <avpack/base/flac.h>
#include <FLAC/FLAC-phi.h>

typedef struct ffflac_dec {
Expand Down
2 changes: 1 addition & 1 deletion src/acodec/alib3-bridge/flac-enc-if.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once
#include <ffbase/vector.h>
#include <avpack/flac-fmt.h>
#include <avpack/base/flac.h>
#include <FLAC/FLAC-phi.h>

enum {
Expand Down
6 changes: 1 addition & 5 deletions src/acodec/ape-dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ static void ape_dec_free(void *ctx, phi_track *t)
phi_track_free(t, a);
}

/** Return bits/sec. */
#define pcm_brate(bytes, samples, rate) \
FFINT_DIVSAFE((uint64)(bytes) * 8 * (rate), samples)

static void ape_info(struct ape_dec *a, phi_track *t, const ffape_info *info)
{
t->audio.decoder = "APE";
Expand All @@ -38,7 +34,7 @@ static void ape_info(struct ape_dec *a, phi_track *t, const ffape_info *info)
};
t->audio.format = f;
t->data_type = "pcm";
t->audio.bitrate = pcm_brate(t->input.size, t->audio.total, info->fmt.rate);
t->audio.bitrate = bitrate_compute(t->input.size, t->audio.total, info->fmt.rate);
t->audio.total = info->total_samples;
}

Expand Down
7 changes: 3 additions & 4 deletions src/acodec/opus-enc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ struct opus_enc {
uint state;
struct phi_af fmt;
ffopus_enc opus;
uint64 npkt;
uint64 endpos;
};

Expand Down Expand Up @@ -42,6 +41,7 @@ static int opus_enc_encode(void *ctx, phi_track *t)
{
struct opus_enc *o = ctx;
int r;
uint in_len;
enum { W_CONV, W_CREATE, W_DATA };

switch (o->state) {
Expand Down Expand Up @@ -91,14 +91,14 @@ static int opus_enc_encode(void *ctx, phi_track *t)
if (t->chain_flags & PHI_FFWD)
o->opus.pcm = (void*)t->data_in.ptr, o->opus.pcmlen = t->data_in.len;

in_len = o->opus.pcmlen;
r = ffopus_encode(&o->opus);

switch (r) {
case FFOPUS_RMORE:
return PHI_MORE;

case FFOPUS_RDONE:

t->audio.pos = ffopus_enc_pos(&o->opus);
return PHI_DONE;

Expand All @@ -112,9 +112,8 @@ static int opus_enc_encode(void *ctx, phi_track *t)

t->audio.pos = o->endpos;
o->endpos = ffopus_enc_pos(&o->opus);
o->npkt++;
dbglog(t, "encoded %L samples into %L bytes @%U [%U]"
, (t->data_in.len - o->opus.pcmlen) / phi_af_size(&o->fmt), o->opus.data.len
, (in_len - o->opus.pcmlen) / phi_af_size(&o->fmt), o->opus.data.len
, t->audio.pos, o->endpos);
ffstr_set(&t->data_out, o->opus.data.ptr, o->opus.data.len);
return PHI_DATA;
Expand Down
5 changes: 5 additions & 0 deletions src/afilter/soxr-conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ static void* soxr_open(phi_track *t)
.o_interleaved = oaf.interleaved,
.channels = t->aconv.in.channels,
};
if (!conf.i_format || !conf.o_format) {
errlog(t, "sample rate conversion with %s sample format is not supported"
, (!conf.i_format) ? phi_af_name(t->aconv.in.format) : phi_af_name(oaf.format));
goto end;
}
if ((r = phi_soxr_create(&c->soxr, &conf))
|| (core->conf.log_level >= PHI_LOG_DEBUG)) {
log_pcmconv(r, &t->aconv.in, &t->aconv.out, t);
Expand Down
6 changes: 4 additions & 2 deletions src/format/aac-read.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ static int aac_adts_process(void *ctx, phi_track *t)
}

t->audio.pos = apos;
dbglog(t, "passing frame #%u samples:%u @%U size:%u"
const struct aacread_info *i = &a->adts.info;
dbglog(t, "passing frame #%u samples:%u @%U size:%u aot:%u rate:%u chan:%u"
, a->frno, aacread_frame_samples(&a->adts), t->audio.pos
, out.len);
, out.len
, i->codec, i->sample_rate, i->channels);
a->frno++;
t->data_out = out;
return PHI_DATA;
Expand Down
6 changes: 3 additions & 3 deletions src/format/detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
2020, Simon Zolin */

#include <track.h>
#include <avpack/mpeg1-fmt.h>
#include <avpack/base/mpeg1.h>
#include <avpack/aac-read.h>

enum FILE_FORMAT {
Expand Down Expand Up @@ -118,8 +118,8 @@ int file_format_detect(const void *data, ffsize len)
}

if (len >= 7) {
struct aacadts_hdr h;
if (!aacadts_parse(&h, d))
struct adts_hdr h;
if (adts_hdr_read(&h, d, len) > 0)
return FILE_AAC;
}

Expand Down
2 changes: 0 additions & 2 deletions src/format/flac-read.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ static int flac_in_read(void *ctx, phi_track *t)
ffstr out = {};

if (t->chain_flags & PHI_FSTOP) {

return PHI_LASTOUT;
}

Expand All @@ -115,7 +114,6 @@ static int flac_in_read(void *ctx, phi_track *t)
case FLACREAD_MORE:
if (t->chain_flags & PHI_FFIRST) {
warnlog(t, "file is incomplete");

return PHI_DONE;
}
return PHI_MORE;
Expand Down
6 changes: 1 addition & 5 deletions src/format/ogg-read.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,13 @@ static int add_decoder(struct ogg_r *o, phi_track *t, ffstr data)
return 0;
}

/** Return bits/sec. */
#define pcm_brate(bytes, samples, rate) \
FFINT_DIVSAFE((uint64)(bytes) * 8 * (rate), samples)

#define pcm_time(samples, rate) ((uint64)(samples) * 1000 / (rate))

static uint file_bitrate(phi_track *t, oggread *og, uint sample_rate)
{
if (t->audio.total == 0 || og->total_size == 0)
return 0;
return pcm_brate(og->total_size, t->audio.total, sample_rate);
return bitrate_compute(og->total_size, t->audio.total, sample_rate);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/format/opus-meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <track.h>
#include <avpack/vorbistag.h>
#include <avpack/opus-fmt.h>
#include <avpack/base/opus.h>

extern int vorbistag_read(phi_track *t, ffstr vc);

Expand Down
4 changes: 2 additions & 2 deletions src/format/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <avpack/ogg-read.h>
#include <avpack/ogg-write.h>
#include <avpack/vorbistag.h>
#include <avpack/opus-fmt.h>
#include <avpack/vorbis-fmt.h>
#include <avpack/flac-read.h>
#include <avpack/base/opus.h>
#include <avpack/base/vorbis.h>
#include <ffsys/file.h>
#include <ffsys/path.h>

Expand Down
2 changes: 1 addition & 1 deletion src/format/vorbis-meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <track.h>
#include <avpack/vorbistag.h>
#include <avpack/vorbis-fmt.h>
#include <avpack/base/vorbis.h>

struct vorbismeta {
uint state;
Expand Down
1 change: 0 additions & 1 deletion src/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ struct phi_track {

// (ogg|mkv).read -> ogg.write
uint64 ogg_granule_pos; // stream_copy=1: granule-position value from source
uint ogg_flush :1;
uint ogg_gen_opus_tag :1; // ogg.write must generate Opus-tag packet

/** Order AO filter to pause playing, then just wait until the track is woken up.
Expand Down
92 changes: 75 additions & 17 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,16 @@ test_convert_encode() {
./phiola pl co_wav_he2.m4a | grep 'HE-AACv2'

convert__from_to wav ogg
./phiola i co_wav.ogg | grep -E '95,... samples'
./phiola i co_wav.ogg | grep -E '96,000 samples'
./phiola i co_wav.ogg -peaks | grep '96,000 total'
./phiola i -u 1 co_wav.ogg -peaks | grep -E '48,... total'
./phiola i -s 1 co_wav.ogg -peaks | grep -E '4[78],... total'
./phiola i -s 1 co_wav.ogg -peaks | grep -E '4[678],... total'

convert__from_to wav opus
./phiola i co_wav.opus | grep -E '94,... samples'
./phiola i co_wav.opus | grep -E '96,... samples'
./phiola i co_wav.opus -peaks | grep '96,000 total'
./phiola i -u 1 co_wav.opus -peaks | grep '48,000 total'
./phiola i -s 1 co_wav.opus -peaks | grep -E '46,... total'
./phiola i -s 1 co_wav.opus -peaks | grep -E '48,000 total'
}

test_convert_parallel() {
Expand Down Expand Up @@ -351,6 +351,74 @@ test_copy_seek() {
./phiola i -peaks $2 | grep -E "$3"
}

test_copy_ogg_ogg() {
if ! test -f co_vorbis.ogg ; then
./phiola co co.wav -o co_vorbis.ogg -f
./phiola co co.wav -o co_opus.opus -f
fi

# Copy ogg -> ogg (Opus)
I=co_opus.opus
O=copy_u_opus.ogg
./phiola -D co -copy -f -u 1 $I -o $O | grep -E 'page |page:'
./phiola i -peaks $O | grep 'samples'
# Note: due to Opus preskip value, decoder may cut/skip samples from the last packet, thus making the file length less than was requested

O=copy_s_opus.ogg
./phiola -D co -copy -f -s 1 $I -o $O | grep -E 'page |page:'
./phiola i -peaks $O | grep 'samples'

O=copy_su_opus.ogg
./phiola -D co -copy -f -s 1 -u 2 $I -o $O | grep -E 'page |page:'
./phiola i -peaks $O | grep 'samples'

# Copy ogg -> ogg (Vorbis)
I=co_vorbis.ogg
O=copy_u_vorbis.ogg
# Note: copy less than 1 second or else the 2nd page will be also copied because 48000 is not divisible by Vorbis packet length
./phiola -D co -copy -f -u 0.950 $I -o $O | grep -E 'page |page:'
./phiola i -peaks $O | grep 'samples'

O=copy_s_vorbis.ogg
./phiola -D co -copy -f -s 1 $I -o $O | grep -E 'page |page:'
./phiola i -peaks $O | grep 'samples'
# Note: the output file length is less than requested when seeking is performed, because the first packet is skipped/delayed by decoder

O=copy_su_vorbis.ogg
./phiola -D co -copy -f -s 1 -u 2 $I -o $O | grep -E 'page |page:'
./phiola i -peaks $O | grep 'samples'
}

test_copy_mkv_ogg() {
# Copy mkv -> ogg (Opus)
I=fm_opus.mkv
O=copy_u_opus_mkv.ogg
./phiola -D co -copy -f -u 1 $I -o $O | grep -a 'page:'
./phiola i -peaks $O | grep 'samples'

O=copy_s_opus_mkv.ogg
./phiola -D co -copy -f -s 1 $I -o $O | grep -a 'page:'
./phiola i -peaks $O | grep 'samples'

O=copy_su_opus_mkv.ogg
./phiola -D co -copy -f -s 1 -u 2 $I -o $O | grep -a 'page:'
./phiola i -peaks $O | grep 'samples'

# Copy mkv -> ogg (Vorbis)
I=fm_vorbis.mkv
O=copy_u_vorbis_mkv.ogg
./phiola -D co -copy -f -u 0.950 $I -o $O | grep -a 'page:'
./phiola i -peaks $O | grep 'samples'

O=copy_s_vorbis_mkv.ogg
./phiola -D co -copy -f -s 1 $I -o $O | grep -a 'page:'
./phiola i -peaks $O | grep 'samples'

O=copy_su_vorbis_mkv.ogg
./phiola -D co -copy -f -s 1 -u 2 $I -o $O | grep -a 'page:'
./phiola i -peaks $O | grep 'samples'
}

test_copy() {
if ! test -f co.wav ; then
./phiola rec -rate 48000 -o co.wav -f -u 2
Expand All @@ -360,17 +428,16 @@ test_copy() {
ffmpeg_encode co.wav
fi

test_copy_ogg_ogg
test_copy_mkv_ogg

## Until
test_copy_until fm_aac.aac copy_u_aac.m4a '4[89],...'
test_copy_until fm_aac.mkv copy_u_mkv.m4a '48,...'
test_copy_until fm_aac.mp4 copy_u_mp4.m4a '48,...'
test_copy_until fm_mp3.mkv copy_u_mp3_mkv.mp3 '4[89],...'
test_copy_until fm_mp3.mp3 copy_u_mp3.mp3 '4[89],...'
test_copy_until fm_mp3_320.mp3 copy_u_mp3_320.mp3 '4[89],...'
test_copy_until fm_opus.mkv copy_u_opus_mkv.ogg '4[6789],...'
test_copy_until fm_opus.ogg copy_u_opus.ogg '4[78],...'
test_copy_until fm_vorbis.mkv copy_u_vorbis_mkv.ogg '4[78],...'
test_copy_until fm_vorbis.ogg copy_u_vorbis.ogg '..,...'

## Seek
## mkv seeking implementation is not precise
Expand All @@ -381,22 +448,13 @@ test_copy() {
test_copy_seek fm_mp3.mkv copy_s_mp3_mkv.mp3 '4[789],...'
test_copy_seek fm_mp3.mp3 copy_s_mp3.mp3 '5[01],...'
test_copy_seek fm_mp3_320.mp3 copy_s_mp3_320.mp3 '5[01],...'
test_copy_seek fm_opus.mkv copy_s_opus_mkv.ogg '4[789],...'
test_copy_seek fm_opus.ogg copy_s_opus.ogg '48,...'
test_copy_seek fm_vorbis.mkv copy_s_vorbis_mkv.ogg '4[6789],...'
./phiola co co.wav -o co_vorbis.ogg -f
test_copy_seek co_vorbis.ogg copy_s_vorbis.ogg '4[78],...'

## Seek + Until
O=copy_aac.m4a ; ./phiola co -copy -f -s 1 -u 2 fm_aac.aac -o $O ; ./phiola pl $O
O=copy_aac_mkv.m4a ; ./phiola co -copy -f -s 1 -u 2 fm_aac.mkv -o $O ; ./phiola pl $O
O=copy_mp4.m4a ; ./phiola co -copy -f -s 1 -u 2 fm_aac.mp4 -o $O ; ./phiola pl $O
O=copy_mp3.mp3 ; ./phiola co -copy -f -s 1 -u 2 fm_mp3.mp3 -o $O ; ./phiola pl $O
O=copy_mp3_mkv.mp3 ; ./phiola co -copy -f -s 1 -u 2 fm_mp3.mkv -o $O ; ./phiola pl $O
O=copy_opus_mkv.ogg ; ./phiola co -copy -f -s 1 -u 2 fm_opus.mkv -o $O ; ./phiola pl $O
O=copy_opus.ogg ; ./phiola co -copy -f -s 1 -u 2 fm_opus.ogg -o $O ; ./phiola pl $O
O=copy_vorbis_mkv.ogg ; ./phiola co -copy -f -s 1 -u 2 fm_vorbis.mkv -o $O ; ./phiola pl $O
O=copy_vorbis.ogg ; ./phiola co -copy -f -s 1 -u 2 fm_vorbis.ogg -o $O ; ./phiola pl $O
}

test_danorm() {
Expand Down

0 comments on commit 98d01ee

Please sign in to comment.