ref: cacc8e350c4066ff1bb3ffb2cbf9813bd26d7baa
parent: 0c88560789b4388cc1d2113110574040606a0b45
author: Luc Trudeau <[email protected]>
date: Fri Feb 21 05:01:18 EST 2020
cli: remove init_[de]muxers() functions Muxer and demuxers arrays are now statically initialized
--- a/tools/dav1d.c
+++ b/tools/dav1d.c
@@ -155,8 +155,6 @@
return EXIT_FAILURE;
}
- init_demuxers();
- init_muxers();
parse(argc, argv, &cli_settings, &lib_settings);
if ((res = input_open(&in, cli_settings.demuxer,
--- a/tools/input/input.c
+++ b/tools/input/input.c
@@ -43,22 +43,16 @@
const Demuxer *impl;
};
-#define MAX_NUM_DEMUXERS 3
-static const Demuxer *demuxers[MAX_NUM_DEMUXERS];
-static int num_demuxers = 0;
+extern const Demuxer ivf_demuxer;
+extern const Demuxer annexb_demuxer;
+extern const Demuxer section5_demuxer;
+static const Demuxer *const demuxers[] = {
+ &ivf_demuxer,
+ &annexb_demuxer,
+ §ion5_demuxer,
+ NULL
+};
-#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);
-}
-
int input_open(DemuxerContext **const c_out,
const char *const name, const char *const filename,
unsigned fps[2], unsigned *const num_frames, unsigned timebase[2])
@@ -68,19 +62,19 @@
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,7 +90,7 @@
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;
@@ -103,7 +97,7 @@
}
}
free(probe_data);
- if (i == num_demuxers) {
+ if (!demuxers[i]) {
fprintf(stderr,
"Failed to probe demuxer for file %s\n",
filename);
--- a/tools/input/input.h
+++ b/tools/input/input.h
@@ -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]);
--- a/tools/output/output.c
+++ b/tools/output/output.c
@@ -42,23 +42,18 @@
const Muxer *impl;
};
-#define MAX_NUM_MUXERS 4
-static const Muxer *muxers[MAX_NUM_MUXERS];
-static unsigned num_muxers = 0;
+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
+};
-#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);
-}
-
static const char *find_extension(const char *const f) {
const size_t l = strlen(f);
@@ -86,13 +81,13 @@
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);
}
@@ -99,18 +94,18 @@
} 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_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 @@
}
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;
}
--- a/tools/output/output.h
+++ b/tools/output/output.h
@@ -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);