MT#62571 abstract sink/output

Change-Id: Ie08b27b268f9e9aa1bdea134bc20ef4b98ae7425
pull/1967/head
Richard Fuchs 7 months ago
parent 374357302a
commit 08ee3b2b31

@ -140,7 +140,7 @@ no_mix_out:
dbg("SSRC %lx of stream #%lu has single output", ssrc->ssrc, stream->id); dbg("SSRC %lx of stream #%lu has single output", ssrc->ssrc, stream->id);
if (output_config(output, &dec->dest_format, NULL)) if (output_config(output, &dec->dest_format, NULL))
goto err; goto err;
if (output_add(output, frame)) if (!sink_add(&output->sink, frame))
ilog(LOG_ERR, "Failed to add decoded packet to individual output"); ilog(LOG_ERR, "Failed to add decoded packet to individual output");
} }

@ -390,13 +390,13 @@ int mix_add(mix_t *mix, AVFrame *frame, unsigned int idx, void *ptr, output_t *o
} }
frame = resample_frame(&mix->resample, mix->sink_frame, &mix->out_format); frame = resample_frame(&mix->resample, mix->sink_frame, &mix->out_format);
ret = output_add(output, frame); bool ok = sink_add(&output->sink, frame);
av_frame_unref(mix->sink_frame); av_frame_unref(mix->sink_frame);
if (frame != mix->sink_frame) if (frame != mix->sink_frame)
av_frame_free(&frame); av_frame_free(&frame);
if (ret) if (!ok)
return -1; return -1;
} }

@ -42,14 +42,26 @@ static int output_got_packet(encoder_t *enc, void *u1, void *u2) {
} }
int output_add(output_t *output, AVFrame *frame) { bool sink_add(sink_t *sink, AVFrame *frame) {
if (!output) if (!sink)
return -1; return false;
return sink->add(sink, frame);
}
static bool output_add(sink_t *sink, AVFrame *frame) {
bool ret = false;
output_t *output = sink->output;
if (!output->encoder) // not ready - not configured if (!output->encoder) // not ready - not configured
return -1; goto out;
if (!output->fmtctx) // output not open if (!output->fmtctx) // output not open
return -1; goto out;
return encoder_input_fifo(output->encoder, frame, output_got_packet, output, NULL); ret = encoder_input_fifo(output->encoder, frame, output_got_packet, output, NULL) == 0;
out:
av_frame_free(&frame);
return ret;
} }
@ -87,6 +99,11 @@ static void create_parent_dirs(char *dir) {
} }
} }
void sink_init(sink_t *sink) {
*sink = (__typeof(*sink)) {
};
}
static output_t *output_alloc(const char *path, const char *name) { static output_t *output_alloc(const char *path, const char *name) {
output_t *ret = g_new0(output_t, 1); output_t *ret = g_new0(output_t, 1);
ret->file_path = g_strdup(path); ret->file_path = g_strdup(path);
@ -99,6 +116,10 @@ static output_t *output_alloc(const char *path, const char *name) {
ret->actual_format.format = -1; ret->actual_format.format = -1;
ret->start_time_us = now_us(); ret->start_time_us = now_us();
sink_init(&ret->sink);
ret->sink.output = ret;
ret->sink.add = output_add;
return ret; return ret;
} }

@ -14,7 +14,11 @@ output_t *output_new_ext(metafile_t *, const char *type, const char *kind, const
void output_close(metafile_t *, output_t *, tag_t *, bool discard); void output_close(metafile_t *, output_t *, tag_t *, bool discard);
int output_config(output_t *output, const format_t *requested_format, format_t *actual_format); int output_config(output_t *output, const format_t *requested_format, format_t *actual_format);
int output_add(output_t *output, AVFrame *frame);
void sink_init(sink_t *);
bool sink_add(sink_t *, AVFrame *frame);
#endif #endif

@ -33,6 +33,7 @@ typedef struct decode_s decode_t;
typedef struct packet_s packet_t; typedef struct packet_s packet_t;
typedef struct stream_s stream_t; typedef struct stream_s stream_t;
typedef struct ssrc_s ssrc_t; typedef struct ssrc_s ssrc_t;
typedef struct sink_s sink_t;
typedef void handler_func(handler_t *); typedef void handler_func(handler_t *);
@ -44,6 +45,15 @@ struct handler_s {
}; };
struct sink_s {
bool (*add)(sink_t *, AVFrame *);
union {
output_t *output;
};
};
struct stream_s { struct stream_s {
pthread_mutex_t lock; pthread_mutex_t lock;
char *name; char *name;
@ -156,6 +166,8 @@ struct metafile_s {
struct output_s { struct output_s {
sink_t sink;
char *full_filename, // path + filename char *full_filename, // path + filename
*file_path, *file_path,
*file_name, *file_name,

Loading…
Cancel
Save