comparison foosdk/sdk/foobar2000/SDK/playback_stream_capture.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 //! \since 1.0
4 //! Implemented by components - register with playback_stream_capture methods.
5 class NOVTABLE playback_stream_capture_callback {
6 public:
7 //! Delivers a real-time chunk of audio data. \n
8 //! Audio is roughly synchronized with what can currently be heard. This API is provided for utility purposes such as streaming; if you want to implement a visualisation, use the visualisation_manager API instead. \n
9 //! Contrary to visualisation methods, this guarantees that all played audio data is coming thru. \n
10 //! Called only from the main thread. \n
11 virtual void on_chunk(const audio_chunk &) = 0;
12 protected:
13 playback_stream_capture_callback() {}
14 ~playback_stream_capture_callback() {}
15 };
16
17 //! \since 1.0
18 //! Implemented by core.
19 class NOVTABLE playback_stream_capture : public service_base {
20 FB2K_MAKE_SERVICE_COREAPI(playback_stream_capture)
21 public:
22 //! Register a playback_stream_capture_callback. \n
23 //! Possible to call only from the main thread.
24 virtual void add_callback(playback_stream_capture_callback * ) = 0;
25 //! Un-register a playback_stream_capture_callback. \n
26 //! Possible to call only from the main thread.
27 virtual void remove_callback(playback_stream_capture_callback * ) = 0;
28 };
29
30 //! \since 2.0.
31 //! Implemented by core.
32 class NOVTABLE playback_stream_capture_v2 : public playback_stream_capture {
33 FB2K_MAKE_SERVICE_COREAPI_EXTENSION(playback_stream_capture_v2, playback_stream_capture);
34 public:
35 //! @param requestInterval Interval, in seconds, in which the callback expects to be called. \n
36 //! Set to -1 to use defaults. \n
37 //! Note that if many callbacks are registered, they all get called at once; one callback requesting lower interval lowers the interval for all. \n
38 //! Non negative values are clamped to allowed range, that is, request of zero results in lowest possible update interval.
39 virtual void add_callback_v2(playback_stream_capture_callback* cb, double requestInterval = -1) = 0;
40 };
41
42 class playback_stream_capture_callback_impl : public playback_stream_capture_callback {
43 public:
44 void on_chunk(const audio_chunk&) override {}
45
46 //! @param interval requested update interval, see playback_stream_capture_v2::add_callback_v2()
47 playback_stream_capture_callback_impl(double interval = -1) {
48 PFC_ASSERT(core_api::is_main_thread());
49 #if FOOBAR2020
50 playback_stream_capture_v2::get()->add_callback_v2(this, interval);
51 #else
52 auto api = playback_stream_capture::get();
53 playback_stream_capture_v2::ptr v2;
54 if (v2 &= api) v2->add_callback_v2(this, interval);
55 else api->add_callback(this);
56 #endif
57 }
58 ~playback_stream_capture_callback_impl() {
59 PFC_ASSERT(core_api::is_main_thread());
60 playback_stream_capture::get()->remove_callback(this);
61 }
62
63 playback_stream_capture_callback_impl(const playback_stream_capture_callback_impl&) = delete;
64 void operator=(const playback_stream_capture_callback_impl&) = delete;
65 };