Browse Source

MT#62571 abstract sink/output

Change-Id: Ie08b27b268f9e9aa1bdea134bc20ef4b98ae7425
pull/1967/head
Richard Fuchs 6 months ago
parent
commit
08ee3b2b31
5 changed files with 47 additions and 10 deletions
  1. +1
    -1
      recording-daemon/decoder.c
  2. +2
    -2
      recording-daemon/mix.c
  3. +27
    -6
      recording-daemon/output.c
  4. +5
    -1
      recording-daemon/output.h
  5. +12
    -0
      recording-daemon/types.h

+ 1
- 1
recording-daemon/decoder.c View File

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


+ 2
- 2
recording-daemon/mix.c View File

@ -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);
ret = output_add(output, frame);
bool ok = sink_add(&output->sink, frame);
av_frame_unref(mix->sink_frame);
if (frame != mix->sink_frame)
av_frame_free(&frame);
if (ret)
if (!ok)
return -1;
}


+ 27
- 6
recording-daemon/output.c View File

@ -42,14 +42,26 @@ static int output_got_packet(encoder_t *enc, void *u1, void *u2) {
}
int output_add(output_t *output, AVFrame *frame) {
if (!output)
return -1;
bool sink_add(sink_t *sink, AVFrame *frame) {
if (!sink)
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
return -1;
goto out;
if (!output->fmtctx) // output not open
return -1;
return encoder_input_fifo(output->encoder, frame, output_got_packet, output, NULL);
goto out;
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) {
output_t *ret = g_new0(output_t, 1);
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->start_time_us = now_us();
sink_init(&ret->sink);
ret->sink.output = ret;
ret->sink.add = output_add;
return ret;
}


+ 5
- 1
recording-daemon/output.h View File

@ -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);
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

+ 12
- 0
recording-daemon/types.h View File

@ -33,6 +33,7 @@ typedef struct decode_s decode_t;
typedef struct packet_s packet_t;
typedef struct stream_s stream_t;
typedef struct ssrc_s ssrc_t;
typedef struct sink_s sink_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 {
pthread_mutex_t lock;
char *name;
@ -156,6 +166,8 @@ struct metafile_s {
struct output_s {
sink_t sink;
char *full_filename, // path + filename
*file_path,
*file_name,


Loading…
Cancel
Save