2022-02-03 02:37:28 +08:00
|
|
|
#ifndef SC_RECORDER_H
|
|
|
|
#define SC_RECORDER_H
|
2018-11-09 19:21:17 +08:00
|
|
|
|
2021-01-09 02:24:51 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
2018-11-09 19:21:17 +08:00
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
|
2021-01-09 02:15:29 +08:00
|
|
|
#include "coords.h"
|
2021-10-28 00:43:47 +08:00
|
|
|
#include "options.h"
|
2021-04-11 21:01:05 +08:00
|
|
|
#include "trait/packet_sink.h"
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/queue.h"
|
2021-02-01 01:24:35 +08:00
|
|
|
#include "util/thread.h"
|
2018-11-09 19:21:17 +08:00
|
|
|
|
2022-02-03 02:37:28 +08:00
|
|
|
struct sc_record_packet {
|
2021-06-14 15:07:49 +08:00
|
|
|
AVPacket *packet;
|
2022-02-03 02:37:28 +08:00
|
|
|
struct sc_record_packet *next;
|
2019-07-31 07:55:40 +08:00
|
|
|
};
|
|
|
|
|
2022-02-03 02:37:28 +08:00
|
|
|
struct sc_recorder_queue SC_QUEUE(struct sc_record_packet);
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2022-02-03 02:37:28 +08:00
|
|
|
struct sc_recorder {
|
2021-04-11 21:01:05 +08:00
|
|
|
struct sc_packet_sink packet_sink; // packet sink trait
|
|
|
|
|
2018-11-09 19:21:17 +08:00
|
|
|
char *filename;
|
2020-06-20 04:04:06 +08:00
|
|
|
enum sc_record_format format;
|
2018-11-09 19:21:17 +08:00
|
|
|
AVFormatContext *ctx;
|
2021-10-30 21:20:39 +08:00
|
|
|
struct sc_size declared_frame_size;
|
2019-03-03 06:52:22 +08:00
|
|
|
bool header_written;
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_thread thread;
|
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond queue_cond;
|
2021-04-11 21:01:05 +08:00
|
|
|
bool stopped; // set on recorder_close()
|
2019-07-31 07:55:40 +08:00
|
|
|
bool failed; // set on packet write failure
|
2022-02-03 02:37:28 +08:00
|
|
|
struct sc_recorder_queue queue;
|
2023-02-11 01:10:24 +08: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 19:21:17 +08:00
|
|
|
};
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2022-02-03 02:37:28 +08:00
|
|
|
sc_recorder_init(struct sc_recorder *recorder, const char *filename,
|
|
|
|
enum sc_record_format format,
|
2023-02-11 01:10:24 +08:00
|
|
|
struct sc_size declared_frame_size,
|
|
|
|
const struct sc_recorder_callbacks *cbs, void *cbs_userdata);
|
2019-02-09 22:20:07 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
2022-02-03 02:37:28 +08:00
|
|
|
sc_recorder_destroy(struct sc_recorder *recorder);
|
2018-11-09 19:21:17 +08:00
|
|
|
|
|
|
|
#endif
|