X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=player.h;h=3321a303efc3ed6dc7910649bcb2bf6620f3bd57;hb=8e43dfe18004c80528c72ea5ee3691689611dba1;hp=960bc22fcd713f2f7a58d4a9e168f78958206c0e;hpb=d9913b0d39d6ea0362f31157e5979ffa351f3888;p=nageru diff --git a/player.h b/player.h index 960bc22..3321a30 100644 --- a/player.h +++ b/player.h @@ -2,8 +2,46 @@ #define _PLAYER_H 1 #include "clip_list.h" +#include "video_stream.h" -void start_player_thread(); -void play_clip(const Clip &clip, unsigned stream_idx); +#include +#include +#include + +class JPEGFrameView; + +class Player { +public: + Player(JPEGFrameView *destination); + + void play_clip(const Clip &clip, unsigned stream_idx); + void override_angle(unsigned stream_idx); // For the current clip only. + + // Not thread-safe to set concurrently with playing. + // Will be called back from the player thread. + using done_callback_func = std::function; + void set_done_callback(done_callback_func cb) { done_callback = cb; } + +private: + void thread_func(); + void open_output_stream(); + static int write_packet2_thunk(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time); + int write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time); + + JPEGFrameView *destination; + done_callback_func done_callback; + + std::mutex mu; + Clip current_clip; // Under mu. Can have pts_in = -1 for no clip. + unsigned current_stream_idx; // Under mu. + + std::mutex queue_state_mu; + std::condition_variable new_clip_changed; + bool new_clip_ready = false; // Under queue_state_mu. + bool playing = false; // Under queue_state_mu. + int override_stream_idx = -1; // Under queue_state_mu. + + VideoStream video_stream; +}; #endif // !defined(_PLAYER_H)