Skip to content

Commit

Permalink
libtxproto/encoder: Gather all params in a single struct
Browse files Browse the repository at this point in the history
  • Loading branch information
rofferom committed Apr 8, 2024
1 parent bdf8bd6 commit 08f95c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
11 changes: 7 additions & 4 deletions src/include/libtxproto/txproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ AVBufferRef *tx_decoder_create(
AVDictionary *init_opts
);

typedef struct TxEncoderOptions {
const char *enc_name;
const char *name;
AVDictionary *options;
AVDictionary *init_opts;
} TxEncoderOptions;
AVBufferRef *tx_encoder_create(
TXMainContext *ctx,
const char *enc_name,
const char *name,
AVDictionary *options,
AVDictionary *init_opts
const TxEncoderOptions *options
);

AVBufferRef *tx_muxer_create(
Expand Down
17 changes: 7 additions & 10 deletions src/txproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,33 +182,30 @@ AVBufferRef *tx_decoder_create(

AVBufferRef *tx_encoder_create(
TXMainContext *ctx,
const char *enc_name,
const char *name,
AVDictionary *options,
AVDictionary *init_opts
const TxEncoderOptions *options
) {
int err;
AVBufferRef *ectx_ref = sp_encoder_alloc();
EncodingContext *ectx = (EncodingContext *)ectx_ref->data;

ectx->codec = avcodec_find_encoder_by_name(enc_name);
ectx->codec = avcodec_find_encoder_by_name(options->enc_name);
if (!ectx->codec) {
sp_log(ctx, SP_LOG_ERROR, "Encoder \"%s\" not found!", enc_name);
sp_log(ctx, SP_LOG_ERROR, "Encoder \"%s\" not found!", options->enc_name);
goto err;
}

ectx->name = name;
ectx->name = options->name;

err = sp_encoder_init(ectx_ref);
if (err < 0) {
sp_log(ctx, SP_LOG_ERROR, "Unable to init encoder: %s!", av_err2str(err));
goto err;
}

ectx->codec_config = options;
ectx->codec_config = options->options;

if (init_opts) {
err = sp_encoder_ctrl(ectx_ref, SP_EVENT_CTRL_OPTS | SP_EVENT_FLAG_IMMEDIATE, init_opts);
if (options->init_opts) {
err = sp_encoder_ctrl(ectx_ref, SP_EVENT_CTRL_OPTS | SP_EVENT_FLAG_IMMEDIATE, options->init_opts);
if (err < 0) {
sp_log(ctx, SP_LOG_ERROR, "Unable to set options: %s!", av_err2str(err));
goto err;
Expand Down

0 comments on commit 08f95c6

Please sign in to comment.