2023-03-01 23:31:43 +00:00
|
|
|
#ifndef SC_DELAY_BUFFER_H
|
|
|
|
#define SC_DELAY_BUFFER_H
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "clock.h"
|
2023-03-02 20:30:24 +00:00
|
|
|
#include "trait/frame_source.h"
|
|
|
|
#include "trait/frame_sink.h"
|
2023-03-01 23:31:43 +00:00
|
|
|
#include "util/thread.h"
|
|
|
|
#include "util/tick.h"
|
|
|
|
#include "util/vecdeque.h"
|
|
|
|
|
|
|
|
// forward declarations
|
|
|
|
typedef struct AVFrame AVFrame;
|
|
|
|
|
|
|
|
struct sc_delayed_frame {
|
|
|
|
AVFrame *frame;
|
|
|
|
#ifndef NDEBUG
|
|
|
|
sc_tick push_date;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sc_delayed_frame_queue SC_VECDEQUE(struct sc_delayed_frame);
|
|
|
|
|
|
|
|
struct sc_delay_buffer {
|
2023-03-02 20:30:24 +00:00
|
|
|
struct sc_frame_source frame_source; // frame source trait
|
|
|
|
struct sc_frame_sink frame_sink; // frame sink trait
|
|
|
|
|
2023-03-01 23:31:43 +00:00
|
|
|
sc_tick delay;
|
2023-03-02 21:33:31 +00:00
|
|
|
bool first_frame_asap;
|
2023-03-01 23:31:43 +00:00
|
|
|
|
2023-03-02 20:30:24 +00:00
|
|
|
sc_thread thread;
|
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond queue_cond;
|
|
|
|
sc_cond wait_cond;
|
|
|
|
|
|
|
|
struct sc_clock clock;
|
|
|
|
struct sc_delayed_frame_queue queue;
|
|
|
|
bool stopped;
|
2023-03-01 23:31:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sc_delay_buffer_callbacks {
|
|
|
|
bool (*on_new_frame)(struct sc_delay_buffer *db, const AVFrame *frame,
|
|
|
|
void *userdata);
|
|
|
|
};
|
|
|
|
|
2023-03-02 20:30:24 +00:00
|
|
|
/**
|
|
|
|
* Initialize a delay buffer.
|
|
|
|
*
|
|
|
|
* \param delay a (strictly) positive delay
|
2023-03-02 21:33:31 +00:00
|
|
|
* \param first_frame_asap if true, do not delay the first frame (useful for
|
|
|
|
a video stream).
|
2023-03-02 20:30:24 +00:00
|
|
|
*/
|
2023-03-01 23:31:43 +00:00
|
|
|
void
|
2023-03-02 21:33:31 +00:00
|
|
|
sc_delay_buffer_init(struct sc_delay_buffer *db, sc_tick delay,
|
|
|
|
bool first_frame_asap);
|
2023-03-01 23:31:43 +00:00
|
|
|
|
|
|
|
#endif
|