cli: remove init_[de]muxers() functions

Muxer and demuxers arrays are now statically initialized
This commit is contained in:
Luc Trudeau
2020-02-21 11:01:08 -05:00
parent 0c88560789
commit cacc8e350c
5 changed files with 34 additions and 54 deletions
-2
View File
@@ -155,8 +155,6 @@ int main(const int argc, char *const *const argv) {
return EXIT_FAILURE;
}
init_demuxers();
init_muxers();
parse(argc, argv, &cli_settings, &lib_settings);
if ((res = input_open(&in, cli_settings.demuxer,
+14 -20
View File
@@ -43,21 +43,15 @@ struct DemuxerContext {
const Demuxer *impl;
};
#define MAX_NUM_DEMUXERS 3
static const Demuxer *demuxers[MAX_NUM_DEMUXERS];
static int num_demuxers = 0;
#define register_demuxer(impl) { \
extern const Demuxer impl; \
assert(num_demuxers < MAX_NUM_DEMUXERS); \
demuxers[num_demuxers++] = &impl; \
}
void init_demuxers(void) {
register_demuxer(ivf_demuxer);
register_demuxer(annexb_demuxer);
register_demuxer(section5_demuxer);
}
extern const Demuxer ivf_demuxer;
extern const Demuxer annexb_demuxer;
extern const Demuxer section5_demuxer;
static const Demuxer *const demuxers[] = {
&ivf_demuxer,
&annexb_demuxer,
&section5_demuxer,
NULL
};
int input_open(DemuxerContext **const c_out,
const char *const name, const char *const filename,
@@ -68,19 +62,19 @@ int input_open(DemuxerContext **const c_out,
int res, i;
if (name) {
for (i = 0; i < num_demuxers; i++) {
for (i = 0; demuxers[i]; i++) {
if (!strcmp(demuxers[i]->name, name)) {
impl = demuxers[i];
break;
}
}
if (i == num_demuxers) {
if (!demuxers[i]) {
fprintf(stderr, "Failed to find demuxer named \"%s\"\n", name);
return DAV1D_ERR(ENOPROTOOPT);
}
} else {
int probe_sz = 0;
for (i = 0; i < num_demuxers; i++)
for (i = 0; demuxers[i]; i++)
probe_sz = imax(probe_sz, demuxers[i]->probe_sz);
uint8_t *const probe_data = malloc(probe_sz);
if (!probe_data) {
@@ -96,14 +90,14 @@ int input_open(DemuxerContext **const c_out,
return errno ? DAV1D_ERR(errno) : DAV1D_ERR(EIO);
}
for (i = 0; i < num_demuxers; i++) {
for (i = 0; demuxers[i]; i++) {
if (demuxers[i]->probe(probe_data)) {
impl = demuxers[i];
break;
}
}
free(probe_data);
if (i == num_demuxers) {
if (!demuxers[i]) {
fprintf(stderr,
"Failed to probe demuxer for file %s\n",
filename);
-1
View File
@@ -32,7 +32,6 @@
typedef struct DemuxerContext DemuxerContext;
void init_demuxers(void);
int input_open(DemuxerContext **const c_out,
const char *const name, const char *const filename,
unsigned fps[2], unsigned *num_frames, unsigned timebase[2]);
+20 -30
View File
@@ -42,22 +42,17 @@ struct MuxerContext {
const Muxer *impl;
};
#define MAX_NUM_MUXERS 4
static const Muxer *muxers[MAX_NUM_MUXERS];
static unsigned num_muxers = 0;
#define register_muxer(impl) { \
extern const Muxer impl; \
assert(num_muxers < MAX_NUM_MUXERS); \
muxers[num_muxers++] = &impl; \
}
void init_muxers(void) {
register_muxer(null_muxer);
register_muxer(md5_muxer);
register_muxer(yuv_muxer);
register_muxer(y4m2_muxer);
}
extern const Muxer null_muxer;
extern const Muxer md5_muxer;
extern const Muxer yuv_muxer;
extern const Muxer y4m2_muxer;
static const Muxer *muxers[] = {
&null_muxer,
&md5_muxer,
&yuv_muxer,
&y4m2_muxer,
NULL
};
static const char *find_extension(const char *const f) {
const size_t l = strlen(f);
@@ -86,31 +81,31 @@ int output_open(MuxerContext **const c_out,
int res;
if (name) {
for (i = 0; i < num_muxers; i++) {
for (i = 0; muxers[i]; i++) {
if (!strcmp(muxers[i]->name, name)) {
impl = muxers[i];
break;
}
}
if (i == num_muxers) {
if (!muxers[i]) {
fprintf(stderr, "Failed to find muxer named \"%s\"\n", name);
return DAV1D_ERR(ENOPROTOOPT);
}
} else if (!strcmp(filename, "/dev/null")) {
impl = muxers[0];
} else {
const char *ext = find_extension(filename);
const char *const ext = find_extension(filename);
if (!ext) {
fprintf(stderr, "No extension found for file %s\n", filename);
return -1;
}
for (i = 0; i < num_muxers; i++) {
for (i = 0; muxers[i]; i++) {
if (!strcmp(muxers[i]->extension, ext)) {
impl = muxers[i];
break;
}
}
if (i == num_muxers) {
if (!muxers[i]) {
fprintf(stderr, "Failed to find muxer for extension \"%s\"\n", ext);
return DAV1D_ERR(ENOPROTOOPT);
}
@@ -132,12 +127,8 @@ int output_open(MuxerContext **const c_out,
}
int output_write(MuxerContext *const ctx, Dav1dPicture *const p) {
int res;
if ((res = ctx->impl->write_picture(ctx->data, p)) < 0)
return res;
return 0;
const int res = ctx->impl->write_picture(ctx->data, p);
return res < 0 ? res : 0;
}
void output_close(MuxerContext *const ctx) {
@@ -147,9 +138,8 @@ void output_close(MuxerContext *const ctx) {
}
int output_verify(MuxerContext *const ctx, const char *const md5_str) {
int res = 0;
if (ctx->impl->verify)
res = ctx->impl->verify(ctx->data, md5_str);
const int res = ctx->impl->verify ?
ctx->impl->verify(ctx->data, md5_str) : 0;
free(ctx);
return res;
}
-1
View File
@@ -32,7 +32,6 @@
typedef struct MuxerContext MuxerContext;
void init_muxers(void);
int output_open(MuxerContext **c, const char *name, const char *filename,
const Dav1dPictureParameters *p, const unsigned fps[2]);
int output_write(MuxerContext *ctx, Dav1dPicture *pic);