Banuba SDK
Loading...
Searching...
No Matches
player.hpp
1#pragma once
2
3#include <bnb/player_api/interfaces/input.hpp>
4#include <bnb/player_api/interfaces/output.hpp>
5#include <bnb/player_api/interfaces/render_delegate.hpp>
8#include <bnb/utils/defs.hpp>
9
10#include <memory>
11
12namespace bnb::player_api::interfaces
13{
14 class player;
15} // namespace bnb::player_api::interfaces
16
17namespace bnb::player_api
18{
19 using player_sptr = std::shared_ptr<bnb::player_api::interfaces::player>;
20 using effect_sptr = std::shared_ptr<bnb::interfaces::effect>;
21 using js_callback_sptr = std::shared_ptr<bnb::interfaces::js_callback>;
22 using effect_player_sptr = std::shared_ptr<bnb::interfaces::effect_player>;
23} // namespace bnb::player_api
24
25namespace bnb::player_api::interfaces
26{
27
28 /**
29 * Class manages the lifecycle of the EffectPlayer and is responsible for drawing FrameData
30 * that comes from Input, then processing frame and sending it to Output (or Outputs).
31 * Owns and manages the render thread.
32 */
33 class BNB_EXPORT player
34 {
35 public:
36 enum class render_mode : int32_t
37 {
38 /**
39 *Render in display linked loop with defined `fps`
40 */
41 loop,
42 /**
43 * Render manually by `render` call
44 */
45 manual
46 };
47
48 public:
49 virtual ~player() = default;
50
51 /**
52 * Set rendering mode to another. By default, the render mode is set to LOOP.
53 * @param new_render_mode new rendering mode
54 */
55 virtual void set_render_mode(render_mode new_render_mode) = 0;
56
57 /**
58 * Resume the playback of the effect.
59 */
60 virtual void play() = 0;
61
62 /**
63 * Pause the playback of the effect.
64 */
65 virtual void pause() = 0;
66
67 /**
68 * Get an instance of the EffectPlayer
69 */
70 virtual effect_player_sptr get_effect_player() = 0;
71
72 /**
73 * Use the new input to replace the old one
74 * @param input frames will be receive from it
75 */
76 virtual player& use(const input_sptr& input) = 0;
77
78 /**
79 * Add a new one output to output list
80 * @param output processed frames will be push to it
81 */
82 virtual player& use(const output_sptr& output) = 0;
83
84 /**
85 * Remove one output. If the output `nullptr` is passed as an output, then all outputs are removed.
86 * @param output delete this output from outputs
87 */
88 virtual player& unuse(const output_sptr& output = nullptr) = 0;
89
90 /**
91 * Synchronous loading of an effect by name
92 * @param url path to the effect or effect name
93 */
94 virtual effect_sptr load(const std::string& url) = 0;
95
96 /**
97 * Load effect asynchronously by name
98 * @param url path to the effect or effect name
99 */
100 virtual effect_sptr load_async(const std::string& url) = 0;
101
102 /**
103 * Evaluate the `script` in effect
104 * @param script JS string to execute
105 * @param resultCallback Callback for result, will be called in render thread.
106 */
107 virtual void eval_js(const std::string& script, js_callback_sptr callback) = 0;
108
109 /**
110 * Draw and present rendered result synchronously, can be used only in `manual` rendering mode.
111 * @return returns the number of the drawn frame, or -1 if nothing could be drawn.
112 */
113 virtual int64_t render() = 0;
114 }; // class player
115
116} // namespace bnb::player_api::interfaces
The interface is inherited by all classes that must work with the player, responsible for providing f...
Definition input.hpp:29
The interface is inherited by all classes that must work with player, and responsible for passing the...
Definition output.hpp:26
Class manages the lifecycle of the EffectPlayer and is responsible for drawing FrameData that comes f...
Definition player.hpp:34
virtual player & use(const output_sptr &output)=0
Add a new one output to output list.
virtual player & use(const input_sptr &input)=0
Use the new input to replace the old one.
virtual void eval_js(const std::string &script, js_callback_sptr callback)=0
Evaluate the script in effect.
virtual int64_t render()=0
Draw and present rendered result synchronously, can be used only in manual rendering mode.
virtual effect_sptr load_async(const std::string &url)=0
Load effect asynchronously by name.
virtual void play()=0
Resume the playback of the effect.
virtual effect_sptr load(const std::string &url)=0
Synchronous loading of an effect by name.
virtual void pause()=0
Pause the playback of the effect.
virtual player & unuse(const output_sptr &output=nullptr)=0
Remove one output.
virtual effect_player_sptr get_effect_player()=0
Get an instance of the EffectPlayer.
virtual void set_render_mode(render_mode new_render_mode)=0
Set rendering mode to another.