2022-02-02 19:37:28 +01:00
|
|
|
#ifndef SC_RECORDER_H
|
|
|
|
#define SC_RECORDER_H
|
2018-11-09 12:21:17 +01:00
|
|
|
|
2021-01-08 19:24:51 +01:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-03-02 23:52:22 +01:00
|
|
|
#include <stdbool.h>
|
2018-11-09 12:21:17 +01:00
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
|
2021-01-08 19:15:29 +01:00
|
|
|
#include "coords.h"
|
2021-10-27 18:43:47 +02:00
|
|
|
#include "options.h"
|
2021-04-11 15:01:05 +02:00
|
|
|
#include "trait/packet_sink.h"
|
2019-11-24 11:53:00 +01:00
|
|
|
#include "util/queue.h"
|
2021-01-31 18:24:35 +01:00
|
|
|
#include "util/thread.h"
|
2018-11-09 12:21:17 +01:00
|
|
|
|
2022-02-02 19:37:28 +01:00
|
|
|
struct sc_record_packet {
|
2021-06-14 09:07:49 +02:00
|
|
|
AVPacket *packet;
|
2022-02-02 19:37:28 +01:00
|
|
|
struct sc_record_packet *next;
|
2019-07-31 01:55:40 +02:00
|
|
|
};
|
|
|
|
|
2022-02-02 19:37:28 +01:00
|
|
|
struct sc_recorder_queue SC_QUEUE(struct sc_record_packet);
|
2019-07-31 01:55:40 +02:00
|
|
|
|
2022-02-02 19:37:28 +01:00
|
|
|
struct sc_recorder {
|
2021-04-11 15:01:05 +02:00
|
|
|
struct sc_packet_sink packet_sink; // packet sink trait
|
|
|
|
|
2018-11-09 12:21:17 +01:00
|
|
|
char *filename;
|
2020-06-19 22:04:06 +02:00
|
|
|
enum sc_record_format format;
|
2018-11-09 12:21:17 +01:00
|
|
|
AVFormatContext *ctx;
|
2021-10-30 15:20:39 +02:00
|
|
|
struct sc_size declared_frame_size;
|
2019-07-31 01:55:40 +02:00
|
|
|
|
2021-01-31 18:24:35 +01:00
|
|
|
sc_thread thread;
|
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond queue_cond;
|
2023-02-14 09:25:50 +01:00
|
|
|
// set on sc_recorder_stop(), packet_sink close or recording failure
|
|
|
|
bool stopped;
|
2022-02-02 19:37:28 +01:00
|
|
|
struct sc_recorder_queue queue;
|
2023-02-10 18:10:24 +01:00
|
|
|
|
2023-02-14 09:25:50 +01:00
|
|
|
// wake up the recorder thread once the codec in known
|
|
|
|
sc_cond stream_cond;
|
|
|
|
const AVCodec *codec;
|
|
|
|
|
2023-02-10 18:10:24 +01:00
|
|
|
const struct sc_recorder_callbacks *cbs;
|
|
|
|
void *cbs_userdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sc_recorder_callbacks {
|
|
|
|
void (*on_ended)(struct sc_recorder *recorder, bool success,
|
|
|
|
void *userdata);
|
2018-11-09 12:21:17 +01:00
|
|
|
};
|
|
|
|
|
2019-03-02 23:52:22 +01:00
|
|
|
bool
|
2022-02-02 19:37:28 +01:00
|
|
|
sc_recorder_init(struct sc_recorder *recorder, const char *filename,
|
|
|
|
enum sc_record_format format,
|
2023-02-10 18:10:24 +01:00
|
|
|
struct sc_size declared_frame_size,
|
|
|
|
const struct sc_recorder_callbacks *cbs, void *cbs_userdata);
|
2019-02-09 15:20:07 +01:00
|
|
|
|
2023-02-23 11:00:34 +01:00
|
|
|
bool
|
|
|
|
sc_recorder_start(struct sc_recorder *recorder);
|
|
|
|
|
2023-02-14 09:25:50 +01:00
|
|
|
void
|
|
|
|
sc_recorder_stop(struct sc_recorder *recorder);
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_recorder_join(struct sc_recorder *recorder);
|
|
|
|
|
2019-03-02 20:09:56 +01:00
|
|
|
void
|
2022-02-02 19:37:28 +01:00
|
|
|
sc_recorder_destroy(struct sc_recorder *recorder);
|
2018-11-09 12:21:17 +01:00
|
|
|
|
|
|
|
#endif
|