7 #include <libavformat/avio.h>
10 #include <condition_variable>
21 Player(JPEGFrameView *destination, bool also_output_to_stream);
23 void play_clip(const Clip &clip, unsigned stream_idx);
24 void override_angle(unsigned stream_idx); // For the current clip only.
26 // Not thread-safe to set concurrently with playing.
27 // Will be called back from the player thread.
28 using done_callback_func = std::function<void()>;
29 void set_done_callback(done_callback_func cb) { done_callback = cb; }
31 // Not thread-safe to set concurrently with playing.
32 // Will be called back from the player thread.
33 using progress_callback_func = std::function<void(double played_this_clip, double total_length)>;
34 void set_progress_callback(progress_callback_func cb) { progress_callback = cb; }
37 void thread_func(bool also_output_to_stream);
38 void open_output_stream();
39 static int write_packet2_thunk(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
40 int write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
42 // Find the frame immediately before and after this point.
43 // Returns false if pts is after the last frame.
44 bool find_surrounding_frames(int64_t pts, int stream_idx, int64_t *pts_lower, int64_t *pts_upper);
46 JPEGFrameView *destination;
47 done_callback_func done_callback;
48 progress_callback_func progress_callback;
51 Clip current_clip; // Under mu. Can have pts_in = -1 for no clip.
52 unsigned current_stream_idx; // Under mu.
54 std::mutex queue_state_mu;
55 std::condition_variable new_clip_changed;
56 bool new_clip_ready = false; // Under queue_state_mu.
57 bool playing = false; // Under queue_state_mu.
58 int override_stream_idx = -1; // Under queue_state_mu.
60 std::unique_ptr<VideoStream> video_stream; // Can be nullptr.
63 #endif // !defined(_PLAYER_H)