2018-11-09 19:21:17 +08:00
|
|
|
#ifndef RECORDER_H
|
|
|
|
#define RECORDER_H
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
2018-11-09 19:21:17 +08:00
|
|
|
#include <libavformat/avformat.h>
|
2019-07-31 07:55:40 +08:00
|
|
|
#include <SDL2/SDL_mutex.h>
|
|
|
|
#include <SDL2/SDL_thread.h>
|
2018-11-09 19:21:17 +08:00
|
|
|
|
|
|
|
#include "common.h"
|
2019-08-02 05:15:47 +08:00
|
|
|
#include "queue.h"
|
2018-11-09 19:21:17 +08:00
|
|
|
|
2019-02-09 22:20:07 +08:00
|
|
|
enum recorder_format {
|
|
|
|
RECORDER_FORMAT_MP4 = 1,
|
|
|
|
RECORDER_FORMAT_MKV,
|
|
|
|
};
|
|
|
|
|
2019-07-31 07:55:40 +08:00
|
|
|
struct record_packet {
|
|
|
|
AVPacket packet;
|
|
|
|
struct record_packet *next;
|
|
|
|
};
|
|
|
|
|
2019-08-02 05:15:47 +08:00
|
|
|
struct recorder_queue QUEUE(struct record_packet);
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2018-11-09 19:21:17 +08:00
|
|
|
struct recorder {
|
|
|
|
char *filename;
|
2019-02-09 22:20:07 +08:00
|
|
|
enum recorder_format format;
|
2018-11-09 19:21:17 +08:00
|
|
|
AVFormatContext *ctx;
|
|
|
|
struct size declared_frame_size;
|
2019-03-03 06:52:22 +08:00
|
|
|
bool header_written;
|
2019-07-31 07:55:40 +08:00
|
|
|
|
|
|
|
SDL_Thread *thread;
|
|
|
|
SDL_mutex *mutex;
|
|
|
|
SDL_cond *queue_cond;
|
|
|
|
bool stopped; // set on recorder_stop() by the stream reader
|
|
|
|
bool failed; // set on packet write failure
|
|
|
|
struct recorder_queue queue;
|
2019-08-09 00:57:20 +08:00
|
|
|
|
|
|
|
// we can write a packet only once we received the next one so that we can
|
|
|
|
// set its duration (next_pts - current_pts)
|
|
|
|
// "previous" is only accessed from the recorder thread, so it does not
|
|
|
|
// need to be protected by the mutex
|
|
|
|
struct record_packet *previous;
|
2018-11-09 19:21:17 +08:00
|
|
|
};
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-05-31 22:08:30 +08:00
|
|
|
recorder_init(struct recorder *recorder, const char *filename,
|
2019-03-03 03:09:56 +08:00
|
|
|
enum recorder_format format, struct size declared_frame_size);
|
2019-02-09 22:20:07 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
recorder_destroy(struct recorder *recorder);
|
2018-11-09 19:21:17 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-03-03 18:59:31 +08:00
|
|
|
recorder_open(struct recorder *recorder, const AVCodec *input_codec);
|
2018-11-09 19:21:17 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
recorder_close(struct recorder *recorder);
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-07-31 07:55:40 +08:00
|
|
|
recorder_start(struct recorder *recorder);
|
|
|
|
|
|
|
|
void
|
|
|
|
recorder_stop(struct recorder *recorder);
|
|
|
|
|
|
|
|
void
|
|
|
|
recorder_join(struct recorder *recorder);
|
|
|
|
|
|
|
|
bool
|
|
|
|
recorder_push(struct recorder *recorder, const AVPacket *packet);
|
2018-11-09 19:21:17 +08:00
|
|
|
|
|
|
|
#endif
|