]> git.sesse.net Git - nageru/blobdiff - player.h
Make it impossible to queue unfinished clips.
[nageru] / player.h
index 3321a303efc3ed6dc7910649bcb2bf6620f3bd57..a10a7cb9671f09924b5eda46266d6a492baccb25 100644 (file)
--- a/player.h
+++ b/player.h
@@ -2,17 +2,23 @@
 #define _PLAYER_H 1
 
 #include "clip_list.h"
-#include "video_stream.h"
+
+extern "C" {
+#include <libavformat/avio.h>
+}
 
 #include <condition_variable>
 #include <functional>
 #include <mutex>
 
 class JPEGFrameView;
+class VideoStream;
+class QSurface;
+class QSurfaceFormat;
 
 class Player {
 public:
-       Player(JPEGFrameView *destination);
+       Player(JPEGFrameView *destination, bool also_output_to_stream);
 
        void play_clip(const Clip &clip, unsigned stream_idx);
        void override_angle(unsigned stream_idx);  // For the current clip only.
@@ -22,14 +28,20 @@ public:
        using done_callback_func = std::function<void()>;
        void set_done_callback(done_callback_func cb) { done_callback = cb; }
 
+       // Not thread-safe to set concurrently with playing.
+       // Will be called back from the player thread.
+       using progress_callback_func = std::function<void(double played_this_clip, double total_length)>;
+       void set_progress_callback(progress_callback_func cb) { progress_callback = cb; }
+
 private:
-       void thread_func();
+       void thread_func(bool also_output_to_stream);
        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;
+       progress_callback_func progress_callback;
 
        std::mutex mu;
        Clip current_clip;  // Under mu. Can have pts_in = -1 for no clip.
@@ -41,7 +53,7 @@ private:
        bool playing = false;  // Under queue_state_mu.
        int override_stream_idx = -1;  // Under queue_state_mu.
 
-       VideoStream video_stream;
+       std::unique_ptr<VideoStream> video_stream;  // Can be nullptr.
 };
 
 #endif  // !defined(_PLAYER_H)