Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/helpers/input_helpers.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 | |
| 3 #include <functional> | |
| 4 #include <list> | |
| 5 #include <SDK/input.h> | |
| 6 #include <SDK/tracks.h> | |
| 7 | |
| 8 class input_helper { | |
| 9 public: | |
| 10 input_helper(); | |
| 11 | |
| 12 typedef std::function<input_decoder::ptr (input_decoder::ptr, const char*, abort_callback&) > shim_t; | |
| 13 typedef std::function<void (input_decoder::ptr, const char*, abort_callback&) > infoHook_t; | |
| 14 | |
| 15 typedef std::function< bool ( file::ptr &, const char *, abort_callback & ) > ioFilter_t; | |
| 16 typedef std::list<ioFilter_t> ioFilters_t; | |
| 17 | |
| 18 struct decodeInfo_t { | |
| 19 bool m_flush_on_pause; | |
| 20 bool m_can_seek; | |
| 21 bool m_seeking_expensive; | |
| 22 }; | |
| 23 | |
| 24 struct decodeOpen_t { | |
| 25 bool m_from_redirect = false; | |
| 26 bool m_skip_hints = false; | |
| 27 unsigned m_flags = 0; | |
| 28 file::ptr m_hint; | |
| 29 unsigned m_setSampleRate = 0; | |
| 30 | |
| 31 ioFilters_t m_ioFilters; | |
| 32 event_logger::ptr m_logger; | |
| 33 infoHook_t m_infoHook; | |
| 34 shim_t m_shim; | |
| 35 }; | |
| 36 | |
| 37 void open(service_ptr_t<file> p_filehint,const playable_location & p_location,unsigned p_flags,abort_callback & p_abort,bool p_from_redirect = false,bool p_skip_hints = false); | |
| 38 void attach(input_decoder::ptr dec, const char * path); | |
| 39 | |
| 40 void open(const playable_location & location, abort_callback & abort, decodeOpen_t const & other); | |
| 41 | |
| 42 void open(service_ptr_t<file> p_filehint,trackRef p_location,unsigned p_flags,abort_callback & p_abort,bool p_from_redirect = false,bool p_skip_hints = false); | |
| 43 void open(trackRef location, abort_callback & abort, decodeOpen_t const & other); | |
| 44 | |
| 45 | |
| 46 //! Multilevel open helpers. | |
| 47 //! @returns Diagnostic/helper value: true if the decoder had to be re-opened entirely, false if the instance was reused. | |
| 48 bool open_path(const char * path, abort_callback & abort, decodeOpen_t const & other); | |
| 49 //! Multilevel open helpers. | |
| 50 void open_decoding(t_uint32 subsong, t_uint32 flags, abort_callback & p_abort); | |
| 51 | |
| 52 bool need_file_reopen(const char * newPath) const; | |
| 53 | |
| 54 decodeInfo_t decode_info(); | |
| 55 | |
| 56 void close(); | |
| 57 bool is_open(); | |
| 58 //! Single decode pass. | |
| 59 //! @returns True if a chunk was returned, false if EOF (no more audio to return). | |
| 60 bool run(audio_chunk & p_chunk,abort_callback & p_abort); | |
| 61 //! Single decode pass with raw output for integrity verification. \n | |
| 62 //! Throws pfc::exception_not_implemented if this input doesn't support run_raw(). | |
| 63 //! @returns True if a chunk was returned, false if EOF (no more audio to return). | |
| 64 bool run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort); | |
| 65 //! Single decode pass with raw output for integrity verification. \n | |
| 66 //! If the input doesn't support run_raw(), raw PCM is recreated from audio_chunk. | |
| 67 //! @returns True if a chunk was returned, false if EOF (no more audio to return). | |
| 68 bool run_raw_v2(audio_chunk& p_chunk, mem_block_container& p_raw, uint32_t knownBPS, abort_callback& p_abort); | |
| 69 void seek(double seconds,abort_callback & p_abort); | |
| 70 bool can_seek(); | |
| 71 size_t extended_param( const GUID & type, size_t arg1 = 0, void * arg2 = nullptr, size_t arg2size = 0); | |
| 72 static ioFilter_t ioFilter_full_buffer(t_filesize val ); | |
| 73 static ioFilter_t ioFilter_block_buffer(size_t val); | |
| 74 static ioFilter_t ioFilter_remote_read_ahead( size_t val ); | |
| 75 static ioFilter_t ioFilter_local_read_ahead(size_t val); | |
| 76 | |
| 77 void on_idle(abort_callback & p_abort); | |
| 78 bool get_dynamic_info(file_info & p_out,double & p_timestamp_delta); | |
| 79 bool get_dynamic_info_track(file_info & p_out,double & p_timestamp_delta); | |
| 80 void set_logger(event_logger::ptr ptr); | |
| 81 void set_pause(bool state); | |
| 82 bool flush_on_pause(); | |
| 83 | |
| 84 //! If this decoder has its own special position reporting, decoder-signaled logical decoding position will be returned. \n | |
| 85 //! Otherwise, position calculated from returned audio duration should be assumed. \n | |
| 86 //! Very few special-purpose decoders do this. | |
| 87 bool query_position( double & val ); | |
| 88 | |
| 89 //! Retrieves path of currently open file. | |
| 90 const char * get_path() const; | |
| 91 | |
| 92 //! Retrieves info about specific subsong of currently open file. | |
| 93 void get_info(t_uint32 p_subsong,file_info & p_info,abort_callback & p_abort); | |
| 94 | |
| 95 static void g_get_info(const playable_location & p_location,file_info & p_info,abort_callback & p_abort,bool p_from_redirect = false); | |
| 96 static void g_set_info(const playable_location & p_location,file_info & p_info,abort_callback & p_abort,bool p_from_redirect = false); | |
| 97 | |
| 98 | |
| 99 #ifdef FOOBAR2000_HAVE_METADB | |
| 100 static bool g_mark_dead(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,bit_array_var & p_mask,abort_callback & p_abort); | |
| 101 #endif | |
| 102 | |
| 103 static void fileOpenTools(service_ptr_t<file>& p_file, const char* p_path, ioFilters_t const& filters, abort_callback& p_abort); | |
| 104 | |
| 105 bool test_if_lockless(abort_callback&); | |
| 106 | |
| 107 uint32_t get_subsong_count() const { return m_input->get_subsong_count(); } | |
| 108 uint32_t get_subsong(uint32_t i) const { return m_input->get_subsong(i); } | |
| 109 private: | |
| 110 bool m_file_in_memory = false; | |
| 111 service_ptr_t<input_decoder> m_input; | |
| 112 pfc::string8 m_path; | |
| 113 event_logger::ptr m_logger; | |
| 114 }; | |
| 115 | |
| 116 #ifdef FOOBAR2000_HAVE_METADB | |
| 117 class NOVTABLE dead_item_filter : public abort_callback { | |
| 118 public: | |
| 119 virtual void on_progress(t_size p_position,t_size p_total) = 0; | |
| 120 | |
| 121 bool run(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,bit_array_var & p_mask); | |
| 122 }; | |
| 123 #endif | |
| 124 | |
| 125 class input_info_read_helper { | |
| 126 public: | |
| 127 input_info_read_helper() {} | |
| 128 void get_info(const playable_location & p_location,file_info & p_info,t_filestats & p_stats,abort_callback & p_abort); | |
| 129 #ifdef FOOBAR2000_HAVE_METADB | |
| 130 void get_info_check(const playable_location & p_location,file_info & p_info,t_filestats & p_stats,bool & p_reloaded,abort_callback & p_abort); | |
| 131 #endif | |
| 132 private: | |
| 133 void open(const char * p_path,abort_callback & p_abort); | |
| 134 | |
| 135 pfc::string8 m_path; | |
| 136 service_ptr_t<input_info_reader> m_input; | |
| 137 }; | |
| 138 | |
| 139 | |
| 140 //! openAudioData return value, see openAudioData() | |
| 141 struct openAudioData_t { | |
| 142 file::ptr audioData; // audio data stream | |
| 143 audio_chunk::spec_t audioSpec; // format description (sample rate, channel layout). | |
| 144 }; | |
| 145 | |
| 146 //! Opens the specified location as a stream of audio_samples. \n | |
| 147 //! Returns a file object that allows you to read the audio data stream as if it was a physical file, together with audio stream format description (sample rate, channel layout). \n | |
| 148 //! Please keep in mind that certain features of the returned file object are only as reliable as the underlying file format or decoder implementation allows them to be. \n | |
| 149 //! Reported exact file size may be either unavailable or unreliable if the file format does not let us known the exact value without decoding the whole file. \n | |
| 150 //! Seeking may be inaccurate with certain file formats. \n | |
| 151 //! In general, all file object methods will work as intended on core-supported file formats such as FLAC or WavPack. \n | |
| 152 //! However, if you want 100% functionality regardless of file format being worked with, mirror the content to a temp file and let go of the file object returned by openAudioData(). | |
| 153 openAudioData_t openAudioData(playable_location const & loc, bool bSeekable, file::ptr fileHint, abort_callback & aborter); | |
| 154 openAudioData_t openAudioData2(playable_location const & loc, input_helper::decodeOpen_t const & openArg, abort_callback & aborter); | |
| 155 | |
| 156 | |
| 157 //! openAudioData3 allows explicit format: float32 or float64, for use cases that need such. | |
| 158 enum class openAudioDataFormat { | |
| 159 float32, | |
| 160 float64 | |
| 161 }; | |
| 162 openAudioData_t openAudioData3(playable_location const& loc, input_helper::decodeOpen_t const& openArg, openAudioDataFormat format, abort_callback& aborter); |
