John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
John Koleszar | c2140b8 | 2010-09-09 08:16:39 -0400 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 7 | * in the file PATENTS. All contributing project authors may |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 8 | * be found in the AUTHORS file in the root of the source tree. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
John Koleszar | da58436 | 2013-05-06 15:52:06 -0700 | [diff] [blame] | 11 | #include <assert.h> |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <stdarg.h> |
| 15 | #include <string.h> |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 16 | #include <limits.h> |
Tero Rintaluoma | 11a222f | 2011-01-24 11:21:40 +0200 | [diff] [blame] | 17 | |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 18 | #include "./vpx_config.h" |
| 19 | |
| 20 | #if CONFIG_LIBYUV |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 21 | #include "third_party/libyuv/include/libyuv/scale.h" |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 22 | #endif |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 23 | |
| 24 | #include "./args.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 25 | #include "./ivfdec.h" |
| 26 | |
John Koleszar | b749234 | 2010-05-24 11:39:59 -0400 | [diff] [blame] | 27 | #include "vpx/vpx_decoder.h" |
Dmitry Kovalev | 4334c07 | 2014-02-26 16:32:09 -0800 | [diff] [blame] | 28 | #include "vpx_ports/mem_ops.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 29 | #include "vpx_ports/vpx_timer.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 30 | |
John Koleszar | 7b8dfcb | 2012-11-06 16:59:01 -0800 | [diff] [blame] | 31 | #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER |
John Koleszar | b749234 | 2010-05-24 11:39:59 -0400 | [diff] [blame] | 32 | #include "vpx/vp8dx.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 33 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 34 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 35 | #include "./md5_utils.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 36 | |
| 37 | #include "./tools_common.h" |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 38 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 39 | #include "./webmdec.h" |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 40 | #endif |
Dmitry Kovalev | 5ab6358 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 41 | #include "./y4menc.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 42 | |
| 43 | static const char *exec_name; |
| 44 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 45 | struct VpxDecInputContext { |
| 46 | struct VpxInputContext *vpx_input_ctx; |
| 47 | struct WebmInputContext *webm_ctx; |
| 48 | }; |
| 49 | |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 50 | static const arg_def_t looparg = ARG_DEF( |
| 51 | NULL, "loops", 1, "Number of times to decode the file"); |
| 52 | static const arg_def_t codecarg = ARG_DEF( |
| 53 | NULL, "codec", 1, "Codec to use"); |
| 54 | static const arg_def_t use_yv12 = ARG_DEF( |
| 55 | NULL, "yv12", 0, "Output raw YV12 frames"); |
| 56 | static const arg_def_t use_i420 = ARG_DEF( |
| 57 | NULL, "i420", 0, "Output raw I420 frames"); |
| 58 | static const arg_def_t flipuvarg = ARG_DEF( |
| 59 | NULL, "flipuv", 0, "Flip the chroma planes in the output"); |
| 60 | static const arg_def_t rawvideo = ARG_DEF( |
| 61 | NULL, "rawvideo", 0, "Output raw YUV frames"); |
| 62 | static const arg_def_t noblitarg = ARG_DEF( |
| 63 | NULL, "noblit", 0, "Don't process the decoded frames"); |
| 64 | static const arg_def_t progressarg = ARG_DEF( |
| 65 | NULL, "progress", 0, "Show progress after each frame decodes"); |
| 66 | static const arg_def_t limitarg = ARG_DEF( |
| 67 | NULL, "limit", 1, "Stop decoding after n frames"); |
| 68 | static const arg_def_t skiparg = ARG_DEF( |
| 69 | NULL, "skip", 1, "Skip the first n input frames"); |
| 70 | static const arg_def_t postprocarg = ARG_DEF( |
| 71 | NULL, "postproc", 0, "Postprocess decoded frames"); |
| 72 | static const arg_def_t summaryarg = ARG_DEF( |
| 73 | NULL, "summary", 0, "Show timing summary"); |
| 74 | static const arg_def_t outputfile = ARG_DEF( |
| 75 | "o", "output", 1, "Output file name pattern (see below)"); |
| 76 | static const arg_def_t threadsarg = ARG_DEF( |
| 77 | "t", "threads", 1, "Max threads to use"); |
| 78 | static const arg_def_t verbosearg = ARG_DEF( |
| 79 | "v", "verbose", 0, "Show version string"); |
| 80 | static const arg_def_t error_concealment = ARG_DEF( |
| 81 | NULL, "error-concealment", 0, "Enable decoder error-concealment"); |
| 82 | static const arg_def_t scalearg = ARG_DEF( |
| 83 | "S", "scale", 0, "Scale output frames uniformly"); |
| 84 | static const arg_def_t continuearg = ARG_DEF( |
| 85 | "k", "keep-going", 0, "(debug) Continue decoding after error"); |
| 86 | static const arg_def_t fb_arg = ARG_DEF( |
| 87 | NULL, "frame-buffers", 1, "Number of frame buffers to use"); |
| 88 | static const arg_def_t md5arg = ARG_DEF( |
| 89 | NULL, "md5", 0, "Compute the MD5 sum of the decoded frame"); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 90 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 91 | static const arg_def_t outbitdeptharg = ARG_DEF( |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 92 | NULL, "output-bit-depth", 1, "Output bit-depth for decoded frames"); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 93 | #endif |
Dmitry Kovalev | d24f4e4 | 2013-12-27 16:10:18 -0800 | [diff] [blame] | 94 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 95 | static const arg_def_t *all_args[] = { |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 96 | &codecarg, &use_yv12, &use_i420, &flipuvarg, &rawvideo, &noblitarg, |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 97 | &progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile, |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 98 | &threadsarg, &verbosearg, &scalearg, &fb_arg, |
James Zern | 95853db | 2014-07-01 19:02:15 -0700 | [diff] [blame] | 99 | &md5arg, &error_concealment, &continuearg, |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 100 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 101 | &outbitdeptharg, |
| 102 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 103 | NULL |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 104 | }; |
| 105 | |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 106 | #if CONFIG_VP8_DECODER |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 107 | static const arg_def_t addnoise_level = ARG_DEF(NULL, "noise-level", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 108 | "Enable VP8 postproc add noise"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 109 | static const arg_def_t deblock = ARG_DEF(NULL, "deblock", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 110 | "Enable VP8 deblocking"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 111 | static const arg_def_t demacroblock_level = ARG_DEF(NULL, "demacroblock-level", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 112 | "Enable VP8 demacroblocking, w/ level"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 113 | static const arg_def_t pp_debug_info = ARG_DEF(NULL, "pp-debug-info", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 114 | "Enable VP8 visible debug info"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 115 | static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL, "pp-dbg-ref-frame", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 116 | "Display only selected reference frame per macro block"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 117 | static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL, "pp-dbg-mb-modes", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 118 | "Display only selected macro block modes"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 119 | static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL, "pp-dbg-b-modes", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 120 | "Display only selected block modes"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 121 | static const arg_def_t pp_disp_mvs = ARG_DEF(NULL, "pp-dbg-mvs", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 122 | "Draw only selected motion vectors"); |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 123 | static const arg_def_t mfqe = ARG_DEF(NULL, "mfqe", 0, |
| 124 | "Enable multiframe quality enhancement"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 125 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 126 | static const arg_def_t *vp8_pp_args[] = { |
| 127 | &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info, |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 128 | &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 129 | NULL |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 130 | }; |
| 131 | #endif |
| 132 | |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 133 | #if CONFIG_LIBYUV |
Jim Bankoski | f452961 | 2014-08-12 16:51:07 -0700 | [diff] [blame] | 134 | static INLINE int vpx_image_scale(vpx_image_t *src, vpx_image_t *dst, |
| 135 | FilterModeEnum mode) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 136 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 137 | if (src->fmt == VPX_IMG_FMT_I42016) { |
| 138 | assert(dst->fmt == VPX_IMG_FMT_I42016); |
| 139 | return I420Scale_16((uint16_t*)src->planes[VPX_PLANE_Y], |
| 140 | src->stride[VPX_PLANE_Y]/2, |
| 141 | (uint16_t*)src->planes[VPX_PLANE_U], |
| 142 | src->stride[VPX_PLANE_U]/2, |
| 143 | (uint16_t*)src->planes[VPX_PLANE_V], |
| 144 | src->stride[VPX_PLANE_V]/2, |
| 145 | src->d_w, src->d_h, |
| 146 | (uint16_t*)dst->planes[VPX_PLANE_Y], |
| 147 | dst->stride[VPX_PLANE_Y]/2, |
| 148 | (uint16_t*)dst->planes[VPX_PLANE_U], |
| 149 | dst->stride[VPX_PLANE_U]/2, |
| 150 | (uint16_t*)dst->planes[VPX_PLANE_V], |
| 151 | dst->stride[VPX_PLANE_V]/2, |
| 152 | dst->d_w, dst->d_h, |
| 153 | mode); |
| 154 | } |
| 155 | #endif |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 156 | assert(src->fmt == VPX_IMG_FMT_I420); |
| 157 | assert(dst->fmt == VPX_IMG_FMT_I420); |
| 158 | return I420Scale(src->planes[VPX_PLANE_Y], src->stride[VPX_PLANE_Y], |
| 159 | src->planes[VPX_PLANE_U], src->stride[VPX_PLANE_U], |
| 160 | src->planes[VPX_PLANE_V], src->stride[VPX_PLANE_V], |
| 161 | src->d_w, src->d_h, |
| 162 | dst->planes[VPX_PLANE_Y], dst->stride[VPX_PLANE_Y], |
| 163 | dst->planes[VPX_PLANE_U], dst->stride[VPX_PLANE_U], |
| 164 | dst->planes[VPX_PLANE_V], dst->stride[VPX_PLANE_V], |
| 165 | dst->d_w, dst->d_h, |
| 166 | mode); |
| 167 | } |
James Zern | 1e681d9 | 2014-08-15 21:00:09 -0700 | [diff] [blame] | 168 | #endif |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 169 | |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 170 | void usage_exit() { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 171 | int i; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 172 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 173 | fprintf(stderr, "Usage: %s <options> filename\n\n" |
| 174 | "Options:\n", exec_name); |
| 175 | arg_show_usage(stderr, all_args); |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 176 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 177 | fprintf(stderr, "\nVP8 Postprocessing Options:\n"); |
| 178 | arg_show_usage(stderr, vp8_pp_args); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 179 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 180 | fprintf(stderr, |
| 181 | "\nOutput File Patterns:\n\n" |
| 182 | " The -o argument specifies the name of the file(s) to " |
| 183 | "write to. If the\n argument does not include any escape " |
| 184 | "characters, the output will be\n written to a single file. " |
| 185 | "Otherwise, the filename will be calculated by\n expanding " |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 186 | "the following escape characters:\n"); |
| 187 | fprintf(stderr, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 188 | "\n\t%%w - Frame width" |
| 189 | "\n\t%%h - Frame height" |
| 190 | "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)" |
| 191 | "\n\n Pattern arguments are only supported in conjunction " |
| 192 | "with the --yv12 and\n --i420 options. If the -o option is " |
| 193 | "not specified, the output will be\n directed to stdout.\n" |
| 194 | ); |
| 195 | fprintf(stderr, "\nIncluded decoders:\n\n"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 196 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 197 | for (i = 0; i < get_vpx_decoder_count(); ++i) { |
| 198 | const VpxInterface *const decoder = get_vpx_decoder_by_index(i); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 199 | fprintf(stderr, " %-6s - %s\n", |
Deb Mukherjee | f332c63 | 2014-07-15 16:55:12 -0700 | [diff] [blame] | 200 | decoder->name, vpx_codec_iface_name(decoder->codec_interface())); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 201 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 202 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 203 | exit(EXIT_FAILURE); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 204 | } |
| 205 | |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 206 | static int raw_read_frame(FILE *infile, uint8_t **buffer, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 207 | size_t *bytes_read, size_t *buffer_size) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 208 | char raw_hdr[RAW_FRAME_HDR_SZ]; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 209 | size_t frame_size = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 210 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 211 | if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) { |
| 212 | if (!feof(infile)) |
| 213 | warn("Failed to read RAW frame size\n"); |
| 214 | } else { |
James Zern | 75d7ee3 | 2014-02-04 20:06:28 -0800 | [diff] [blame] | 215 | const size_t kCorruptFrameThreshold = 256 * 1024 * 1024; |
| 216 | const size_t kFrameTooSmallThreshold = 256 * 1024; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 217 | frame_size = mem_get_le32(raw_hdr); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 218 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 219 | if (frame_size > kCorruptFrameThreshold) { |
| 220 | warn("Read invalid frame size (%u)\n", (unsigned int)frame_size); |
| 221 | frame_size = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 222 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 223 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 224 | if (frame_size < kFrameTooSmallThreshold) { |
| 225 | warn("Warning: Read invalid frame size (%u) - not a raw file?\n", |
| 226 | (unsigned int)frame_size); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 227 | } |
| 228 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 229 | if (frame_size > *buffer_size) { |
| 230 | uint8_t *new_buf = realloc(*buffer, 2 * frame_size); |
| 231 | if (new_buf) { |
| 232 | *buffer = new_buf; |
| 233 | *buffer_size = 2 * frame_size; |
| 234 | } else { |
| 235 | warn("Failed to allocate compressed data buffer\n"); |
| 236 | frame_size = 0; |
| 237 | } |
| 238 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 239 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 240 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 241 | if (!feof(infile)) { |
| 242 | if (fread(*buffer, 1, frame_size, infile) != frame_size) { |
| 243 | warn("Failed to read full frame\n"); |
| 244 | return 1; |
| 245 | } |
| 246 | *bytes_read = frame_size; |
| 247 | } |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static int read_frame(struct VpxDecInputContext *input, uint8_t **buf, |
| 253 | size_t *bytes_in_buffer, size_t *buffer_size) { |
| 254 | switch (input->vpx_input_ctx->file_type) { |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 255 | #if CONFIG_WEBM_IO |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 256 | case FILE_TYPE_WEBM: |
| 257 | return webm_read_frame(input->webm_ctx, |
| 258 | buf, bytes_in_buffer, buffer_size); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 259 | #endif |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 260 | case FILE_TYPE_RAW: |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 261 | return raw_read_frame(input->vpx_input_ctx->file, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 262 | buf, bytes_in_buffer, buffer_size); |
| 263 | case FILE_TYPE_IVF: |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 264 | return ivf_read_frame(input->vpx_input_ctx->file, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 265 | buf, bytes_in_buffer, buffer_size); |
| 266 | default: |
| 267 | return 1; |
| 268 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 269 | } |
| 270 | |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 271 | static void update_image_md5(const vpx_image_t *img, const int planes[3], |
| 272 | MD5Context *md5) { |
| 273 | int i, y; |
| 274 | |
| 275 | for (i = 0; i < 3; ++i) { |
| 276 | const int plane = planes[i]; |
| 277 | const unsigned char *buf = img->planes[plane]; |
| 278 | const int stride = img->stride[plane]; |
Deb Mukherjee | bec307a | 2014-10-20 23:51:58 -0700 | [diff] [blame] | 279 | const int w = vpx_img_plane_width(img, plane) * |
| 280 | ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); |
Dmitry Kovalev | 2bdd43d | 2014-02-12 18:36:36 -0800 | [diff] [blame] | 281 | const int h = vpx_img_plane_height(img, plane); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 282 | |
| 283 | for (y = 0; y < h; ++y) { |
| 284 | MD5Update(md5, buf, w); |
| 285 | buf += stride; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | static void write_image_file(const vpx_image_t *img, const int planes[3], |
| 291 | FILE *file) { |
| 292 | int i, y; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 293 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 294 | const int bytes_per_sample = ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); |
| 295 | #else |
| 296 | const int bytes_per_sample = 1; |
| 297 | #endif |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 298 | |
| 299 | for (i = 0; i < 3; ++i) { |
| 300 | const int plane = planes[i]; |
| 301 | const unsigned char *buf = img->planes[plane]; |
| 302 | const int stride = img->stride[plane]; |
Dmitry Kovalev | 2bdd43d | 2014-02-12 18:36:36 -0800 | [diff] [blame] | 303 | const int w = vpx_img_plane_width(img, plane); |
| 304 | const int h = vpx_img_plane_height(img, plane); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 305 | |
| 306 | for (y = 0; y < h; ++y) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 307 | fwrite(buf, bytes_per_sample, w, file); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 308 | buf += stride; |
| 309 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 310 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 313 | int file_is_raw(struct VpxInputContext *input) { |
| 314 | uint8_t buf[32]; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 315 | int is_raw = 0; |
| 316 | vpx_codec_stream_info_t si; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 317 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 318 | si.sz = sizeof(si); |
John Koleszar | 19255b8 | 2010-11-23 13:40:31 -0500 | [diff] [blame] | 319 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 320 | if (fread(buf, 1, 32, input->file) == 32) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 321 | int i; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 322 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 323 | if (mem_get_le32(buf) < 256 * 1024 * 1024) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 324 | for (i = 0; i < get_vpx_decoder_count(); ++i) { |
| 325 | const VpxInterface *const decoder = get_vpx_decoder_by_index(i); |
Deb Mukherjee | f332c63 | 2014-07-15 16:55:12 -0700 | [diff] [blame] | 326 | if (!vpx_codec_peek_stream_info(decoder->codec_interface(), |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 327 | buf + 4, 32 - 4, &si)) { |
| 328 | is_raw = 1; |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 329 | input->fourcc = decoder->fourcc; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 330 | input->width = si.w; |
| 331 | input->height = si.h; |
| 332 | input->framerate.numerator = 30; |
| 333 | input->framerate.denominator = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 334 | break; |
| 335 | } |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 336 | } |
| 337 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 338 | } |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 339 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 340 | rewind(input->file); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 341 | return is_raw; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 342 | } |
| 343 | |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 344 | void show_progress(int frame_in, int frame_out, uint64_t dx_time) { |
| 345 | fprintf(stderr, |
| 346 | "%d decoded frames/%d showed frames in %"PRId64" us (%.2f fps)\r", |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 347 | frame_in, frame_out, dx_time, |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 348 | (double)frame_out * 1000000.0 / (double)dx_time); |
John Koleszar | 5d12e04 | 2010-10-21 17:28:34 -0400 | [diff] [blame] | 349 | } |
| 350 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 351 | struct ExternalFrameBuffer { |
| 352 | uint8_t* data; |
| 353 | size_t size; |
| 354 | int in_use; |
| 355 | }; |
| 356 | |
| 357 | struct ExternalFrameBufferList { |
| 358 | int num_external_frame_buffers; |
| 359 | struct ExternalFrameBuffer *ext_fb; |
| 360 | }; |
| 361 | |
| 362 | // Callback used by libvpx to request an external frame buffer. |cb_priv| |
| 363 | // Application private data passed into the set function. |min_size| is the |
| 364 | // minimum size in bytes needed to decode the next frame. |fb| pointer to the |
| 365 | // frame buffer. |
| 366 | int get_vp9_frame_buffer(void *cb_priv, size_t min_size, |
| 367 | vpx_codec_frame_buffer_t *fb) { |
| 368 | int i; |
| 369 | struct ExternalFrameBufferList *const ext_fb_list = |
| 370 | (struct ExternalFrameBufferList *)cb_priv; |
| 371 | if (ext_fb_list == NULL) |
| 372 | return -1; |
| 373 | |
| 374 | // Find a free frame buffer. |
| 375 | for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) { |
| 376 | if (!ext_fb_list->ext_fb[i].in_use) |
| 377 | break; |
| 378 | } |
| 379 | |
| 380 | if (i == ext_fb_list->num_external_frame_buffers) |
| 381 | return -1; |
| 382 | |
| 383 | if (ext_fb_list->ext_fb[i].size < min_size) { |
| 384 | free(ext_fb_list->ext_fb[i].data); |
Frank Galligan | 175d9df | 2014-09-11 08:39:38 -0700 | [diff] [blame] | 385 | ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size, sizeof(uint8_t)); |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 386 | if (!ext_fb_list->ext_fb[i].data) |
| 387 | return -1; |
| 388 | |
| 389 | ext_fb_list->ext_fb[i].size = min_size; |
| 390 | } |
| 391 | |
| 392 | fb->data = ext_fb_list->ext_fb[i].data; |
| 393 | fb->size = ext_fb_list->ext_fb[i].size; |
| 394 | ext_fb_list->ext_fb[i].in_use = 1; |
| 395 | |
| 396 | // Set the frame buffer's private data to point at the external frame buffer. |
| 397 | fb->priv = &ext_fb_list->ext_fb[i]; |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | // Callback used by libvpx when there are no references to the frame buffer. |
| 402 | // |cb_priv| user private data passed into the set function. |fb| pointer |
| 403 | // to the frame buffer. |
| 404 | int release_vp9_frame_buffer(void *cb_priv, |
| 405 | vpx_codec_frame_buffer_t *fb) { |
| 406 | struct ExternalFrameBuffer *const ext_fb = |
| 407 | (struct ExternalFrameBuffer *)fb->priv; |
| 408 | (void)cb_priv; |
| 409 | ext_fb->in_use = 0; |
| 410 | return 0; |
| 411 | } |
| 412 | |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 413 | void generate_filename(const char *pattern, char *out, size_t q_len, |
| 414 | unsigned int d_w, unsigned int d_h, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 415 | unsigned int frame_in) { |
| 416 | const char *p = pattern; |
| 417 | char *q = out; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 418 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 419 | do { |
| 420 | char *next_pat = strchr(p, '%'); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 421 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 422 | if (p == next_pat) { |
| 423 | size_t pat_len; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 424 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 425 | /* parse the pattern */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 426 | q[q_len - 1] = '\0'; |
| 427 | switch (p[1]) { |
| 428 | case 'w': |
| 429 | snprintf(q, q_len - 1, "%d", d_w); |
| 430 | break; |
| 431 | case 'h': |
| 432 | snprintf(q, q_len - 1, "%d", d_h); |
| 433 | break; |
| 434 | case '1': |
| 435 | snprintf(q, q_len - 1, "%d", frame_in); |
| 436 | break; |
| 437 | case '2': |
| 438 | snprintf(q, q_len - 1, "%02d", frame_in); |
| 439 | break; |
| 440 | case '3': |
| 441 | snprintf(q, q_len - 1, "%03d", frame_in); |
| 442 | break; |
| 443 | case '4': |
| 444 | snprintf(q, q_len - 1, "%04d", frame_in); |
| 445 | break; |
| 446 | case '5': |
| 447 | snprintf(q, q_len - 1, "%05d", frame_in); |
| 448 | break; |
| 449 | case '6': |
| 450 | snprintf(q, q_len - 1, "%06d", frame_in); |
| 451 | break; |
| 452 | case '7': |
| 453 | snprintf(q, q_len - 1, "%07d", frame_in); |
| 454 | break; |
| 455 | case '8': |
| 456 | snprintf(q, q_len - 1, "%08d", frame_in); |
| 457 | break; |
| 458 | case '9': |
| 459 | snprintf(q, q_len - 1, "%09d", frame_in); |
| 460 | break; |
| 461 | default: |
| 462 | die("Unrecognized pattern %%%c\n", p[1]); |
Jim Bankoski | 5c41891 | 2014-08-01 07:11:43 -0700 | [diff] [blame] | 463 | break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 464 | } |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 465 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 466 | pat_len = strlen(q); |
| 467 | if (pat_len >= q_len - 1) |
| 468 | die("Output filename too long.\n"); |
| 469 | q += pat_len; |
| 470 | p += 2; |
| 471 | q_len -= pat_len; |
| 472 | } else { |
| 473 | size_t copy_len; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 474 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 475 | /* copy the next segment */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 476 | if (!next_pat) |
| 477 | copy_len = strlen(p); |
| 478 | else |
| 479 | copy_len = next_pat - p; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 480 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 481 | if (copy_len >= q_len - 1) |
| 482 | die("Output filename too long.\n"); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 483 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 484 | memcpy(q, p, copy_len); |
| 485 | q[copy_len] = '\0'; |
| 486 | q += copy_len; |
| 487 | p += copy_len; |
| 488 | q_len -= copy_len; |
| 489 | } |
| 490 | } while (*p); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 493 | static int is_single_file(const char *outfile_pattern) { |
| 494 | const char *p = outfile_pattern; |
| 495 | |
| 496 | do { |
| 497 | p = strchr(p, '%'); |
| 498 | if (p && p[1] >= '1' && p[1] <= '9') |
| 499 | return 0; // pattern contains sequence number, so it's not unique |
| 500 | if (p) |
| 501 | p++; |
| 502 | } while (p); |
| 503 | |
| 504 | return 1; |
| 505 | } |
| 506 | |
| 507 | static void print_md5(unsigned char digest[16], const char *filename) { |
| 508 | int i; |
| 509 | |
| 510 | for (i = 0; i < 16; ++i) |
| 511 | printf("%02x", digest[i]); |
| 512 | printf(" %s\n", filename); |
| 513 | } |
| 514 | |
| 515 | static FILE *open_outfile(const char *name) { |
| 516 | if (strcmp("-", name) == 0) { |
| 517 | set_binary_mode(stdout); |
| 518 | return stdout; |
| 519 | } else { |
| 520 | FILE *file = fopen(name, "wb"); |
| 521 | if (!file) |
| 522 | fatal("Failed to output file %s", name); |
| 523 | return file; |
| 524 | } |
| 525 | } |
| 526 | |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 527 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 528 | static int img_shifted_realloc_required(const vpx_image_t *img, |
| 529 | const vpx_image_t *shifted, |
| 530 | vpx_img_fmt_t required_fmt) { |
| 531 | return img->d_w != shifted->d_w || |
| 532 | img->d_h != shifted->d_h || |
| 533 | required_fmt != shifted->fmt; |
| 534 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 535 | #endif |
| 536 | |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 537 | int main_loop(int argc, const char **argv_) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 538 | vpx_codec_ctx_t decoder; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 539 | char *fn = NULL; |
Alex Converse | 2eccbd0 | 2014-02-13 17:02:50 -0800 | [diff] [blame] | 540 | int i; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 541 | uint8_t *buf = NULL; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 542 | size_t bytes_in_buffer = 0, buffer_size = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 543 | FILE *infile; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 544 | int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0; |
| 545 | int do_md5 = 0, progress = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 546 | int stop_after = 0, postproc = 0, summary = 0, quiet = 1; |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 547 | int arg_skip = 0; |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 548 | int ec_enabled = 0; |
James Zern | 95853db | 2014-07-01 19:02:15 -0700 | [diff] [blame] | 549 | int keep_going = 0; |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 550 | const VpxInterface *interface = NULL; |
| 551 | const VpxInterface *fourcc_interface = NULL; |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 552 | uint64_t dx_time = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 553 | struct arg arg; |
| 554 | char **argv, **argi, **argj; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 555 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 556 | int single_file; |
| 557 | int use_y4m = 1; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 558 | int opt_yv12 = 0; |
| 559 | int opt_i420 = 0; |
Jim Bankoski | 5c41891 | 2014-08-01 07:11:43 -0700 | [diff] [blame] | 560 | vpx_codec_dec_cfg_t cfg = {0, 0, 0}; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 561 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 562 | int output_bit_depth = 0; |
| 563 | #endif |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 564 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 565 | vp8_postproc_cfg_t vp8_pp_cfg = {0}; |
| 566 | int vp8_dbg_color_ref_frame = 0; |
| 567 | int vp8_dbg_color_mb_modes = 0; |
| 568 | int vp8_dbg_color_b_modes = 0; |
| 569 | int vp8_dbg_display_mv = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 570 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 571 | int frames_corrupted = 0; |
| 572 | int dec_flags = 0; |
John Koleszar | 83f2a11 | 2013-03-11 12:30:29 -0700 | [diff] [blame] | 573 | int do_scale = 0; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 574 | vpx_image_t *scaled_img = NULL; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 575 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 576 | vpx_image_t *img_shifted = NULL; |
| 577 | #endif |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 578 | int frame_avail, got_data; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 579 | int num_external_frame_buffers = 0; |
Jim Bankoski | 5c41891 | 2014-08-01 07:11:43 -0700 | [diff] [blame] | 580 | struct ExternalFrameBufferList ext_fb_list = {0, NULL}; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 581 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 582 | const char *outfile_pattern = NULL; |
| 583 | char outfile_name[PATH_MAX] = {0}; |
| 584 | FILE *outfile = NULL; |
| 585 | |
| 586 | MD5Context md5_ctx; |
| 587 | unsigned char md5_digest[16]; |
| 588 | |
Jim Bankoski | 5c41891 | 2014-08-01 07:11:43 -0700 | [diff] [blame] | 589 | struct VpxDecInputContext input = {NULL, NULL}; |
| 590 | struct VpxInputContext vpx_input_ctx; |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 591 | #if CONFIG_WEBM_IO |
Jim Bankoski | 7ae3269 | 2014-08-19 06:44:10 -0700 | [diff] [blame] | 592 | struct WebmInputContext webm_ctx; |
| 593 | memset(&(webm_ctx), 0, sizeof(webm_ctx)); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 594 | input.webm_ctx = &webm_ctx; |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 595 | #endif |
| 596 | input.vpx_input_ctx = &vpx_input_ctx; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 597 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 598 | /* Parse command line */ |
| 599 | exec_name = argv_[0]; |
| 600 | argv = argv_dup(argc - 1, argv_ + 1); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 601 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 602 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 603 | memset(&arg, 0, sizeof(arg)); |
| 604 | arg.argv_step = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 605 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 606 | if (arg_match(&arg, &codecarg, argi)) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 607 | interface = get_vpx_decoder_by_name(arg.val); |
| 608 | if (!interface) |
| 609 | die("Error: Unrecognized argument (%s) to --codec\n", arg.val); |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 610 | } else if (arg_match(&arg, &looparg, argi)) { |
| 611 | // no-op |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 612 | } else if (arg_match(&arg, &outputfile, argi)) |
| 613 | outfile_pattern = arg.val; |
| 614 | else if (arg_match(&arg, &use_yv12, argi)) { |
| 615 | use_y4m = 0; |
| 616 | flipuv = 1; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 617 | opt_yv12 = 1; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 618 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 619 | output_bit_depth = 8; // For yv12 8-bit depth output is assumed |
| 620 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 621 | } else if (arg_match(&arg, &use_i420, argi)) { |
| 622 | use_y4m = 0; |
| 623 | flipuv = 0; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 624 | opt_i420 = 1; |
| 625 | } else if (arg_match(&arg, &rawvideo, argi)) { |
| 626 | use_y4m = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 627 | } else if (arg_match(&arg, &flipuvarg, argi)) |
| 628 | flipuv = 1; |
| 629 | else if (arg_match(&arg, &noblitarg, argi)) |
| 630 | noblit = 1; |
| 631 | else if (arg_match(&arg, &progressarg, argi)) |
| 632 | progress = 1; |
| 633 | else if (arg_match(&arg, &limitarg, argi)) |
| 634 | stop_after = arg_parse_uint(&arg); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 635 | else if (arg_match(&arg, &skiparg, argi)) |
| 636 | arg_skip = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 637 | else if (arg_match(&arg, &postprocarg, argi)) |
| 638 | postproc = 1; |
| 639 | else if (arg_match(&arg, &md5arg, argi)) |
| 640 | do_md5 = 1; |
| 641 | else if (arg_match(&arg, &summaryarg, argi)) |
| 642 | summary = 1; |
| 643 | else if (arg_match(&arg, &threadsarg, argi)) |
| 644 | cfg.threads = arg_parse_uint(&arg); |
| 645 | else if (arg_match(&arg, &verbosearg, argi)) |
| 646 | quiet = 0; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 647 | else if (arg_match(&arg, &scalearg, argi)) |
| 648 | do_scale = 1; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 649 | else if (arg_match(&arg, &fb_arg, argi)) |
| 650 | num_external_frame_buffers = arg_parse_uint(&arg); |
James Zern | 7690d88 | 2014-08-22 18:01:28 -0700 | [diff] [blame] | 651 | else if (arg_match(&arg, &continuearg, argi)) |
| 652 | keep_going = 1; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 653 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 654 | else if (arg_match(&arg, &outbitdeptharg, argi)) { |
| 655 | output_bit_depth = arg_parse_uint(&arg); |
| 656 | } |
| 657 | #endif |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 658 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 659 | else if (arg_match(&arg, &addnoise_level, argi)) { |
| 660 | postproc = 1; |
| 661 | vp8_pp_cfg.post_proc_flag |= VP8_ADDNOISE; |
| 662 | vp8_pp_cfg.noise_level = arg_parse_uint(&arg); |
| 663 | } else if (arg_match(&arg, &demacroblock_level, argi)) { |
| 664 | postproc = 1; |
| 665 | vp8_pp_cfg.post_proc_flag |= VP8_DEMACROBLOCK; |
| 666 | vp8_pp_cfg.deblocking_level = arg_parse_uint(&arg); |
| 667 | } else if (arg_match(&arg, &deblock, argi)) { |
| 668 | postproc = 1; |
| 669 | vp8_pp_cfg.post_proc_flag |= VP8_DEBLOCK; |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 670 | } else if (arg_match(&arg, &mfqe, argi)) { |
| 671 | postproc = 1; |
| 672 | vp8_pp_cfg.post_proc_flag |= VP8_MFQE; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 673 | } else if (arg_match(&arg, &pp_debug_info, argi)) { |
| 674 | unsigned int level = arg_parse_uint(&arg); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 675 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 676 | postproc = 1; |
| 677 | vp8_pp_cfg.post_proc_flag &= ~0x7; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 678 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 679 | if (level) |
| 680 | vp8_pp_cfg.post_proc_flag |= level; |
| 681 | } else if (arg_match(&arg, &pp_disp_ref_frame, argi)) { |
| 682 | unsigned int flags = arg_parse_int(&arg); |
| 683 | if (flags) { |
| 684 | postproc = 1; |
| 685 | vp8_dbg_color_ref_frame = flags; |
| 686 | } |
| 687 | } else if (arg_match(&arg, &pp_disp_mb_modes, argi)) { |
| 688 | unsigned int flags = arg_parse_int(&arg); |
| 689 | if (flags) { |
| 690 | postproc = 1; |
| 691 | vp8_dbg_color_mb_modes = flags; |
| 692 | } |
| 693 | } else if (arg_match(&arg, &pp_disp_b_modes, argi)) { |
| 694 | unsigned int flags = arg_parse_int(&arg); |
| 695 | if (flags) { |
| 696 | postproc = 1; |
| 697 | vp8_dbg_color_b_modes = flags; |
| 698 | } |
| 699 | } else if (arg_match(&arg, &pp_disp_mvs, argi)) { |
| 700 | unsigned int flags = arg_parse_int(&arg); |
| 701 | if (flags) { |
| 702 | postproc = 1; |
| 703 | vp8_dbg_display_mv = flags; |
| 704 | } |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 705 | } else if (arg_match(&arg, &error_concealment, argi)) { |
| 706 | ec_enabled = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 707 | } |
James Zern | 7690d88 | 2014-08-22 18:01:28 -0700 | [diff] [blame] | 708 | #endif // CONFIG_VP8_DECODER |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 709 | else |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 710 | argj++; |
| 711 | } |
| 712 | |
| 713 | /* Check for unrecognized options */ |
| 714 | for (argi = argv; *argi; argi++) |
| 715 | if (argi[0][0] == '-' && strlen(argi[0]) > 1) |
| 716 | die("Error: Unrecognized option %s\n", *argi); |
| 717 | |
| 718 | /* Handle non-option arguments */ |
| 719 | fn = argv[0]; |
| 720 | |
| 721 | if (!fn) |
| 722 | usage_exit(); |
| 723 | |
| 724 | /* Open file */ |
| 725 | infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin); |
| 726 | |
| 727 | if (!infile) { |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 728 | fprintf(stderr, "Failed to open file '%s'", strcmp(fn, "-") ? fn : "stdin"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 729 | return EXIT_FAILURE; |
| 730 | } |
| 731 | #if CONFIG_OS_SUPPORT |
| 732 | /* Make sure we don't dump to the terminal, unless forced to with -o - */ |
| 733 | if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) { |
| 734 | fprintf(stderr, |
| 735 | "Not dumping raw video to your terminal. Use '-o -' to " |
| 736 | "override.\n"); |
| 737 | return EXIT_FAILURE; |
| 738 | } |
| 739 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 740 | input.vpx_input_ctx->file = infile; |
| 741 | if (file_is_ivf(input.vpx_input_ctx)) |
| 742 | input.vpx_input_ctx->file_type = FILE_TYPE_IVF; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 743 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 744 | else if (file_is_webm(input.webm_ctx, input.vpx_input_ctx)) |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 745 | input.vpx_input_ctx->file_type = FILE_TYPE_WEBM; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 746 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 747 | else if (file_is_raw(input.vpx_input_ctx)) |
| 748 | input.vpx_input_ctx->file_type = FILE_TYPE_RAW; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 749 | else { |
| 750 | fprintf(stderr, "Unrecognized input file type.\n"); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 751 | #if !CONFIG_WEBM_IO |
| 752 | fprintf(stderr, "vpxdec was built without WebM container support.\n"); |
| 753 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 754 | return EXIT_FAILURE; |
| 755 | } |
| 756 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 757 | outfile_pattern = outfile_pattern ? outfile_pattern : "-"; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 758 | single_file = is_single_file(outfile_pattern); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 759 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 760 | if (!noblit && single_file) { |
| 761 | generate_filename(outfile_pattern, outfile_name, PATH_MAX, |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 762 | vpx_input_ctx.width, vpx_input_ctx.height, 0); |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 763 | if (do_md5) |
| 764 | MD5Init(&md5_ctx); |
| 765 | else |
| 766 | outfile = open_outfile(outfile_name); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | if (use_y4m && !noblit) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 770 | if (!single_file) { |
| 771 | fprintf(stderr, "YUV4MPEG2 not supported with output patterns," |
Deb Mukherjee | a30774c | 2014-10-01 12:17:37 -0700 | [diff] [blame] | 772 | " try --i420 or --yv12 or --rawvideo.\n"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 773 | return EXIT_FAILURE; |
| 774 | } |
| 775 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 776 | #if CONFIG_WEBM_IO |
Dmitry Kovalev | 5ab6358 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 777 | if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) { |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 778 | if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 779 | fprintf(stderr, "Failed to guess framerate -- error parsing " |
| 780 | "webm file?\n"); |
Timothy B. Terriberry | 7f9db41 | 2010-05-26 19:36:20 -0400 | [diff] [blame] | 781 | return EXIT_FAILURE; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 782 | } |
Dmitry Kovalev | 5ab6358 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 783 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 784 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 787 | fourcc_interface = get_vpx_decoder_by_fourcc(vpx_input_ctx.fourcc); |
| 788 | if (interface && fourcc_interface && interface != fourcc_interface) |
| 789 | warn("Header indicates codec: %s\n", fourcc_interface->name); |
| 790 | else |
| 791 | interface = fourcc_interface; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 792 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 793 | if (!interface) |
| 794 | interface = get_vpx_decoder_by_index(0); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 795 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 796 | dec_flags = (postproc ? VPX_CODEC_USE_POSTPROC : 0) | |
| 797 | (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0); |
Deb Mukherjee | f332c63 | 2014-07-15 16:55:12 -0700 | [diff] [blame] | 798 | if (vpx_codec_dec_init(&decoder, interface->codec_interface(), |
| 799 | &cfg, dec_flags)) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 800 | fprintf(stderr, "Failed to initialize decoder: %s\n", |
| 801 | vpx_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 802 | return EXIT_FAILURE; |
| 803 | } |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 804 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 805 | if (!quiet) |
| 806 | fprintf(stderr, "%s\n", decoder.name); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 807 | |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 808 | #if CONFIG_VP8_DECODER |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 809 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 810 | if (vp8_pp_cfg.post_proc_flag |
| 811 | && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) { |
| 812 | fprintf(stderr, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder)); |
| 813 | return EXIT_FAILURE; |
| 814 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 815 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 816 | if (vp8_dbg_color_ref_frame |
| 817 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, vp8_dbg_color_ref_frame)) { |
| 818 | fprintf(stderr, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 819 | return EXIT_FAILURE; |
| 820 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 821 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 822 | if (vp8_dbg_color_mb_modes |
| 823 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, vp8_dbg_color_mb_modes)) { |
| 824 | fprintf(stderr, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 825 | return EXIT_FAILURE; |
| 826 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 827 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 828 | if (vp8_dbg_color_b_modes |
| 829 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, vp8_dbg_color_b_modes)) { |
| 830 | fprintf(stderr, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 831 | return EXIT_FAILURE; |
| 832 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 833 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 834 | if (vp8_dbg_display_mv |
| 835 | && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, vp8_dbg_display_mv)) { |
| 836 | fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder)); |
| 837 | return EXIT_FAILURE; |
| 838 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 839 | #endif |
| 840 | |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 841 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 842 | if (arg_skip) |
Adrian Grange | 475d1d6 | 2013-11-20 09:49:33 -0800 | [diff] [blame] | 843 | fprintf(stderr, "Skipping first %d frames.\n", arg_skip); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 844 | while (arg_skip) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 845 | if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 846 | break; |
| 847 | arg_skip--; |
| 848 | } |
| 849 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 850 | if (num_external_frame_buffers > 0) { |
| 851 | ext_fb_list.num_external_frame_buffers = num_external_frame_buffers; |
| 852 | ext_fb_list.ext_fb = (struct ExternalFrameBuffer *)calloc( |
| 853 | num_external_frame_buffers, sizeof(*ext_fb_list.ext_fb)); |
| 854 | if (vpx_codec_set_frame_buffer_functions( |
| 855 | &decoder, get_vp9_frame_buffer, release_vp9_frame_buffer, |
| 856 | &ext_fb_list)) { |
| 857 | fprintf(stderr, "Failed to configure external frame buffers: %s\n", |
| 858 | vpx_codec_error(&decoder)); |
| 859 | return EXIT_FAILURE; |
| 860 | } |
| 861 | } |
| 862 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 863 | frame_avail = 1; |
| 864 | got_data = 0; |
| 865 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 866 | /* Decode file */ |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 867 | while (frame_avail || got_data) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 868 | vpx_codec_iter_t iter = NULL; |
| 869 | vpx_image_t *img; |
| 870 | struct vpx_usec_timer timer; |
| 871 | int corrupted; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 872 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 873 | frame_avail = 0; |
| 874 | if (!stop_after || frame_in < stop_after) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 875 | if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) { |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 876 | frame_avail = 1; |
| 877 | frame_in++; |
| 878 | |
| 879 | vpx_usec_timer_start(&timer); |
| 880 | |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 881 | if (vpx_codec_decode(&decoder, buf, (unsigned int)bytes_in_buffer, |
| 882 | NULL, 0)) { |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 883 | const char *detail = vpx_codec_error_detail(&decoder); |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 884 | warn("Failed to decode frame %d: %s", |
| 885 | frame_in, vpx_codec_error(&decoder)); |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 886 | |
| 887 | if (detail) |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 888 | warn("Additional information: %s", detail); |
James Zern | 95853db | 2014-07-01 19:02:15 -0700 | [diff] [blame] | 889 | if (!keep_going) |
| 890 | goto fail; |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | vpx_usec_timer_mark(&timer); |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 894 | dx_time += vpx_usec_timer_elapsed(&timer); |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 898 | vpx_usec_timer_start(&timer); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 899 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 900 | got_data = 0; |
| 901 | if ((img = vpx_codec_get_frame(&decoder, &iter))) { |
| 902 | ++frame_out; |
| 903 | got_data = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 904 | } |
| 905 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 906 | vpx_usec_timer_mark(&timer); |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 907 | dx_time += (unsigned int)vpx_usec_timer_elapsed(&timer); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 908 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 909 | if (vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) { |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 910 | warn("Failed VP8_GET_FRAME_CORRUPTED: %s", vpx_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 911 | goto fail; |
| 912 | } |
| 913 | frames_corrupted += corrupted; |
| 914 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 915 | if (progress) |
| 916 | show_progress(frame_in, frame_out, dx_time); |
| 917 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 918 | if (!noblit && img) { |
| 919 | const int PLANES_YUV[] = {VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V}; |
| 920 | const int PLANES_YVU[] = {VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U}; |
| 921 | const int *planes = flipuv ? PLANES_YVU : PLANES_YUV; |
John Koleszar | da58436 | 2013-05-06 15:52:06 -0700 | [diff] [blame] | 922 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 923 | if (do_scale) { |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 924 | if (frame_out == 1) { |
| 925 | // If the output frames are to be scaled to a fixed display size then |
| 926 | // use the width and height specified in the container. If either of |
| 927 | // these is set to 0, use the display size set in the first frame |
Adrian Grange | 82f6af6 | 2014-01-22 09:36:07 -0800 | [diff] [blame] | 928 | // header. If that is unavailable, use the raw decoded size of the |
| 929 | // first decoded frame. |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 930 | int display_width = vpx_input_ctx.width; |
| 931 | int display_height = vpx_input_ctx.height; |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 932 | if (!display_width || !display_height) { |
| 933 | int display_size[2]; |
| 934 | if (vpx_codec_control(&decoder, VP9D_GET_DISPLAY_SIZE, |
| 935 | display_size)) { |
| 936 | // As last resort use size of first frame as display size. |
| 937 | display_width = img->d_w; |
| 938 | display_height = img->d_h; |
| 939 | } else { |
| 940 | display_width = display_size[0]; |
| 941 | display_height = display_size[1]; |
| 942 | } |
Adrian Grange | 2117fe0 | 2013-11-19 14:01:44 -0800 | [diff] [blame] | 943 | } |
Deb Mukherjee | e9f85d3 | 2014-08-22 13:14:58 -0700 | [diff] [blame] | 944 | scaled_img = vpx_img_alloc(NULL, img->fmt, display_width, |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 945 | display_height, 16); |
Deb Mukherjee | 449e5f2 | 2014-07-11 11:43:31 -0700 | [diff] [blame] | 946 | scaled_img->bit_depth = img->bit_depth; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 947 | } |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 948 | |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 949 | if (img->d_w != scaled_img->d_w || img->d_h != scaled_img->d_h) { |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 950 | #if CONFIG_LIBYUV |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 951 | vpx_image_scale(img, scaled_img, kFilterBox); |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 952 | img = scaled_img; |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 953 | #else |
| 954 | fprintf(stderr, "Failed to scale output frame: %s.\n" |
| 955 | "Scaling is disabled in this configuration. " |
| 956 | "To enable scaling, configure with --enable-libyuv\n", |
| 957 | vpx_codec_error(&decoder)); |
| 958 | return EXIT_FAILURE; |
| 959 | #endif |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 960 | } |
| 961 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 962 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 963 | // Default to codec bit depth if output bit depth not set |
| 964 | if (!output_bit_depth) { |
| 965 | output_bit_depth = img->bit_depth; |
| 966 | } |
| 967 | // Shift up or down if necessary |
| 968 | if (output_bit_depth != img->bit_depth) { |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 969 | const vpx_img_fmt_t shifted_fmt = output_bit_depth == 8 ? |
| 970 | img->fmt ^ (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) : |
| 971 | img->fmt | VPX_IMG_FMT_HIGHBITDEPTH; |
| 972 | if (img_shifted && |
| 973 | img_shifted_realloc_required(img, img_shifted, shifted_fmt)) { |
| 974 | vpx_img_free(img_shifted); |
| 975 | img_shifted = NULL; |
| 976 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 977 | if (!img_shifted) { |
Deb Mukherjee | 9ed23de | 2014-09-25 15:46:50 -0700 | [diff] [blame] | 978 | img_shifted = vpx_img_alloc(NULL, shifted_fmt, |
| 979 | img->d_w, img->d_h, 16); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 980 | img_shifted->bit_depth = output_bit_depth; |
| 981 | } |
| 982 | if (output_bit_depth > img->bit_depth) { |
Deb Mukherjee | 7a2a611 | 2014-10-06 20:46:11 -0700 | [diff] [blame] | 983 | vpx_img_upshift(img_shifted, img, |
| 984 | output_bit_depth - img->bit_depth); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 985 | } else { |
Deb Mukherjee | 7a2a611 | 2014-10-06 20:46:11 -0700 | [diff] [blame] | 986 | vpx_img_downshift(img_shifted, img, |
| 987 | img->bit_depth - output_bit_depth); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 988 | } |
| 989 | img = img_shifted; |
| 990 | } |
| 991 | #endif |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 992 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 993 | if (single_file) { |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 994 | if (use_y4m) { |
| 995 | char buf[Y4M_BUFFER_SIZE] = {0}; |
| 996 | size_t len = 0; |
Deb Mukherjee | a30774c | 2014-10-01 12:17:37 -0700 | [diff] [blame] | 997 | if (img->fmt == VPX_IMG_FMT_I440 || img->fmt == VPX_IMG_FMT_I44016) { |
| 998 | fprintf(stderr, "Cannot produce y4m output for 440 sampling.\n"); |
| 999 | goto fail; |
| 1000 | } |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1001 | if (frame_out == 1) { |
| 1002 | // Y4M file header |
| 1003 | len = y4m_write_file_header(buf, sizeof(buf), |
| 1004 | vpx_input_ctx.width, |
| 1005 | vpx_input_ctx.height, |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1006 | &vpx_input_ctx.framerate, |
Deb Mukherjee | 449e5f2 | 2014-07-11 11:43:31 -0700 | [diff] [blame] | 1007 | img->fmt, img->bit_depth); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1008 | if (do_md5) { |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 1009 | MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1010 | } else { |
| 1011 | fputs(buf, outfile); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | // Y4M frame header |
| 1016 | len = y4m_write_frame_header(buf, sizeof(buf)); |
| 1017 | if (do_md5) { |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 1018 | MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1019 | } else { |
| 1020 | fputs(buf, outfile); |
| 1021 | } |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 1022 | } else { |
| 1023 | if (frame_out == 1) { |
| 1024 | // Check if --yv12 or --i420 options are consistent with the |
| 1025 | // bit-stream decoded |
| 1026 | if (opt_i420) { |
| 1027 | if (img->fmt != VPX_IMG_FMT_I420 && |
| 1028 | img->fmt != VPX_IMG_FMT_I42016) { |
| 1029 | fprintf(stderr, "Cannot produce i420 output for bit-stream.\n"); |
| 1030 | goto fail; |
| 1031 | } |
| 1032 | } |
| 1033 | if (opt_yv12) { |
| 1034 | if ((img->fmt != VPX_IMG_FMT_I420 && |
| 1035 | img->fmt != VPX_IMG_FMT_YV12) || img->bit_depth != 8) { |
| 1036 | fprintf(stderr, "Cannot produce yv12 output for bit-stream.\n"); |
| 1037 | goto fail; |
| 1038 | } |
| 1039 | } |
| 1040 | } |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 1043 | if (do_md5) { |
| 1044 | update_image_md5(img, planes, &md5_ctx); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 1045 | } else { |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 1046 | write_image_file(img, planes, outfile); |
| 1047 | } |
| 1048 | } else { |
| 1049 | generate_filename(outfile_pattern, outfile_name, PATH_MAX, |
| 1050 | img->d_w, img->d_h, frame_in); |
| 1051 | if (do_md5) { |
| 1052 | MD5Init(&md5_ctx); |
| 1053 | update_image_md5(img, planes, &md5_ctx); |
| 1054 | MD5Final(md5_digest, &md5_ctx); |
| 1055 | print_md5(md5_digest, outfile_name); |
| 1056 | } else { |
| 1057 | outfile = open_outfile(outfile_name); |
| 1058 | write_image_file(img, planes, outfile); |
| 1059 | fclose(outfile); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1060 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1061 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1064 | if (stop_after && frame_in >= stop_after) |
| 1065 | break; |
| 1066 | } |
| 1067 | |
| 1068 | if (summary || progress) { |
| 1069 | show_progress(frame_in, frame_out, dx_time); |
| 1070 | fprintf(stderr, "\n"); |
| 1071 | } |
| 1072 | |
| 1073 | if (frames_corrupted) |
| 1074 | fprintf(stderr, "WARNING: %d frames corrupted.\n", frames_corrupted); |
John Koleszar | 4226f0c | 2011-04-27 12:04:48 -0400 | [diff] [blame] | 1075 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1076 | fail: |
| 1077 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1078 | if (vpx_codec_destroy(&decoder)) { |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 1079 | fprintf(stderr, "Failed to destroy decoder: %s\n", |
| 1080 | vpx_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1081 | return EXIT_FAILURE; |
| 1082 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1083 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 1084 | if (!noblit && single_file) { |
| 1085 | if (do_md5) { |
| 1086 | MD5Final(md5_digest, &md5_ctx); |
| 1087 | print_md5(md5_digest, outfile_name); |
| 1088 | } else { |
| 1089 | fclose(outfile); |
| 1090 | } |
| 1091 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1092 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1093 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 1094 | if (input.vpx_input_ctx->file_type == FILE_TYPE_WEBM) |
| 1095 | webm_free(input.webm_ctx); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1096 | #endif |
| 1097 | |
| 1098 | if (input.vpx_input_ctx->file_type != FILE_TYPE_WEBM) |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1099 | free(buf); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 1100 | |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 1101 | if (scaled_img) vpx_img_free(scaled_img); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1102 | #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH |
| 1103 | if (img_shifted) vpx_img_free(img_shifted); |
| 1104 | #endif |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 1105 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 1106 | for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) { |
| 1107 | free(ext_fb_list.ext_fb[i].data); |
| 1108 | } |
| 1109 | free(ext_fb_list.ext_fb); |
| 1110 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1111 | fclose(infile); |
| 1112 | free(argv); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1113 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1114 | return frames_corrupted ? EXIT_FAILURE : EXIT_SUCCESS; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1115 | } |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 1116 | |
| 1117 | int main(int argc, const char **argv_) { |
| 1118 | unsigned int loops = 1, i; |
| 1119 | char **argv, **argi, **argj; |
| 1120 | struct arg arg; |
| 1121 | int error = 0; |
| 1122 | |
| 1123 | argv = argv_dup(argc - 1, argv_ + 1); |
| 1124 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 1125 | memset(&arg, 0, sizeof(arg)); |
| 1126 | arg.argv_step = 1; |
| 1127 | |
| 1128 | if (arg_match(&arg, &looparg, argi)) { |
| 1129 | loops = arg_parse_uint(&arg); |
| 1130 | break; |
| 1131 | } |
| 1132 | } |
| 1133 | free(argv); |
| 1134 | for (i = 0; !error && i < loops; i++) |
| 1135 | error = main_loop(argc, argv_); |
| 1136 | return error; |
| 1137 | } |