2018-11-09 19:21:17 +08:00
|
|
|
#include "recorder.h"
|
|
|
|
|
2019-11-28 04:11:40 +08:00
|
|
|
#include <assert.h>
|
2021-09-21 00:27:37 +08:00
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
2018-11-09 19:21:17 +08:00
|
|
|
#include <libavutil/time.h>
|
|
|
|
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/log.h"
|
2021-11-13 06:12:51 +08:00
|
|
|
#include "util/str.h"
|
2018-11-09 19:21:17 +08:00
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
/** Downcast packet_sink to recorder */
|
|
|
|
#define DOWNCAST(SINK) container_of(SINK, struct recorder, packet_sink)
|
|
|
|
|
2019-02-09 22:08:36 +08:00
|
|
|
static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static const AVOutputFormat *
|
|
|
|
find_muxer(const char *name) {
|
2019-02-16 22:04:32 +08:00
|
|
|
#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
|
2018-11-09 19:21:17 +08:00
|
|
|
void *opaque = NULL;
|
2018-11-10 19:00:30 +08:00
|
|
|
#endif
|
|
|
|
const AVOutputFormat *oformat = NULL;
|
2018-11-09 19:21:17 +08:00
|
|
|
do {
|
2019-02-16 22:04:32 +08:00
|
|
|
#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
|
2018-11-09 19:21:17 +08:00
|
|
|
oformat = av_muxer_iterate(&opaque);
|
2018-11-10 19:00:30 +08:00
|
|
|
#else
|
|
|
|
oformat = av_oformat_next(oformat);
|
|
|
|
#endif
|
2021-04-19 15:28:28 +08:00
|
|
|
// until null or containing the requested name
|
2021-11-13 06:08:19 +08:00
|
|
|
} while (oformat && !sc_str_list_contains(oformat->name, ',', name));
|
2018-11-09 19:21:17 +08:00
|
|
|
return oformat;
|
|
|
|
}
|
|
|
|
|
2019-07-31 07:55:40 +08:00
|
|
|
static struct record_packet *
|
|
|
|
record_packet_new(const AVPacket *packet) {
|
2021-01-24 22:14:53 +08:00
|
|
|
struct record_packet *rec = malloc(sizeof(*rec));
|
2019-07-31 07:55:40 +08:00
|
|
|
if (!rec) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-08-14 00:49:25 +08:00
|
|
|
|
2021-06-14 15:07:49 +08:00
|
|
|
rec->packet = av_packet_alloc();
|
|
|
|
if (!rec->packet) {
|
|
|
|
free(rec);
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-08-14 00:49:25 +08:00
|
|
|
|
2021-06-14 15:07:49 +08:00
|
|
|
if (av_packet_ref(rec->packet, packet)) {
|
|
|
|
av_packet_free(&rec->packet);
|
2021-01-24 22:14:53 +08:00
|
|
|
free(rec);
|
2019-07-31 07:55:40 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
record_packet_delete(struct record_packet *rec) {
|
2021-06-14 15:07:49 +08:00
|
|
|
av_packet_free(&rec->packet);
|
2021-01-24 22:14:53 +08:00
|
|
|
free(rec);
|
2019-07-31 07:55:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_queue_clear(struct recorder_queue *queue) {
|
2021-07-04 21:05:08 +08:00
|
|
|
while (!sc_queue_is_empty(queue)) {
|
2019-08-02 05:15:47 +08:00
|
|
|
struct record_packet *rec;
|
2021-07-04 21:05:08 +08:00
|
|
|
sc_queue_take(queue, next, &rec);
|
2019-08-02 05:15:47 +08:00
|
|
|
record_packet_delete(rec);
|
2019-07-31 07:55:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 22:20:07 +08:00
|
|
|
static const char *
|
2020-06-20 04:04:06 +08:00
|
|
|
recorder_get_format_name(enum sc_record_format format) {
|
2019-02-09 22:20:07 +08:00
|
|
|
switch (format) {
|
2020-06-20 04:04:06 +08:00
|
|
|
case SC_RECORD_FORMAT_MP4: return "mp4";
|
|
|
|
case SC_RECORD_FORMAT_MKV: return "matroska";
|
2019-02-09 22:20:07 +08:00
|
|
|
default: return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
static bool
|
2019-03-03 18:59:31 +08:00
|
|
|
recorder_write_header(struct recorder *recorder, const AVPacket *packet) {
|
2019-02-09 19:54:12 +08:00
|
|
|
AVStream *ostream = recorder->ctx->streams[0];
|
|
|
|
|
2019-02-16 07:50:14 +08:00
|
|
|
uint8_t *extradata = av_malloc(packet->size * sizeof(uint8_t));
|
2019-02-09 19:54:12 +08:00
|
|
|
if (!extradata) {
|
2019-06-24 02:49:38 +08:00
|
|
|
LOGC("Could not allocate extradata");
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-09 19:54:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy the first packet to the extra data
|
|
|
|
memcpy(extradata, packet->data, packet->size);
|
|
|
|
|
|
|
|
ostream->codecpar->extradata = extradata;
|
|
|
|
ostream->codecpar->extradata_size = packet->size;
|
|
|
|
|
|
|
|
int ret = avformat_write_header(recorder->ctx, NULL);
|
|
|
|
if (ret < 0) {
|
|
|
|
LOGE("Failed to write header to %s", recorder->filename);
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-09 19:54:12 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
return true;
|
2019-02-09 19:54:12 +08:00
|
|
|
}
|
|
|
|
|
2019-02-09 22:08:36 +08:00
|
|
|
static void
|
|
|
|
recorder_rescale_packet(struct recorder *recorder, AVPacket *packet) {
|
|
|
|
AVStream *ostream = recorder->ctx->streams[0];
|
|
|
|
av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base);
|
|
|
|
}
|
|
|
|
|
2021-04-07 22:41:57 +08:00
|
|
|
static bool
|
2019-03-03 03:09:56 +08:00
|
|
|
recorder_write(struct recorder *recorder, AVPacket *packet) {
|
2019-02-09 19:54:12 +08:00
|
|
|
if (!recorder->header_written) {
|
2019-07-31 07:55:32 +08:00
|
|
|
if (packet->pts != AV_NOPTS_VALUE) {
|
|
|
|
LOGE("The first packet is not a config packet");
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-03 06:52:22 +08:00
|
|
|
bool ok = recorder_write_header(recorder, packet);
|
2019-02-09 19:54:12 +08:00
|
|
|
if (!ok) {
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2019-02-09 19:54:12 +08:00
|
|
|
}
|
2019-03-03 06:52:22 +08:00
|
|
|
recorder->header_written = true;
|
2019-07-31 07:55:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packet->pts == AV_NOPTS_VALUE) {
|
|
|
|
// ignore config packets
|
|
|
|
return true;
|
2019-02-09 19:54:12 +08:00
|
|
|
}
|
|
|
|
|
2019-02-09 22:08:36 +08:00
|
|
|
recorder_rescale_packet(recorder, packet);
|
2018-11-09 19:21:17 +08:00
|
|
|
return av_write_frame(recorder->ctx, packet) >= 0;
|
|
|
|
}
|
2019-07-31 07:55:40 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
run_recorder(void *data) {
|
|
|
|
struct recorder *recorder = data;
|
|
|
|
|
|
|
|
for (;;) {
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_lock(&recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
while (!recorder->stopped && sc_queue_is_empty(&recorder->queue)) {
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_cond_wait(&recorder->queue_cond, &recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// if stopped is set, continue to process the remaining events (to
|
|
|
|
// finish the recording) before actually stopping
|
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) {
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_unlock(&recorder->mutex);
|
2019-08-09 00:57:20 +08:00
|
|
|
struct record_packet *last = recorder->previous;
|
|
|
|
if (last) {
|
|
|
|
// assign an arbitrary duration to the last packet
|
2021-06-14 15:07:49 +08:00
|
|
|
last->packet->duration = 100000;
|
|
|
|
bool ok = recorder_write(recorder, last->packet);
|
2019-08-09 00:57:20 +08:00
|
|
|
if (!ok) {
|
|
|
|
// failing to write the last frame is not very serious, no
|
|
|
|
// future frame may depend on it, so the resulting file
|
|
|
|
// will still be valid
|
|
|
|
LOGW("Could not record last packet");
|
|
|
|
}
|
|
|
|
record_packet_delete(last);
|
|
|
|
}
|
2019-07-31 07:55:40 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-02 05:15:47 +08:00
|
|
|
struct record_packet *rec;
|
2021-07-04 21:05:08 +08:00
|
|
|
sc_queue_take(&recorder->queue, next, &rec);
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_unlock(&recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2019-08-09 00:57:20 +08:00
|
|
|
// recorder->previous is only written from this thread, no need to lock
|
|
|
|
struct record_packet *previous = recorder->previous;
|
|
|
|
recorder->previous = rec;
|
|
|
|
|
|
|
|
if (!previous) {
|
|
|
|
// we just received the first packet
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-11-13 23:04:16 +08:00
|
|
|
// config packets have no PTS, we must ignore them
|
2021-06-14 15:07:49 +08:00
|
|
|
if (rec->packet->pts != AV_NOPTS_VALUE
|
|
|
|
&& previous->packet->pts != AV_NOPTS_VALUE) {
|
2019-11-13 23:04:16 +08:00
|
|
|
// we now know the duration of the previous packet
|
2021-06-14 15:07:49 +08:00
|
|
|
previous->packet->duration =
|
|
|
|
rec->packet->pts - previous->packet->pts;
|
2019-11-13 23:04:16 +08:00
|
|
|
}
|
2019-08-09 00:57:20 +08:00
|
|
|
|
2021-06-14 15:07:49 +08:00
|
|
|
bool ok = recorder_write(recorder, previous->packet);
|
2019-08-09 00:57:20 +08:00
|
|
|
record_packet_delete(previous);
|
2019-07-31 07:55:40 +08:00
|
|
|
if (!ok) {
|
|
|
|
LOGE("Could not record packet");
|
|
|
|
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_lock(&recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
recorder->failed = true;
|
|
|
|
// discard pending packets
|
|
|
|
recorder_queue_clear(&recorder->queue);
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_unlock(&recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-04-11 21:01:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!recorder->failed) {
|
|
|
|
if (recorder->header_written) {
|
|
|
|
int ret = av_write_trailer(recorder->ctx);
|
|
|
|
if (ret < 0) {
|
|
|
|
LOGE("Failed to write trailer to %s", recorder->filename);
|
|
|
|
recorder->failed = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// the recorded file is empty
|
|
|
|
recorder->failed = true;
|
|
|
|
}
|
|
|
|
}
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
if (recorder->failed) {
|
|
|
|
LOGE("Recording failed to %s", recorder->filename);
|
|
|
|
} else {
|
|
|
|
const char *format_name = recorder_get_format_name(recorder->format);
|
2021-07-16 00:07:39 +08:00
|
|
|
LOGI("Recording complete to %s file: %s", format_name,
|
|
|
|
recorder->filename);
|
2019-07-31 07:55:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LOGD("Recorder thread ended");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
static bool
|
2021-04-11 21:01:05 +08:00
|
|
|
recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
|
2021-04-18 17:25:58 +08:00
|
|
|
bool ok = sc_mutex_init(&recorder->mutex);
|
|
|
|
if (!ok) {
|
|
|
|
LOGC("Could not create mutex");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = sc_cond_init(&recorder->queue_cond);
|
|
|
|
if (!ok) {
|
|
|
|
LOGC("Could not create cond");
|
2021-04-18 17:32:21 +08:00
|
|
|
goto error_mutex_destroy;
|
2021-04-18 17:25:58 +08:00
|
|
|
}
|
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
sc_queue_init(&recorder->queue);
|
2021-04-18 17:25:58 +08:00
|
|
|
recorder->stopped = false;
|
|
|
|
recorder->failed = false;
|
|
|
|
recorder->header_written = false;
|
|
|
|
recorder->previous = NULL;
|
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
const char *format_name = recorder_get_format_name(recorder->format);
|
|
|
|
assert(format_name);
|
|
|
|
const AVOutputFormat *format = find_muxer(format_name);
|
|
|
|
if (!format) {
|
|
|
|
LOGE("Could not find muxer");
|
2021-04-18 17:32:21 +08:00
|
|
|
goto error_cond_destroy;
|
2021-04-11 21:01:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
recorder->ctx = avformat_alloc_context();
|
|
|
|
if (!recorder->ctx) {
|
|
|
|
LOGE("Could not allocate output context");
|
2021-04-18 17:32:21 +08:00
|
|
|
goto error_cond_destroy;
|
2021-04-11 21:01:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// contrary to the deprecated API (av_oformat_next()), av_muxer_iterate()
|
|
|
|
// returns (on purpose) a pointer-to-const, but AVFormatContext.oformat
|
|
|
|
// still expects a pointer-to-non-const (it has not be updated accordingly)
|
|
|
|
// <https://github.com/FFmpeg/FFmpeg/commit/0694d8702421e7aff1340038559c438b61bb30dd>
|
|
|
|
recorder->ctx->oformat = (AVOutputFormat *) format;
|
|
|
|
|
|
|
|
av_dict_set(&recorder->ctx->metadata, "comment",
|
|
|
|
"Recorded by scrcpy " SCRCPY_VERSION, 0);
|
|
|
|
|
|
|
|
AVStream *ostream = avformat_new_stream(recorder->ctx, input_codec);
|
|
|
|
if (!ostream) {
|
2021-04-18 17:32:21 +08:00
|
|
|
goto error_avformat_free_context;
|
2021-04-11 21:01:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ostream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
|
ostream->codecpar->codec_id = input_codec->id;
|
|
|
|
ostream->codecpar->format = AV_PIX_FMT_YUV420P;
|
|
|
|
ostream->codecpar->width = recorder->declared_frame_size.width;
|
|
|
|
ostream->codecpar->height = recorder->declared_frame_size.height;
|
|
|
|
|
|
|
|
int ret = avio_open(&recorder->ctx->pb, recorder->filename,
|
|
|
|
AVIO_FLAG_WRITE);
|
|
|
|
if (ret < 0) {
|
|
|
|
LOGE("Failed to open output file: %s", recorder->filename);
|
|
|
|
// ostream will be cleaned up during context cleaning
|
2021-04-18 17:32:21 +08:00
|
|
|
goto error_avformat_free_context;
|
2021-04-11 21:01:05 +08:00
|
|
|
}
|
|
|
|
|
2019-07-31 07:55:40 +08:00
|
|
|
LOGD("Starting recorder thread");
|
2021-04-18 17:25:58 +08:00
|
|
|
ok = sc_thread_create(&recorder->thread, run_recorder, "recorder",
|
2021-02-01 01:24:35 +08:00
|
|
|
recorder);
|
|
|
|
if (!ok) {
|
2019-07-31 07:55:40 +08:00
|
|
|
LOGC("Could not start recorder thread");
|
2021-04-18 17:32:21 +08:00
|
|
|
goto error_avio_close;
|
2019-07-31 07:55:40 +08:00
|
|
|
}
|
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
LOGI("Recording started to %s file: %s", format_name, recorder->filename);
|
|
|
|
|
2019-07-31 07:55:40 +08:00
|
|
|
return true;
|
2021-04-18 17:32:21 +08:00
|
|
|
|
|
|
|
error_avio_close:
|
|
|
|
avio_close(recorder->ctx->pb);
|
|
|
|
error_avformat_free_context:
|
|
|
|
avformat_free_context(recorder->ctx);
|
|
|
|
error_cond_destroy:
|
|
|
|
sc_cond_destroy(&recorder->queue_cond);
|
|
|
|
error_mutex_destroy:
|
|
|
|
sc_mutex_destroy(&recorder->mutex);
|
|
|
|
|
|
|
|
return false;
|
2019-07-31 07:55:40 +08:00
|
|
|
}
|
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
static void
|
2021-04-11 21:01:05 +08:00
|
|
|
recorder_close(struct recorder *recorder) {
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_lock(&recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
recorder->stopped = true;
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_cond_signal(&recorder->queue_cond);
|
|
|
|
sc_mutex_unlock(&recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_thread_join(&recorder->thread, NULL);
|
2021-04-11 21:01:05 +08:00
|
|
|
|
|
|
|
avio_close(recorder->ctx->pb);
|
|
|
|
avformat_free_context(recorder->ctx);
|
2021-04-18 17:25:58 +08:00
|
|
|
sc_cond_destroy(&recorder->queue_cond);
|
|
|
|
sc_mutex_destroy(&recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
}
|
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
static bool
|
2019-07-31 07:55:40 +08:00
|
|
|
recorder_push(struct recorder *recorder, const AVPacket *packet) {
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_lock(&recorder->mutex);
|
2019-11-28 04:11:40 +08:00
|
|
|
assert(!recorder->stopped);
|
2019-07-31 07:55:40 +08:00
|
|
|
|
|
|
|
if (recorder->failed) {
|
|
|
|
// reject any new packet (this will stop the stream)
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_unlock(&recorder->mutex);
|
2019-07-31 07:55:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-02 05:15:47 +08:00
|
|
|
struct record_packet *rec = record_packet_new(packet);
|
|
|
|
if (!rec) {
|
|
|
|
LOGC("Could not allocate record packet");
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_unlock(&recorder->mutex);
|
2019-08-02 05:15:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-04 21:05:08 +08:00
|
|
|
sc_queue_push(&recorder->queue, next, rec);
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_cond_signal(&recorder->queue_cond);
|
2019-07-31 07:55:40 +08:00
|
|
|
|
2021-02-01 01:24:35 +08:00
|
|
|
sc_mutex_unlock(&recorder->mutex);
|
2019-08-02 05:15:47 +08:00
|
|
|
return true;
|
2019-07-31 07:55:40 +08:00
|
|
|
}
|
2021-04-11 21:01:05 +08:00
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
static bool
|
|
|
|
recorder_packet_sink_open(struct sc_packet_sink *sink, const AVCodec *codec) {
|
|
|
|
struct recorder *recorder = DOWNCAST(sink);
|
|
|
|
return recorder_open(recorder, codec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_packet_sink_close(struct sc_packet_sink *sink) {
|
|
|
|
struct recorder *recorder = DOWNCAST(sink);
|
|
|
|
recorder_close(recorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
recorder_packet_sink_push(struct sc_packet_sink *sink, const AVPacket *packet) {
|
|
|
|
struct recorder *recorder = DOWNCAST(sink);
|
|
|
|
return recorder_push(recorder, packet);
|
|
|
|
}
|
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
bool
|
|
|
|
recorder_init(struct recorder *recorder,
|
|
|
|
const char *filename,
|
|
|
|
enum sc_record_format format,
|
2021-10-30 21:20:39 +08:00
|
|
|
struct sc_size declared_frame_size) {
|
2021-04-11 21:01:05 +08:00
|
|
|
recorder->filename = strdup(filename);
|
|
|
|
if (!recorder->filename) {
|
|
|
|
LOGE("Could not strdup filename");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
recorder->format = format;
|
|
|
|
recorder->declared_frame_size = declared_frame_size;
|
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
static const struct sc_packet_sink_ops ops = {
|
|
|
|
.open = recorder_packet_sink_open,
|
|
|
|
.close = recorder_packet_sink_close,
|
|
|
|
.push = recorder_packet_sink_push,
|
|
|
|
};
|
|
|
|
|
|
|
|
recorder->packet_sink.ops = &ops;
|
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
recorder_destroy(struct recorder *recorder) {
|
|
|
|
free(recorder->filename);
|
|
|
|
}
|