X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fplayer.h;h=27676e3f9480e750e97427e86ce748e38fb44197;hb=4b0234d5b2bce39ce701d0bf264ab2257e7ddd01;hp=03da29e364b80db3c2a503fc3e3d98b25ee90a84;hpb=eaba7288c4fb39ca195c9355970293bcaf088dbc;p=nageru diff --git a/futatabi/player.h b/futatabi/player.h index 03da29e..27676e3 100644 --- a/futatabi/player.h +++ b/futatabi/player.h @@ -20,6 +20,8 @@ class VideoStream; class QSurface; class QSurfaceFormat; +double compute_time_left(const std::vector &clips, const std::map &progress); + class Player : public QueueInterface { public: enum StreamOutput { @@ -30,8 +32,8 @@ public: Player(JPEGFrameView *destination, StreamOutput stream_output, AVFormatContext *file_avctx = nullptr); ~Player(); - void play_clip(const Clip &clip, size_t clip_idx, unsigned stream_idx); - void override_angle(unsigned stream_idx); // For the current clip only. + void play(const std::vector &clips); + void override_angle(unsigned stream_idx); // Assumes one-clip playlist only. // Not thread-safe to set concurrently with playing. // Will be called back from the player thread. @@ -40,12 +42,7 @@ public: // Not thread-safe to set concurrently with playing. // Will be called back from the player thread. - // The second parameter is the clip's position in the play list. - using next_clip_callback_func = std::function()>; - void set_next_clip_callback(next_clip_callback_func cb) { next_clip_callback = cb; } - - // Not thread-safe to set concurrently with playing. - // Will be called back from the player thread. + // The keys in the given map are indexes in the vector given to play(). using progress_callback_func = std::function &progress)>; void set_progress_callback(progress_callback_func cb) { progress_callback = cb; } @@ -54,7 +51,9 @@ public: void release_queue_spot() override; private: - void thread_func(StreamOutput stream_output, AVFormatContext *file_avctx); + void thread_func(AVFormatContext *file_avctx); + void play_playlist_once(); + void display_single_frame(int primary_stream_idx, const FrameOnDisk &primary_frame, int secondary_stream_idx, const FrameOnDisk &secondary_frame, double fade_alpha, std::chrono::steady_clock::time_point frame_start, bool snapped); 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); @@ -68,26 +67,36 @@ private: JPEGFrameView *destination; done_callback_func done_callback; - next_clip_callback_func next_clip_callback; progress_callback_func progress_callback; - std::mutex mu; - Clip current_clip; // Under mu. Can have pts_in = -1 for no clip. - size_t current_clip_idx; // Under mu. - unsigned current_stream_idx; // Under mu. - std::mutex queue_state_mu; std::condition_variable new_clip_changed; + std::vector queued_clip_list; // Under queue_state_mu. 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. + int64_t last_pts_played = -1; // Under queue_state_mu. Used by previews only. std::unique_ptr video_stream; // Can be nullptr. + std::atomic metric_dropped_interpolated_frame{0}; + std::atomic metric_dropped_unconditional_frame{0}; + std::atomic metric_faded_frame{0}; + std::atomic metric_faded_snapped_frame{0}; + std::atomic metric_original_frame{0}; + std::atomic metric_original_snapped_frame{0}; + std::atomic metric_refresh_frame{0}; + std::atomic metric_interpolated_frame{0}; + std::atomic metric_interpolated_faded_frame{0}; + // under queue_state_mu. Part of this instead of VideoStream so that we own // its lock and can sleep on it. size_t num_queued_frames = 0; static constexpr size_t max_queued_frames = 10; + + // State private to the player thread. + int64_t pts = 0; + const StreamOutput stream_output; }; #endif // !defined(_PLAYER_H)