check_add_cflags -Wdeclaration-after-statement
check_add_cflags -Wdisabled-optimization
check_add_cflags -Wfloat-conversion
+ check_add_cflags -Wformat=2
check_add_cflags -Wparentheses-equality
check_add_cflags -Wpointer-arith
check_add_cflags -Wtype-limits
#include <stdlib.h>
#include <string.h>
#define VPX_DISABLE_CTRL_TYPECHECKS 1
+#include "../tools_common.h"
#include "./vpx_config.h"
#include "./svc_context.h"
#include "vpx/vp8cx.h"
return (const SvcInternal_t *)svc_ctx->internal;
}
-static int svc_log(SvcContext *svc_ctx, SVC_LOG_LEVEL level, const char *fmt,
- ...) {
+static VPX_TOOLS_FORMAT_PRINTF(3, 4) int svc_log(SvcContext *svc_ctx,
+ SVC_LOG_LEVEL level,
+ const char *fmt, ...) {
char buf[512];
int retval = 0;
va_list ap;
if (alt_ref_enabled > REF_FRAMES - svc_ctx->spatial_layers) {
svc_log(svc_ctx, SVC_LOG_ERROR,
"svc: auto alt ref: Maxinum %d(REF_FRAMES - layers) layers could"
- "enabled auto alt reference frame, but % layers are enabled\n",
+ "enabled auto alt reference frame, but %d layers are enabled\n",
REF_FRAMES - svc_ctx->spatial_layers, alt_ref_enabled);
res = VPX_CODEC_INVALID_PARAM;
}
svc_ctx->temporal_layers = VPX_TS_MAX_LAYERS;
if (svc_ctx->temporal_layers * svc_ctx->spatial_layers > VPX_MAX_LAYERS) {
- svc_log(svc_ctx, SVC_LOG_ERROR,
- "spatial layers * temporal layers exceeds the maximum number of "
- "allowed layers of %d\n",
- svc_ctx->spatial_layers * svc_ctx->temporal_layers, VPX_MAX_LAYERS);
+ svc_log(
+ svc_ctx, SVC_LOG_ERROR,
+ "spatial layers * temporal layers (%d) exceeds the maximum number of "
+ "allowed layers of %d\n",
+ svc_ctx->spatial_layers * svc_ctx->temporal_layers, VPX_MAX_LAYERS);
return VPX_CODEC_INVALID_PARAM;
}
res = assign_layer_bitrates(svc_ctx, enc_cfg);
die("Invalid frame size: %dx%d", w, h);
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, w, h, 1))
- die("Failed to allocate image", w, h);
+ die("Failed to allocate image (%dx%d)", w, h);
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
framerate = (int)strtol(argv[3], NULL, 0);
if (width < 16 || width % 2 || height < 16 || height % 2)
- die("Invalid resolution: %ldx%ld", width, height);
+ die("Invalid resolution: %dx%d", width, height);
/* Open input video file for encoding */
if (!(infile = fopen(argv[4], "rb")))
(int)strtol(argv[2 * NUM_ENCODERS + 5 + i], NULL, 0);
if (num_temporal_layers[i] < 1 || num_temporal_layers[i] > 3)
die("Invalid temporal layers: %d, Must be 1, 2, or 3. \n",
- num_temporal_layers);
+ num_temporal_layers[i]);
}
/* Open file to write out each spatially downsampled input stream. */
/* Allocate image for each encoder */
for (i = 0; i < NUM_ENCODERS; i++)
if (!vpx_img_alloc(&raw[i], VPX_IMG_FMT_I420, cfg[i].g_w, cfg[i].g_h, 32))
- die("Failed to allocate image", cfg[i].g_w, cfg[i].g_h);
+ die("Failed to allocate image (%dx%d)", cfg[i].g_w, cfg[i].g_h);
if (raw[0].stride[VPX_PLANE_Y] == (int)raw[0].d_w)
read_frame_p = mulres_read_frame;
&raw,
bit_depth == VPX_BITS_8 ? VPX_IMG_FMT_I420 : VPX_IMG_FMT_I42016,
width, height, 32)) {
- die("Failed to allocate image", width, height);
+ die("Failed to allocate image (%dx%d)", width, height);
}
}
#else
// Y4M reader has its own allocation.
if (input_ctx.file_type != FILE_TYPE_Y4M) {
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, width, height, 32)) {
- die("Failed to allocate image", width, height);
+ die("Failed to allocate image (%dx%d)", width, height);
}
}
#endif // CONFIG_VP9_HIGHBITDEPTH
static void show_histogram(const struct hist_bucket *bucket, int buckets,
int total, int scale) {
- const char *pat1, *pat2;
+ int width1, width2;
int i;
assert(bucket != NULL);
switch ((int)(log(bucket[buckets - 1].high) / log(10)) + 1) {
case 1:
case 2:
- pat1 = "%4d %2s: ";
- pat2 = "%4d-%2d: ";
+ width1 = 4;
+ width2 = 2;
break;
case 3:
- pat1 = "%5d %3s: ";
- pat2 = "%5d-%3d: ";
+ width1 = 5;
+ width2 = 3;
break;
case 4:
- pat1 = "%6d %4s: ";
- pat2 = "%6d-%4d: ";
+ width1 = 6;
+ width2 = 4;
break;
case 5:
- pat1 = "%7d %5s: ";
- pat2 = "%7d-%5d: ";
+ width1 = 7;
+ width2 = 5;
break;
case 6:
- pat1 = "%8d %6s: ";
- pat2 = "%8d-%6d: ";
+ width1 = 8;
+ width2 = 6;
break;
case 7:
- pat1 = "%9d %7s: ";
- pat2 = "%9d-%7d: ";
+ width1 = 9;
+ width2 = 7;
break;
default:
- pat1 = "%12d %10s: ";
- pat2 = "%12d-%10d: ";
+ width1 = 12;
+ width2 = 10;
break;
}
assert(len <= HIST_BAR_MAX);
if (bucket[i].low == bucket[i].high)
- fprintf(stderr, pat1, bucket[i].low, "");
+ fprintf(stderr, "%*d %*s: ", width1, bucket[i].low, width2, "");
else
- fprintf(stderr, pat2, bucket[i].low, bucket[i].high);
+ fprintf(stderr, "%*d-%*d: ", width1, bucket[i].low, width2,
+ bucket[i].high);
for (j = 0; j < HIST_BAR_MAX; j++) fprintf(stderr, j < len ? "=" : " ");
fprintf(stderr, "\t%5d (%6.2f%%)\n", bucket[i].count, pct);
#define VPX_NO_RETURN
#endif
+// Tells the compiler to perform `printf` format string checking if the
+// compiler supports it; see the 'format' attribute in
+// <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html>.
+#define VPX_TOOLS_FORMAT_PRINTF(string_index, first_to_check)
+#if defined(__has_attribute)
+#if __has_attribute(format)
+#undef VPX_TOOLS_FORMAT_PRINTF
+#define VPX_TOOLS_FORMAT_PRINTF(string_index, first_to_check) \
+ __attribute__((__format__(__printf__, string_index, first_to_check)))
+#endif
+#endif
+
/* Sets a stdio stream into binary mode */
FILE *set_binary_mode(FILE *stream);
-VPX_NO_RETURN void die(const char *fmt, ...);
-VPX_NO_RETURN void fatal(const char *fmt, ...);
-void warn(const char *fmt, ...);
+VPX_NO_RETURN void die(const char *fmt, ...) VPX_TOOLS_FORMAT_PRINTF(1, 2);
+VPX_NO_RETURN void fatal(const char *fmt, ...) VPX_TOOLS_FORMAT_PRINTF(1, 2);
+void warn(const char *fmt, ...) VPX_TOOLS_FORMAT_PRINTF(1, 2);
VPX_NO_RETURN void die_codec(vpx_codec_ctx_t *ctx, const char *s);
static const char *exec_name;
-static void warn_or_exit_on_errorv(vpx_codec_ctx_t *ctx, int fatal,
- const char *s, va_list ap) {
+static VPX_TOOLS_FORMAT_PRINTF(3, 0) void warn_or_exit_on_errorv(
+ vpx_codec_ctx_t *ctx, int fatal, const char *s, va_list ap) {
if (ctx->err) {
const char *detail = vpx_codec_error_detail(ctx);
}
}
-static void ctx_exit_on_error(vpx_codec_ctx_t *ctx, const char *s, ...) {
+static VPX_TOOLS_FORMAT_PRINTF(2,
+ 3) void ctx_exit_on_error(vpx_codec_ctx_t *ctx,
+ const char *s, ...) {
va_list ap;
va_start(ap, s);
va_end(ap);
}
-static void warn_or_exit_on_error(vpx_codec_ctx_t *ctx, int fatal,
- const char *s, ...) {
+static VPX_TOOLS_FORMAT_PRINTF(3, 4) void warn_or_exit_on_error(
+ vpx_codec_ctx_t *ctx, int fatal, const char *s, ...) {
va_list ap;
va_start(ap, s);
stats->buf.buf = malloc(stats->buf_alloc_sz);
if (!stats->buf.buf)
- fatal("Failed to allocate first-pass stats buffer (%lu bytes)",
+ fatal("Failed to allocate first-pass stats buffer (%u bytes)",
(unsigned int)stats->buf_alloc_sz);
nbytes = fread(stats->buf.buf, 1, stats->buf.sz, stats->file);
/* Count and print warnings. */
for (warning = warning_list.warning_node; warning != NULL;
warning = warning->next_warning, ++num_warnings) {
- warn(warning->warning_string);
+ warn("%s", warning->warning_string);
}
free_warning_list(&warning_list);