From 98d01eead76e66281ac01a5fbc9142c46e87212c Mon Sep 17 00:00:00 2001 From: Simon Zolin <4729655+stsaz@users.noreply.github.com> Date: Sat, 1 Mar 2025 08:47:02 +0300 Subject: [PATCH] minor --- README.md | 2 - src/acodec/aac-dec.h | 6 +- src/acodec/alib3-bridge/flac-dec-if.h | 2 +- src/acodec/alib3-bridge/flac-enc-if.h | 2 +- src/acodec/ape-dec.h | 6 +- src/acodec/opus-enc.h | 7 +- src/afilter/soxr-conv.c | 5 ++ src/format/aac-read.h | 6 +- src/format/detector.h | 6 +- src/format/flac-read.h | 2 - src/format/ogg-read.h | 6 +- src/format/opus-meta.h | 2 +- src/format/tag.c | 4 +- src/format/vorbis-meta.h | 2 +- src/track.h | 1 - test.sh | 92 ++++++++++++++++++++++----- 16 files changed, 102 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 75468c1..56dc460 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/acodec/aac-dec.h b/src/acodec/aac-dec.h index 5e07a82..aba0f2f 100644 --- a/src/acodec/aac-dec.h +++ b/src/acodec/aac-dec.h @@ -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) { diff --git a/src/acodec/alib3-bridge/flac-dec-if.h b/src/acodec/alib3-bridge/flac-dec-if.h index b7391d6..be464f9 100644 --- a/src/acodec/alib3-bridge/flac-dec-if.h +++ b/src/acodec/alib3-bridge/flac-dec-if.h @@ -2,7 +2,7 @@ 2015, Simon Zolin */ #pragma once -#include +#include #include typedef struct ffflac_dec { diff --git a/src/acodec/alib3-bridge/flac-enc-if.h b/src/acodec/alib3-bridge/flac-enc-if.h index 7186b17..e259d8d 100644 --- a/src/acodec/alib3-bridge/flac-enc-if.h +++ b/src/acodec/alib3-bridge/flac-enc-if.h @@ -3,7 +3,7 @@ #pragma once #include -#include +#include #include enum { diff --git a/src/acodec/ape-dec.h b/src/acodec/ape-dec.h index 0c9af98..13e9cb9 100644 --- a/src/acodec/ape-dec.h +++ b/src/acodec/ape-dec.h @@ -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"; @@ -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; } diff --git a/src/acodec/opus-enc.h b/src/acodec/opus-enc.h index cceb93e..cf35bd2 100644 --- a/src/acodec/opus-enc.h +++ b/src/acodec/opus-enc.h @@ -7,7 +7,6 @@ struct opus_enc { uint state; struct phi_af fmt; ffopus_enc opus; - uint64 npkt; uint64 endpos; }; @@ -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) { @@ -91,6 +91,7 @@ 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) { @@ -98,7 +99,6 @@ static int opus_enc_encode(void *ctx, phi_track *t) return PHI_MORE; case FFOPUS_RDONE: - t->audio.pos = ffopus_enc_pos(&o->opus); return PHI_DONE; @@ -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; diff --git a/src/afilter/soxr-conv.c b/src/afilter/soxr-conv.c index 2737238..9ab4f66 100644 --- a/src/afilter/soxr-conv.c +++ b/src/afilter/soxr-conv.c @@ -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); diff --git a/src/format/aac-read.h b/src/format/aac-read.h index ca33467..5c30aa5 100644 --- a/src/format/aac-read.h +++ b/src/format/aac-read.h @@ -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; diff --git a/src/format/detector.h b/src/format/detector.h index bd7bdaa..3d40412 100644 --- a/src/format/detector.h +++ b/src/format/detector.h @@ -2,7 +2,7 @@ 2020, Simon Zolin */ #include -#include +#include #include enum FILE_FORMAT { @@ -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; } diff --git a/src/format/flac-read.h b/src/format/flac-read.h index ed6fcb8..b673ed5 100644 --- a/src/format/flac-read.h +++ b/src/format/flac-read.h @@ -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; } @@ -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; diff --git a/src/format/ogg-read.h b/src/format/ogg-read.h index 3852989..aa547b6 100644 --- a/src/format/ogg-read.h +++ b/src/format/ogg-read.h @@ -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); } /* diff --git a/src/format/opus-meta.h b/src/format/opus-meta.h index 3dc2086..bf186ff 100644 --- a/src/format/opus-meta.h +++ b/src/format/opus-meta.h @@ -3,7 +3,7 @@ #include #include -#include +#include extern int vorbistag_read(phi_track *t, ffstr vc); diff --git a/src/format/tag.c b/src/format/tag.c index 26817d5..15a867f 100644 --- a/src/format/tag.c +++ b/src/format/tag.c @@ -10,9 +10,9 @@ #include #include #include -#include -#include #include +#include +#include #include #include diff --git a/src/format/vorbis-meta.h b/src/format/vorbis-meta.h index c627d55..ce94645 100644 --- a/src/format/vorbis-meta.h +++ b/src/format/vorbis-meta.h @@ -3,7 +3,7 @@ #include #include -#include +#include struct vorbismeta { uint state; diff --git a/src/track.h b/src/track.h index 46f87c8..bb5c5a8 100644 --- a/src/track.h +++ b/src/track.h @@ -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. diff --git a/test.sh b/test.sh index ebdea4b..1f0eac1 100644 --- a/test.sh +++ b/test.sh @@ -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() { @@ -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 @@ -360,6 +428,9 @@ 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,...' @@ -367,10 +438,6 @@ test_copy() { 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 @@ -381,11 +448,6 @@ 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 @@ -393,10 +455,6 @@ test_copy() { 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() {