diff --git a/args.c b/args.c index 14b031040..51c0fb9c4 100644 --- a/args.c +++ b/args.c @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - #include #include #include @@ -22,42 +21,36 @@ extern void die(const char *fmt, ...) __attribute__((noreturn)); extern void die(const char *fmt, ...); #endif - struct arg arg_init(char **argv) { struct arg a; - a.argv = argv; + a.argv = argv; a.argv_step = 1; - a.name = NULL; - a.val = NULL; - a.def = NULL; + a.name = NULL; + a.val = NULL; + a.def = NULL; return a; } int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) { struct arg arg; - if (!argv[0] || argv[0][0] != '-') - return 0; + if (!argv[0] || argv[0][0] != '-') return 0; arg = arg_init(argv); - if (def->short_name - && strlen(arg.argv[0]) == strlen(def->short_name) + 1 - && !strcmp(arg.argv[0] + 1, def->short_name)) { - + if (def->short_name && strlen(arg.argv[0]) == strlen(def->short_name) + 1 && + !strcmp(arg.argv[0] + 1, def->short_name)) { arg.name = arg.argv[0] + 1; arg.val = def->has_val ? arg.argv[1] : NULL; arg.argv_step = def->has_val ? 2 : 1; } else if (def->long_name) { const size_t name_len = strlen(def->long_name); - if (strlen(arg.argv[0]) >= name_len + 2 - && arg.argv[0][1] == '-' - && !strncmp(arg.argv[0] + 2, def->long_name, name_len) - && (arg.argv[0][name_len + 2] == '=' - || arg.argv[0][name_len + 2] == '\0')) { - + if (strlen(arg.argv[0]) >= name_len + 2 && arg.argv[0][1] == '-' && + !strncmp(arg.argv[0] + 2, def->long_name, name_len) && + (arg.argv[0][name_len + 2] == '=' || + arg.argv[0][name_len + 2] == '\0')) { arg.name = arg.argv[0] + 2; arg.val = arg.name[name_len] == '=' ? arg.name + name_len + 1 : NULL; arg.argv_step = 1; @@ -70,8 +63,7 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) { if (arg.name && arg.val && !def->has_val) die("Error: option %s requires no argument.\n", arg.name); - if (arg.name - && (arg.val || !def->has_val)) { + if (arg.name && (arg.val || !def->has_val)) { arg.def = def; *arg_ = arg; return 1; @@ -80,15 +72,12 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) { return 0; } - const char *arg_next(struct arg *arg) { - if (arg->argv[0]) - arg->argv += arg->argv_step; + if (arg->argv[0]) arg->argv += arg->argv_step; return *arg->argv; } - char **argv_dup(int argc, const char **argv) { char **new_argv = malloc((argc + 1) * sizeof(*argv)); @@ -97,9 +86,8 @@ char **argv_dup(int argc, const char **argv) { return new_argv; } - void arg_show_usage(FILE *fp, const struct arg_def *const *defs) { - char option_text[40] = {0}; + char option_text[40] = { 0 }; for (; *defs; defs++) { const struct arg_def *def = *defs; @@ -109,15 +97,12 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs) { if (def->short_name && def->long_name) { char *comma = def->has_val ? "," : ", "; - snprintf(option_text, 37, "-%s%s%s --%s%6s", - def->short_name, short_val, comma, - def->long_name, long_val); + snprintf(option_text, 37, "-%s%s%s --%s%6s", def->short_name, short_val, + comma, def->long_name, long_val); } else if (def->short_name) - snprintf(option_text, 37, "-%s%s", - def->short_name, short_val); + snprintf(option_text, 37, "-%s%s", def->short_name, short_val); else if (def->long_name) - snprintf(option_text, 37, " --%s%s", - def->long_name, long_val); + snprintf(option_text, 37, " --%s%s", def->long_name, long_val); fprintf(fp, " %-37s\t%s\n", option_text, def->desc); @@ -127,59 +112,53 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs) { fprintf(fp, " %-37s\t ", ""); for (listptr = def->enums; listptr->name; listptr++) - fprintf(fp, "%s%s", listptr->name, - listptr[1].name ? ", " : "\n"); + fprintf(fp, "%s%s", listptr->name, listptr[1].name ? ", " : "\n"); } } } - unsigned int arg_parse_uint(const struct arg *arg) { - long int rawval; - char *endptr; + long int rawval; + char *endptr; rawval = strtol(arg->val, &endptr, 10); if (arg->val[0] != '\0' && endptr[0] == '\0') { - if (rawval >= 0 && rawval <= UINT_MAX) - return rawval; + if (rawval >= 0 && rawval <= UINT_MAX) return rawval; - die("Option %s: Value %ld out of range for unsigned int\n", - arg->name, rawval); + die("Option %s: Value %ld out of range for unsigned int\n", arg->name, + rawval); } die("Option %s: Invalid character '%c'\n", arg->name, *endptr); return 0; } - int arg_parse_int(const struct arg *arg) { - long int rawval; - char *endptr; + long int rawval; + char *endptr; rawval = strtol(arg->val, &endptr, 10); if (arg->val[0] != '\0' && endptr[0] == '\0') { - if (rawval >= INT_MIN && rawval <= INT_MAX) - return rawval; + if (rawval >= INT_MIN && rawval <= INT_MAX) return rawval; - die("Option %s: Value %ld out of range for signed int\n", - arg->name, rawval); + die("Option %s: Value %ld out of range for signed int\n", arg->name, + rawval); } die("Option %s: Invalid character '%c'\n", arg->name, *endptr); return 0; } - struct vpx_rational { int num; /**< fraction numerator */ int den; /**< fraction denominator */ }; struct vpx_rational arg_parse_rational(const struct arg *arg) { - long int rawval; - char *endptr; - struct vpx_rational rat; + long int rawval; + char *endptr; + struct vpx_rational rat; /* parse numerator */ rawval = strtol(arg->val, &endptr, 10); @@ -187,9 +166,11 @@ struct vpx_rational arg_parse_rational(const struct arg *arg) { if (arg->val[0] != '\0' && endptr[0] == '/') { if (rawval >= INT_MIN && rawval <= INT_MAX) rat.num = rawval; - else die("Option %s: Value %ld out of range for signed int\n", - arg->name, rawval); - } else die("Option %s: Expected / at '%c'\n", arg->name, *endptr); + else + die("Option %s: Value %ld out of range for signed int\n", arg->name, + rawval); + } else + die("Option %s: Expected / at '%c'\n", arg->name, *endptr); /* parse denominator */ rawval = strtol(endptr + 1, &endptr, 10); @@ -197,40 +178,37 @@ struct vpx_rational arg_parse_rational(const struct arg *arg) { if (arg->val[0] != '\0' && endptr[0] == '\0') { if (rawval >= INT_MIN && rawval <= INT_MAX) rat.den = rawval; - else die("Option %s: Value %ld out of range for signed int\n", - arg->name, rawval); - } else die("Option %s: Invalid character '%c'\n", arg->name, *endptr); + else + die("Option %s: Value %ld out of range for signed int\n", arg->name, + rawval); + } else + die("Option %s: Invalid character '%c'\n", arg->name, *endptr); return rat; } - int arg_parse_enum(const struct arg *arg) { const struct arg_enum_list *listptr; - long int rawval; - char *endptr; + long int rawval; + char *endptr; /* First see if the value can be parsed as a raw value */ rawval = strtol(arg->val, &endptr, 10); if (arg->val[0] != '\0' && endptr[0] == '\0') { /* Got a raw value, make sure it's valid */ for (listptr = arg->def->enums; listptr->name; listptr++) - if (listptr->val == rawval) - return rawval; + if (listptr->val == rawval) return rawval; } /* Next see if it can be parsed as a string */ for (listptr = arg->def->enums; listptr->name; listptr++) - if (!strcmp(arg->val, listptr->name)) - return listptr->val; + if (!strcmp(arg->val, listptr->name)) return listptr->val; die("Option %s: Invalid value '%s'\n", arg->name, arg->val); return 0; } - int arg_parse_enum_or_int(const struct arg *arg) { - if (arg->def->enums) - return arg_parse_enum(arg); + if (arg->def->enums) return arg_parse_enum(arg); return arg_parse_int(arg); } diff --git a/args.h b/args.h index 1f37151a0..54abe0460 100644 --- a/args.h +++ b/args.h @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - #ifndef ARGS_H_ #define ARGS_H_ #include @@ -18,29 +17,33 @@ extern "C" { #endif struct arg { - char **argv; - const char *name; - const char *val; - unsigned int argv_step; - const struct arg_def *def; + char **argv; + const char *name; + const char *val; + unsigned int argv_step; + const struct arg_def *def; }; struct arg_enum_list { const char *name; - int val; + int val; }; -#define ARG_ENUM_LIST_END {0} +#define ARG_ENUM_LIST_END \ + { 0 } typedef struct arg_def { const char *short_name; const char *long_name; - int has_val; + int has_val; const char *desc; const struct arg_enum_list *enums; } arg_def_t; -#define ARG_DEF(s,l,v,d) {s,l,v,d, NULL} -#define ARG_DEF_ENUM(s,l,v,d,e) {s,l,v,d,e} -#define ARG_DEF_LIST_END {0} +#define ARG_DEF(s, l, v, d) \ + { s, l, v, d, NULL } +#define ARG_DEF_ENUM(s, l, v, d, e) \ + { s, l, v, d, e } +#define ARG_DEF_LIST_END \ + { 0 } struct arg arg_init(char **argv); int arg_match(struct arg *arg_, const struct arg_def *def, char **argv); diff --git a/ivfdec.c b/ivfdec.c index 7fc25a0e8..f64e594ab 100644 --- a/ivfdec.c +++ b/ivfdec.c @@ -46,7 +46,8 @@ int file_is_ivf(struct VpxInputContext *input_ctx) { is_ivf = 1; if (mem_get_le16(raw_hdr + 4) != 0) { - fprintf(stderr, "Error: Unrecognized IVF version! This file may not" + fprintf(stderr, + "Error: Unrecognized IVF version! This file may not" " decode properly."); } @@ -69,14 +70,13 @@ int file_is_ivf(struct VpxInputContext *input_ctx) { return is_ivf; } -int ivf_read_frame(FILE *infile, uint8_t **buffer, - size_t *bytes_read, size_t *buffer_size) { - char raw_header[IVF_FRAME_HDR_SZ] = {0}; +int ivf_read_frame(FILE *infile, uint8_t **buffer, size_t *bytes_read, + size_t *buffer_size) { + char raw_header[IVF_FRAME_HDR_SZ] = { 0 }; size_t frame_size = 0; if (fread(raw_header, IVF_FRAME_HDR_SZ, 1, infile) != 1) { - if (!feof(infile)) - warn("Failed to read frame size\n"); + if (!feof(infile)) warn("Failed to read frame size\n"); } else { frame_size = mem_get_le32(raw_header); diff --git a/ivfdec.h b/ivfdec.h index dd29cc617..af725572b 100644 --- a/ivfdec.h +++ b/ivfdec.h @@ -18,11 +18,11 @@ extern "C" { int file_is_ivf(struct VpxInputContext *input); -int ivf_read_frame(FILE *infile, uint8_t **buffer, - size_t *bytes_read, size_t *buffer_size); +int ivf_read_frame(FILE *infile, uint8_t **buffer, size_t *bytes_read, + size_t *buffer_size); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif #endif // IVFDEC_H_ diff --git a/ivfenc.c b/ivfenc.c index 4a97c4273..a50d31839 100644 --- a/ivfenc.c +++ b/ivfenc.c @@ -13,10 +13,8 @@ #include "vpx/vpx_encoder.h" #include "vpx_ports/mem_ops.h" -void ivf_write_file_header(FILE *outfile, - const struct vpx_codec_enc_cfg *cfg, - unsigned int fourcc, - int frame_cnt) { +void ivf_write_file_header(FILE *outfile, const struct vpx_codec_enc_cfg *cfg, + unsigned int fourcc, int frame_cnt) { char header[32]; header[0] = 'D'; diff --git a/ivfenc.h b/ivfenc.h index 6623687e8..ebdce47be 100644 --- a/ivfenc.h +++ b/ivfenc.h @@ -19,17 +19,15 @@ struct vpx_codec_cx_pkt; extern "C" { #endif -void ivf_write_file_header(FILE *outfile, - const struct vpx_codec_enc_cfg *cfg, - uint32_t fourcc, - int frame_cnt); +void ivf_write_file_header(FILE *outfile, const struct vpx_codec_enc_cfg *cfg, + uint32_t fourcc, int frame_cnt); void ivf_write_frame_header(FILE *outfile, int64_t pts, size_t frame_size); void ivf_write_frame_size(FILE *outfile, size_t frame_size); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif #endif // IVFENC_H_ diff --git a/md5_utils.c b/md5_utils.c index a9b979a41..093798b83 100644 --- a/md5_utils.c +++ b/md5_utils.c @@ -20,19 +20,17 @@ * Still in the public domain. */ -#include /* for memcpy() */ +#include /* for memcpy() */ #include "md5_utils.h" -static void -byteSwap(UWORD32 *buf, unsigned words) { +static void byteSwap(UWORD32 *buf, unsigned words) { md5byte *p; /* Only swap bytes for big endian machines */ int i = 1; - if (*(char *)&i == 1) - return; + if (*(char *)&i == 1) return; p = (md5byte *)buf; @@ -47,8 +45,7 @@ byteSwap(UWORD32 *buf, unsigned words) { * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ -void -MD5Init(struct MD5Context *ctx) { +void MD5Init(struct MD5Context *ctx) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; ctx->buf[2] = 0x98badcfe; @@ -62,8 +59,7 @@ MD5Init(struct MD5Context *ctx) { * Update context to reflect the concatenation of another buffer full * of bytes. */ -void -MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) { +void MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) { UWORD32 t; /* Update byte count */ @@ -71,9 +67,9 @@ MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) { t = ctx->bytes[0]; if ((ctx->bytes[0] = t + len) < t) - ctx->bytes[1]++; /* Carry from low to high */ + ctx->bytes[1]++; /* Carry from low to high */ - t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ + t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ if (t > len) { memcpy((md5byte *)ctx->in + 64 - t, buf, len); @@ -104,8 +100,7 @@ MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) { * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ -void -MD5Final(md5byte digest[16], struct MD5Context *ctx) { +void MD5Final(md5byte digest[16], struct MD5Context *ctx) { int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ md5byte *p = (md5byte *)ctx->in + count; @@ -115,7 +110,7 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx) { /* Bytes of padding needed to make 56 bytes (-8..55) */ count = 56 - 1 - count; - if (count < 0) { /* Padding forces an extra block */ + if (count < 0) { /* Padding forces an extra block */ memset(p, 0, count + 8); byteSwap(ctx->in, 16); MD5Transform(ctx->buf, ctx->in); @@ -147,8 +142,8 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx) { #define F4(x, y, z) (y ^ (x | ~z)) /* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f,w,x,y,z,in,s) \ - (w += f(x,y,z) + in, w = (w<>(32-s)) + x) +#define MD5STEP(f, w, x, y, z, in, s) \ + (w += f(x, y, z) + in, w = (w << s | w >> (32 - s)) + x) #if defined(__clang__) && defined(__has_attribute) #if __has_attribute(no_sanitize) @@ -166,8 +161,8 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx) { * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ -VPX_NO_UNSIGNED_OVERFLOW_CHECK void -MD5Transform(UWORD32 buf[4], UWORD32 const in[16]) { +VPX_NO_UNSIGNED_OVERFLOW_CHECK void MD5Transform(UWORD32 buf[4], + UWORD32 const in[16]) { register UWORD32 a, b, c, d; a = buf[0]; diff --git a/rate_hist.c b/rate_hist.c index a77222b16..872a10bae 100644 --- a/rate_hist.c +++ b/rate_hist.c @@ -45,8 +45,7 @@ struct rate_hist *init_rate_histogram(const vpx_codec_enc_cfg_t *cfg, hist->samples = cfg->rc_buf_sz * 5 / 4 * fps->num / fps->den / 1000; // prevent division by zero - if (hist->samples == 0) - hist->samples = 1; + if (hist->samples == 0) hist->samples = 1; hist->frames = 0; hist->total = 0; @@ -78,18 +77,16 @@ void update_rate_histogram(struct rate_hist *hist, int64_t avg_bitrate = 0; int64_t sum_sz = 0; const int64_t now = pkt->data.frame.pts * 1000 * - (uint64_t)cfg->g_timebase.num / - (uint64_t)cfg->g_timebase.den; + (uint64_t)cfg->g_timebase.num / + (uint64_t)cfg->g_timebase.den; int idx = hist->frames++ % hist->samples; hist->pts[idx] = now; hist->sz[idx] = (int)pkt->data.frame.sz; - if (now < cfg->rc_buf_initial_sz) - return; + if (now < cfg->rc_buf_initial_sz) return; - if (!cfg->rc_target_bitrate) - return; + if (!cfg->rc_target_bitrate) return; then = now; @@ -98,20 +95,16 @@ void update_rate_histogram(struct rate_hist *hist, const int i_idx = (i - 1) % hist->samples; then = hist->pts[i_idx]; - if (now - then > cfg->rc_buf_sz) - break; + if (now - then > cfg->rc_buf_sz) break; sum_sz += hist->sz[i_idx]; } - if (now == then) - return; + if (now == then) return; avg_bitrate = sum_sz * 8 * 1000 / (now - then); idx = (int)(avg_bitrate * (RATE_BINS / 2) / (cfg->rc_target_bitrate * 1000)); - if (idx < 0) - idx = 0; - if (idx > RATE_BINS - 1) - idx = RATE_BINS - 1; + if (idx < 0) idx = 0; + if (idx > RATE_BINS - 1) idx = RATE_BINS - 1; if (hist->bucket[idx].low > avg_bitrate) hist->bucket[idx].low = (int)avg_bitrate; if (hist->bucket[idx].high < avg_bitrate) @@ -120,8 +113,8 @@ void update_rate_histogram(struct rate_hist *hist, hist->total++; } -static int merge_hist_buckets(struct hist_bucket *bucket, - int max_buckets, int *num_buckets) { +static int merge_hist_buckets(struct hist_bucket *bucket, int max_buckets, + int *num_buckets) { int small_bucket = 0, merge_bucket = INT_MAX, big_bucket = 0; int buckets = *num_buckets; int i; @@ -129,10 +122,8 @@ static int merge_hist_buckets(struct hist_bucket *bucket, /* Find the extrema for this list of buckets */ big_bucket = small_bucket = 0; for (i = 0; i < buckets; i++) { - if (bucket[i].count < bucket[small_bucket].count) - small_bucket = i; - if (bucket[i].count > bucket[big_bucket].count) - big_bucket = i; + if (bucket[i].count < bucket[small_bucket].count) small_bucket = i; + if (bucket[i].count > bucket[big_bucket].count) big_bucket = i; } /* If we have too many buckets, merge the smallest with an adjacent @@ -174,13 +165,10 @@ static int merge_hist_buckets(struct hist_bucket *bucket, */ big_bucket = small_bucket = 0; for (i = 0; i < buckets; i++) { - if (i > merge_bucket) - bucket[i] = bucket[i + 1]; + if (i > merge_bucket) bucket[i] = bucket[i + 1]; - if (bucket[i].count < bucket[small_bucket].count) - small_bucket = i; - if (bucket[i].count > bucket[big_bucket].count) - big_bucket = i; + if (bucket[i].count < bucket[small_bucket].count) small_bucket = i; + if (bucket[i].count > bucket[big_bucket].count) big_bucket = i; } } @@ -188,8 +176,8 @@ static int merge_hist_buckets(struct hist_bucket *bucket, return bucket[big_bucket].count; } -static void show_histogram(const struct hist_bucket *bucket, - int buckets, int total, int scale) { +static void show_histogram(const struct hist_bucket *bucket, int buckets, + int total, int scale) { const char *pat1, *pat2; int i; @@ -232,8 +220,7 @@ static void show_histogram(const struct hist_bucket *bucket, pct = (float)(100.0 * bucket[i].count / total); len = HIST_BAR_MAX * bucket[i].count / scale; - if (len < 1) - len = 1; + if (len < 1) len = 1; assert(len <= HIST_BAR_MAX); if (bucket[i].low == bucket[i].high) @@ -241,8 +228,7 @@ static void show_histogram(const struct hist_bucket *bucket, else fprintf(stderr, pat2, bucket[i].low, bucket[i].high); - for (j = 0; j < HIST_BAR_MAX; j++) - fprintf(stderr, j < len ? "=" : " "); + for (j = 0; j < HIST_BAR_MAX; j++) fprintf(stderr, j < len ? "=" : " "); fprintf(stderr, "\t%5d (%6.2f%%)\n", bucket[i].count, pct); } } @@ -268,14 +254,13 @@ void show_q_histogram(const int counts[64], int max_buckets) { show_histogram(bucket, buckets, total, scale); } -void show_rate_histogram(struct rate_hist *hist, - const vpx_codec_enc_cfg_t *cfg, int max_buckets) { +void show_rate_histogram(struct rate_hist *hist, const vpx_codec_enc_cfg_t *cfg, + int max_buckets) { int i, scale; int buckets = 0; for (i = 0; i < RATE_BINS; i++) { - if (hist->bucket[i].low == INT_MAX) - continue; + if (hist->bucket[i].low == INT_MAX) continue; hist->bucket[buckets++] = hist->bucket[i]; } diff --git a/tools_common.c b/tools_common.c index 17c0d44f5..6f14c2556 100644 --- a/tools_common.c +++ b/tools_common.c @@ -29,23 +29,22 @@ #include #ifdef __OS2__ -#define _setmode setmode -#define _fileno fileno -#define _O_BINARY O_BINARY +#define _setmode setmode +#define _fileno fileno +#define _O_BINARY O_BINARY #endif #endif -#define LOG_ERROR(label) do {\ - const char *l = label;\ - va_list ap;\ - va_start(ap, fmt);\ - if (l)\ - fprintf(stderr, "%s: ", l);\ - vfprintf(stderr, fmt, ap);\ - fprintf(stderr, "\n");\ - va_end(ap);\ -} while (0) - +#define LOG_ERROR(label) \ + do { \ + const char *l = label; \ + va_list ap; \ + va_start(ap, fmt); \ + if (l) fprintf(stderr, "%s: ", l); \ + vfprintf(stderr, fmt, ap); \ + fprintf(stderr, "\n"); \ + va_end(ap); \ + } while (0) FILE *set_binary_mode(FILE *stream) { (void)stream; @@ -65,16 +64,13 @@ void fatal(const char *fmt, ...) { exit(EXIT_FAILURE); } -void warn(const char *fmt, ...) { - LOG_ERROR("Warning"); -} +void warn(const char *fmt, ...) { LOG_ERROR("Warning"); } void die_codec(vpx_codec_ctx_t *ctx, const char *s) { const char *detail = vpx_codec_error_detail(ctx); printf("%s: %s\n", s, vpx_codec_error(ctx)); - if (detail) - printf(" %s\n", detail); + if (detail) printf(" %s\n", detail); exit(EXIT_FAILURE); } @@ -97,15 +93,16 @@ int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame) { */ switch (plane) { case 1: - ptr = yuv_frame->planes[ - yuv_frame->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_V : VPX_PLANE_U]; + ptr = + yuv_frame->planes[yuv_frame->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_V + : VPX_PLANE_U]; break; case 2: - ptr = yuv_frame->planes[ - yuv_frame->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_U : VPX_PLANE_V]; + ptr = + yuv_frame->planes[yuv_frame->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_U + : VPX_PLANE_V]; break; - default: - ptr = yuv_frame->planes[plane]; + default: ptr = yuv_frame->planes[plane]; } for (r = 0; r < h; ++r) { @@ -134,11 +131,11 @@ int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame) { static const VpxInterface vpx_encoders[] = { #if CONFIG_VP8_ENCODER - {"vp8", VP8_FOURCC, &vpx_codec_vp8_cx}, + { "vp8", VP8_FOURCC, &vpx_codec_vp8_cx }, #endif #if CONFIG_VP9_ENCODER - {"vp9", VP9_FOURCC, &vpx_codec_vp9_cx}, + { "vp9", VP9_FOURCC, &vpx_codec_vp9_cx }, #endif }; @@ -146,17 +143,14 @@ int get_vpx_encoder_count(void) { return sizeof(vpx_encoders) / sizeof(vpx_encoders[0]); } -const VpxInterface *get_vpx_encoder_by_index(int i) { - return &vpx_encoders[i]; -} +const VpxInterface *get_vpx_encoder_by_index(int i) { return &vpx_encoders[i]; } const VpxInterface *get_vpx_encoder_by_name(const char *name) { int i; for (i = 0; i < get_vpx_encoder_count(); ++i) { const VpxInterface *encoder = get_vpx_encoder_by_index(i); - if (strcmp(encoder->name, name) == 0) - return encoder; + if (strcmp(encoder->name, name) == 0) return encoder; } return NULL; @@ -168,11 +162,11 @@ const VpxInterface *get_vpx_encoder_by_name(const char *name) { static const VpxInterface vpx_decoders[] = { #if CONFIG_VP8_DECODER - {"vp8", VP8_FOURCC, &vpx_codec_vp8_dx}, + { "vp8", VP8_FOURCC, &vpx_codec_vp8_dx }, #endif #if CONFIG_VP9_DECODER - {"vp9", VP9_FOURCC, &vpx_codec_vp9_dx}, + { "vp9", VP9_FOURCC, &vpx_codec_vp9_dx }, #endif }; @@ -180,17 +174,14 @@ int get_vpx_decoder_count(void) { return sizeof(vpx_decoders) / sizeof(vpx_decoders[0]); } -const VpxInterface *get_vpx_decoder_by_index(int i) { - return &vpx_decoders[i]; -} +const VpxInterface *get_vpx_decoder_by_index(int i) { return &vpx_decoders[i]; } const VpxInterface *get_vpx_decoder_by_name(const char *name) { int i; for (i = 0; i < get_vpx_decoder_count(); ++i) { - const VpxInterface *const decoder = get_vpx_decoder_by_index(i); - if (strcmp(decoder->name, name) == 0) - return decoder; + const VpxInterface *const decoder = get_vpx_decoder_by_index(i); + if (strcmp(decoder->name, name) == 0) return decoder; } return NULL; @@ -201,8 +192,7 @@ const VpxInterface *get_vpx_decoder_by_fourcc(uint32_t fourcc) { for (i = 0; i < get_vpx_decoder_count(); ++i) { const VpxInterface *const decoder = get_vpx_decoder_by_index(i); - if (decoder->fourcc == fourcc) - return decoder; + if (decoder->fourcc == fourcc) return decoder; } return NULL; @@ -220,7 +210,7 @@ int vpx_img_plane_width(const vpx_image_t *img, int plane) { } int vpx_img_plane_height(const vpx_image_t *img, int plane) { - if (plane > 0 && img->y_chroma_shift > 0) + if (plane > 0 && img->y_chroma_shift > 0) return (img->d_h + 1) >> img->y_chroma_shift; else return img->d_h; @@ -233,7 +223,7 @@ void vpx_img_write(const vpx_image_t *img, FILE *file) { const unsigned char *buf = img->planes[plane]; const int stride = img->stride[plane]; const int w = vpx_img_plane_width(img, plane) * - ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); const int h = vpx_img_plane_height(img, plane); int y; @@ -251,13 +241,12 @@ int vpx_img_read(vpx_image_t *img, FILE *file) { unsigned char *buf = img->planes[plane]; const int stride = img->stride[plane]; const int w = vpx_img_plane_width(img, plane) * - ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); const int h = vpx_img_plane_height(img, plane); int y; for (y = 0; y < h; ++y) { - if (fread(buf, 1, w, file) != (size_t)w) - return 0; + if (fread(buf, 1, w, file) != (size_t)w) return 0; buf += stride; } } @@ -286,19 +275,16 @@ static void highbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, int plane; if (dst->d_w != src->d_w || dst->d_h != src->d_h || dst->x_chroma_shift != src->x_chroma_shift || - dst->y_chroma_shift != src->y_chroma_shift || - dst->fmt != src->fmt || input_shift < 0) { + dst->y_chroma_shift != src->y_chroma_shift || dst->fmt != src->fmt || + input_shift < 0) { fatal("Unsupported image conversion"); } switch (src->fmt) { case VPX_IMG_FMT_I42016: case VPX_IMG_FMT_I42216: case VPX_IMG_FMT_I44416: - case VPX_IMG_FMT_I44016: - break; - default: - fatal("Unsupported image conversion"); - break; + case VPX_IMG_FMT_I44016: break; + default: fatal("Unsupported image conversion"); break; } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -313,8 +299,7 @@ static void highbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, (uint16_t *)(src->planes[plane] + y * src->stride[plane]); uint16_t *p_dst = (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]); - for (x = 0; x < w; x++) - *p_dst++ = (*p_src++ << input_shift) + offset; + for (x = 0; x < w; x++) *p_dst++ = (*p_src++ << input_shift) + offset; } } } @@ -327,19 +312,15 @@ static void lowbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, if (dst->d_w != src->d_w || dst->d_h != src->d_h || dst->x_chroma_shift != src->x_chroma_shift || dst->y_chroma_shift != src->y_chroma_shift || - dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH || - input_shift < 0) { + dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH || input_shift < 0) { fatal("Unsupported image conversion"); } switch (src->fmt) { case VPX_IMG_FMT_I420: case VPX_IMG_FMT_I422: case VPX_IMG_FMT_I444: - case VPX_IMG_FMT_I440: - break; - default: - fatal("Unsupported image conversion"); - break; + case VPX_IMG_FMT_I440: break; + default: fatal("Unsupported image conversion"); break; } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -360,8 +341,7 @@ static void lowbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, } } -void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src, - int input_shift) { +void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src, int input_shift) { if (src->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { highbd_img_upshift(dst, src, input_shift); } else { @@ -371,9 +351,8 @@ void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src, void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src) { int plane; - if (dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH != src->fmt || - dst->d_w != src->d_w || dst->d_h != src->d_h || - dst->x_chroma_shift != src->x_chroma_shift || + if (dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH != src->fmt || dst->d_w != src->d_w || + dst->d_h != src->d_h || dst->x_chroma_shift != src->x_chroma_shift || dst->y_chroma_shift != src->y_chroma_shift) { fatal("Unsupported image conversion"); } @@ -381,11 +360,8 @@ void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src) { case VPX_IMG_FMT_I420: case VPX_IMG_FMT_I422: case VPX_IMG_FMT_I444: - case VPX_IMG_FMT_I440: - break; - default: - fatal("Unsupported image conversion"); - break; + case VPX_IMG_FMT_I440: break; + default: fatal("Unsupported image conversion"); break; } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -411,19 +387,16 @@ static void highbd_img_downshift(vpx_image_t *dst, vpx_image_t *src, int plane; if (dst->d_w != src->d_w || dst->d_h != src->d_h || dst->x_chroma_shift != src->x_chroma_shift || - dst->y_chroma_shift != src->y_chroma_shift || - dst->fmt != src->fmt || down_shift < 0) { + dst->y_chroma_shift != src->y_chroma_shift || dst->fmt != src->fmt || + down_shift < 0) { fatal("Unsupported image conversion"); } switch (src->fmt) { case VPX_IMG_FMT_I42016: case VPX_IMG_FMT_I42216: case VPX_IMG_FMT_I44416: - case VPX_IMG_FMT_I44016: - break; - default: - fatal("Unsupported image conversion"); - break; + case VPX_IMG_FMT_I44016: break; + default: fatal("Unsupported image conversion"); break; } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -438,8 +411,7 @@ static void highbd_img_downshift(vpx_image_t *dst, vpx_image_t *src, (uint16_t *)(src->planes[plane] + y * src->stride[plane]); uint16_t *p_dst = (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]); - for (x = 0; x < w; x++) - *p_dst++ = *p_src++ >> down_shift; + for (x = 0; x < w; x++) *p_dst++ = *p_src++ >> down_shift; } } } @@ -450,19 +422,15 @@ static void lowbd_img_downshift(vpx_image_t *dst, vpx_image_t *src, if (dst->d_w != src->d_w || dst->d_h != src->d_h || dst->x_chroma_shift != src->x_chroma_shift || dst->y_chroma_shift != src->y_chroma_shift || - src->fmt != dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH || - down_shift < 0) { + src->fmt != dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH || down_shift < 0) { fatal("Unsupported image conversion"); } switch (dst->fmt) { case VPX_IMG_FMT_I420: case VPX_IMG_FMT_I422: case VPX_IMG_FMT_I444: - case VPX_IMG_FMT_I440: - break; - default: - fatal("Unsupported image conversion"); - break; + case VPX_IMG_FMT_I440: break; + default: fatal("Unsupported image conversion"); break; } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -483,8 +451,7 @@ static void lowbd_img_downshift(vpx_image_t *dst, vpx_image_t *src, } } -void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src, - int down_shift) { +void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src, int down_shift) { if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { highbd_img_downshift(dst, src, down_shift); } else { diff --git a/tools_common.h b/tools_common.h index 310b5695f..73ba1bc03 100644 --- a/tools_common.h +++ b/tools_common.h @@ -30,24 +30,24 @@ /* MinGW uses f{seek,tell}o64 for large files. */ #define fseeko fseeko64 #define ftello ftello64 -#endif /* _WIN32 */ +#endif /* _WIN32 */ #if CONFIG_OS_SUPPORT #if defined(_MSC_VER) -#include /* NOLINT */ -#define isatty _isatty -#define fileno _fileno +#include /* NOLINT */ +#define isatty _isatty +#define fileno _fileno #else -#include /* NOLINT */ -#endif /* _MSC_VER */ -#endif /* CONFIG_OS_SUPPORT */ +#include /* NOLINT */ +#endif /* _MSC_VER */ +#endif /* CONFIG_OS_SUPPORT */ /* Use 32-bit file operations in WebM file format when building ARM * executables (.axf) with RVCT. */ #if !CONFIG_OS_SUPPORT #define fseeko fseek #define ftello ftell -#endif /* CONFIG_OS_SUPPORT */ +#endif /* CONFIG_OS_SUPPORT */ #define LITERALU64(hi, lo) ((((uint64_t)hi) << 32) | lo) @@ -55,7 +55,7 @@ #define PATH_MAX 512 #endif -#define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */ +#define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */ #define IVF_FILE_HDR_SZ 32 #define RAW_FRAME_HDR_SZ sizeof(uint32_t) @@ -157,7 +157,7 @@ void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src); #endif #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif #endif // TOOLS_COMMON_H_ diff --git a/video_reader.c b/video_reader.c index 39c7edba1..a0ba2521c 100644 --- a/video_reader.c +++ b/video_reader.c @@ -30,21 +30,17 @@ VpxVideoReader *vpx_video_reader_open(const char *filename) { char header[32]; VpxVideoReader *reader = NULL; FILE *const file = fopen(filename, "rb"); - if (!file) - return NULL; // Can't open file + if (!file) return NULL; // Can't open file - if (fread(header, 1, 32, file) != 32) - return NULL; // Can't read file header + if (fread(header, 1, 32, file) != 32) return NULL; // Can't read file header if (memcmp(kIVFSignature, header, 4) != 0) return NULL; // Wrong IVF signature - if (mem_get_le16(header + 4) != 0) - return NULL; // Wrong IVF version + if (mem_get_le16(header + 4) != 0) return NULL; // Wrong IVF version reader = calloc(1, sizeof(*reader)); - if (!reader) - return NULL; // Can't allocate VpxVideoReader + if (!reader) return NULL; // Can't allocate VpxVideoReader reader->file = file; reader->info.codec_fourcc = mem_get_le32(header + 8); @@ -71,8 +67,7 @@ int vpx_video_reader_read_frame(VpxVideoReader *reader) { const uint8_t *vpx_video_reader_get_frame(VpxVideoReader *reader, size_t *size) { - if (size) - *size = reader->frame_size; + if (size) *size = reader->frame_size; return reader->buffer; } @@ -80,4 +75,3 @@ const uint8_t *vpx_video_reader_get_frame(VpxVideoReader *reader, const VpxVideoInfo *vpx_video_reader_get_info(VpxVideoReader *reader) { return &reader->info; } - diff --git a/video_reader.h b/video_reader.h index a62c6d710..73c25b00a 100644 --- a/video_reader.h +++ b/video_reader.h @@ -39,8 +39,7 @@ int vpx_video_reader_read_frame(VpxVideoReader *reader); // Returns the pointer to memory buffer with frame data read by last call to // vpx_video_reader_read_frame(). -const uint8_t *vpx_video_reader_get_frame(VpxVideoReader *reader, - size_t *size); +const uint8_t *vpx_video_reader_get_frame(VpxVideoReader *reader, size_t *size); // Fills VpxVideoInfo with information from opened video file. const VpxVideoInfo *vpx_video_reader_get_info(VpxVideoReader *reader); diff --git a/video_writer.c b/video_writer.c index 3695236bf..56d428b07 100644 --- a/video_writer.c +++ b/video_writer.c @@ -37,12 +37,10 @@ VpxVideoWriter *vpx_video_writer_open(const char *filename, if (container == kContainerIVF) { VpxVideoWriter *writer = NULL; FILE *const file = fopen(filename, "wb"); - if (!file) - return NULL; + if (!file) return NULL; writer = malloc(sizeof(*writer)); - if (!writer) - return NULL; + if (!writer) return NULL; writer->frame_count = 0; writer->info = *info; @@ -67,12 +65,10 @@ void vpx_video_writer_close(VpxVideoWriter *writer) { } } -int vpx_video_writer_write_frame(VpxVideoWriter *writer, - const uint8_t *buffer, size_t size, - int64_t pts) { +int vpx_video_writer_write_frame(VpxVideoWriter *writer, const uint8_t *buffer, + size_t size, int64_t pts) { ivf_write_frame_header(writer->file, pts, size); - if (fwrite(buffer, 1, size, writer->file) != size) - return 0; + if (fwrite(buffer, 1, size, writer->file) != size) return 0; ++writer->frame_count; diff --git a/video_writer.h b/video_writer.h index 5dbfe52ea..a769811c4 100644 --- a/video_writer.h +++ b/video_writer.h @@ -13,9 +13,7 @@ #include "./video_common.h" -typedef enum { - kContainerIVF -} VpxContainer; +typedef enum { kContainerIVF } VpxContainer; struct VpxVideoWriterStruct; typedef struct VpxVideoWriterStruct VpxVideoWriter; @@ -36,9 +34,8 @@ VpxVideoWriter *vpx_video_writer_open(const char *filename, void vpx_video_writer_close(VpxVideoWriter *writer); // Writes frame bytes to the file. -int vpx_video_writer_write_frame(VpxVideoWriter *writer, - const uint8_t *buffer, size_t size, - int64_t pts); +int vpx_video_writer_write_frame(VpxVideoWriter *writer, const uint8_t *buffer, + size_t size, int64_t pts); #ifdef __cplusplus } // extern "C" diff --git a/vpxdec.c b/vpxdec.c index dbe64aa94..84a1bf340 100644 --- a/vpxdec.c +++ b/vpxdec.c @@ -47,134 +47,145 @@ struct VpxDecInputContext { struct WebmInputContext *webm_ctx; }; -static const arg_def_t looparg = ARG_DEF( - NULL, "loops", 1, "Number of times to decode the file"); -static const arg_def_t codecarg = ARG_DEF( - NULL, "codec", 1, "Codec to use"); -static const arg_def_t use_yv12 = ARG_DEF( - NULL, "yv12", 0, "Output raw YV12 frames"); -static const arg_def_t use_i420 = ARG_DEF( - NULL, "i420", 0, "Output raw I420 frames"); -static const arg_def_t flipuvarg = ARG_DEF( - NULL, "flipuv", 0, "Flip the chroma planes in the output"); -static const arg_def_t rawvideo = ARG_DEF( - NULL, "rawvideo", 0, "Output raw YUV frames"); -static const arg_def_t noblitarg = ARG_DEF( - NULL, "noblit", 0, "Don't process the decoded frames"); -static const arg_def_t progressarg = ARG_DEF( - NULL, "progress", 0, "Show progress after each frame decodes"); -static const arg_def_t limitarg = ARG_DEF( - NULL, "limit", 1, "Stop decoding after n frames"); -static const arg_def_t skiparg = ARG_DEF( - NULL, "skip", 1, "Skip the first n input frames"); -static const arg_def_t postprocarg = ARG_DEF( - NULL, "postproc", 0, "Postprocess decoded frames"); -static const arg_def_t summaryarg = ARG_DEF( - NULL, "summary", 0, "Show timing summary"); -static const arg_def_t outputfile = ARG_DEF( - "o", "output", 1, "Output file name pattern (see below)"); -static const arg_def_t threadsarg = ARG_DEF( - "t", "threads", 1, "Max threads to use"); -static const arg_def_t frameparallelarg = ARG_DEF( - NULL, "frame-parallel", 0, "Frame parallel decode"); -static const arg_def_t verbosearg = ARG_DEF( - "v", "verbose", 0, "Show version string"); -static const arg_def_t error_concealment = ARG_DEF( - NULL, "error-concealment", 0, "Enable decoder error-concealment"); -static const arg_def_t scalearg = ARG_DEF( - "S", "scale", 0, "Scale output frames uniformly"); -static const arg_def_t continuearg = ARG_DEF( - "k", "keep-going", 0, "(debug) Continue decoding after error"); -static const arg_def_t fb_arg = ARG_DEF( - NULL, "frame-buffers", 1, "Number of frame buffers to use"); -static const arg_def_t md5arg = ARG_DEF( - NULL, "md5", 0, "Compute the MD5 sum of the decoded frame"); +static const arg_def_t looparg = + ARG_DEF(NULL, "loops", 1, "Number of times to decode the file"); +static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, "Codec to use"); +static const arg_def_t use_yv12 = + ARG_DEF(NULL, "yv12", 0, "Output raw YV12 frames"); +static const arg_def_t use_i420 = + ARG_DEF(NULL, "i420", 0, "Output raw I420 frames"); +static const arg_def_t flipuvarg = + ARG_DEF(NULL, "flipuv", 0, "Flip the chroma planes in the output"); +static const arg_def_t rawvideo = + ARG_DEF(NULL, "rawvideo", 0, "Output raw YUV frames"); +static const arg_def_t noblitarg = + ARG_DEF(NULL, "noblit", 0, "Don't process the decoded frames"); +static const arg_def_t progressarg = + ARG_DEF(NULL, "progress", 0, "Show progress after each frame decodes"); +static const arg_def_t limitarg = + ARG_DEF(NULL, "limit", 1, "Stop decoding after n frames"); +static const arg_def_t skiparg = + ARG_DEF(NULL, "skip", 1, "Skip the first n input frames"); +static const arg_def_t postprocarg = + ARG_DEF(NULL, "postproc", 0, "Postprocess decoded frames"); +static const arg_def_t summaryarg = + ARG_DEF(NULL, "summary", 0, "Show timing summary"); +static const arg_def_t outputfile = + ARG_DEF("o", "output", 1, "Output file name pattern (see below)"); +static const arg_def_t threadsarg = + ARG_DEF("t", "threads", 1, "Max threads to use"); +static const arg_def_t frameparallelarg = + ARG_DEF(NULL, "frame-parallel", 0, "Frame parallel decode"); +static const arg_def_t verbosearg = + ARG_DEF("v", "verbose", 0, "Show version string"); +static const arg_def_t error_concealment = + ARG_DEF(NULL, "error-concealment", 0, "Enable decoder error-concealment"); +static const arg_def_t scalearg = + ARG_DEF("S", "scale", 0, "Scale output frames uniformly"); +static const arg_def_t continuearg = + ARG_DEF("k", "keep-going", 0, "(debug) Continue decoding after error"); +static const arg_def_t fb_arg = + ARG_DEF(NULL, "frame-buffers", 1, "Number of frame buffers to use"); +static const arg_def_t md5arg = + ARG_DEF(NULL, "md5", 0, "Compute the MD5 sum of the decoded frame"); #if CONFIG_VP9_HIGHBITDEPTH -static const arg_def_t outbitdeptharg = ARG_DEF( - NULL, "output-bit-depth", 1, "Output bit-depth for decoded frames"); +static const arg_def_t outbitdeptharg = + ARG_DEF(NULL, "output-bit-depth", 1, "Output bit-depth for decoded frames"); #endif -static const arg_def_t *all_args[] = { - &codecarg, &use_yv12, &use_i420, &flipuvarg, &rawvideo, &noblitarg, - &progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile, - &threadsarg, &frameparallelarg, &verbosearg, &scalearg, &fb_arg, - &md5arg, &error_concealment, &continuearg, +static const arg_def_t *all_args[] = { &codecarg, + &use_yv12, + &use_i420, + &flipuvarg, + &rawvideo, + &noblitarg, + &progressarg, + &limitarg, + &skiparg, + &postprocarg, + &summaryarg, + &outputfile, + &threadsarg, + &frameparallelarg, + &verbosearg, + &scalearg, + &fb_arg, + &md5arg, + &error_concealment, + &continuearg, #if CONFIG_VP9_HIGHBITDEPTH - &outbitdeptharg, + &outbitdeptharg, #endif - NULL -}; + NULL }; #if CONFIG_VP8_DECODER -static const arg_def_t addnoise_level = ARG_DEF( - NULL, "noise-level", 1, "Enable VP8 postproc add noise"); -static const arg_def_t deblock = ARG_DEF( - NULL, "deblock", 0, "Enable VP8 deblocking"); +static const arg_def_t addnoise_level = + ARG_DEF(NULL, "noise-level", 1, "Enable VP8 postproc add noise"); +static const arg_def_t deblock = + ARG_DEF(NULL, "deblock", 0, "Enable VP8 deblocking"); static const arg_def_t demacroblock_level = ARG_DEF( NULL, "demacroblock-level", 1, "Enable VP8 demacroblocking, w/ level"); -static const arg_def_t pp_debug_info = ARG_DEF( - NULL, "pp-debug-info", 1, "Enable VP8 visible debug info"); -static const arg_def_t pp_disp_ref_frame = ARG_DEF( - NULL, "pp-dbg-ref-frame", 1, - "Display only selected reference frame per macro block"); +static const arg_def_t pp_debug_info = + ARG_DEF(NULL, "pp-debug-info", 1, "Enable VP8 visible debug info"); +static const arg_def_t pp_disp_ref_frame = + ARG_DEF(NULL, "pp-dbg-ref-frame", 1, + "Display only selected reference frame per macro block"); static const arg_def_t pp_disp_mb_modes = ARG_DEF( NULL, "pp-dbg-mb-modes", 1, "Display only selected macro block modes"); -static const arg_def_t pp_disp_b_modes = ARG_DEF( - NULL, "pp-dbg-b-modes", 1, "Display only selected block modes"); -static const arg_def_t pp_disp_mvs = ARG_DEF( - NULL, "pp-dbg-mvs", 1, "Draw only selected motion vectors"); -static const arg_def_t mfqe = ARG_DEF( - NULL, "mfqe", 0, "Enable multiframe quality enhancement"); +static const arg_def_t pp_disp_b_modes = + ARG_DEF(NULL, "pp-dbg-b-modes", 1, "Display only selected block modes"); +static const arg_def_t pp_disp_mvs = + ARG_DEF(NULL, "pp-dbg-mvs", 1, "Draw only selected motion vectors"); +static const arg_def_t mfqe = + ARG_DEF(NULL, "mfqe", 0, "Enable multiframe quality enhancement"); -static const arg_def_t *vp8_pp_args[] = { - &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info, - &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe, - NULL -}; +static const arg_def_t *vp8_pp_args[] = { &addnoise_level, + &deblock, + &demacroblock_level, + &pp_debug_info, + &pp_disp_ref_frame, + &pp_disp_mb_modes, + &pp_disp_b_modes, + &pp_disp_mvs, + &mfqe, + NULL }; #endif #if CONFIG_LIBYUV static INLINE int libyuv_scale(vpx_image_t *src, vpx_image_t *dst, - FilterModeEnum mode) { + FilterModeEnum mode) { #if CONFIG_VP9_HIGHBITDEPTH if (src->fmt == VPX_IMG_FMT_I42016) { assert(dst->fmt == VPX_IMG_FMT_I42016); - return I420Scale_16((uint16_t*)src->planes[VPX_PLANE_Y], - src->stride[VPX_PLANE_Y]/2, - (uint16_t*)src->planes[VPX_PLANE_U], - src->stride[VPX_PLANE_U]/2, - (uint16_t*)src->planes[VPX_PLANE_V], - src->stride[VPX_PLANE_V]/2, - src->d_w, src->d_h, - (uint16_t*)dst->planes[VPX_PLANE_Y], - dst->stride[VPX_PLANE_Y]/2, - (uint16_t*)dst->planes[VPX_PLANE_U], - dst->stride[VPX_PLANE_U]/2, - (uint16_t*)dst->planes[VPX_PLANE_V], - dst->stride[VPX_PLANE_V]/2, - dst->d_w, dst->d_h, - mode); + return I420Scale_16( + (uint16_t *)src->planes[VPX_PLANE_Y], src->stride[VPX_PLANE_Y] / 2, + (uint16_t *)src->planes[VPX_PLANE_U], src->stride[VPX_PLANE_U] / 2, + (uint16_t *)src->planes[VPX_PLANE_V], src->stride[VPX_PLANE_V] / 2, + src->d_w, src->d_h, (uint16_t *)dst->planes[VPX_PLANE_Y], + dst->stride[VPX_PLANE_Y] / 2, (uint16_t *)dst->planes[VPX_PLANE_U], + dst->stride[VPX_PLANE_U] / 2, (uint16_t *)dst->planes[VPX_PLANE_V], + dst->stride[VPX_PLANE_V] / 2, dst->d_w, dst->d_h, mode); } #endif assert(src->fmt == VPX_IMG_FMT_I420); assert(dst->fmt == VPX_IMG_FMT_I420); return I420Scale(src->planes[VPX_PLANE_Y], src->stride[VPX_PLANE_Y], src->planes[VPX_PLANE_U], src->stride[VPX_PLANE_U], - src->planes[VPX_PLANE_V], src->stride[VPX_PLANE_V], - src->d_w, src->d_h, - dst->planes[VPX_PLANE_Y], dst->stride[VPX_PLANE_Y], + src->planes[VPX_PLANE_V], src->stride[VPX_PLANE_V], src->d_w, + src->d_h, dst->planes[VPX_PLANE_Y], dst->stride[VPX_PLANE_Y], dst->planes[VPX_PLANE_U], dst->stride[VPX_PLANE_U], - dst->planes[VPX_PLANE_V], dst->stride[VPX_PLANE_V], - dst->d_w, dst->d_h, - mode); + dst->planes[VPX_PLANE_V], dst->stride[VPX_PLANE_V], dst->d_w, + dst->d_h, mode); } #endif void usage_exit(void) { int i; - fprintf(stderr, "Usage: %s filename\n\n" - "Options:\n", exec_name); + fprintf(stderr, + "Usage: %s filename\n\n" + "Options:\n", + exec_name); arg_show_usage(stderr, all_args); #if CONFIG_VP8_DECODER fprintf(stderr, "\nVP8 Postprocessing Options:\n"); @@ -193,27 +204,25 @@ void usage_exit(void) { "\n\t%% - Frame number, zero padded to places (1..9)" "\n\n Pattern arguments are only supported in conjunction " "with the --yv12 and\n --i420 options. If the -o option is " - "not specified, the output will be\n directed to stdout.\n" - ); + "not specified, the output will be\n directed to stdout.\n"); fprintf(stderr, "\nIncluded decoders:\n\n"); for (i = 0; i < get_vpx_decoder_count(); ++i) { const VpxInterface *const decoder = get_vpx_decoder_by_index(i); - fprintf(stderr, " %-6s - %s\n", - decoder->name, vpx_codec_iface_name(decoder->codec_interface())); + fprintf(stderr, " %-6s - %s\n", decoder->name, + vpx_codec_iface_name(decoder->codec_interface())); } exit(EXIT_FAILURE); } -static int raw_read_frame(FILE *infile, uint8_t **buffer, - size_t *bytes_read, size_t *buffer_size) { +static int raw_read_frame(FILE *infile, uint8_t **buffer, size_t *bytes_read, + size_t *buffer_size) { char raw_hdr[RAW_FRAME_HDR_SZ]; size_t frame_size = 0; if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) { - if (!feof(infile)) - warn("Failed to read RAW frame size\n"); + if (!feof(infile)) warn("Failed to read RAW frame size\n"); } else { const size_t kCorruptFrameThreshold = 256 * 1024 * 1024; const size_t kFrameTooSmallThreshold = 256 * 1024; @@ -260,13 +269,12 @@ static int read_frame(struct VpxDecInputContext *input, uint8_t **buf, return webm_read_frame(input->webm_ctx, buf, bytes_in_buffer); #endif case FILE_TYPE_RAW: - return raw_read_frame(input->vpx_input_ctx->file, - buf, bytes_in_buffer, buffer_size); + return raw_read_frame(input->vpx_input_ctx->file, buf, bytes_in_buffer, + buffer_size); case FILE_TYPE_IVF: - return ivf_read_frame(input->vpx_input_ctx->file, - buf, bytes_in_buffer, buffer_size); - default: - return 1; + return ivf_read_frame(input->vpx_input_ctx->file, buf, bytes_in_buffer, + buffer_size); + default: return 1; } } @@ -279,7 +287,7 @@ static void update_image_md5(const vpx_image_t *img, const int planes[3], const unsigned char *buf = img->planes[plane]; const int stride = img->stride[plane]; const int w = vpx_img_plane_width(img, plane) * - ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); const int h = vpx_img_plane_height(img, plane); for (y = 0; y < h; ++y) { @@ -325,8 +333,8 @@ static int file_is_raw(struct VpxInputContext *input) { if (mem_get_le32(buf) < 256 * 1024 * 1024) { for (i = 0; i < get_vpx_decoder_count(); ++i) { const VpxInterface *const decoder = get_vpx_decoder_by_index(i); - if (!vpx_codec_peek_stream_info(decoder->codec_interface(), - buf + 4, 32 - 4, &si)) { + if (!vpx_codec_peek_stream_info(decoder->codec_interface(), buf + 4, + 32 - 4, &si)) { is_raw = 1; input->fourcc = decoder->fourcc; input->width = si.w; @@ -345,13 +353,13 @@ static int file_is_raw(struct VpxInputContext *input) { static void show_progress(int frame_in, int frame_out, uint64_t dx_time) { fprintf(stderr, - "%d decoded frames/%d showed frames in %"PRId64" us (%.2f fps)\r", + "%d decoded frames/%d showed frames in %" PRId64 " us (%.2f fps)\r", frame_in, frame_out, dx_time, (double)frame_out * 1000000.0 / (double)dx_time); } struct ExternalFrameBuffer { - uint8_t* data; + uint8_t *data; size_t size; int in_use; }; @@ -370,23 +378,19 @@ static int get_vp9_frame_buffer(void *cb_priv, size_t min_size, int i; struct ExternalFrameBufferList *const ext_fb_list = (struct ExternalFrameBufferList *)cb_priv; - if (ext_fb_list == NULL) - return -1; + if (ext_fb_list == NULL) return -1; // Find a free frame buffer. for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) { - if (!ext_fb_list->ext_fb[i].in_use) - break; + if (!ext_fb_list->ext_fb[i].in_use) break; } - if (i == ext_fb_list->num_external_frame_buffers) - return -1; + if (i == ext_fb_list->num_external_frame_buffers) return -1; if (ext_fb_list->ext_fb[i].size < min_size) { free(ext_fb_list->ext_fb[i].data); ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size, sizeof(uint8_t)); - if (!ext_fb_list->ext_fb[i].data) - return -1; + if (!ext_fb_list->ext_fb[i].data) return -1; ext_fb_list->ext_fb[i].size = min_size; } @@ -427,47 +431,22 @@ static void generate_filename(const char *pattern, char *out, size_t q_len, /* parse the pattern */ q[q_len - 1] = '\0'; switch (p[1]) { - case 'w': - snprintf(q, q_len - 1, "%d", d_w); - break; - case 'h': - snprintf(q, q_len - 1, "%d", d_h); - break; - case '1': - snprintf(q, q_len - 1, "%d", frame_in); - break; - case '2': - snprintf(q, q_len - 1, "%02d", frame_in); - break; - case '3': - snprintf(q, q_len - 1, "%03d", frame_in); - break; - case '4': - snprintf(q, q_len - 1, "%04d", frame_in); - break; - case '5': - snprintf(q, q_len - 1, "%05d", frame_in); - break; - case '6': - snprintf(q, q_len - 1, "%06d", frame_in); - break; - case '7': - snprintf(q, q_len - 1, "%07d", frame_in); - break; - case '8': - snprintf(q, q_len - 1, "%08d", frame_in); - break; - case '9': - snprintf(q, q_len - 1, "%09d", frame_in); - break; - default: - die("Unrecognized pattern %%%c\n", p[1]); - break; + case 'w': snprintf(q, q_len - 1, "%d", d_w); break; + case 'h': snprintf(q, q_len - 1, "%d", d_h); break; + case '1': snprintf(q, q_len - 1, "%d", frame_in); break; + case '2': snprintf(q, q_len - 1, "%02d", frame_in); break; + case '3': snprintf(q, q_len - 1, "%03d", frame_in); break; + case '4': snprintf(q, q_len - 1, "%04d", frame_in); break; + case '5': snprintf(q, q_len - 1, "%05d", frame_in); break; + case '6': snprintf(q, q_len - 1, "%06d", frame_in); break; + case '7': snprintf(q, q_len - 1, "%07d", frame_in); break; + case '8': snprintf(q, q_len - 1, "%08d", frame_in); break; + case '9': snprintf(q, q_len - 1, "%09d", frame_in); break; + default: die("Unrecognized pattern %%%c\n", p[1]); break; } pat_len = strlen(q); - if (pat_len >= q_len - 1) - die("Output filename too long.\n"); + if (pat_len >= q_len - 1) die("Output filename too long.\n"); q += pat_len; p += 2; q_len -= pat_len; @@ -480,8 +459,7 @@ static void generate_filename(const char *pattern, char *out, size_t q_len, else copy_len = next_pat - p; - if (copy_len >= q_len - 1) - die("Output filename too long.\n"); + if (copy_len >= q_len - 1) die("Output filename too long.\n"); memcpy(q, p, copy_len); q[copy_len] = '\0'; @@ -499,8 +477,7 @@ static int is_single_file(const char *outfile_pattern) { p = strchr(p, '%'); if (p && p[1] >= '1' && p[1] <= '9') return 0; // pattern contains sequence number, so it's not unique - if (p) - p++; + if (p) p++; } while (p); return 1; @@ -509,8 +486,7 @@ static int is_single_file(const char *outfile_pattern) { static void print_md5(unsigned char digest[16], const char *filename) { int i; - for (i = 0; i < 16; ++i) - printf("%02x", digest[i]); + for (i = 0; i < 16; ++i) printf("%02x", digest[i]); printf(" %s\n", filename); } @@ -520,8 +496,7 @@ static FILE *open_outfile(const char *name) { return stdout; } else { FILE *file = fopen(name, "wb"); - if (!file) - fatal("Failed to open output file '%s'", name); + if (!file) fatal("Failed to open output file '%s'", name); return file; } } @@ -530,65 +505,64 @@ static FILE *open_outfile(const char *name) { static int img_shifted_realloc_required(const vpx_image_t *img, const vpx_image_t *shifted, vpx_img_fmt_t required_fmt) { - return img->d_w != shifted->d_w || - img->d_h != shifted->d_h || + return img->d_w != shifted->d_w || img->d_h != shifted->d_h || required_fmt != shifted->fmt; } #endif static int main_loop(int argc, const char **argv_) { - vpx_codec_ctx_t decoder; - char *fn = NULL; - int i; - uint8_t *buf = NULL; - size_t bytes_in_buffer = 0, buffer_size = 0; - FILE *infile; - int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0; - int do_md5 = 0, progress = 0, frame_parallel = 0; - int stop_after = 0, postproc = 0, summary = 0, quiet = 1; - int arg_skip = 0; - int ec_enabled = 0; - int keep_going = 0; + vpx_codec_ctx_t decoder; + char *fn = NULL; + int i; + uint8_t *buf = NULL; + size_t bytes_in_buffer = 0, buffer_size = 0; + FILE *infile; + int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0; + int do_md5 = 0, progress = 0, frame_parallel = 0; + int stop_after = 0, postproc = 0, summary = 0, quiet = 1; + int arg_skip = 0; + int ec_enabled = 0; + int keep_going = 0; const VpxInterface *interface = NULL; const VpxInterface *fourcc_interface = NULL; uint64_t dx_time = 0; - struct arg arg; - char **argv, **argi, **argj; + struct arg arg; + char **argv, **argi, **argj; - int single_file; - int use_y4m = 1; - int opt_yv12 = 0; - int opt_i420 = 0; - vpx_codec_dec_cfg_t cfg = {0, 0, 0}; + int single_file; + int use_y4m = 1; + int opt_yv12 = 0; + int opt_i420 = 0; + vpx_codec_dec_cfg_t cfg = { 0, 0, 0 }; #if CONFIG_VP9_HIGHBITDEPTH - unsigned int output_bit_depth = 0; + unsigned int output_bit_depth = 0; #endif #if CONFIG_VP8_DECODER - vp8_postproc_cfg_t vp8_pp_cfg = {0}; - int vp8_dbg_color_ref_frame = 0; - int vp8_dbg_color_mb_modes = 0; - int vp8_dbg_color_b_modes = 0; - int vp8_dbg_display_mv = 0; + vp8_postproc_cfg_t vp8_pp_cfg = { 0 }; + int vp8_dbg_color_ref_frame = 0; + int vp8_dbg_color_mb_modes = 0; + int vp8_dbg_color_b_modes = 0; + int vp8_dbg_display_mv = 0; #endif - int frames_corrupted = 0; - int dec_flags = 0; - int do_scale = 0; - vpx_image_t *scaled_img = NULL; + int frames_corrupted = 0; + int dec_flags = 0; + int do_scale = 0; + vpx_image_t *scaled_img = NULL; #if CONFIG_VP9_HIGHBITDEPTH - vpx_image_t *img_shifted = NULL; + vpx_image_t *img_shifted = NULL; #endif - int frame_avail, got_data, flush_decoder = 0; - int num_external_frame_buffers = 0; - struct ExternalFrameBufferList ext_fb_list = {0, NULL}; + int frame_avail, got_data, flush_decoder = 0; + int num_external_frame_buffers = 0; + struct ExternalFrameBufferList ext_fb_list = { 0, NULL }; const char *outfile_pattern = NULL; - char outfile_name[PATH_MAX] = {0}; + char outfile_name[PATH_MAX] = { 0 }; FILE *outfile = NULL; MD5Context md5_ctx; unsigned char md5_digest[16]; - struct VpxDecInputContext input = {NULL, NULL}; + struct VpxDecInputContext input = { NULL, NULL }; struct VpxInputContext vpx_input_ctx; #if CONFIG_WEBM_IO struct WebmInputContext webm_ctx; @@ -679,8 +653,7 @@ static int main_loop(int argc, const char **argv_) { postproc = 1; vp8_pp_cfg.post_proc_flag &= ~0x7; - if (level) - vp8_pp_cfg.post_proc_flag |= level; + if (level) vp8_pp_cfg.post_proc_flag |= level; } else if (arg_match(&arg, &pp_disp_ref_frame, argi)) { unsigned int flags = arg_parse_int(&arg); if (flags) { @@ -771,7 +744,8 @@ static int main_loop(int argc, const char **argv_) { if (use_y4m && !noblit) { if (!single_file) { - fprintf(stderr, "YUV4MPEG2 not supported with output patterns," + fprintf(stderr, + "YUV4MPEG2 not supported with output patterns," " try --i420 or --yv12 or --rawvideo.\n"); return EXIT_FAILURE; } @@ -779,7 +753,8 @@ static int main_loop(int argc, const char **argv_) { #if CONFIG_WEBM_IO if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) { if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) { - fprintf(stderr, "Failed to guess framerate -- error parsing " + fprintf(stderr, + "Failed to guess framerate -- error parsing " "webm file?\n"); return EXIT_FAILURE; } @@ -793,69 +768,63 @@ static int main_loop(int argc, const char **argv_) { else interface = fourcc_interface; - if (!interface) - interface = get_vpx_decoder_by_index(0); + if (!interface) interface = get_vpx_decoder_by_index(0); dec_flags = (postproc ? VPX_CODEC_USE_POSTPROC : 0) | (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0) | (frame_parallel ? VPX_CODEC_USE_FRAME_THREADING : 0); - if (vpx_codec_dec_init(&decoder, interface->codec_interface(), - &cfg, dec_flags)) { + if (vpx_codec_dec_init(&decoder, interface->codec_interface(), &cfg, + dec_flags)) { fprintf(stderr, "Failed to initialize decoder: %s\n", vpx_codec_error(&decoder)); return EXIT_FAILURE; } - if (!quiet) - fprintf(stderr, "%s\n", decoder.name); + if (!quiet) fprintf(stderr, "%s\n", decoder.name); #if CONFIG_VP8_DECODER - if (vp8_pp_cfg.post_proc_flag - && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) { + if (vp8_pp_cfg.post_proc_flag && + vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) { fprintf(stderr, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder)); return EXIT_FAILURE; } - if (vp8_dbg_color_ref_frame - && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, - vp8_dbg_color_ref_frame)) { + if (vp8_dbg_color_ref_frame && + vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, + vp8_dbg_color_ref_frame)) { fprintf(stderr, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder)); return EXIT_FAILURE; } - if (vp8_dbg_color_mb_modes - && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, - vp8_dbg_color_mb_modes)) { + if (vp8_dbg_color_mb_modes && + vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, + vp8_dbg_color_mb_modes)) { fprintf(stderr, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder)); return EXIT_FAILURE; } - if (vp8_dbg_color_b_modes - && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, - vp8_dbg_color_b_modes)) { + if (vp8_dbg_color_b_modes && + vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, + vp8_dbg_color_b_modes)) { fprintf(stderr, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder)); return EXIT_FAILURE; } - if (vp8_dbg_display_mv - && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, - vp8_dbg_display_mv)) { + if (vp8_dbg_display_mv && + vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, vp8_dbg_display_mv)) { fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder)); return EXIT_FAILURE; } #endif - - if (arg_skip) - fprintf(stderr, "Skipping first %d frames.\n", arg_skip); + if (arg_skip) fprintf(stderr, "Skipping first %d frames.\n", arg_skip); while (arg_skip) { - if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) - break; + if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) break; arg_skip--; } @@ -863,9 +832,9 @@ static int main_loop(int argc, const char **argv_) { ext_fb_list.num_external_frame_buffers = num_external_frame_buffers; ext_fb_list.ext_fb = (struct ExternalFrameBuffer *)calloc( num_external_frame_buffers, sizeof(*ext_fb_list.ext_fb)); - if (vpx_codec_set_frame_buffer_functions( - &decoder, get_vp9_frame_buffer, release_vp9_frame_buffer, - &ext_fb_list)) { + if (vpx_codec_set_frame_buffer_functions(&decoder, get_vp9_frame_buffer, + release_vp9_frame_buffer, + &ext_fb_list)) { fprintf(stderr, "Failed to configure external frame buffers: %s\n", vpx_codec_error(&decoder)); return EXIT_FAILURE; @@ -877,10 +846,10 @@ static int main_loop(int argc, const char **argv_) { /* Decode file */ while (frame_avail || got_data) { - vpx_codec_iter_t iter = NULL; - vpx_image_t *img; + vpx_codec_iter_t iter = NULL; + vpx_image_t *img; struct vpx_usec_timer timer; - int corrupted = 0; + int corrupted = 0; frame_avail = 0; if (!stop_after || frame_in < stop_after) { @@ -890,16 +859,14 @@ static int main_loop(int argc, const char **argv_) { vpx_usec_timer_start(&timer); - if (vpx_codec_decode(&decoder, buf, (unsigned int)bytes_in_buffer, - NULL, 0)) { + if (vpx_codec_decode(&decoder, buf, (unsigned int)bytes_in_buffer, NULL, + 0)) { const char *detail = vpx_codec_error_detail(&decoder); - warn("Failed to decode frame %d: %s", - frame_in, vpx_codec_error(&decoder)); + warn("Failed to decode frame %d: %s", frame_in, + vpx_codec_error(&decoder)); - if (detail) - warn("Additional information: %s", detail); - if (!keep_going) - goto fail; + if (detail) warn("Additional information: %s", detail); + if (!keep_going) goto fail; } vpx_usec_timer_mark(&timer); @@ -932,17 +899,15 @@ static int main_loop(int argc, const char **argv_) { if (!frame_parallel && vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) { warn("Failed VP8_GET_FRAME_CORRUPTED: %s", vpx_codec_error(&decoder)); - if (!keep_going) - goto fail; + if (!keep_going) goto fail; } frames_corrupted += corrupted; - if (progress) - show_progress(frame_in, frame_out, dx_time); + if (progress) show_progress(frame_in, frame_out, dx_time); if (!noblit && img) { - const int PLANES_YUV[] = {VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V}; - const int PLANES_YVU[] = {VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U}; + const int PLANES_YUV[] = { VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V }; + const int PLANES_YVU[] = { VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U }; const int *planes = flipuv ? PLANES_YVU : PLANES_YUV; if (do_scale) { @@ -966,8 +931,8 @@ static int main_loop(int argc, const char **argv_) { render_height = render_size[1]; } } - scaled_img = vpx_img_alloc(NULL, img->fmt, render_width, - render_height, 16); + scaled_img = + vpx_img_alloc(NULL, img->fmt, render_width, render_height, 16); scaled_img->bit_depth = img->bit_depth; } @@ -976,7 +941,8 @@ static int main_loop(int argc, const char **argv_) { libyuv_scale(img, scaled_img, kFilterBox); img = scaled_img; #else - fprintf(stderr, "Failed to scale output frame: %s.\n" + fprintf(stderr, + "Failed to scale output frame: %s.\n" "Scaling is disabled in this configuration. " "To enable scaling, configure with --enable-libyuv\n", vpx_codec_error(&decoder)); @@ -991,22 +957,22 @@ static int main_loop(int argc, const char **argv_) { } // Shift up or down if necessary if (output_bit_depth != 0 && output_bit_depth != img->bit_depth) { - const vpx_img_fmt_t shifted_fmt = output_bit_depth == 8 ? - img->fmt ^ (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) : - img->fmt | VPX_IMG_FMT_HIGHBITDEPTH; + const vpx_img_fmt_t shifted_fmt = + output_bit_depth == 8 + ? img->fmt ^ (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) + : img->fmt | VPX_IMG_FMT_HIGHBITDEPTH; if (img_shifted && img_shifted_realloc_required(img, img_shifted, shifted_fmt)) { vpx_img_free(img_shifted); img_shifted = NULL; } if (!img_shifted) { - img_shifted = vpx_img_alloc(NULL, shifted_fmt, - img->d_w, img->d_h, 16); + img_shifted = + vpx_img_alloc(NULL, shifted_fmt, img->d_w, img->d_h, 16); img_shifted->bit_depth = output_bit_depth; } if (output_bit_depth > img->bit_depth) { - vpx_img_upshift(img_shifted, img, - output_bit_depth - img->bit_depth); + vpx_img_upshift(img_shifted, img, output_bit_depth - img->bit_depth); } else { vpx_img_downshift(img_shifted, img, img->bit_depth - output_bit_depth); @@ -1017,7 +983,7 @@ static int main_loop(int argc, const char **argv_) { if (single_file) { if (use_y4m) { - char buf[Y4M_BUFFER_SIZE] = {0}; + char buf[Y4M_BUFFER_SIZE] = { 0 }; size_t len = 0; if (img->fmt == VPX_IMG_FMT_I440 || img->fmt == VPX_IMG_FMT_I44016) { fprintf(stderr, "Cannot produce y4m output for 440 sampling.\n"); @@ -1025,11 +991,9 @@ static int main_loop(int argc, const char **argv_) { } if (frame_out == 1) { // Y4M file header - len = y4m_write_file_header(buf, sizeof(buf), - vpx_input_ctx.width, - vpx_input_ctx.height, - &vpx_input_ctx.framerate, - img->fmt, img->bit_depth); + len = y4m_write_file_header( + buf, sizeof(buf), vpx_input_ctx.width, vpx_input_ctx.height, + &vpx_input_ctx.framerate, img->fmt, img->bit_depth); if (do_md5) { MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); } else { @@ -1057,7 +1021,8 @@ static int main_loop(int argc, const char **argv_) { } if (opt_yv12) { if ((img->fmt != VPX_IMG_FMT_I420 && - img->fmt != VPX_IMG_FMT_YV12) || img->bit_depth != 8) { + img->fmt != VPX_IMG_FMT_YV12) || + img->bit_depth != 8) { fprintf(stderr, "Cannot produce yv12 output for bit-stream.\n"); goto fail; } @@ -1071,8 +1036,8 @@ static int main_loop(int argc, const char **argv_) { write_image_file(img, planes, outfile); } } else { - generate_filename(outfile_pattern, outfile_name, PATH_MAX, - img->d_w, img->d_h, frame_in); + generate_filename(outfile_pattern, outfile_name, PATH_MAX, img->d_w, + img->d_h, frame_in); if (do_md5) { MD5Init(&md5_ctx); update_image_md5(img, planes, &md5_ctx); @@ -1117,8 +1082,7 @@ fail: webm_free(input.webm_ctx); #endif - if (input.vpx_input_ctx->file_type != FILE_TYPE_WEBM) - free(buf); + if (input.vpx_input_ctx->file_type != FILE_TYPE_WEBM) free(buf); if (scaled_img) vpx_img_free(scaled_img); #if CONFIG_VP9_HIGHBITDEPTH @@ -1153,7 +1117,6 @@ int main(int argc, const char **argv_) { } } free(argv); - for (i = 0; !error && i < loops; i++) - error = main_loop(argc, argv_); + for (i = 0; !error && i < loops; i++) error = main_loop(argc, argv_); return error; } diff --git a/vpxenc.c b/vpxenc.c index 6d59dd5a8..c414ae0cd 100644 --- a/vpxenc.c +++ b/vpxenc.c @@ -51,8 +51,7 @@ #include "./y4minput.h" /* Swallow warnings about unused results of fread/fwrite */ -static size_t wrap_fread(void *ptr, size_t size, size_t nmemb, - FILE *stream) { +static size_t wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { return fread(ptr, size, nmemb, stream); } #define fread wrap_fread @@ -63,7 +62,6 @@ static size_t wrap_fwrite(const void *ptr, size_t size, size_t nmemb, } #define fwrite wrap_fwrite - static const char *exec_name; static void warn_or_exit_on_errorv(vpx_codec_ctx_t *ctx, int fatal, @@ -74,11 +72,9 @@ static void warn_or_exit_on_errorv(vpx_codec_ctx_t *ctx, int fatal, vfprintf(stderr, s, ap); fprintf(stderr, ": %s\n", vpx_codec_error(ctx)); - if (detail) - fprintf(stderr, " %s\n", detail); + if (detail) fprintf(stderr, " %s\n", detail); - if (fatal) - exit(EXIT_FAILURE); + if (fatal) exit(EXIT_FAILURE); } } @@ -105,8 +101,7 @@ static int read_frame(struct VpxInputContext *input_ctx, vpx_image_t *img) { int shortread = 0; if (input_ctx->file_type == FILE_TYPE_Y4M) { - if (y4m_input_fetch_frame(y4m, f, img) < 1) - return 0; + if (y4m_input_fetch_frame(y4m, f, img) < 1) return 0; } else { shortread = read_yuv_frame(input_ctx, img); } @@ -128,275 +123,291 @@ static int fourcc_is_ivf(const char detect[4]) { return 0; } -static const arg_def_t debugmode = ARG_DEF( - "D", "debug", 0, "Debug mode (makes output deterministic)"); -static const arg_def_t outputfile = ARG_DEF( - "o", "output", 1, "Output filename"); -static const arg_def_t use_yv12 = ARG_DEF( - NULL, "yv12", 0, "Input file is YV12 "); -static const arg_def_t use_i420 = ARG_DEF( - NULL, "i420", 0, "Input file is I420 (default)"); -static const arg_def_t use_i422 = ARG_DEF( - NULL, "i422", 0, "Input file is I422"); -static const arg_def_t use_i444 = ARG_DEF( - NULL, "i444", 0, "Input file is I444"); -static const arg_def_t use_i440 = ARG_DEF( - NULL, "i440", 0, "Input file is I440"); -static const arg_def_t codecarg = ARG_DEF( - NULL, "codec", 1, "Codec to use"); -static const arg_def_t passes = ARG_DEF( - "p", "passes", 1, "Number of passes (1/2)"); -static const arg_def_t pass_arg = ARG_DEF( - NULL, "pass", 1, "Pass to execute (1/2)"); -static const arg_def_t fpf_name = ARG_DEF( - NULL, "fpf", 1, "First pass statistics file name"); +static const arg_def_t debugmode = + ARG_DEF("D", "debug", 0, "Debug mode (makes output deterministic)"); +static const arg_def_t outputfile = + ARG_DEF("o", "output", 1, "Output filename"); +static const arg_def_t use_yv12 = + ARG_DEF(NULL, "yv12", 0, "Input file is YV12 "); +static const arg_def_t use_i420 = + ARG_DEF(NULL, "i420", 0, "Input file is I420 (default)"); +static const arg_def_t use_i422 = + ARG_DEF(NULL, "i422", 0, "Input file is I422"); +static const arg_def_t use_i444 = + ARG_DEF(NULL, "i444", 0, "Input file is I444"); +static const arg_def_t use_i440 = + ARG_DEF(NULL, "i440", 0, "Input file is I440"); +static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, "Codec to use"); +static const arg_def_t passes = + ARG_DEF("p", "passes", 1, "Number of passes (1/2)"); +static const arg_def_t pass_arg = + ARG_DEF(NULL, "pass", 1, "Pass to execute (1/2)"); +static const arg_def_t fpf_name = + ARG_DEF(NULL, "fpf", 1, "First pass statistics file name"); #if CONFIG_FP_MB_STATS -static const arg_def_t fpmbf_name = ARG_DEF( - NULL, "fpmbf", 1, "First pass block statistics file name"); +static const arg_def_t fpmbf_name = + ARG_DEF(NULL, "fpmbf", 1, "First pass block statistics file name"); #endif -static const arg_def_t limit = ARG_DEF( - NULL, "limit", 1, "Stop encoding after n input frames"); -static const arg_def_t skip = ARG_DEF( - NULL, "skip", 1, "Skip the first n input frames"); -static const arg_def_t deadline = ARG_DEF( - "d", "deadline", 1, "Deadline per frame (usec)"); -static const arg_def_t best_dl = ARG_DEF( - NULL, "best", 0, "Use Best Quality Deadline"); -static const arg_def_t good_dl = ARG_DEF( - NULL, "good", 0, "Use Good Quality Deadline"); -static const arg_def_t rt_dl = ARG_DEF( - NULL, "rt", 0, "Use Realtime Quality Deadline"); -static const arg_def_t quietarg = ARG_DEF( - "q", "quiet", 0, "Do not print encode progress"); -static const arg_def_t verbosearg = ARG_DEF( - "v", "verbose", 0, "Show encoder parameters"); -static const arg_def_t psnrarg = ARG_DEF( - NULL, "psnr", 0, "Show PSNR in status line"); +static const arg_def_t limit = + ARG_DEF(NULL, "limit", 1, "Stop encoding after n input frames"); +static const arg_def_t skip = + ARG_DEF(NULL, "skip", 1, "Skip the first n input frames"); +static const arg_def_t deadline = + ARG_DEF("d", "deadline", 1, "Deadline per frame (usec)"); +static const arg_def_t best_dl = + ARG_DEF(NULL, "best", 0, "Use Best Quality Deadline"); +static const arg_def_t good_dl = + ARG_DEF(NULL, "good", 0, "Use Good Quality Deadline"); +static const arg_def_t rt_dl = + ARG_DEF(NULL, "rt", 0, "Use Realtime Quality Deadline"); +static const arg_def_t quietarg = + ARG_DEF("q", "quiet", 0, "Do not print encode progress"); +static const arg_def_t verbosearg = + ARG_DEF("v", "verbose", 0, "Show encoder parameters"); +static const arg_def_t psnrarg = + ARG_DEF(NULL, "psnr", 0, "Show PSNR in status line"); static const struct arg_enum_list test_decode_enum[] = { - {"off", TEST_DECODE_OFF}, - {"fatal", TEST_DECODE_FATAL}, - {"warn", TEST_DECODE_WARN}, - {NULL, 0} + { "off", TEST_DECODE_OFF }, + { "fatal", TEST_DECODE_FATAL }, + { "warn", TEST_DECODE_WARN }, + { NULL, 0 } }; static const arg_def_t recontest = ARG_DEF_ENUM( NULL, "test-decode", 1, "Test encode/decode mismatch", test_decode_enum); -static const arg_def_t framerate = ARG_DEF( - NULL, "fps", 1, "Stream frame rate (rate/scale)"); -static const arg_def_t use_webm = ARG_DEF( - NULL, "webm", 0, "Output WebM (default when WebM IO is enabled)"); -static const arg_def_t use_ivf = ARG_DEF( - NULL, "ivf", 0, "Output IVF"); -static const arg_def_t out_part = ARG_DEF( - "P", "output-partitions", 0, - "Makes encoder output partitions. Requires IVF output!"); -static const arg_def_t q_hist_n = ARG_DEF( - NULL, "q-hist", 1, "Show quantizer histogram (n-buckets)"); -static const arg_def_t rate_hist_n = ARG_DEF( - NULL, "rate-hist", 1, "Show rate histogram (n-buckets)"); -static const arg_def_t disable_warnings = ARG_DEF( - NULL, "disable-warnings", 0, - "Disable warnings about potentially incorrect encode settings."); -static const arg_def_t disable_warning_prompt = ARG_DEF( - "y", "disable-warning-prompt", 0, - "Display warnings, but do not prompt user to continue."); +static const arg_def_t framerate = + ARG_DEF(NULL, "fps", 1, "Stream frame rate (rate/scale)"); +static const arg_def_t use_webm = + ARG_DEF(NULL, "webm", 0, "Output WebM (default when WebM IO is enabled)"); +static const arg_def_t use_ivf = ARG_DEF(NULL, "ivf", 0, "Output IVF"); +static const arg_def_t out_part = + ARG_DEF("P", "output-partitions", 0, + "Makes encoder output partitions. Requires IVF output!"); +static const arg_def_t q_hist_n = + ARG_DEF(NULL, "q-hist", 1, "Show quantizer histogram (n-buckets)"); +static const arg_def_t rate_hist_n = + ARG_DEF(NULL, "rate-hist", 1, "Show rate histogram (n-buckets)"); +static const arg_def_t disable_warnings = + ARG_DEF(NULL, "disable-warnings", 0, + "Disable warnings about potentially incorrect encode settings."); +static const arg_def_t disable_warning_prompt = + ARG_DEF("y", "disable-warning-prompt", 0, + "Display warnings, but do not prompt user to continue."); #if CONFIG_VP9_HIGHBITDEPTH static const arg_def_t test16bitinternalarg = ARG_DEF( NULL, "test-16bit-internal", 0, "Force use of 16 bit internal buffer"); #endif -static const arg_def_t *main_args[] = { - &debugmode, - &outputfile, &codecarg, &passes, &pass_arg, &fpf_name, &limit, &skip, - &deadline, &best_dl, &good_dl, &rt_dl, - &quietarg, &verbosearg, &psnrarg, &use_webm, &use_ivf, &out_part, &q_hist_n, - &rate_hist_n, &disable_warnings, &disable_warning_prompt, &recontest, - NULL -}; +static const arg_def_t *main_args[] = { &debugmode, + &outputfile, + &codecarg, + &passes, + &pass_arg, + &fpf_name, + &limit, + &skip, + &deadline, + &best_dl, + &good_dl, + &rt_dl, + &quietarg, + &verbosearg, + &psnrarg, + &use_webm, + &use_ivf, + &out_part, + &q_hist_n, + &rate_hist_n, + &disable_warnings, + &disable_warning_prompt, + &recontest, + NULL }; -static const arg_def_t usage = ARG_DEF( - "u", "usage", 1, "Usage profile number to use"); -static const arg_def_t threads = ARG_DEF( - "t", "threads", 1, "Max number of threads to use"); -static const arg_def_t profile = ARG_DEF( - NULL, "profile", 1, "Bitstream profile number to use"); +static const arg_def_t usage = + ARG_DEF("u", "usage", 1, "Usage profile number to use"); +static const arg_def_t threads = + ARG_DEF("t", "threads", 1, "Max number of threads to use"); +static const arg_def_t profile = + ARG_DEF(NULL, "profile", 1, "Bitstream profile number to use"); static const arg_def_t width = ARG_DEF("w", "width", 1, "Frame width"); static const arg_def_t height = ARG_DEF("h", "height", 1, "Frame height"); #if CONFIG_WEBM_IO static const struct arg_enum_list stereo_mode_enum[] = { - {"mono", STEREO_FORMAT_MONO}, - {"left-right", STEREO_FORMAT_LEFT_RIGHT}, - {"bottom-top", STEREO_FORMAT_BOTTOM_TOP}, - {"top-bottom", STEREO_FORMAT_TOP_BOTTOM}, - {"right-left", STEREO_FORMAT_RIGHT_LEFT}, - {NULL, 0} + { "mono", STEREO_FORMAT_MONO }, + { "left-right", STEREO_FORMAT_LEFT_RIGHT }, + { "bottom-top", STEREO_FORMAT_BOTTOM_TOP }, + { "top-bottom", STEREO_FORMAT_TOP_BOTTOM }, + { "right-left", STEREO_FORMAT_RIGHT_LEFT }, + { NULL, 0 } }; static const arg_def_t stereo_mode = ARG_DEF_ENUM( NULL, "stereo-mode", 1, "Stereo 3D video format", stereo_mode_enum); #endif static const arg_def_t timebase = ARG_DEF( NULL, "timebase", 1, "Output timestamp precision (fractional seconds)"); -static const arg_def_t error_resilient = ARG_DEF( - NULL, "error-resilient", 1, "Enable error resiliency features"); -static const arg_def_t lag_in_frames = ARG_DEF( - NULL, "lag-in-frames", 1, "Max number of frames to lag"); +static const arg_def_t error_resilient = + ARG_DEF(NULL, "error-resilient", 1, "Enable error resiliency features"); +static const arg_def_t lag_in_frames = + ARG_DEF(NULL, "lag-in-frames", 1, "Max number of frames to lag"); -static const arg_def_t *global_args[] = { - &use_yv12, &use_i420, &use_i422, &use_i444, &use_i440, - &usage, &threads, &profile, - &width, &height, +static const arg_def_t *global_args[] = { &use_yv12, + &use_i420, + &use_i422, + &use_i444, + &use_i440, + &usage, + &threads, + &profile, + &width, + &height, #if CONFIG_WEBM_IO - &stereo_mode, + &stereo_mode, #endif - &timebase, &framerate, - &error_resilient, + &timebase, + &framerate, + &error_resilient, #if CONFIG_VP9_HIGHBITDEPTH - &test16bitinternalarg, + &test16bitinternalarg, #endif - &lag_in_frames, NULL -}; + &lag_in_frames, + NULL }; -static const arg_def_t dropframe_thresh = ARG_DEF( - NULL, "drop-frame", 1, "Temporal resampling threshold (buf %)"); -static const arg_def_t resize_allowed = ARG_DEF( - NULL, "resize-allowed", 1, "Spatial resampling enabled (bool)"); -static const arg_def_t resize_width = ARG_DEF( - NULL, "resize-width", 1, "Width of encoded frame"); -static const arg_def_t resize_height = ARG_DEF( - NULL, "resize-height", 1, "Height of encoded frame"); -static const arg_def_t resize_up_thresh = ARG_DEF( - NULL, "resize-up", 1, "Upscale threshold (buf %)"); -static const arg_def_t resize_down_thresh = ARG_DEF( - NULL, "resize-down", 1, "Downscale threshold (buf %)"); -static const struct arg_enum_list end_usage_enum[] = { - {"vbr", VPX_VBR}, - {"cbr", VPX_CBR}, - {"cq", VPX_CQ}, - {"q", VPX_Q}, - {NULL, 0} -}; -static const arg_def_t end_usage = ARG_DEF_ENUM( - NULL, "end-usage", 1, "Rate control mode", end_usage_enum); -static const arg_def_t target_bitrate = ARG_DEF( - NULL, "target-bitrate", 1, "Bitrate (kbps)"); -static const arg_def_t min_quantizer = ARG_DEF( - NULL, "min-q", 1, "Minimum (best) quantizer"); -static const arg_def_t max_quantizer = ARG_DEF( - NULL, "max-q", 1, "Maximum (worst) quantizer"); -static const arg_def_t undershoot_pct = ARG_DEF( - NULL, "undershoot-pct", 1, "Datarate undershoot (min) target (%)"); -static const arg_def_t overshoot_pct = ARG_DEF( - NULL, "overshoot-pct", 1, "Datarate overshoot (max) target (%)"); -static const arg_def_t buf_sz = ARG_DEF( - NULL, "buf-sz", 1, "Client buffer size (ms)"); -static const arg_def_t buf_initial_sz = ARG_DEF( - NULL, "buf-initial-sz", 1, "Client initial buffer size (ms)"); -static const arg_def_t buf_optimal_sz = ARG_DEF( - NULL, "buf-optimal-sz", 1, "Client optimal buffer size (ms)"); +static const arg_def_t dropframe_thresh = + ARG_DEF(NULL, "drop-frame", 1, "Temporal resampling threshold (buf %)"); +static const arg_def_t resize_allowed = + ARG_DEF(NULL, "resize-allowed", 1, "Spatial resampling enabled (bool)"); +static const arg_def_t resize_width = + ARG_DEF(NULL, "resize-width", 1, "Width of encoded frame"); +static const arg_def_t resize_height = + ARG_DEF(NULL, "resize-height", 1, "Height of encoded frame"); +static const arg_def_t resize_up_thresh = + ARG_DEF(NULL, "resize-up", 1, "Upscale threshold (buf %)"); +static const arg_def_t resize_down_thresh = + ARG_DEF(NULL, "resize-down", 1, "Downscale threshold (buf %)"); +static const struct arg_enum_list end_usage_enum[] = { { "vbr", VPX_VBR }, + { "cbr", VPX_CBR }, + { "cq", VPX_CQ }, + { "q", VPX_Q }, + { NULL, 0 } }; +static const arg_def_t end_usage = + ARG_DEF_ENUM(NULL, "end-usage", 1, "Rate control mode", end_usage_enum); +static const arg_def_t target_bitrate = + ARG_DEF(NULL, "target-bitrate", 1, "Bitrate (kbps)"); +static const arg_def_t min_quantizer = + ARG_DEF(NULL, "min-q", 1, "Minimum (best) quantizer"); +static const arg_def_t max_quantizer = + ARG_DEF(NULL, "max-q", 1, "Maximum (worst) quantizer"); +static const arg_def_t undershoot_pct = + ARG_DEF(NULL, "undershoot-pct", 1, "Datarate undershoot (min) target (%)"); +static const arg_def_t overshoot_pct = + ARG_DEF(NULL, "overshoot-pct", 1, "Datarate overshoot (max) target (%)"); +static const arg_def_t buf_sz = + ARG_DEF(NULL, "buf-sz", 1, "Client buffer size (ms)"); +static const arg_def_t buf_initial_sz = + ARG_DEF(NULL, "buf-initial-sz", 1, "Client initial buffer size (ms)"); +static const arg_def_t buf_optimal_sz = + ARG_DEF(NULL, "buf-optimal-sz", 1, "Client optimal buffer size (ms)"); static const arg_def_t *rc_args[] = { - &dropframe_thresh, &resize_allowed, &resize_width, &resize_height, - &resize_up_thresh, &resize_down_thresh, &end_usage, &target_bitrate, - &min_quantizer, &max_quantizer, &undershoot_pct, &overshoot_pct, &buf_sz, - &buf_initial_sz, &buf_optimal_sz, NULL + &dropframe_thresh, &resize_allowed, &resize_width, &resize_height, + &resize_up_thresh, &resize_down_thresh, &end_usage, &target_bitrate, + &min_quantizer, &max_quantizer, &undershoot_pct, &overshoot_pct, + &buf_sz, &buf_initial_sz, &buf_optimal_sz, NULL }; +static const arg_def_t bias_pct = + ARG_DEF(NULL, "bias-pct", 1, "CBR/VBR bias (0=CBR, 100=VBR)"); +static const arg_def_t minsection_pct = + ARG_DEF(NULL, "minsection-pct", 1, "GOP min bitrate (% of target)"); +static const arg_def_t maxsection_pct = + ARG_DEF(NULL, "maxsection-pct", 1, "GOP max bitrate (% of target)"); +static const arg_def_t *rc_twopass_args[] = { &bias_pct, &minsection_pct, + &maxsection_pct, NULL }; -static const arg_def_t bias_pct = ARG_DEF( - NULL, "bias-pct", 1, "CBR/VBR bias (0=CBR, 100=VBR)"); -static const arg_def_t minsection_pct = ARG_DEF( - NULL, "minsection-pct", 1, "GOP min bitrate (% of target)"); -static const arg_def_t maxsection_pct = ARG_DEF( - NULL, "maxsection-pct", 1, "GOP max bitrate (% of target)"); -static const arg_def_t *rc_twopass_args[] = { - &bias_pct, &minsection_pct, &maxsection_pct, NULL -}; +static const arg_def_t kf_min_dist = + ARG_DEF(NULL, "kf-min-dist", 1, "Minimum keyframe interval (frames)"); +static const arg_def_t kf_max_dist = + ARG_DEF(NULL, "kf-max-dist", 1, "Maximum keyframe interval (frames)"); +static const arg_def_t kf_disabled = + ARG_DEF(NULL, "disable-kf", 0, "Disable keyframe placement"); +static const arg_def_t *kf_args[] = { &kf_min_dist, &kf_max_dist, &kf_disabled, + NULL }; - -static const arg_def_t kf_min_dist = ARG_DEF( - NULL, "kf-min-dist", 1, "Minimum keyframe interval (frames)"); -static const arg_def_t kf_max_dist = ARG_DEF( - NULL, "kf-max-dist", 1, "Maximum keyframe interval (frames)"); -static const arg_def_t kf_disabled = ARG_DEF( - NULL, "disable-kf", 0, "Disable keyframe placement"); -static const arg_def_t *kf_args[] = { - &kf_min_dist, &kf_max_dist, &kf_disabled, NULL -}; - - -static const arg_def_t noise_sens = ARG_DEF( - NULL, "noise-sensitivity", 1, "Noise sensitivity (frames to blur)"); -static const arg_def_t sharpness = ARG_DEF( - NULL, "sharpness", 1, "Loop filter sharpness (0..7)"); -static const arg_def_t static_thresh = ARG_DEF( - NULL, "static-thresh", 1, "Motion detection threshold"); -static const arg_def_t auto_altref = ARG_DEF( - NULL, "auto-alt-ref", 1, "Enable automatic alt reference frames"); -static const arg_def_t arnr_maxframes = ARG_DEF( - NULL, "arnr-maxframes", 1, "AltRef max frames (0..15)"); -static const arg_def_t arnr_strength = ARG_DEF( - NULL, "arnr-strength", 1, "AltRef filter strength (0..6)"); -static const arg_def_t arnr_type = ARG_DEF( - NULL, "arnr-type", 1, "AltRef type"); +static const arg_def_t noise_sens = + ARG_DEF(NULL, "noise-sensitivity", 1, "Noise sensitivity (frames to blur)"); +static const arg_def_t sharpness = + ARG_DEF(NULL, "sharpness", 1, "Loop filter sharpness (0..7)"); +static const arg_def_t static_thresh = + ARG_DEF(NULL, "static-thresh", 1, "Motion detection threshold"); +static const arg_def_t auto_altref = + ARG_DEF(NULL, "auto-alt-ref", 1, "Enable automatic alt reference frames"); +static const arg_def_t arnr_maxframes = + ARG_DEF(NULL, "arnr-maxframes", 1, "AltRef max frames (0..15)"); +static const arg_def_t arnr_strength = + ARG_DEF(NULL, "arnr-strength", 1, "AltRef filter strength (0..6)"); +static const arg_def_t arnr_type = ARG_DEF(NULL, "arnr-type", 1, "AltRef type"); static const struct arg_enum_list tuning_enum[] = { - {"psnr", VP8_TUNE_PSNR}, - {"ssim", VP8_TUNE_SSIM}, - {NULL, 0} + { "psnr", VP8_TUNE_PSNR }, { "ssim", VP8_TUNE_SSIM }, { NULL, 0 } }; -static const arg_def_t tune_ssim = ARG_DEF_ENUM( - NULL, "tune", 1, "Material to favor", tuning_enum); -static const arg_def_t cq_level = ARG_DEF( - NULL, "cq-level", 1, "Constant/Constrained Quality level"); -static const arg_def_t max_intra_rate_pct = ARG_DEF( - NULL, "max-intra-rate", 1, "Max I-frame bitrate (pct)"); +static const arg_def_t tune_ssim = + ARG_DEF_ENUM(NULL, "tune", 1, "Material to favor", tuning_enum); +static const arg_def_t cq_level = + ARG_DEF(NULL, "cq-level", 1, "Constant/Constrained Quality level"); +static const arg_def_t max_intra_rate_pct = + ARG_DEF(NULL, "max-intra-rate", 1, "Max I-frame bitrate (pct)"); #if CONFIG_VP8_ENCODER -static const arg_def_t cpu_used_vp8 = ARG_DEF( - NULL, "cpu-used", 1, "CPU Used (-16..16)"); -static const arg_def_t token_parts = ARG_DEF( - NULL, "token-parts", 1, "Number of token partitions to use, log2"); -static const arg_def_t screen_content_mode = ARG_DEF( - NULL, "screen-content-mode", 1, "Screen content mode"); +static const arg_def_t cpu_used_vp8 = + ARG_DEF(NULL, "cpu-used", 1, "CPU Used (-16..16)"); +static const arg_def_t token_parts = + ARG_DEF(NULL, "token-parts", 1, "Number of token partitions to use, log2"); +static const arg_def_t screen_content_mode = + ARG_DEF(NULL, "screen-content-mode", 1, "Screen content mode"); static const arg_def_t *vp8_args[] = { - &cpu_used_vp8, &auto_altref, &noise_sens, &sharpness, &static_thresh, - &token_parts, &arnr_maxframes, &arnr_strength, &arnr_type, - &tune_ssim, &cq_level, &max_intra_rate_pct, &screen_content_mode, - NULL -}; -static const int vp8_arg_ctrl_map[] = { - VP8E_SET_CPUUSED, VP8E_SET_ENABLEAUTOALTREF, - VP8E_SET_NOISE_SENSITIVITY, VP8E_SET_SHARPNESS, VP8E_SET_STATIC_THRESHOLD, - VP8E_SET_TOKEN_PARTITIONS, - VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE, - VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT, - VP8E_SET_SCREEN_CONTENT_MODE, - 0 + &cpu_used_vp8, &auto_altref, &noise_sens, &sharpness, + &static_thresh, &token_parts, &arnr_maxframes, &arnr_strength, + &arnr_type, &tune_ssim, &cq_level, &max_intra_rate_pct, + &screen_content_mode, NULL }; +static const int vp8_arg_ctrl_map[] = { VP8E_SET_CPUUSED, + VP8E_SET_ENABLEAUTOALTREF, + VP8E_SET_NOISE_SENSITIVITY, + VP8E_SET_SHARPNESS, + VP8E_SET_STATIC_THRESHOLD, + VP8E_SET_TOKEN_PARTITIONS, + VP8E_SET_ARNR_MAXFRAMES, + VP8E_SET_ARNR_STRENGTH, + VP8E_SET_ARNR_TYPE, + VP8E_SET_TUNING, + VP8E_SET_CQ_LEVEL, + VP8E_SET_MAX_INTRA_BITRATE_PCT, + VP8E_SET_SCREEN_CONTENT_MODE, + 0 }; #endif #if CONFIG_VP9_ENCODER -static const arg_def_t cpu_used_vp9 = ARG_DEF( - NULL, "cpu-used", 1, "CPU Used (-8..8)"); -static const arg_def_t tile_cols = ARG_DEF( - NULL, "tile-columns", 1, "Number of tile columns to use, log2"); -static const arg_def_t tile_rows = ARG_DEF( - NULL, "tile-rows", 1, - "Number of tile rows to use, log2 (set to 0 while threads > 1)"); -static const arg_def_t lossless = ARG_DEF( - NULL, "lossless", 1, "Lossless mode (0: false (default), 1: true)"); +static const arg_def_t cpu_used_vp9 = + ARG_DEF(NULL, "cpu-used", 1, "CPU Used (-8..8)"); +static const arg_def_t tile_cols = + ARG_DEF(NULL, "tile-columns", 1, "Number of tile columns to use, log2"); +static const arg_def_t tile_rows = + ARG_DEF(NULL, "tile-rows", 1, + "Number of tile rows to use, log2 (set to 0 while threads > 1)"); +static const arg_def_t lossless = + ARG_DEF(NULL, "lossless", 1, "Lossless mode (0: false (default), 1: true)"); static const arg_def_t frame_parallel_decoding = ARG_DEF( NULL, "frame-parallel", 1, "Enable frame parallel decodability features"); static const arg_def_t aq_mode = ARG_DEF( NULL, "aq-mode", 1, "Adaptive quantization mode (0: off (default), 1: variance 2: complexity, " "3: cyclic refresh, 4: equator360)"); -static const arg_def_t frame_periodic_boost = ARG_DEF( - NULL, "frame-boost", 1, - "Enable frame periodic boost (0: off (default), 1: on)"); +static const arg_def_t frame_periodic_boost = + ARG_DEF(NULL, "frame-boost", 1, + "Enable frame periodic boost (0: off (default), 1: on)"); static const arg_def_t gf_cbr_boost_pct = ARG_DEF( NULL, "gf-cbr-boost", 1, "Boost for Golden Frame in CBR mode (pct)"); -static const arg_def_t max_inter_rate_pct = ARG_DEF( - NULL, "max-inter-rate", 1, "Max P-frame bitrate (pct)"); +static const arg_def_t max_inter_rate_pct = + ARG_DEF(NULL, "max-inter-rate", 1, "Max P-frame bitrate (pct)"); static const arg_def_t min_gf_interval = ARG_DEF( NULL, "min-gf-interval", 1, "min gf/arf frame interval (default 0, indicating in-built behavior)"); @@ -416,30 +427,27 @@ static const struct arg_enum_list color_space_enum[] = { { NULL, 0 } }; -static const arg_def_t input_color_space = ARG_DEF_ENUM( - NULL, "color-space", 1, - "The color space of input content:", color_space_enum); +static const arg_def_t input_color_space = + ARG_DEF_ENUM(NULL, "color-space", 1, "The color space of input content:", + color_space_enum); #if CONFIG_VP9_HIGHBITDEPTH static const struct arg_enum_list bitdepth_enum[] = { - {"8", VPX_BITS_8}, - {"10", VPX_BITS_10}, - {"12", VPX_BITS_12}, - {NULL, 0} + { "8", VPX_BITS_8 }, { "10", VPX_BITS_10 }, { "12", VPX_BITS_12 }, { NULL, 0 } }; static const arg_def_t bitdeptharg = ARG_DEF_ENUM( "b", "bit-depth", 1, "Bit depth for codec (8 for version <=1, 10 or 12 for version 2)", bitdepth_enum); -static const arg_def_t inbitdeptharg = ARG_DEF( - NULL, "input-bit-depth", 1, "Bit depth of input"); +static const arg_def_t inbitdeptharg = + ARG_DEF(NULL, "input-bit-depth", 1, "Bit depth of input"); #endif static const struct arg_enum_list tune_content_enum[] = { - {"default", VP9E_CONTENT_DEFAULT}, - {"screen", VP9E_CONTENT_SCREEN}, - {NULL, 0} + { "default", VP9E_CONTENT_DEFAULT }, + { "screen", VP9E_CONTENT_SCREEN }, + { NULL, 0 } }; static const arg_def_t tune_content = ARG_DEF_ENUM( @@ -452,32 +460,60 @@ static const arg_def_t target_level = ARG_DEF( #endif #if CONFIG_VP9_ENCODER -static const arg_def_t *vp9_args[] = { - &cpu_used_vp9, &auto_altref, &sharpness, &static_thresh, - &tile_cols, &tile_rows, &arnr_maxframes, &arnr_strength, &arnr_type, - &tune_ssim, &cq_level, &max_intra_rate_pct, &max_inter_rate_pct, - &gf_cbr_boost_pct, &lossless, - &frame_parallel_decoding, &aq_mode, &frame_periodic_boost, - &noise_sens, &tune_content, &input_color_space, - &min_gf_interval, &max_gf_interval, &target_level, +static const arg_def_t *vp9_args[] = { &cpu_used_vp9, + &auto_altref, + &sharpness, + &static_thresh, + &tile_cols, + &tile_rows, + &arnr_maxframes, + &arnr_strength, + &arnr_type, + &tune_ssim, + &cq_level, + &max_intra_rate_pct, + &max_inter_rate_pct, + &gf_cbr_boost_pct, + &lossless, + &frame_parallel_decoding, + &aq_mode, + &frame_periodic_boost, + &noise_sens, + &tune_content, + &input_color_space, + &min_gf_interval, + &max_gf_interval, + &target_level, #if CONFIG_VP9_HIGHBITDEPTH - &bitdeptharg, &inbitdeptharg, + &bitdeptharg, + &inbitdeptharg, #endif // CONFIG_VP9_HIGHBITDEPTH - NULL -}; -static const int vp9_arg_ctrl_map[] = { - VP8E_SET_CPUUSED, VP8E_SET_ENABLEAUTOALTREF, - VP8E_SET_SHARPNESS, VP8E_SET_STATIC_THRESHOLD, - VP9E_SET_TILE_COLUMNS, VP9E_SET_TILE_ROWS, - VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE, - VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT, - VP9E_SET_MAX_INTER_BITRATE_PCT, VP9E_SET_GF_CBR_BOOST_PCT, - VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE, - VP9E_SET_FRAME_PERIODIC_BOOST, VP9E_SET_NOISE_SENSITIVITY, - VP9E_SET_TUNE_CONTENT, VP9E_SET_COLOR_SPACE, - VP9E_SET_MIN_GF_INTERVAL, VP9E_SET_MAX_GF_INTERVAL, VP9E_SET_TARGET_LEVEL, - 0 -}; + NULL }; +static const int vp9_arg_ctrl_map[] = { VP8E_SET_CPUUSED, + VP8E_SET_ENABLEAUTOALTREF, + VP8E_SET_SHARPNESS, + VP8E_SET_STATIC_THRESHOLD, + VP9E_SET_TILE_COLUMNS, + VP9E_SET_TILE_ROWS, + VP8E_SET_ARNR_MAXFRAMES, + VP8E_SET_ARNR_STRENGTH, + VP8E_SET_ARNR_TYPE, + VP8E_SET_TUNING, + VP8E_SET_CQ_LEVEL, + VP8E_SET_MAX_INTRA_BITRATE_PCT, + VP9E_SET_MAX_INTER_BITRATE_PCT, + VP9E_SET_GF_CBR_BOOST_PCT, + VP9E_SET_LOSSLESS, + VP9E_SET_FRAME_PARALLEL_DECODING, + VP9E_SET_AQ_MODE, + VP9E_SET_FRAME_PERIODIC_BOOST, + VP9E_SET_NOISE_SENSITIVITY, + VP9E_SET_TUNE_CONTENT, + VP9E_SET_COLOR_SPACE, + VP9E_SET_MIN_GF_INTERVAL, + VP9E_SET_MAX_GF_INTERVAL, + VP9E_SET_TARGET_LEVEL, + 0 }; #endif static const arg_def_t *no_args[] = { NULL }; @@ -507,17 +543,17 @@ void usage_exit(void) { fprintf(stderr, "\nVP9 Specific Options:\n"); arg_show_usage(stderr, vp9_args); #endif - fprintf(stderr, "\nStream timebase (--timebase):\n" + fprintf(stderr, + "\nStream timebase (--timebase):\n" " The desired precision of timestamps in the output, expressed\n" " in fractional seconds. Default is 1/1000.\n"); fprintf(stderr, "\nIncluded encoders:\n\n"); for (i = 0; i < num_encoder; ++i) { const VpxInterface *const encoder = get_vpx_encoder_by_index(i); - const char* defstr = (i == (num_encoder - 1)) ? "(default)" : ""; - fprintf(stderr, " %-6s - %s %s\n", - encoder->name, vpx_codec_iface_name(encoder->codec_interface()), - defstr); + const char *defstr = (i == (num_encoder - 1)) ? "(default)" : ""; + fprintf(stderr, " %-6s - %s %s\n", encoder->name, + vpx_codec_iface_name(encoder->codec_interface()), defstr); } fprintf(stderr, "\n "); fprintf(stderr, "Use --codec to switch to a non-default encoder.\n\n"); @@ -525,12 +561,12 @@ void usage_exit(void) { exit(EXIT_FAILURE); } -#define mmin(a, b) ((a) < (b) ? (a) : (b)) +#define mmin(a, b) ((a) < (b) ? (a) : (b)) #if CONFIG_VP9_HIGHBITDEPTH static void find_mismatch_high(const vpx_image_t *const img1, - const vpx_image_t *const img2, - int yloc[4], int uloc[4], int vloc[4]) { + const vpx_image_t *const img2, int yloc[4], + int uloc[4], int vloc[4]) { uint16_t *plane1, *plane2; uint32_t stride1, stride2; const uint32_t bsize = 64; @@ -543,10 +579,10 @@ static void find_mismatch_high(const vpx_image_t *const img1, int match = 1; uint32_t i, j; yloc[0] = yloc[1] = yloc[2] = yloc[3] = -1; - plane1 = (uint16_t*)img1->planes[VPX_PLANE_Y]; - plane2 = (uint16_t*)img2->planes[VPX_PLANE_Y]; - stride1 = img1->stride[VPX_PLANE_Y]/2; - stride2 = img2->stride[VPX_PLANE_Y]/2; + plane1 = (uint16_t *)img1->planes[VPX_PLANE_Y]; + plane2 = (uint16_t *)img2->planes[VPX_PLANE_Y]; + stride1 = img1->stride[VPX_PLANE_Y] / 2; + stride2 = img2->stride[VPX_PLANE_Y] / 2; for (i = 0, match = 1; match && i < img1->d_h; i += bsize) { for (j = 0; match && j < img1->d_w; j += bsize) { int k, l; @@ -569,10 +605,10 @@ static void find_mismatch_high(const vpx_image_t *const img1, } uloc[0] = uloc[1] = uloc[2] = uloc[3] = -1; - plane1 = (uint16_t*)img1->planes[VPX_PLANE_U]; - plane2 = (uint16_t*)img2->planes[VPX_PLANE_U]; - stride1 = img1->stride[VPX_PLANE_U]/2; - stride2 = img2->stride[VPX_PLANE_U]/2; + plane1 = (uint16_t *)img1->planes[VPX_PLANE_U]; + plane2 = (uint16_t *)img2->planes[VPX_PLANE_U]; + stride1 = img1->stride[VPX_PLANE_U] / 2; + stride2 = img2->stride[VPX_PLANE_U] / 2; for (i = 0, match = 1; match && i < c_h; i += bsizey) { for (j = 0; match && j < c_w; j += bsizex) { int k, l; @@ -595,10 +631,10 @@ static void find_mismatch_high(const vpx_image_t *const img1, } vloc[0] = vloc[1] = vloc[2] = vloc[3] = -1; - plane1 = (uint16_t*)img1->planes[VPX_PLANE_V]; - plane2 = (uint16_t*)img2->planes[VPX_PLANE_V]; - stride1 = img1->stride[VPX_PLANE_V]/2; - stride2 = img2->stride[VPX_PLANE_V]/2; + plane1 = (uint16_t *)img1->planes[VPX_PLANE_V]; + plane2 = (uint16_t *)img2->planes[VPX_PLANE_V]; + stride1 = img1->stride[VPX_PLANE_V] / 2; + stride2 = img2->stride[VPX_PLANE_V] / 2; for (i = 0, match = 1; match && i < c_h; i += bsizey) { for (j = 0; match && j < c_w; j += bsizex) { int k, l; @@ -623,8 +659,8 @@ static void find_mismatch_high(const vpx_image_t *const img1, #endif static void find_mismatch(const vpx_image_t *const img1, - const vpx_image_t *const img2, - int yloc[4], int uloc[4], int vloc[4]) { + const vpx_image_t *const img2, int yloc[4], + int uloc[4], int vloc[4]) { const uint32_t bsize = 64; const uint32_t bsizey = bsize >> img1->y_chroma_shift; const uint32_t bsizex = bsize >> img1->x_chroma_shift; @@ -715,8 +751,7 @@ static void find_mismatch(const vpx_image_t *const img1, static int compare_img(const vpx_image_t *const img1, const vpx_image_t *const img2) { uint32_t l_w = img1->d_w; - uint32_t c_w = - (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; + uint32_t c_w = (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; const uint32_t c_h = (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; uint32_t i; @@ -750,8 +785,7 @@ static int compare_img(const vpx_image_t *const img1, return match; } - -#define NELEMENTS(x) (sizeof(x)/sizeof(x[0])) +#define NELEMENTS(x) (sizeof(x) / sizeof(x[0])) #if CONFIG_VP9_ENCODER #define ARG_CTRL_CNT_MAX NELEMENTS(vp9_arg_ctrl_map) #else @@ -760,76 +794,72 @@ static int compare_img(const vpx_image_t *const img1, #if !CONFIG_WEBM_IO typedef int stereo_format_t; -struct WebmOutputContext { int debug; }; +struct WebmOutputContext { + int debug; +}; #endif /* Per-stream configuration */ struct stream_config { - struct vpx_codec_enc_cfg cfg; - const char *out_fn; - const char *stats_fn; + struct vpx_codec_enc_cfg cfg; + const char *out_fn; + const char *stats_fn; #if CONFIG_FP_MB_STATS - const char *fpmb_stats_fn; + const char *fpmb_stats_fn; #endif - stereo_format_t stereo_fmt; - int arg_ctrls[ARG_CTRL_CNT_MAX][2]; - int arg_ctrl_cnt; - int write_webm; + stereo_format_t stereo_fmt; + int arg_ctrls[ARG_CTRL_CNT_MAX][2]; + int arg_ctrl_cnt; + int write_webm; #if CONFIG_VP9_HIGHBITDEPTH // whether to use 16bit internal buffers - int use_16bit_internal; + int use_16bit_internal; #endif }; - struct stream_state { - int index; - struct stream_state *next; - struct stream_config config; - FILE *file; - struct rate_hist *rate_hist; - struct WebmOutputContext webm_ctx; - uint64_t psnr_sse_total; - uint64_t psnr_samples_total; - double psnr_totals[4]; - int psnr_count; - int counts[64]; - vpx_codec_ctx_t encoder; - unsigned int frames_out; - uint64_t cx_time; - size_t nbytes; - stats_io_t stats; + int index; + struct stream_state *next; + struct stream_config config; + FILE *file; + struct rate_hist *rate_hist; + struct WebmOutputContext webm_ctx; + uint64_t psnr_sse_total; + uint64_t psnr_samples_total; + double psnr_totals[4]; + int psnr_count; + int counts[64]; + vpx_codec_ctx_t encoder; + unsigned int frames_out; + uint64_t cx_time; + size_t nbytes; + stats_io_t stats; #if CONFIG_FP_MB_STATS - stats_io_t fpmb_stats; + stats_io_t fpmb_stats; #endif - struct vpx_image *img; - vpx_codec_ctx_t decoder; - int mismatch_seen; + struct vpx_image *img; + vpx_codec_ctx_t decoder; + int mismatch_seen; }; - -static void validate_positive_rational(const char *msg, +static void validate_positive_rational(const char *msg, struct vpx_rational *rat) { if (rat->den < 0) { rat->num *= -1; rat->den *= -1; } - if (rat->num < 0) - die("Error: %s must be positive\n", msg); + if (rat->num < 0) die("Error: %s must be positive\n", msg); - if (!rat->den) - die("Error: %s has zero denominator\n", msg); + if (!rat->den) die("Error: %s has zero denominator\n", msg); } - static void parse_global_config(struct VpxEncoderConfig *global, char **argv) { - char **argi, **argj; - struct arg arg; + char **argi, **argj; + struct arg arg; const int num_encoder = get_vpx_encoder_count(); - if (num_encoder < 1) - die("Error: no valid encoder available\n"); + if (num_encoder < 1) die("Error: no valid encoder available\n"); /* Initialize default parameters */ memset(global, 0, sizeof(*global)); @@ -855,8 +885,7 @@ static void parse_global_config(struct VpxEncoderConfig *global, char **argv) { global->pass = arg_parse_uint(&arg); if (global->pass < 1 || global->pass > 2) - die("Error: Invalid pass selected (%d)\n", - global->pass); + die("Error: Invalid pass selected (%d)\n", global->pass); } else if (arg_match(&arg, &usage, argi)) global->usage = arg_parse_uint(&arg); else if (arg_match(&arg, &deadline, argi)) @@ -912,8 +941,8 @@ static void parse_global_config(struct VpxEncoderConfig *global, char **argv) { if (global->pass) { /* DWIM: Assume the user meant passes=2 if pass=2 is specified */ if (global->pass > global->passes) { - warn("Assuming --pass=%d implies --passes=%d\n", - global->pass, global->pass); + warn("Assuming --pass=%d implies --passes=%d\n", global->pass, + global->pass); global->passes = global->pass; } } @@ -924,27 +953,26 @@ static void parse_global_config(struct VpxEncoderConfig *global, char **argv) { // encoder if (global->codec != NULL && global->codec->name != NULL) global->passes = (strcmp(global->codec->name, "vp9") == 0 && - global->deadline != VPX_DL_REALTIME) ? 2 : 1; + global->deadline != VPX_DL_REALTIME) + ? 2 + : 1; #else global->passes = 1; #endif } - if (global->deadline == VPX_DL_REALTIME && - global->passes > 1) { + if (global->deadline == VPX_DL_REALTIME && global->passes > 1) { warn("Enforcing one-pass encoding in realtime mode\n"); global->passes = 1; } } - static void open_input_file(struct VpxInputContext *input) { /* Parse certain options from the input file, if possible */ - input->file = strcmp(input->filename, "-") - ? fopen(input->filename, "rb") : set_binary_mode(stdin); + input->file = strcmp(input->filename, "-") ? fopen(input->filename, "rb") + : set_binary_mode(stdin); - if (!input->file) - fatal("Failed to open input file"); + if (!input->file) fatal("Failed to open input file"); if (!fseeko(input->file, 0, SEEK_END)) { /* Input file is seekable. Figure out how long it is, so we can get @@ -964,8 +992,7 @@ static void open_input_file(struct VpxInputContext *input) { input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file); input->detect.position = 0; - if (input->detect.buf_read == 4 - && file_is_y4m(input->detect.buf)) { + if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) { if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, input->only_i420) >= 0) { input->file_type = FILE_TYPE_Y4M; @@ -986,11 +1013,9 @@ static void open_input_file(struct VpxInputContext *input) { } } - static void close_input_file(struct VpxInputContext *input) { fclose(input->file); - if (input->file_type == FILE_TYPE_Y4M) - y4m_input_close(&input->y4m); + if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m); } static struct stream_state *new_stream(struct VpxEncoderConfig *global, @@ -1007,14 +1032,12 @@ static struct stream_state *new_stream(struct VpxEncoderConfig *global, stream->index++; prev->next = stream; } else { - vpx_codec_err_t res; + vpx_codec_err_t res; /* Populate encoder configuration */ res = vpx_codec_enc_config_default(global->codec->codec_interface(), - &stream->config.cfg, - global->usage); - if (res) - fatal("Failed to get config: %s\n", vpx_codec_err_to_string(res)); + &stream->config.cfg, global->usage); + if (res) fatal("Failed to get config: %s\n", vpx_codec_err_to_string(res)); /* Change the default timebase to a high enough value so that the * encoder will always create strictly increasing timestamps. @@ -1052,18 +1075,16 @@ static struct stream_state *new_stream(struct VpxEncoderConfig *global, return stream; } - static int parse_stream_params(struct VpxEncoderConfig *global, - struct stream_state *stream, - char **argv) { - char **argi, **argj; - struct arg arg; + struct stream_state *stream, char **argv) { + char **argi, **argj; + struct arg arg; static const arg_def_t **ctrl_args = no_args; - static const int *ctrl_args_map = NULL; - struct stream_config *config = &stream->config; - int eos_mark_found = 0; + static const int *ctrl_args_map = NULL; + struct stream_config *config = &stream->config; + int eos_mark_found = 0; #if CONFIG_VP9_HIGHBITDEPTH - int test_16bit_internal = 0; + int test_16bit_internal = 0; #endif // Handle codec specific options @@ -1138,8 +1159,8 @@ static int parse_stream_params(struct VpxEncoderConfig *global, } else if (arg_match(&arg, &lag_in_frames, argi)) { config->cfg.g_lag_in_frames = arg_parse_uint(&arg); if (global->deadline == VPX_DL_REALTIME && - config->cfg.rc_end_usage == VPX_CBR && - config->cfg.g_lag_in_frames != 0) { + config->cfg.rc_end_usage == VPX_CBR && + config->cfg.g_lag_in_frames != 0) { warn("non-zero %s option ignored in realtime CBR mode.\n", arg.name); config->cfg.g_lag_in_frames = 0; } @@ -1174,7 +1195,7 @@ static int parse_stream_params(struct VpxEncoderConfig *global, } else if (arg_match(&arg, &buf_optimal_sz, argi)) { config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg); } else if (arg_match(&arg, &bias_pct, argi)) { - config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg); + config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg); if (global->passes < 2) warn("option %s ignored in one-pass mode.\n", arg.name); } else if (arg_match(&arg, &minsection_pct, argi)) { @@ -1219,42 +1240,40 @@ static int parse_stream_params(struct VpxEncoderConfig *global, if (ctrl_args_map != NULL && j < (int)ARG_CTRL_CNT_MAX) { config->arg_ctrls[j][0] = ctrl_args_map[i]; config->arg_ctrls[j][1] = arg_parse_enum_or_int(&arg); - if (j == config->arg_ctrl_cnt) - config->arg_ctrl_cnt++; + if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++; } } } - if (!match) - argj++; + if (!match) argj++; } } #if CONFIG_VP9_HIGHBITDEPTH if (strcmp(global->codec->name, "vp9") == 0) { - config->use_16bit_internal = test_16bit_internal | - (config->cfg.g_profile > 1); + config->use_16bit_internal = + test_16bit_internal | (config->cfg.g_profile > 1); } #endif return eos_mark_found; } - -#define FOREACH_STREAM(func) \ - do { \ - struct stream_state *stream; \ +#define FOREACH_STREAM(func) \ + do { \ + struct stream_state *stream; \ for (stream = streams; stream; stream = stream->next) { \ - func; \ - } \ + func; \ + } \ } while (0) - static void validate_stream_config(const struct stream_state *stream, const struct VpxEncoderConfig *global) { const struct stream_state *streami; (void)global; if (!stream->config.cfg.g_w || !stream->config.cfg.g_h) - fatal("Stream %d: Specify stream dimensions with --width (-w) " - " and --height (-h)", stream->index); + fatal( + "Stream %d: Specify stream dimensions with --width (-w) " + " and --height (-h)", + stream->index); // Check that the codec bit depth is greater than the input bit depth. if (stream->config.cfg.g_input_bit_depth > @@ -1301,9 +1320,7 @@ static void validate_stream_config(const struct stream_state *stream, } } - -static void set_stream_dimensions(struct stream_state *stream, - unsigned int w, +static void set_stream_dimensions(struct stream_state *stream, unsigned int w, unsigned int h) { if (!stream->config.cfg.g_w) { if (!stream->config.cfg.g_h) @@ -1316,7 +1333,7 @@ static void set_stream_dimensions(struct stream_state *stream, } } -static const char* file_type_to_string(enum VideoFileType t) { +static const char *file_type_to_string(enum VideoFileType t) { switch (t) { case FILE_TYPE_RAW: return "RAW"; case FILE_TYPE_Y4M: return "Y4M"; @@ -1324,7 +1341,7 @@ static const char* file_type_to_string(enum VideoFileType t) { } } -static const char* image_format_to_string(vpx_img_fmt_t f) { +static const char *image_format_to_string(vpx_img_fmt_t f) { switch (f) { case VPX_IMG_FMT_I420: return "I420"; case VPX_IMG_FMT_I422: return "I422"; @@ -1342,7 +1359,6 @@ static const char* image_format_to_string(vpx_img_fmt_t f) { static void show_stream_config(struct stream_state *stream, struct VpxEncoderConfig *global, struct VpxInputContext *input) { - #define SHOW(field) \ fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field) @@ -1350,8 +1366,7 @@ static void show_stream_config(struct stream_state *stream, fprintf(stderr, "Codec: %s\n", vpx_codec_iface_name(global->codec->codec_interface())); fprintf(stderr, "Source file: %s File Type: %s Format: %s\n", - input->filename, - file_type_to_string(input->file_type), + input->filename, file_type_to_string(input->file_type), image_format_to_string(input->fmt)); } if (stream->next || stream->index) @@ -1394,20 +1409,17 @@ static void show_stream_config(struct stream_state *stream, SHOW(kf_max_dist); } - static void open_output_file(struct stream_state *stream, struct VpxEncoderConfig *global, const struct VpxRational *pixel_aspect_ratio) { const char *fn = stream->config.out_fn; const struct vpx_codec_enc_cfg *const cfg = &stream->config.cfg; - if (cfg->g_pass == VPX_RC_FIRST_PASS) - return; + if (cfg->g_pass == VPX_RC_FIRST_PASS) return; stream->file = strcmp(fn, "-") ? fopen(fn, "wb") : set_binary_mode(stdout); - if (!stream->file) - fatal("Failed to open output file"); + if (!stream->file) fatal("Failed to open output file"); if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR)) fatal("WebM output to pipes not supported."); @@ -1415,10 +1427,8 @@ static void open_output_file(struct stream_state *stream, #if CONFIG_WEBM_IO if (stream->config.write_webm) { stream->webm_ctx.stream = stream->file; - write_webm_file_header(&stream->webm_ctx, cfg, - &global->framerate, - stream->config.stereo_fmt, - global->codec->fourcc, + write_webm_file_header(&stream->webm_ctx, cfg, &global->framerate, + stream->config.stereo_fmt, global->codec->fourcc, pixel_aspect_ratio); } #else @@ -1430,13 +1440,11 @@ static void open_output_file(struct stream_state *stream, } } - static void close_output_file(struct stream_state *stream, unsigned int fourcc) { const struct vpx_codec_enc_cfg *const cfg = &stream->config.cfg; - if (cfg->g_pass == VPX_RC_FIRST_PASS) - return; + if (cfg->g_pass == VPX_RC_FIRST_PASS) return; #if CONFIG_WEBM_IO if (stream->config.write_webm) { @@ -1446,21 +1454,17 @@ static void close_output_file(struct stream_state *stream, if (!stream->config.write_webm) { if (!fseek(stream->file, 0, SEEK_SET)) - ivf_write_file_header(stream->file, &stream->config.cfg, - fourcc, + ivf_write_file_header(stream->file, &stream->config.cfg, fourcc, stream->frames_out); } fclose(stream->file); } - static void setup_pass(struct stream_state *stream, - struct VpxEncoderConfig *global, - int pass) { + struct VpxEncoderConfig *global, int pass) { if (stream->config.stats_fn) { - if (!stats_open_file(&stream->stats, stream->config.stats_fn, - pass)) + if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass)) fatal("Failed to open statistics store"); } else { if (!stats_open_mem(&stream->stats, pass)) @@ -1469,8 +1473,8 @@ static void setup_pass(struct stream_state *stream, #if CONFIG_FP_MB_STATS if (stream->config.fpmb_stats_fn) { - if (!stats_open_file(&stream->fpmb_stats, - stream->config.fpmb_stats_fn, pass)) + if (!stats_open_file(&stream->fpmb_stats, stream->config.fpmb_stats_fn, + pass)) fatal("Failed to open mb statistics store"); } else { if (!stats_open_mem(&stream->fpmb_stats, pass)) @@ -1479,8 +1483,8 @@ static void setup_pass(struct stream_state *stream, #endif stream->config.cfg.g_pass = global->passes == 2 - ? pass ? VPX_RC_LAST_PASS : VPX_RC_FIRST_PASS - : VPX_RC_ONE_PASS; + ? pass ? VPX_RC_LAST_PASS : VPX_RC_FIRST_PASS + : VPX_RC_ONE_PASS; if (pass) { stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats); #if CONFIG_FP_MB_STATS @@ -1494,7 +1498,6 @@ static void setup_pass(struct stream_state *stream, stream->frames_out = 0; } - static void initialize_encoder(struct stream_state *stream, struct VpxEncoderConfig *global) { int i; @@ -1519,8 +1522,7 @@ static void initialize_encoder(struct stream_state *stream, int ctrl = stream->config.arg_ctrls[i][0]; int value = stream->config.arg_ctrls[i][1]; if (vpx_codec_control_(&stream->encoder, ctrl, value)) - fprintf(stderr, "Error: Tried to set control %d = %d\n", - ctrl, value); + fprintf(stderr, "Error: Tried to set control %d = %d\n", ctrl, value); ctx_exit_on_error(&stream->encoder, "Failed to control codec"); } @@ -1533,23 +1535,21 @@ static void initialize_encoder(struct stream_state *stream, #endif } - static void encode_frame(struct stream_state *stream, - struct VpxEncoderConfig *global, - struct vpx_image *img, + struct VpxEncoderConfig *global, struct vpx_image *img, unsigned int frames_in) { vpx_codec_pts_t frame_start, next_frame_start; struct vpx_codec_enc_cfg *cfg = &stream->config.cfg; struct vpx_usec_timer timer; - frame_start = (cfg->g_timebase.den * (int64_t)(frames_in - 1) - * global->framerate.den) - / cfg->g_timebase.num / global->framerate.num; - next_frame_start = (cfg->g_timebase.den * (int64_t)(frames_in) - * global->framerate.den) - / cfg->g_timebase.num / global->framerate.num; + frame_start = + (cfg->g_timebase.den * (int64_t)(frames_in - 1) * global->framerate.den) / + cfg->g_timebase.num / global->framerate.num; + next_frame_start = + (cfg->g_timebase.den * (int64_t)(frames_in)*global->framerate.den) / + cfg->g_timebase.num / global->framerate.num; - /* Scale if necessary */ +/* Scale if necessary */ #if CONFIG_VP9_HIGHBITDEPTH if (img) { if ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) && @@ -1560,32 +1560,28 @@ static void encode_frame(struct stream_state *stream, } #if CONFIG_LIBYUV if (!stream->img) { - stream->img = vpx_img_alloc(NULL, VPX_IMG_FMT_I42016, - cfg->g_w, cfg->g_h, 16); + stream->img = + vpx_img_alloc(NULL, VPX_IMG_FMT_I42016, cfg->g_w, cfg->g_h, 16); } - I420Scale_16((uint16*)img->planes[VPX_PLANE_Y], - img->stride[VPX_PLANE_Y]/2, - (uint16*)img->planes[VPX_PLANE_U], - img->stride[VPX_PLANE_U]/2, - (uint16*)img->planes[VPX_PLANE_V], - img->stride[VPX_PLANE_V]/2, - img->d_w, img->d_h, - (uint16*)stream->img->planes[VPX_PLANE_Y], - stream->img->stride[VPX_PLANE_Y]/2, - (uint16*)stream->img->planes[VPX_PLANE_U], - stream->img->stride[VPX_PLANE_U]/2, - (uint16*)stream->img->planes[VPX_PLANE_V], - stream->img->stride[VPX_PLANE_V]/2, - stream->img->d_w, stream->img->d_h, - kFilterBox); + I420Scale_16( + (uint16 *)img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y] / 2, + (uint16 *)img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U] / 2, + (uint16 *)img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V] / 2, + img->d_w, img->d_h, (uint16 *)stream->img->planes[VPX_PLANE_Y], + stream->img->stride[VPX_PLANE_Y] / 2, + (uint16 *)stream->img->planes[VPX_PLANE_U], + stream->img->stride[VPX_PLANE_U] / 2, + (uint16 *)stream->img->planes[VPX_PLANE_V], + stream->img->stride[VPX_PLANE_V] / 2, stream->img->d_w, + stream->img->d_h, kFilterBox); img = stream->img; #else - stream->encoder.err = 1; - ctx_exit_on_error(&stream->encoder, - "Stream %d: Failed to encode frame.\n" - "Scaling disabled in this configuration. \n" - "To enable, configure with --enable-libyuv\n", - stream->index); + stream->encoder.err = 1; + ctx_exit_on_error(&stream->encoder, + "Stream %d: Failed to encode frame.\n" + "Scaling disabled in this configuration. \n" + "To enable, configure with --enable-libyuv\n", + stream->index); #endif } } @@ -1597,20 +1593,16 @@ static void encode_frame(struct stream_state *stream, } #if CONFIG_LIBYUV if (!stream->img) - stream->img = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, - cfg->g_w, cfg->g_h, 16); - I420Scale(img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y], - img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U], - img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V], - img->d_w, img->d_h, - stream->img->planes[VPX_PLANE_Y], - stream->img->stride[VPX_PLANE_Y], - stream->img->planes[VPX_PLANE_U], - stream->img->stride[VPX_PLANE_U], - stream->img->planes[VPX_PLANE_V], - stream->img->stride[VPX_PLANE_V], - stream->img->d_w, stream->img->d_h, - kFilterBox); + stream->img = + vpx_img_alloc(NULL, VPX_IMG_FMT_I420, cfg->g_w, cfg->g_h, 16); + I420Scale( + img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y], + img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U], + img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V], img->d_w, img->d_h, + stream->img->planes[VPX_PLANE_Y], stream->img->stride[VPX_PLANE_Y], + stream->img->planes[VPX_PLANE_U], stream->img->stride[VPX_PLANE_U], + stream->img->planes[VPX_PLANE_V], stream->img->stride[VPX_PLANE_V], + stream->img->d_w, stream->img->d_h, kFilterBox); img = stream->img; #else stream->encoder.err = 1; @@ -1624,15 +1616,14 @@ static void encode_frame(struct stream_state *stream, vpx_usec_timer_start(&timer); vpx_codec_encode(&stream->encoder, img, frame_start, - (unsigned long)(next_frame_start - frame_start), - 0, global->deadline); + (unsigned long)(next_frame_start - frame_start), 0, + global->deadline); vpx_usec_timer_mark(&timer); stream->cx_time += vpx_usec_timer_elapsed(&timer); ctx_exit_on_error(&stream->encoder, "Stream %d: Failed to encode frame", stream->index); } - static void update_quantizer_histogram(struct stream_state *stream) { if (stream->config.cfg.g_pass != VPX_RC_FIRST_PASS) { int q; @@ -1643,10 +1634,8 @@ static void update_quantizer_histogram(struct stream_state *stream) { } } - static void get_cx_data(struct stream_state *stream, - struct VpxEncoderConfig *global, - int *got_data) { + struct VpxEncoderConfig *global, int *got_data) { const vpx_codec_cx_pkt_t *pkt; const struct vpx_codec_enc_cfg *cfg = &stream->config.cfg; vpx_codec_iter_t iter = NULL; @@ -1687,8 +1676,8 @@ static void get_cx_data(struct stream_state *stream, } } - (void) fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, - stream->file); + (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, + stream->file); } stream->nbytes += pkt->data.raw.sz; @@ -1709,15 +1698,13 @@ static void get_cx_data(struct stream_state *stream, break; case VPX_CODEC_STATS_PKT: stream->frames_out++; - stats_write(&stream->stats, - pkt->data.twopass_stats.buf, + stats_write(&stream->stats, pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz); stream->nbytes += pkt->data.raw.sz; break; #if CONFIG_FP_MB_STATS case VPX_CODEC_FPMB_STATS_PKT: - stats_write(&stream->fpmb_stats, - pkt->data.firstpass_mb_stats.buf, + stats_write(&stream->fpmb_stats, pkt->data.firstpass_mb_stats.buf, pkt->data.firstpass_mb_stats.sz); stream->nbytes += pkt->data.raw.sz; break; @@ -1738,19 +1725,16 @@ static void get_cx_data(struct stream_state *stream, } break; - default: - break; + default: break; } } } - -static void show_psnr(struct stream_state *stream, double peak) { +static void show_psnr(struct stream_state *stream, double peak) { int i; double ovpsnr; - if (!stream->psnr_count) - return; + if (!stream->psnr_count) return; fprintf(stderr, "Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index); ovpsnr = sse_to_psnr((double)stream->psnr_samples_total, peak, @@ -1763,18 +1747,16 @@ static void show_psnr(struct stream_state *stream, double peak) { fprintf(stderr, "\n"); } - static float usec_to_fps(uint64_t usec, unsigned int frames) { return (float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0); } -static void test_decode(struct stream_state *stream, +static void test_decode(struct stream_state *stream, enum TestDecodeFatality fatal, const VpxInterface *codec) { vpx_image_t enc_img, dec_img; - if (stream->mismatch_seen) - return; + if (stream->mismatch_seen) return; /* Get the internal reference frame */ if (strcmp(codec->name, "vp8") == 0) { @@ -1837,10 +1819,8 @@ static void test_decode(struct stream_state *stream, " Y[%d, %d] {%d/%d}," " U[%d, %d] {%d/%d}," " V[%d, %d] {%d/%d}", - stream->index, stream->frames_out, - y[0], y[1], y[2], y[3], - u[0], u[1], u[2], u[3], - v[0], v[1], v[2], v[3]); + stream->index, stream->frames_out, y[0], y[1], y[2], + y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]); stream->mismatch_seen = stream->frames_out; } @@ -1848,7 +1828,6 @@ static void test_decode(struct stream_state *stream, vpx_img_free(&dec_img); } - static void print_time(const char *label, int64_t etl) { int64_t hours; int64_t mins; @@ -1861,14 +1840,13 @@ static void print_time(const char *label, int64_t etl) { etl -= mins * 60; secs = etl; - fprintf(stderr, "[%3s %2"PRId64":%02"PRId64":%02"PRId64"] ", - label, hours, mins, secs); + fprintf(stderr, "[%3s %2" PRId64 ":%02" PRId64 ":%02" PRId64 "] ", label, + hours, mins, secs); } else { fprintf(stderr, "[%3s unknown] ", label); } } - int main(int argc, const char **argv_) { int pass; vpx_image_t raw; @@ -1891,8 +1869,7 @@ int main(int argc, const char **argv_) { memset(&input, 0, sizeof(input)); exec_name = argv_[0]; - if (argc < 3) - usage_exit(); + if (argc < 3) usage_exit(); /* Setup default input stream settings */ input.framerate.numerator = 30; @@ -1908,21 +1885,11 @@ int main(int argc, const char **argv_) { parse_global_config(&global, argv); switch (global.color_type) { - case I420: - input.fmt = VPX_IMG_FMT_I420; - break; - case I422: - input.fmt = VPX_IMG_FMT_I422; - break; - case I444: - input.fmt = VPX_IMG_FMT_I444; - break; - case I440: - input.fmt = VPX_IMG_FMT_I440; - break; - case YV12: - input.fmt = VPX_IMG_FMT_YV12; - break; + case I420: input.fmt = VPX_IMG_FMT_I420; break; + case I422: input.fmt = VPX_IMG_FMT_I422; break; + case I444: input.fmt = VPX_IMG_FMT_I444; break; + case I440: input.fmt = VPX_IMG_FMT_I440; break; + case YV12: input.fmt = VPX_IMG_FMT_YV12; break; } { @@ -1935,8 +1902,7 @@ int main(int argc, const char **argv_) { do { stream = new_stream(&global, stream); stream_cnt++; - if (!streams) - streams = stream; + if (!streams) streams = stream; } while (parse_stream_params(&global, stream, argv)); } @@ -1945,18 +1911,16 @@ int main(int argc, const char **argv_) { if (argi[0][0] == '-' && argi[0][1]) die("Error: Unrecognized option %s\n", *argi); - FOREACH_STREAM(check_encoder_config(global.disable_warning_prompt, - &global, &stream->config.cfg);); + FOREACH_STREAM(check_encoder_config(global.disable_warning_prompt, &global, + &stream->config.cfg);); /* Handle non-option arguments */ input.filename = argv[0]; - if (!input.filename) - usage_exit(); + if (!input.filename) usage_exit(); /* Decide if other chroma subsamplings than 4:2:0 are supported */ - if (global.codec->fourcc == VP9_FOURCC) - input.only_i420 = 0; + if (global.codec->fourcc == VP9_FOURCC) input.only_i420 = 0; for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) { int frames_in = 0, seen_frames = 0; @@ -1981,8 +1945,9 @@ int main(int argc, const char **argv_) { /* Update stream configurations from the input file's parameters */ if (!input.width || !input.height) - fatal("Specify stream dimensions with --width (-w) " - " and --height (-h)"); + fatal( + "Specify stream dimensions with --width (-w) " + " and --height (-h)"); /* If input file does not specify bit-depth but input-bit-depth parameter * exists, assume that to be the input bit-depth. However, if the @@ -1999,9 +1964,8 @@ int main(int argc, const char **argv_) { }); if (input.bit_depth > 8) input.fmt |= VPX_IMG_FMT_HIGHBITDEPTH; } else { - FOREACH_STREAM({ - stream->config.cfg.g_input_bit_depth = input.bit_depth; - }); + FOREACH_STREAM( + { stream->config.cfg.g_input_bit_depth = input.bit_depth; }); } FOREACH_STREAM(set_stream_dimensions(stream, input.width, input.height)); @@ -2011,18 +1975,21 @@ int main(int argc, const char **argv_) { * --passes=2, ensure --fpf was set. */ if (global.pass && global.passes == 2) - FOREACH_STREAM( { - if (!stream->config.stats_fn) - die("Stream %d: Must specify --fpf when --pass=%d" - " and --passes=2\n", stream->index, global.pass); - }); + FOREACH_STREAM({ + if (!stream->config.stats_fn) + die( + "Stream %d: Must specify --fpf when --pass=%d" + " and --passes=2\n", + stream->index, global.pass); + }); #if !CONFIG_WEBM_IO FOREACH_STREAM({ if (stream->config.write_webm) { stream->config.write_webm = 0; - warn("vpxenc was compiled without WebM container support." - "Producing IVF output"); + warn( + "vpxenc was compiled without WebM container support." + "Producing IVF output"); } }); #endif @@ -2050,14 +2017,13 @@ int main(int argc, const char **argv_) { else vpx_img_alloc(&raw, input.fmt, input.width, input.height, 32); - FOREACH_STREAM(stream->rate_hist = - init_rate_histogram(&stream->config.cfg, - &global.framerate)); + FOREACH_STREAM(stream->rate_hist = init_rate_histogram( + &stream->config.cfg, &global.framerate)); } FOREACH_STREAM(setup_pass(stream, &global, pass)); - FOREACH_STREAM(open_output_file(stream, &global, - &input.pixel_aspect_ratio)); + FOREACH_STREAM( + open_output_file(stream, &global, &input.pixel_aspect_ratio)); FOREACH_STREAM(initialize_encoder(stream, &global)); #if CONFIG_VP9_HIGHBITDEPTH @@ -2073,7 +2039,7 @@ int main(int argc, const char **argv_) { input_shift = 0; } else { input_shift = (int)stream->config.cfg.g_bit_depth - - stream->config.cfg.g_input_bit_depth; + stream->config.cfg.g_input_bit_depth; } }); } @@ -2088,26 +2054,23 @@ int main(int argc, const char **argv_) { if (!global.limit || frames_in < global.limit) { frame_avail = read_frame(&input, &raw); - if (frame_avail) - frames_in++; - seen_frames = frames_in > global.skip_frames ? - frames_in - global.skip_frames : 0; + if (frame_avail) frames_in++; + seen_frames = + frames_in > global.skip_frames ? frames_in - global.skip_frames : 0; if (!global.quiet) { float fps = usec_to_fps(cx_time, seen_frames); fprintf(stderr, "\rPass %d/%d ", pass + 1, global.passes); if (stream_cnt == 1) - fprintf(stderr, - "frame %4d/%-4d %7"PRId64"B ", - frames_in, streams->frames_out, (int64_t)streams->nbytes); + fprintf(stderr, "frame %4d/%-4d %7" PRId64 "B ", frames_in, + streams->frames_out, (int64_t)streams->nbytes); else fprintf(stderr, "frame %4d ", frames_in); - fprintf(stderr, "%7"PRId64" %s %.2f %s ", + fprintf(stderr, "%7" PRId64 " %s %.2f %s ", cx_time > 9999999 ? cx_time / 1000 : cx_time, - cx_time > 9999999 ? "ms" : "us", - fps >= 1.0 ? fps : fps * 60, + cx_time > 9999999 ? "ms" : "us", fps >= 1.0 ? fps : fps * 60, fps >= 1.0 ? "fps" : "fpm"); print_time("ETA", estimated_time_left); } @@ -2138,8 +2101,7 @@ int main(int argc, const char **argv_) { FOREACH_STREAM({ if (stream->config.use_16bit_internal) encode_frame(stream, &global, - frame_avail ? frame_to_encode : NULL, - frames_in); + frame_avail ? frame_to_encode : NULL, frames_in); else assert(0); }); @@ -2151,8 +2113,7 @@ int main(int argc, const char **argv_) { } #else vpx_usec_timer_start(&timer); - FOREACH_STREAM(encode_frame(stream, &global, - frame_avail ? &raw : NULL, + FOREACH_STREAM(encode_frame(stream, &global, frame_avail ? &raw : NULL, frames_in)); #endif vpx_usec_timer_mark(&timer); @@ -2174,8 +2135,8 @@ int main(int argc, const char **argv_) { const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000; rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0; - remaining = 1000 * (global.limit - global.skip_frames - - seen_frames + lagged_count); + remaining = 1000 * (global.limit - global.skip_frames - + seen_frames + lagged_count); } else { const int64_t input_pos = ftello(input.file); const int64_t input_pos_lagged = input_pos - lagged_count; @@ -2185,9 +2146,8 @@ int main(int argc, const char **argv_) { remaining = limit - input_pos + lagged_count; } - average_rate = (average_rate <= 0) - ? rate - : (average_rate * 7 + rate) / 8; + average_rate = + (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8; estimated_time_left = average_rate ? remaining / average_rate : -1; } @@ -2196,23 +2156,23 @@ int main(int argc, const char **argv_) { } fflush(stdout); - if (!global.quiet) - fprintf(stderr, "\033[K"); + if (!global.quiet) fprintf(stderr, "\033[K"); } - if (stream_cnt > 1) - fprintf(stderr, "\n"); + if (stream_cnt > 1) fprintf(stderr, "\n"); if (!global.quiet) { - FOREACH_STREAM(fprintf(stderr, - "\rPass %d/%d frame %4d/%-4d %7"PRId64"B %7"PRId64"b/f %7"PRId64"b/s" - " %7"PRId64" %s (%.2f fps)\033[K\n", - pass + 1, - global.passes, frames_in, stream->frames_out, (int64_t)stream->nbytes, + FOREACH_STREAM(fprintf( + stderr, "\rPass %d/%d frame %4d/%-4d %7" PRId64 "B %7" PRId64 + "b/f %7" PRId64 "b/s" + " %7" PRId64 " %s (%.2f fps)\033[K\n", + pass + 1, global.passes, frames_in, stream->frames_out, + (int64_t)stream->nbytes, seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0, - seen_frames ? (int64_t)stream->nbytes * 8 * - (int64_t)global.framerate.num / global.framerate.den / - seen_frames : 0, + seen_frames + ? (int64_t)stream->nbytes * 8 * (int64_t)global.framerate.num / + global.framerate.den / seen_frames + : 0, stream->cx_time > 9999999 ? stream->cx_time / 1000 : stream->cx_time, stream->cx_time > 9999999 ? "ms" : "us", usec_to_fps(stream->cx_time, seen_frames))); @@ -2246,17 +2206,15 @@ int main(int argc, const char **argv_) { FOREACH_STREAM(stats_close(&stream->fpmb_stats, global.passes - 1)); #endif - if (global.pass) - break; + if (global.pass) break; } if (global.show_q_hist_buckets) - FOREACH_STREAM(show_q_histogram(stream->counts, - global.show_q_hist_buckets)); + FOREACH_STREAM( + show_q_histogram(stream->counts, global.show_q_hist_buckets)); if (global.show_rate_hist_buckets) - FOREACH_STREAM(show_rate_histogram(stream->rate_hist, - &stream->config.cfg, + FOREACH_STREAM(show_rate_histogram(stream->rate_hist, &stream->config.cfg, global.show_rate_hist_buckets)); FOREACH_STREAM(destroy_rate_histogram(stream->rate_hist)); @@ -2278,8 +2236,7 @@ int main(int argc, const char **argv_) { #endif #if CONFIG_VP9_HIGHBITDEPTH - if (allocated_raw_shift) - vpx_img_free(&raw_shift); + if (allocated_raw_shift) vpx_img_free(&raw_shift); #endif vpx_img_free(&raw); free(argv); diff --git a/vpxstats.c b/vpxstats.c index 16728ce09..142e367bb 100644 --- a/vpxstats.c +++ b/vpxstats.c @@ -30,8 +30,7 @@ int stats_open_file(stats_io_t *stats, const char *fpf, int pass) { stats->file = fopen(fpf, "rb"); - if (stats->file == NULL) - fatal("First-pass stats file does not exist!"); + if (stats->file == NULL) fatal("First-pass stats file does not exist!"); if (fseek(stats->file, 0, SEEK_END)) fatal("First-pass stats file must be seekable!"); @@ -76,18 +75,17 @@ void stats_close(stats_io_t *stats, int last_pass) { fclose(stats->file); stats->file = NULL; } else { - if (stats->pass == last_pass) - free(stats->buf.buf); + if (stats->pass == last_pass) free(stats->buf.buf); } } void stats_write(stats_io_t *stats, const void *pkt, size_t len) { if (stats->file) { - (void) fwrite(pkt, 1, len, stats->file); + (void)fwrite(pkt, 1, len, stats->file); } else { if (stats->buf.sz + len > stats->buf_alloc_sz) { - size_t new_sz = stats->buf_alloc_sz + 64 * 1024; - char *new_ptr = realloc(stats->buf.buf, new_sz); + size_t new_sz = stats->buf_alloc_sz + 64 * 1024; + char *new_ptr = realloc(stats->buf.buf, new_sz); if (new_ptr) { stats->buf_ptr = new_ptr + (stats->buf_ptr - (char *)stats->buf.buf); @@ -104,6 +102,4 @@ void stats_write(stats_io_t *stats, const void *pkt, size_t len) { } } -vpx_fixed_buf_t stats_get(stats_io_t *stats) { - return stats->buf; -} +vpx_fixed_buf_t stats_get(stats_io_t *stats) { return stats->buf; } diff --git a/warnings.c b/warnings.c index 1f4846cf1..a80da527f 100644 --- a/warnings.c +++ b/warnings.c @@ -47,8 +47,7 @@ static void add_warning(const char *warning_string, new_node->warning_string = warning_string; new_node->next_warning = NULL; - while (*node != NULL) - node = &(*node)->next_warning; + while (*node != NULL) node = &(*node)->next_warning; *node = new_node; } @@ -78,9 +77,7 @@ static void check_quantizer(int min_q, int max_q, } static void check_lag_in_frames_realtime_deadline( - int lag_in_frames, - int deadline, - int rc_end_usage, + int lag_in_frames, int deadline, int rc_end_usage, struct WarningList *warning_list) { if (deadline == VPX_DL_REALTIME && lag_in_frames != 0 && rc_end_usage == 1) add_warning(lag_in_frames_with_realtime, warning_list); @@ -91,27 +88,22 @@ void check_encoder_config(int disable_prompt, const struct vpx_codec_enc_cfg *stream_config) { int num_warnings = 0; struct WarningListNode *warning = NULL; - struct WarningList warning_list = {0}; + struct WarningList warning_list = { 0 }; check_quantizer(stream_config->rc_min_quantizer, - stream_config->rc_max_quantizer, - &warning_list); - check_lag_in_frames_realtime_deadline(stream_config->g_lag_in_frames, - global_config->deadline, - stream_config->rc_end_usage, - &warning_list); + stream_config->rc_max_quantizer, &warning_list); + check_lag_in_frames_realtime_deadline( + stream_config->g_lag_in_frames, global_config->deadline, + stream_config->rc_end_usage, &warning_list); /* Count and print warnings. */ - for (warning = warning_list.warning_node; - warning != NULL; - warning = warning->next_warning, - ++num_warnings) { + for (warning = warning_list.warning_node; warning != NULL; + warning = warning->next_warning, ++num_warnings) { warn(warning->warning_string); } free_warning_list(&warning_list); if (num_warnings) { - if (!disable_prompt && !continue_prompt(num_warnings)) - exit(EXIT_FAILURE); + if (!disable_prompt && !continue_prompt(num_warnings)) exit(EXIT_FAILURE); } } diff --git a/webmdec.cc b/webmdec.cc index 36dbd92bf..8f7797038 100644 --- a/webmdec.cc +++ b/webmdec.cc @@ -21,12 +21,12 @@ namespace { void reset(struct WebmInputContext *const webm_ctx) { if (webm_ctx->reader != NULL) { mkvparser::MkvReader *const reader = - reinterpret_cast(webm_ctx->reader); + reinterpret_cast(webm_ctx->reader); delete reader; } if (webm_ctx->segment != NULL) { mkvparser::Segment *const segment = - reinterpret_cast(webm_ctx->segment); + reinterpret_cast(webm_ctx->segment); delete segment; } if (webm_ctx->buffer != NULL) { @@ -46,7 +46,7 @@ void reset(struct WebmInputContext *const webm_ctx) { void get_first_cluster(struct WebmInputContext *const webm_ctx) { mkvparser::Segment *const segment = - reinterpret_cast(webm_ctx->segment); + reinterpret_cast(webm_ctx->segment); const mkvparser::Cluster *const cluster = segment->GetFirst(); webm_ctx->cluster = cluster; } @@ -72,7 +72,7 @@ int file_is_webm(struct WebmInputContext *webm_ctx, return 0; } - mkvparser::Segment* segment; + mkvparser::Segment *segment; if (mkvparser::Segment::CreateInstance(reader, pos, segment)) { rewind_and_reset(webm_ctx, vpx_ctx); return 0; @@ -84,11 +84,11 @@ int file_is_webm(struct WebmInputContext *webm_ctx, } const mkvparser::Tracks *const tracks = segment->GetTracks(); - const mkvparser::VideoTrack* video_track = NULL; + const mkvparser::VideoTrack *video_track = NULL; for (unsigned long i = 0; i < tracks->GetTracksCount(); ++i) { - const mkvparser::Track* const track = tracks->GetTrackByIndex(i); + const mkvparser::Track *const track = tracks->GetTrackByIndex(i); if (track->GetType() == mkvparser::Track::kVideo) { - video_track = static_cast(track); + video_track = static_cast(track); webm_ctx->video_track_index = track->GetNumber(); break; } @@ -118,8 +118,7 @@ int file_is_webm(struct WebmInputContext *webm_ctx, return 1; } -int webm_read_frame(struct WebmInputContext *webm_ctx, - uint8_t **buffer, +int webm_read_frame(struct WebmInputContext *webm_ctx, uint8_t **buffer, size_t *buffer_size) { // This check is needed for frame parallel decoding, in which case this // function could be called even after it has reached end of input stream. @@ -127,13 +126,13 @@ int webm_read_frame(struct WebmInputContext *webm_ctx, return 1; } mkvparser::Segment *const segment = - reinterpret_cast(webm_ctx->segment); - const mkvparser::Cluster* cluster = - reinterpret_cast(webm_ctx->cluster); + reinterpret_cast(webm_ctx->segment); + const mkvparser::Cluster *cluster = + reinterpret_cast(webm_ctx->cluster); const mkvparser::Block *block = - reinterpret_cast(webm_ctx->block); + reinterpret_cast(webm_ctx->block); const mkvparser::BlockEntry *block_entry = - reinterpret_cast(webm_ctx->block_entry); + reinterpret_cast(webm_ctx->block_entry); bool block_entry_eos = false; do { long status = 0; @@ -175,11 +174,11 @@ int webm_read_frame(struct WebmInputContext *webm_ctx, webm_ctx->block_entry = block_entry; webm_ctx->block = block; - const mkvparser::Block::Frame& frame = + const mkvparser::Block::Frame &frame = block->GetFrame(webm_ctx->block_frame_index); ++webm_ctx->block_frame_index; if (frame.len > static_cast(*buffer_size)) { - delete[] *buffer; + delete[] * buffer; *buffer = new uint8_t[frame.len]; if (*buffer == NULL) { return -1; @@ -191,7 +190,7 @@ int webm_read_frame(struct WebmInputContext *webm_ctx, webm_ctx->is_key_frame = block->IsKey(); mkvparser::MkvReader *const reader = - reinterpret_cast(webm_ctx->reader); + reinterpret_cast(webm_ctx->reader); return frame.Read(reader, *buffer) ? -1 : 0; } @@ -221,6 +220,4 @@ int webm_guess_framerate(struct WebmInputContext *webm_ctx, return 0; } -void webm_free(struct WebmInputContext *webm_ctx) { - reset(webm_ctx); -} +void webm_free(struct WebmInputContext *webm_ctx) { reset(webm_ctx); } diff --git a/webmdec.h b/webmdec.h index aa371f321..7dcb170ca 100644 --- a/webmdec.h +++ b/webmdec.h @@ -52,8 +52,7 @@ int file_is_webm(struct WebmInputContext *webm_ctx, // 0 - Success // 1 - End of Stream // -1 - Error -int webm_read_frame(struct WebmInputContext *webm_ctx, - uint8_t **buffer, +int webm_read_frame(struct WebmInputContext *webm_ctx, uint8_t **buffer, size_t *buffer_size); // Guesses the frame rate of the input file based on the container timestamps. diff --git a/webmenc.cc b/webmenc.cc index 9929969a0..52516a6ae 100644 --- a/webmenc.cc +++ b/webmenc.cc @@ -23,8 +23,7 @@ const int kVideoTrackNumber = 1; void write_webm_file_header(struct WebmOutputContext *webm_ctx, const vpx_codec_enc_cfg_t *cfg, const struct vpx_rational *fps, - stereo_format_t stereo_fmt, - unsigned int fourcc, + stereo_format_t stereo_fmt, unsigned int fourcc, const struct VpxRational *par) { mkvmuxer::MkvWriter *const writer = new mkvmuxer::MkvWriter(webm_ctx->stream); mkvmuxer::Segment *const segment = new mkvmuxer::Segment(); @@ -43,29 +42,22 @@ void write_webm_file_header(struct WebmOutputContext *webm_ctx, const uint64_t video_track_id = segment->AddVideoTrack(static_cast(cfg->g_w), - static_cast(cfg->g_h), - kVideoTrackNumber); - mkvmuxer::VideoTrack* const video_track = - static_cast( - segment->GetTrackByNumber(video_track_id)); + static_cast(cfg->g_h), kVideoTrackNumber); + mkvmuxer::VideoTrack *const video_track = static_cast( + segment->GetTrackByNumber(video_track_id)); video_track->SetStereoMode(stereo_fmt); const char *codec_id; switch (fourcc) { - case VP8_FOURCC: - codec_id = "V_VP8"; - break; - case VP9_FOURCC: - default: - codec_id = "V_VP9"; - break; + case VP8_FOURCC: codec_id = "V_VP8"; break; + case VP9_FOURCC: + default: codec_id = "V_VP9"; break; } video_track->set_codec_id(codec_id); if (par->numerator > 1 || par->denominator > 1) { // TODO(fgalligan): Add support of DisplayUnit, Display Aspect Ratio type // to WebM format. - const uint64_t display_width = - static_cast(((cfg->g_w * par->numerator * 1.0) / - par->denominator) + .5); + const uint64_t display_width = static_cast( + ((cfg->g_w * par->numerator * 1.0) / par->denominator) + .5); video_track->set_display_width(display_width); video_track->set_display_height(cfg->g_h); } @@ -80,25 +72,22 @@ void write_webm_block(struct WebmOutputContext *webm_ctx, const vpx_codec_enc_cfg_t *cfg, const vpx_codec_cx_pkt_t *pkt) { mkvmuxer::Segment *const segment = - reinterpret_cast(webm_ctx->segment); - int64_t pts_ns = pkt->data.frame.pts * 1000000000ll * - cfg->g_timebase.num / cfg->g_timebase.den; - if (pts_ns <= webm_ctx->last_pts_ns) - pts_ns = webm_ctx->last_pts_ns + 1000000; + reinterpret_cast(webm_ctx->segment); + int64_t pts_ns = pkt->data.frame.pts * 1000000000ll * cfg->g_timebase.num / + cfg->g_timebase.den; + if (pts_ns <= webm_ctx->last_pts_ns) pts_ns = webm_ctx->last_pts_ns + 1000000; webm_ctx->last_pts_ns = pts_ns; - segment->AddFrame(static_cast(pkt->data.frame.buf), - pkt->data.frame.sz, - kVideoTrackNumber, - pts_ns, + segment->AddFrame(static_cast(pkt->data.frame.buf), + pkt->data.frame.sz, kVideoTrackNumber, pts_ns, pkt->data.frame.flags & VPX_FRAME_IS_KEY); } void write_webm_file_footer(struct WebmOutputContext *webm_ctx) { mkvmuxer::MkvWriter *const writer = - reinterpret_cast(webm_ctx->writer); + reinterpret_cast(webm_ctx->writer); mkvmuxer::Segment *const segment = - reinterpret_cast(webm_ctx->segment); + reinterpret_cast(webm_ctx->segment); segment->Finalize(); delete segment; delete writer; diff --git a/webmenc.h b/webmenc.h index ad30664e3..1ae7786cd 100644 --- a/webmenc.h +++ b/webmenc.h @@ -40,8 +40,7 @@ typedef enum stereo_format { void write_webm_file_header(struct WebmOutputContext *webm_ctx, const vpx_codec_enc_cfg_t *cfg, const struct vpx_rational *fps, - stereo_format_t stereo_fmt, - unsigned int fourcc, + stereo_format_t stereo_fmt, unsigned int fourcc, const struct VpxRational *par); void write_webm_block(struct WebmOutputContext *webm_ctx, diff --git a/y4menc.c b/y4menc.c index b647e8dcc..e26fcaf6e 100644 --- a/y4menc.c +++ b/y4menc.c @@ -17,39 +17,43 @@ int y4m_write_file_header(char *buf, size_t len, int width, int height, const char *color; switch (bit_depth) { case 8: - color = fmt == VPX_IMG_FMT_444A ? "C444alpha\n" : - fmt == VPX_IMG_FMT_I444 ? "C444\n" : - fmt == VPX_IMG_FMT_I422 ? "C422\n" : - "C420jpeg\n"; + color = fmt == VPX_IMG_FMT_444A + ? "C444alpha\n" + : fmt == VPX_IMG_FMT_I444 ? "C444\n" : fmt == VPX_IMG_FMT_I422 + ? "C422\n" + : "C420jpeg\n"; break; case 9: - color = fmt == VPX_IMG_FMT_I44416 ? "C444p9 XYSCSS=444P9\n" : - fmt == VPX_IMG_FMT_I42216 ? "C422p9 XYSCSS=422P9\n" : - "C420p9 XYSCSS=420P9\n"; + color = fmt == VPX_IMG_FMT_I44416 + ? "C444p9 XYSCSS=444P9\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p9 XYSCSS=422P9\n" + : "C420p9 XYSCSS=420P9\n"; break; case 10: - color = fmt == VPX_IMG_FMT_I44416 ? "C444p10 XYSCSS=444P10\n" : - fmt == VPX_IMG_FMT_I42216 ? "C422p10 XYSCSS=422P10\n" : - "C420p10 XYSCSS=420P10\n"; + color = fmt == VPX_IMG_FMT_I44416 + ? "C444p10 XYSCSS=444P10\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p10 XYSCSS=422P10\n" + : "C420p10 XYSCSS=420P10\n"; break; case 12: - color = fmt == VPX_IMG_FMT_I44416 ? "C444p12 XYSCSS=444P12\n" : - fmt == VPX_IMG_FMT_I42216 ? "C422p12 XYSCSS=422P12\n" : - "C420p12 XYSCSS=420P12\n"; + color = fmt == VPX_IMG_FMT_I44416 + ? "C444p12 XYSCSS=444P12\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p12 XYSCSS=422P12\n" + : "C420p12 XYSCSS=420P12\n"; break; case 14: - color = fmt == VPX_IMG_FMT_I44416 ? "C444p14 XYSCSS=444P14\n" : - fmt == VPX_IMG_FMT_I42216 ? "C422p14 XYSCSS=422P14\n" : - "C420p14 XYSCSS=420P14\n"; + color = fmt == VPX_IMG_FMT_I44416 + ? "C444p14 XYSCSS=444P14\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p14 XYSCSS=422P14\n" + : "C420p14 XYSCSS=420P14\n"; break; case 16: - color = fmt == VPX_IMG_FMT_I44416 ? "C444p16 XYSCSS=444P16\n" : - fmt == VPX_IMG_FMT_I42216 ? "C422p16 XYSCSS=422P16\n" : - "C420p16 XYSCSS=420P16\n"; + color = fmt == VPX_IMG_FMT_I44416 + ? "C444p16 XYSCSS=444P16\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p16 XYSCSS=422P16\n" + : "C420p16 XYSCSS=420P16\n"; break; - default: - color = NULL; - assert(0); + default: color = NULL; assert(0); } return snprintf(buf, len, "YUV4MPEG2 W%u H%u F%u:%u I%c %s", width, height, framerate->numerator, framerate->denominator, 'p', color); diff --git a/y4minput.c b/y4minput.c index 34ea96d9d..f845d2151 100644 --- a/y4minput.c +++ b/y4minput.c @@ -25,7 +25,7 @@ static int file_read(void *buf, size_t size, FILE *file) { int file_error; size_t len = 0; do { - const size_t n = fread((uint8_t*)buf + len, 1, size - len, file); + const size_t n = fread((uint8_t *)buf + len, 1, size - len, file); len += n; file_error = ferror(file); if (file_error) { @@ -41,83 +41,77 @@ static int file_read(void *buf, size_t size, FILE *file) { } while (!feof(file) && len < size && ++retry_count < kMaxRetries); if (!feof(file) && len != size) { - fprintf(stderr, "Error reading file: %u of %u bytes read," - " error: %d, retries: %d, %d: %s\n", - (uint32_t)len, (uint32_t)size, file_error, retry_count, - errno, strerror(errno)); + fprintf(stderr, + "Error reading file: %u of %u bytes read," + " error: %d, retries: %d, %d: %s\n", + (uint32_t)len, (uint32_t)size, file_error, retry_count, errno, + strerror(errno)); } return len == size; } static int y4m_parse_tags(y4m_input *_y4m, char *_tags) { - int got_w; - int got_h; - int got_fps; - int got_interlace; - int got_par; - int got_chroma; + int got_w; + int got_h; + int got_fps; + int got_interlace; + int got_par; + int got_chroma; char *p; char *q; got_w = got_h = got_fps = got_interlace = got_par = got_chroma = 0; for (p = _tags;; p = q) { /*Skip any leading spaces.*/ - while (*p == ' ')p++; + while (*p == ' ') p++; /*If that's all we have, stop.*/ - if (p[0] == '\0')break; + if (p[0] == '\0') break; /*Find the end of this tag.*/ - for (q = p + 1; *q != '\0' && *q != ' '; q++); + for (q = p + 1; *q != '\0' && *q != ' '; q++) + ; /*Process the tag.*/ switch (p[0]) { case 'W': { - if (sscanf(p + 1, "%d", &_y4m->pic_w) != 1)return -1; + if (sscanf(p + 1, "%d", &_y4m->pic_w) != 1) return -1; got_w = 1; - } - break; + } break; case 'H': { - if (sscanf(p + 1, "%d", &_y4m->pic_h) != 1)return -1; + if (sscanf(p + 1, "%d", &_y4m->pic_h) != 1) return -1; got_h = 1; - } - break; + } break; case 'F': { if (sscanf(p + 1, "%d:%d", &_y4m->fps_n, &_y4m->fps_d) != 2) { return -1; } got_fps = 1; - } - break; + } break; case 'I': { _y4m->interlace = p[1]; got_interlace = 1; - } - break; + } break; case 'A': { if (sscanf(p + 1, "%d:%d", &_y4m->par_n, &_y4m->par_d) != 2) { return -1; } got_par = 1; - } - break; + } break; case 'C': { - if (q - p > 16)return -1; + if (q - p > 16) return -1; memcpy(_y4m->chroma_type, p + 1, q - p - 1); _y4m->chroma_type[q - p - 1] = '\0'; got_chroma = 1; - } - break; - /*Ignore unknown tags.*/ + } break; + /*Ignore unknown tags.*/ } } - if (!got_w || !got_h || !got_fps)return -1; - if (!got_interlace)_y4m->interlace = '?'; - if (!got_par)_y4m->par_n = _y4m->par_d = 0; + if (!got_w || !got_h || !got_fps) return -1; + if (!got_interlace) _y4m->interlace = '?'; + if (!got_par) _y4m->par_n = _y4m->par_d = 0; /*Chroma-type is not specified in older files, e.g., those generated by mplayer.*/ - if (!got_chroma)strcpy(_y4m->chroma_type, "420"); + if (!got_chroma) strcpy(_y4m->chroma_type, "420"); return 0; } - - /*All anti-aliasing filters in the following conversion functions are based on one of two window functions: The 6-tap Lanczos window (for down-sampling and shifts): @@ -140,9 +134,9 @@ static int y4m_parse_tags(y4m_input *_y4m, char *_tags) { have these steps pipelined, for less memory consumption and better cache performance, but we do them separately for simplicity.*/ -#define OC_MINI(_a,_b) ((_a)>(_b)?(_b):(_a)) -#define OC_MAXI(_a,_b) ((_a)<(_b)?(_b):(_a)) -#define OC_CLAMPI(_a,_b,_c) (OC_MAXI(_a,OC_MINI(_b,_c))) +#define OC_MINI(_a, _b) ((_a) > (_b) ? (_b) : (_a)) +#define OC_MAXI(_a, _b) ((_a) < (_b) ? (_b) : (_a)) +#define OC_CLAMPI(_a, _b, _c) (OC_MAXI(_a, OC_MINI(_b, _c))) /*420jpeg chroma samples are sited like: Y-------Y-------Y-------Y------- @@ -186,25 +180,36 @@ static int y4m_parse_tags(y4m_input *_y4m, char *_tags) { lines, and they are vertically co-sited with the luma samples in both the mpeg2 and jpeg cases (thus requiring no vertical resampling).*/ static void y4m_42xmpeg2_42xjpeg_helper(unsigned char *_dst, - const unsigned char *_src, int _c_w, int _c_h) { + const unsigned char *_src, int _c_w, + int _c_h) { int y; int x; for (y = 0; y < _c_h; y++) { /*Filter: [4 -17 114 35 -9 1]/128, derived from a 6-tap Lanczos window.*/ for (x = 0; x < OC_MINI(_c_w, 2); x++) { - _dst[x] = (unsigned char)OC_CLAMPI(0, (4 * _src[0] - 17 * _src[OC_MAXI(x - 1, 0)] + - 114 * _src[x] + 35 * _src[OC_MINI(x + 1, _c_w - 1)] - 9 * _src[OC_MINI(x + 2, _c_w - 1)] + - _src[OC_MINI(x + 3, _c_w - 1)] + 64) >> 7, 255); + _dst[x] = (unsigned char)OC_CLAMPI( + 0, (4 * _src[0] - 17 * _src[OC_MAXI(x - 1, 0)] + 114 * _src[x] + + 35 * _src[OC_MINI(x + 1, _c_w - 1)] - + 9 * _src[OC_MINI(x + 2, _c_w - 1)] + + _src[OC_MINI(x + 3, _c_w - 1)] + 64) >> + 7, + 255); } for (; x < _c_w - 3; x++) { - _dst[x] = (unsigned char)OC_CLAMPI(0, (4 * _src[x - 2] - 17 * _src[x - 1] + - 114 * _src[x] + 35 * _src[x + 1] - 9 * _src[x + 2] + _src[x + 3] + 64) >> 7, 255); + _dst[x] = (unsigned char)OC_CLAMPI( + 0, (4 * _src[x - 2] - 17 * _src[x - 1] + 114 * _src[x] + + 35 * _src[x + 1] - 9 * _src[x + 2] + _src[x + 3] + 64) >> + 7, + 255); } for (; x < _c_w; x++) { - _dst[x] = (unsigned char)OC_CLAMPI(0, (4 * _src[x - 2] - 17 * _src[x - 1] + - 114 * _src[x] + 35 * _src[OC_MINI(x + 1, _c_w - 1)] - 9 * _src[OC_MINI(x + 2, _c_w - 1)] + - _src[_c_w - 1] + 64) >> 7, 255); + _dst[x] = (unsigned char)OC_CLAMPI( + 0, (4 * _src[x - 2] - 17 * _src[x - 1] + 114 * _src[x] + + 35 * _src[OC_MINI(x + 1, _c_w - 1)] - + 9 * _src[OC_MINI(x + 2, _c_w - 1)] + _src[_c_w - 1] + 64) >> + 7, + 255); } _dst += _c_w; _src += _c_w; @@ -277,12 +282,12 @@ static void y4m_convert_42xmpeg2_42xjpeg(y4m_input *_y4m, unsigned char *_dst, static void y4m_convert_42xpaldv_42xjpeg(y4m_input *_y4m, unsigned char *_dst, unsigned char *_aux) { unsigned char *tmp; - int c_w; - int c_h; - int c_sz; - int pli; - int y; - int x; + int c_w; + int c_h; + int c_sz; + int pli; + int y; + int x; /*Skip past the luma data.*/ _dst += _y4m->pic_w * _y4m->pic_h; /*Compute the size of each chroma plane.*/ @@ -302,53 +307,73 @@ static void y4m_convert_42xpaldv_42xjpeg(y4m_input *_y4m, unsigned char *_dst, This is the same filter used above, but in the other order.*/ for (x = 0; x < c_w; x++) { for (y = 0; y < OC_MINI(c_h, 3); y++) { - _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (tmp[0] - - 9 * tmp[OC_MAXI(y - 2, 0) * c_w] + 35 * tmp[OC_MAXI(y - 1, 0) * c_w] - + 114 * tmp[y * c_w] - 17 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] - + 4 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] + 64) >> 7, 255); + _dst[y * c_w] = (unsigned char)OC_CLAMPI( + 0, (tmp[0] - 9 * tmp[OC_MAXI(y - 2, 0) * c_w] + + 35 * tmp[OC_MAXI(y - 1, 0) * c_w] + 114 * tmp[y * c_w] - + 17 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] + + 4 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] + 64) >> + 7, + 255); } for (; y < c_h - 2; y++) { - _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (tmp[(y - 3) * c_w] - - 9 * tmp[(y - 2) * c_w] + 35 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] - - 17 * tmp[(y + 1) * c_w] + 4 * tmp[(y + 2) * c_w] + 64) >> 7, 255); + _dst[y * c_w] = (unsigned char)OC_CLAMPI( + 0, (tmp[(y - 3) * c_w] - 9 * tmp[(y - 2) * c_w] + + 35 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] - + 17 * tmp[(y + 1) * c_w] + 4 * tmp[(y + 2) * c_w] + 64) >> + 7, + 255); } for (; y < c_h; y++) { - _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (tmp[(y - 3) * c_w] - - 9 * tmp[(y - 2) * c_w] + 35 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] - - 17 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] + 4 * tmp[(c_h - 1) * c_w] + 64) >> 7, 255); + _dst[y * c_w] = (unsigned char)OC_CLAMPI( + 0, (tmp[(y - 3) * c_w] - 9 * tmp[(y - 2) * c_w] + + 35 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] - + 17 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] + + 4 * tmp[(c_h - 1) * c_w] + 64) >> + 7, + 255); } _dst++; tmp++; } _dst += c_sz - c_w; tmp -= c_w; - } - break; + } break; case 2: { /*Slide C_r down a quarter-pel. This is the same as the horizontal filter.*/ for (x = 0; x < c_w; x++) { for (y = 0; y < OC_MINI(c_h, 2); y++) { - _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (4 * tmp[0] - - 17 * tmp[OC_MAXI(y - 1, 0) * c_w] + 114 * tmp[y * c_w] - + 35 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] - 9 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] - + tmp[OC_MINI(y + 3, c_h - 1) * c_w] + 64) >> 7, 255); + _dst[y * c_w] = (unsigned char)OC_CLAMPI( + 0, + (4 * tmp[0] - 17 * tmp[OC_MAXI(y - 1, 0) * c_w] + + 114 * tmp[y * c_w] + 35 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] - + 9 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] + + tmp[OC_MINI(y + 3, c_h - 1) * c_w] + 64) >> + 7, + 255); } for (; y < c_h - 3; y++) { - _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (4 * tmp[(y - 2) * c_w] - - 17 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] + 35 * tmp[(y + 1) * c_w] - - 9 * tmp[(y + 2) * c_w] + tmp[(y + 3) * c_w] + 64) >> 7, 255); + _dst[y * c_w] = (unsigned char)OC_CLAMPI( + 0, (4 * tmp[(y - 2) * c_w] - 17 * tmp[(y - 1) * c_w] + + 114 * tmp[y * c_w] + 35 * tmp[(y + 1) * c_w] - + 9 * tmp[(y + 2) * c_w] + tmp[(y + 3) * c_w] + 64) >> + 7, + 255); } for (; y < c_h; y++) { - _dst[y * c_w] = (unsigned char)OC_CLAMPI(0, (4 * tmp[(y - 2) * c_w] - - 17 * tmp[(y - 1) * c_w] + 114 * tmp[y * c_w] + 35 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] - - 9 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] + tmp[(c_h - 1) * c_w] + 64) >> 7, 255); + _dst[y * c_w] = (unsigned char)OC_CLAMPI( + 0, + (4 * tmp[(y - 2) * c_w] - 17 * tmp[(y - 1) * c_w] + + 114 * tmp[y * c_w] + 35 * tmp[OC_MINI(y + 1, c_h - 1) * c_w] - + 9 * tmp[OC_MINI(y + 2, c_h - 1) * c_w] + tmp[(c_h - 1) * c_w] + + 64) >> + 7, + 255); } _dst++; tmp++; } - } - break; + } break; } /*For actual interlaced material, this would have to be done separately on each field, and the shift amounts would be different. @@ -363,27 +388,37 @@ static void y4m_convert_42xpaldv_42xjpeg(y4m_input *_y4m, unsigned char *_dst, /*Perform vertical filtering to reduce a single plane from 4:2:2 to 4:2:0. This is used as a helper by several converation routines.*/ static void y4m_422jpeg_420jpeg_helper(unsigned char *_dst, - const unsigned char *_src, int _c_w, int _c_h) { + const unsigned char *_src, int _c_w, + int _c_h) { int y; int x; /*Filter: [3 -17 78 78 -17 3]/128, derived from a 6-tap Lanczos window.*/ for (x = 0; x < _c_w; x++) { for (y = 0; y < OC_MINI(_c_h, 2); y += 2) { - _dst[(y >> 1)*_c_w] = OC_CLAMPI(0, (64 * _src[0] - + 78 * _src[OC_MINI(1, _c_h - 1) * _c_w] - - 17 * _src[OC_MINI(2, _c_h - 1) * _c_w] - + 3 * _src[OC_MINI(3, _c_h - 1) * _c_w] + 64) >> 7, 255); + _dst[(y >> 1) * _c_w] = + OC_CLAMPI(0, (64 * _src[0] + 78 * _src[OC_MINI(1, _c_h - 1) * _c_w] - + 17 * _src[OC_MINI(2, _c_h - 1) * _c_w] + + 3 * _src[OC_MINI(3, _c_h - 1) * _c_w] + 64) >> + 7, + 255); } for (; y < _c_h - 3; y += 2) { - _dst[(y >> 1)*_c_w] = OC_CLAMPI(0, (3 * (_src[(y - 2) * _c_w] + _src[(y + 3) * _c_w]) - - 17 * (_src[(y - 1) * _c_w] + _src[(y + 2) * _c_w]) - + 78 * (_src[y * _c_w] + _src[(y + 1) * _c_w]) + 64) >> 7, 255); + _dst[(y >> 1) * _c_w] = + OC_CLAMPI(0, (3 * (_src[(y - 2) * _c_w] + _src[(y + 3) * _c_w]) - + 17 * (_src[(y - 1) * _c_w] + _src[(y + 2) * _c_w]) + + 78 * (_src[y * _c_w] + _src[(y + 1) * _c_w]) + 64) >> + 7, + 255); } for (; y < _c_h; y += 2) { - _dst[(y >> 1)*_c_w] = OC_CLAMPI(0, (3 * (_src[(y - 2) * _c_w] - + _src[(_c_h - 1) * _c_w]) - 17 * (_src[(y - 1) * _c_w] - + _src[OC_MINI(y + 2, _c_h - 1) * _c_w]) - + 78 * (_src[y * _c_w] + _src[OC_MINI(y + 1, _c_h - 1) * _c_w]) + 64) >> 7, 255); + _dst[(y >> 1) * _c_w] = OC_CLAMPI( + 0, + (3 * (_src[(y - 2) * _c_w] + _src[(_c_h - 1) * _c_w]) - + 17 * (_src[(y - 1) * _c_w] + _src[OC_MINI(y + 2, _c_h - 1) * _c_w]) + + 78 * (_src[y * _c_w] + _src[OC_MINI(y + 1, _c_h - 1) * _c_w]) + + 64) >> + 7, + 255); } _src++; _dst++; @@ -496,12 +531,12 @@ static void y4m_convert_422jpeg_420jpeg(y4m_input *_y4m, unsigned char *_dst, static void y4m_convert_422_420jpeg(y4m_input *_y4m, unsigned char *_dst, unsigned char *_aux) { unsigned char *tmp; - int c_w; - int c_h; - int c_sz; - int dst_c_h; - int dst_c_sz; - int pli; + int c_w; + int c_h; + int c_sz; + int dst_c_h; + int dst_c_sz; + int pli; /*Skip past the luma data.*/ _dst += _y4m->pic_w * _y4m->pic_h; /*Compute the size of each chroma plane.*/ @@ -568,16 +603,16 @@ static void y4m_convert_422_420jpeg(y4m_input *_y4m, unsigned char *_dst, static void y4m_convert_411_420jpeg(y4m_input *_y4m, unsigned char *_dst, unsigned char *_aux) { unsigned char *tmp; - int c_w; - int c_h; - int c_sz; - int dst_c_w; - int dst_c_h; - int dst_c_sz; - int tmp_sz; - int pli; - int y; - int x; + int c_w; + int c_h; + int c_sz; + int dst_c_w; + int dst_c_h; + int dst_c_sz; + int tmp_sz; + int pli; + int y; + int x; /*Skip past the luma data.*/ _dst += _y4m->pic_w * _y4m->pic_h; /*Compute the size of each chroma plane.*/ @@ -598,23 +633,42 @@ static void y4m_convert_411_420jpeg(y4m_input *_y4m, unsigned char *_dst, /*Filters: [1 110 18 -1]/128 and [-3 50 86 -5]/128, both derived from a 4-tap Mitchell window.*/ for (x = 0; x < OC_MINI(c_w, 1); x++) { - tmp[x << 1] = (unsigned char)OC_CLAMPI(0, (111 * _aux[0] - + 18 * _aux[OC_MINI(1, c_w - 1)] - _aux[OC_MINI(2, c_w - 1)] + 64) >> 7, 255); - tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI(0, (47 * _aux[0] - + 86 * _aux[OC_MINI(1, c_w - 1)] - 5 * _aux[OC_MINI(2, c_w - 1)] + 64) >> 7, 255); + tmp[x << 1] = (unsigned char)OC_CLAMPI( + 0, (111 * _aux[0] + 18 * _aux[OC_MINI(1, c_w - 1)] - + _aux[OC_MINI(2, c_w - 1)] + 64) >> + 7, + 255); + tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI( + 0, (47 * _aux[0] + 86 * _aux[OC_MINI(1, c_w - 1)] - + 5 * _aux[OC_MINI(2, c_w - 1)] + 64) >> + 7, + 255); } for (; x < c_w - 2; x++) { - tmp[x << 1] = (unsigned char)OC_CLAMPI(0, (_aux[x - 1] + 110 * _aux[x] - + 18 * _aux[x + 1] - _aux[x + 2] + 64) >> 7, 255); - tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI(0, (-3 * _aux[x - 1] + 50 * _aux[x] - + 86 * _aux[x + 1] - 5 * _aux[x + 2] + 64) >> 7, 255); + tmp[x << 1] = + (unsigned char)OC_CLAMPI(0, (_aux[x - 1] + 110 * _aux[x] + + 18 * _aux[x + 1] - _aux[x + 2] + 64) >> + 7, + 255); + tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI( + 0, (-3 * _aux[x - 1] + 50 * _aux[x] + 86 * _aux[x + 1] - + 5 * _aux[x + 2] + 64) >> + 7, + 255); } for (; x < c_w; x++) { - tmp[x << 1] = (unsigned char)OC_CLAMPI(0, (_aux[x - 1] + 110 * _aux[x] - + 18 * _aux[OC_MINI(x + 1, c_w - 1)] - _aux[c_w - 1] + 64) >> 7, 255); + tmp[x << 1] = (unsigned char)OC_CLAMPI( + 0, (_aux[x - 1] + 110 * _aux[x] + + 18 * _aux[OC_MINI(x + 1, c_w - 1)] - _aux[c_w - 1] + 64) >> + 7, + 255); if ((x << 1 | 1) < dst_c_w) { - tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI(0, (-3 * _aux[x - 1] + 50 * _aux[x] - + 86 * _aux[OC_MINI(x + 1, c_w - 1)] - 5 * _aux[c_w - 1] + 64) >> 7, 255); + tmp[x << 1 | 1] = (unsigned char)OC_CLAMPI( + 0, + (-3 * _aux[x - 1] + 50 * _aux[x] + + 86 * _aux[OC_MINI(x + 1, c_w - 1)] - 5 * _aux[c_w - 1] + 64) >> + 7, + 255); } } tmp += dst_c_w; @@ -631,16 +685,16 @@ static void y4m_convert_411_420jpeg(y4m_input *_y4m, unsigned char *_dst, static void y4m_convert_444_420jpeg(y4m_input *_y4m, unsigned char *_dst, unsigned char *_aux) { unsigned char *tmp; - int c_w; - int c_h; - int c_sz; - int dst_c_w; - int dst_c_h; - int dst_c_sz; - int tmp_sz; - int pli; - int y; - int x; + int c_w; + int c_h; + int c_sz; + int dst_c_w; + int dst_c_h; + int dst_c_sz; + int tmp_sz; + int pli; + int y; + int x; /*Skip past the luma data.*/ _dst += _y4m->pic_w * _y4m->pic_h; /*Compute the size of each chroma plane.*/ @@ -656,18 +710,27 @@ static void y4m_convert_444_420jpeg(y4m_input *_y4m, unsigned char *_dst, /*Filter: [3 -17 78 78 -17 3]/128, derived from a 6-tap Lanczos window.*/ for (y = 0; y < c_h; y++) { for (x = 0; x < OC_MINI(c_w, 2); x += 2) { - tmp[x >> 1] = OC_CLAMPI(0, (64 * _aux[0] + 78 * _aux[OC_MINI(1, c_w - 1)] - - 17 * _aux[OC_MINI(2, c_w - 1)] - + 3 * _aux[OC_MINI(3, c_w - 1)] + 64) >> 7, 255); + tmp[x >> 1] = + OC_CLAMPI(0, (64 * _aux[0] + 78 * _aux[OC_MINI(1, c_w - 1)] - + 17 * _aux[OC_MINI(2, c_w - 1)] + + 3 * _aux[OC_MINI(3, c_w - 1)] + 64) >> + 7, + 255); } for (; x < c_w - 3; x += 2) { - tmp[x >> 1] = OC_CLAMPI(0, (3 * (_aux[x - 2] + _aux[x + 3]) - - 17 * (_aux[x - 1] + _aux[x + 2]) + 78 * (_aux[x] + _aux[x + 1]) + 64) >> 7, 255); + tmp[x >> 1] = OC_CLAMPI(0, (3 * (_aux[x - 2] + _aux[x + 3]) - + 17 * (_aux[x - 1] + _aux[x + 2]) + + 78 * (_aux[x] + _aux[x + 1]) + 64) >> + 7, + 255); } for (; x < c_w; x += 2) { - tmp[x >> 1] = OC_CLAMPI(0, (3 * (_aux[x - 2] + _aux[c_w - 1]) - - 17 * (_aux[x - 1] + _aux[OC_MINI(x + 2, c_w - 1)]) + - 78 * (_aux[x] + _aux[OC_MINI(x + 1, c_w - 1)]) + 64) >> 7, 255); + tmp[x >> 1] = OC_CLAMPI( + 0, (3 * (_aux[x - 2] + _aux[c_w - 1]) - + 17 * (_aux[x - 1] + _aux[OC_MINI(x + 2, c_w - 1)]) + + 78 * (_aux[x] + _aux[OC_MINI(x + 1, c_w - 1)]) + 64) >> + 7, + 255); } tmp += dst_c_w; _aux += c_w; @@ -700,9 +763,9 @@ static void y4m_convert_null(y4m_input *_y4m, unsigned char *_dst, int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, int only_420) { - char buffer[80] = {0}; - int ret; - int i; + char buffer[80] = { 0 }; + int ret; + int i; /*Read until newline, or 80 cols, whichever happens first.*/ for (i = 0; i < 79; i++) { if (_nskip > 0) { @@ -711,10 +774,10 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, } else { if (!file_read(buffer + i, 1, _fin)) return -1; } - if (buffer[i] == '\n')break; + if (buffer[i] == '\n') break; } /*We skipped too much header data.*/ - if (_nskip > 0)return -1; + if (_nskip > 0) return -1; if (i == 79) { fprintf(stderr, "Error parsing header; not a YUV2MPEG2 file?\n"); return -1; @@ -733,10 +796,12 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, return ret; } if (_y4m->interlace == '?') { - fprintf(stderr, "Warning: Input video interlacing format unknown; " + fprintf(stderr, + "Warning: Input video interlacing format unknown; " "assuming progressive scan.\n"); } else if (_y4m->interlace != 'p') { - fprintf(stderr, "Input video is interlaced; " + fprintf(stderr, + "Input video is interlaced; " "Only progressive scan handled.\n"); return -1; } @@ -745,9 +810,11 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, _y4m->bit_depth = 8; if (strcmp(_y4m->chroma_type, "420") == 0 || strcmp(_y4m->chroma_type, "420jpeg") == 0) { - _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_v = 2; - _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h - + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); + _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = + _y4m->dst_c_dec_v = 2; + _y4m->dst_buf_read_sz = + _y4m->pic_w * _y4m->pic_h + + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); /* Natively supported: no conversion required. */ _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; _y4m->convert = y4m_convert_null; @@ -756,9 +823,9 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, _y4m->dst_c_dec_h = 2; _y4m->src_c_dec_v = 2; _y4m->dst_c_dec_v = 2; - _y4m->dst_buf_read_sz = 2 * (_y4m->pic_w * _y4m->pic_h + - 2 * ((_y4m->pic_w + 1) / 2) * - ((_y4m->pic_h + 1) / 2)); + _y4m->dst_buf_read_sz = + 2 * (_y4m->pic_w * _y4m->pic_h + + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2)); /* Natively supported: no conversion required. */ _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; _y4m->convert = y4m_convert_null; @@ -774,9 +841,9 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, _y4m->dst_c_dec_h = 2; _y4m->src_c_dec_v = 2; _y4m->dst_c_dec_v = 2; - _y4m->dst_buf_read_sz = 2 * (_y4m->pic_w * _y4m->pic_h + - 2 * ((_y4m->pic_w + 1) / 2) * - ((_y4m->pic_h + 1) / 2)); + _y4m->dst_buf_read_sz = + 2 * (_y4m->pic_w * _y4m->pic_h + + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2)); /* Natively supported: no conversion required. */ _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; _y4m->convert = y4m_convert_null; @@ -788,20 +855,23 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, return -1; } } else if (strcmp(_y4m->chroma_type, "420mpeg2") == 0) { - _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_v = 2; + _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = + _y4m->dst_c_dec_v = 2; _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; /*Chroma filter required: read into the aux buf first.*/ _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = - 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); _y4m->convert = y4m_convert_42xmpeg2_42xjpeg; } else if (strcmp(_y4m->chroma_type, "420paldv") == 0) { - _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_v = 2; + _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = + _y4m->dst_c_dec_v = 2; _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; /*Chroma filter required: read into the aux buf first. We need to make two filter passes, so we need some extra space in the aux buffer.*/ _y4m->aux_buf_sz = 3 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); - _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); + _y4m->aux_buf_read_sz = + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); _y4m->convert = y4m_convert_42xpaldv_42xjpeg; } else if (strcmp(_y4m->chroma_type, "422jpeg") == 0) { _y4m->src_c_dec_h = _y4m->dst_c_dec_h = 2; @@ -809,7 +879,8 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, _y4m->dst_c_dec_v = 2; _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; /*Chroma filter required: read into the aux buf first.*/ - _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; + _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = + 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; _y4m->convert = y4m_convert_422jpeg_420jpeg; } else if (strcmp(_y4m->chroma_type, "422") == 0) { _y4m->src_c_dec_h = 2; @@ -822,16 +893,16 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, We need to make two filter passes, so we need some extra space in the aux buffer.*/ _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; - _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + - ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; + _y4m->aux_buf_sz = + _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; _y4m->convert = y4m_convert_422_420jpeg; } else { _y4m->vpx_fmt = VPX_IMG_FMT_I422; _y4m->bps = 16; _y4m->dst_c_dec_h = _y4m->src_c_dec_h; _y4m->dst_c_dec_v = _y4m->src_c_dec_v; - _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h - + 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; + _y4m->dst_buf_read_sz = + _y4m->pic_w * _y4m->pic_h + 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; /*Natively supported: no conversion required.*/ _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; _y4m->convert = y4m_convert_null; @@ -878,7 +949,8 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, We need to make two filter passes, so we need some extra space in the aux buffer.*/ _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 3) / 4) * _y4m->pic_h; - _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; + _y4m->aux_buf_sz = + _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; _y4m->convert = y4m_convert_411_420jpeg; } else if (strcmp(_y4m->chroma_type, "444") == 0) { _y4m->src_c_dec_h = 1; @@ -891,8 +963,8 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, We need to make two filter passes, so we need some extra space in the aux buffer.*/ _y4m->aux_buf_read_sz = 2 * _y4m->pic_w * _y4m->pic_h; - _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + - ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; + _y4m->aux_buf_sz = + _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; _y4m->convert = y4m_convert_444_420jpeg; } else { _y4m->vpx_fmt = VPX_IMG_FMT_I444; @@ -971,9 +1043,10 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip, } /*The size of the final frame buffers is always computed from the destination chroma decimation type.*/ - _y4m->dst_buf_sz = _y4m->pic_w * _y4m->pic_h - + 2 * ((_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h) * - ((_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v); + _y4m->dst_buf_sz = + _y4m->pic_w * _y4m->pic_h + + 2 * ((_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h) * + ((_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v); if (_y4m->bit_depth == 8) _y4m->dst_buf = (unsigned char *)malloc(_y4m->dst_buf_sz); else @@ -991,11 +1064,11 @@ void y4m_input_close(y4m_input *_y4m) { int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) { char frame[6]; - int pic_sz; - int c_w; - int c_h; - int c_sz; - int bytes_per_sample = _y4m->bit_depth > 8 ? 2 : 1; + int pic_sz; + int c_w; + int c_h; + int c_sz; + int bytes_per_sample = _y4m->bit_depth > 8 ? 2 : 1; /*Read and skip the frame header.*/ if (!file_read(frame, 6, _fin)) return 0; if (memcmp(frame, "FRAME", 5)) { @@ -1004,8 +1077,9 @@ int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) { } if (frame[5] != '\n') { char c; - int j; - for (j = 0; j < 79 && file_read(&c, 1, _fin) && c != '\n'; j++) {} + int j; + for (j = 0; j < 79 && file_read(&c, 1, _fin) && c != '\n'; j++) { + } if (j == 79) { fprintf(stderr, "Error parsing Y4M frame header\n"); return -1; diff --git a/y4minput.h b/y4minput.h index 356cebbcf..9e69ceb83 100644 --- a/y4minput.h +++ b/y4minput.h @@ -14,52 +14,46 @@ #ifndef Y4MINPUT_H_ #define Y4MINPUT_H_ -# include -# include "vpx/vpx_image.h" +#include +#include "vpx/vpx_image.h" #ifdef __cplusplus extern "C" { #endif - - typedef struct y4m_input y4m_input; - - /*The function used to perform chroma conversion.*/ -typedef void (*y4m_convert_func)(y4m_input *_y4m, - unsigned char *_dst, unsigned char *_src); - - +typedef void (*y4m_convert_func)(y4m_input *_y4m, unsigned char *_dst, + unsigned char *_src); struct y4m_input { - int pic_w; - int pic_h; - int fps_n; - int fps_d; - int par_n; - int par_d; - char interlace; - int src_c_dec_h; - int src_c_dec_v; - int dst_c_dec_h; - int dst_c_dec_v; - char chroma_type[16]; + int pic_w; + int pic_h; + int fps_n; + int fps_d; + int par_n; + int par_d; + char interlace; + int src_c_dec_h; + int src_c_dec_v; + int dst_c_dec_h; + int dst_c_dec_v; + char chroma_type[16]; /*The size of each converted frame buffer.*/ - size_t dst_buf_sz; + size_t dst_buf_sz; /*The amount to read directly into the converted frame buffer.*/ - size_t dst_buf_read_sz; + size_t dst_buf_read_sz; /*The size of the auxilliary buffer.*/ - size_t aux_buf_sz; + size_t aux_buf_sz; /*The amount to read into the auxilliary buffer.*/ - size_t aux_buf_read_sz; - y4m_convert_func convert; - unsigned char *dst_buf; - unsigned char *aux_buf; - enum vpx_img_fmt vpx_fmt; - int bps; - unsigned int bit_depth; + size_t aux_buf_read_sz; + y4m_convert_func convert; + unsigned char *dst_buf; + unsigned char *aux_buf; + enum vpx_img_fmt vpx_fmt; + int bps; + unsigned int bit_depth; }; int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip,