# HG changeset patch # User Chris Cannam # Date 1707507253 0 # Fri Feb 09 19:34:13 2024 +0000 # Branch incremental # Node ID 80000094fe383cb82dd935026f962775238f598d # Parent 1e0eb6374c7faa59337912232eb54e66ddd702df Add incremental read support diff --git a/bqaudiostream.sig b/bqaudiostream.sig --- a/bqaudiostream.sig +++ b/bqaudiostream.sig @@ -43,12 +43,20 @@ estimate; reading may stop earlier or continue beyond. *) val estimated_frame_count : t -> int option + (** Return true if the stream has explicit support for synchronous + incremental reading (i.e. reading while the file is still + being written without returning early on EOF). *) + val has_incremental_support : t -> bool + + (** Set timeouts for incremental reading, in milliseconds. *) + val set_incremental_timeouts : t * { retry : int, total : int } -> unit + (** Return the track name for the given stream, if available. *) val track_name : t -> string option (** Return the artist name for the given stream, if available. *) val artist_name : t -> string option - + (** Read interleaved audio data from the given stream. The given number of frames n will be read, if available, and the returned vector will have at most n * channels values in diff --git a/ffi/bqaudiostream.sml b/ffi/bqaudiostream.sml --- a/ffi/bqaudiostream.sml +++ b/ffi/bqaudiostream.sml @@ -63,7 +63,13 @@ case bqar_get_estimated_frame_count t of 0 => NONE | n => SOME (Int64.toInt n) - + + fun has_incremental_support t = + bqar_has_incremental_support t + + fun set_incremental_timeouts (t, { retry, total }) = + bqar_set_incremental_timeouts (t, retry, total) + fun rate t = Int64.toInt (bqar_get_retrieval_sample_rate t) diff --git a/ffi/impl-bqaudiostream.cpp b/ffi/impl-bqaudiostream.cpp --- a/ffi/impl-bqaudiostream.cpp +++ b/ffi/impl-bqaudiostream.cpp @@ -144,6 +144,17 @@ else return 0; } + Bool bqar_has_incremental_support(Pointer sptr) { + stream_rec *rsr = reinterpret_cast(sptr); + if (rsr->rstream) return rsr->rstream->hasIncrementalSupport(); + else return false; + } + + void bqar_set_incremental_timeouts(Pointer sptr, int64_t retry, int64_t total) { + stream_rec *rsr = reinterpret_cast(sptr); + if (rsr->rstream) rsr->rstream->setIncrementalTimeouts(retry, total); + } + int64_t bqar_get_retrieval_sample_rate(Pointer sptr) { stream_rec *rsr = reinterpret_cast(sptr); if (rsr->rstream) return rsr->rstream->getRetrievalSampleRate(); diff --git a/ffi/import-bqaudiostream.sml b/ffi/import-bqaudiostream.sml --- a/ffi/import-bqaudiostream.sml +++ b/ffi/import-bqaudiostream.sml @@ -46,6 +46,14 @@ _import "bqar_get_estimated_frame_count" private: audiostreamhandle -> Int64.int; + val bqar_has_incremental_support = + _import "bqar_has_incremental_support" private: + audiostreamhandle -> bool; + + val bqar_set_incremental_timeouts = + _import "bqar_set_incremental_timeouts" private: + audiostreamhandle * Int64.int * Int64.int -> unit; + val bqar_get_retrieval_sample_rate = _import "bqar_get_retrieval_sample_rate" private: audiostreamhandle -> Int64.int; diff --git a/sml/bqaudiostream.sml b/sml/bqaudiostream.sml --- a/sml/bqaudiostream.sml +++ b/sml/bqaudiostream.sml @@ -53,6 +53,8 @@ | SOME e => if Real.== (ratio, 1.0) then SOME e else SOME (Real.round (ratio * Real.fromInt e)) + fun has_incremental_support (t : t) = false + fun set_incremental_timeouts (t, timeouts) = () open IoResult