Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/helpers/input_fix_seeking.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 "duration_counter.h" | |
| 4 | |
| 5 // Wrapper to implement input_flag_allow_inaccurate_seeking semantics with decoders that do not implement seeking properly. | |
| 6 // If input_flag_allow_inaccurate_seeking is not specified, brute force seeking is used. | |
| 7 template<typename base_t> | |
| 8 class input_fix_seeking : public base_t { | |
| 9 public: | |
| 10 input_fix_seeking() : m_active() {} | |
| 11 | |
| 12 void decode_initialize(unsigned p_flags,abort_callback & p_abort) { | |
| 13 base_t::decode_initialize( p_flags, p_abort ); | |
| 14 m_active = ( p_flags & input_flag_allow_inaccurate_seeking ) == 0; | |
| 15 m_position = 0; | |
| 16 m_decodeFrom = 0; | |
| 17 } | |
| 18 | |
| 19 void decode_initialize(t_uint32 p_subsong,unsigned p_flags,abort_callback & p_abort) { | |
| 20 base_t::decode_initialize( p_subsong, p_flags, p_abort ); | |
| 21 m_active = ( p_flags & input_flag_allow_inaccurate_seeking ) == 0; | |
| 22 m_position = 0; | |
| 23 } | |
| 24 | |
| 25 bool decode_run(audio_chunk & p_chunk,abort_callback & p_abort) { | |
| 26 if ( ! m_active ) { | |
| 27 return base_t::decode_run ( p_chunk, p_abort ); | |
| 28 } | |
| 29 for ( ;; ) { | |
| 30 p_abort.check(); | |
| 31 if (! base_t::decode_run( p_chunk, p_abort ) ) return false; | |
| 32 | |
| 33 double p = m_position.query(); | |
| 34 m_position += p_chunk; | |
| 35 if ( m_decodeFrom > p ) { | |
| 36 auto skip = audio_math::time_to_samples( m_decodeFrom - p, p_chunk.get_sample_rate() ); | |
| 37 if ( skip >= p_chunk.get_sample_count() ) continue; | |
| 38 if ( skip > 0 ) { | |
| 39 p_chunk.skip_first_samples( (size_t) skip ); | |
| 40 } | |
| 41 } | |
| 42 return true; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void decode_seek(double p_seconds,abort_callback & p_abort) { | |
| 47 if ( m_active ) { | |
| 48 if ( ! this->decode_can_seek() ) throw exception_io_object_not_seekable(); | |
| 49 m_decodeFrom = p_seconds; | |
| 50 if ( m_decodeFrom < m_position.query() ) { | |
| 51 base_t::decode_seek(0, p_abort); m_position.reset(); | |
| 52 } | |
| 53 } else { | |
| 54 base_t::decode_seek(p_seconds, p_abort); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 bool decode_run_raw(audio_chunk & p_chunk, mem_block_container & p_raw, abort_callback & p_abort) { | |
| 59 throw pfc::exception_not_implemented(); // shitformats that need this class are not likely to care | |
| 60 } | |
| 61 private: | |
| 62 bool m_active; | |
| 63 duration_counter m_position; | |
| 64 double m_decodeFrom; | |
| 65 }; |
