VP8 for ARMv8 by using NEON intrinsics 17
[aom.git] / vpxdec.c
blob64700816212220b9f9a78e3ad77261d29ba68de1
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
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
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
11 #include <assert.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stdarg.h>
15 #include <string.h>
16 #include <limits.h>
18 #include "./vpx_config.h"
20 #if CONFIG_LIBYUV
21 #include "third_party/libyuv/include/libyuv/scale.h"
22 #endif
24 #include "./args.h"
25 #include "./ivfdec.h"
27 #define VPX_CODEC_DISABLE_COMPAT 1
28 #include "vpx/vpx_decoder.h"
29 #include "vpx_ports/mem_ops.h"
30 #include "vpx_ports/vpx_timer.h"
32 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
33 #include "vpx/vp8dx.h"
34 #endif
36 #include "./md5_utils.h"
38 #include "./tools_common.h"
39 #if CONFIG_WEBM_IO
40 #include "./webmdec.h"
41 #endif
42 #include "./y4menc.h"
44 static const char *exec_name;
46 struct VpxDecInputContext {
47 struct VpxInputContext *vpx_input_ctx;
48 struct WebmInputContext *webm_ctx;
51 static const arg_def_t looparg = ARG_DEF(NULL, "loops", 1,
52 "Number of times to decode the file");
53 static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1,
54 "Codec to use");
55 static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0,
56 "Output raw YV12 frames");
57 static const arg_def_t use_i420 = ARG_DEF(NULL, "i420", 0,
58 "Output raw I420 frames");
59 static const arg_def_t flipuvarg = ARG_DEF(NULL, "flipuv", 0,
60 "Flip the chroma planes in the output");
61 static const arg_def_t rawvideo = ARG_DEF(NULL, "rawvideo", 0,
62 "Output raw YUV frames");
63 static const arg_def_t noblitarg = ARG_DEF(NULL, "noblit", 0,
64 "Don't process the decoded frames");
65 static const arg_def_t progressarg = ARG_DEF(NULL, "progress", 0,
66 "Show progress after each frame decodes");
67 static const arg_def_t limitarg = ARG_DEF(NULL, "limit", 1,
68 "Stop decoding after n frames");
69 static const arg_def_t skiparg = ARG_DEF(NULL, "skip", 1,
70 "Skip the first n input frames");
71 static const arg_def_t postprocarg = ARG_DEF(NULL, "postproc", 0,
72 "Postprocess decoded frames");
73 static const arg_def_t summaryarg = ARG_DEF(NULL, "summary", 0,
74 "Show timing summary");
75 static const arg_def_t outputfile = ARG_DEF("o", "output", 1,
76 "Output file name pattern (see below)");
77 static const arg_def_t threadsarg = ARG_DEF("t", "threads", 1,
78 "Max threads to use");
79 static const arg_def_t verbosearg = ARG_DEF("v", "verbose", 0,
80 "Show version string");
81 static const arg_def_t error_concealment = ARG_DEF(NULL, "error-concealment", 0,
82 "Enable decoder error-concealment");
83 static const arg_def_t scalearg = ARG_DEF("S", "scale", 0,
84 "Scale output frames uniformly");
85 static const arg_def_t continuearg =
86 ARG_DEF("k", "keep-going", 0, "(debug) Continue decoding after error");
88 static const arg_def_t fb_arg =
89 ARG_DEF(NULL, "frame-buffers", 1, "Number of frame buffers to use");
91 static const arg_def_t md5arg = ARG_DEF(NULL, "md5", 0,
92 "Compute the MD5 sum of the decoded frame");
93 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
94 static const arg_def_t outbitdeptharg = ARG_DEF(
95 NULL, "output-bit-depth", 1,
96 "Output bit-depth for decoded frames");
97 #endif
99 static const arg_def_t *all_args[] = {
100 &codecarg, &use_yv12, &use_i420, &flipuvarg, &rawvideo, &noblitarg,
101 &progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile,
102 &threadsarg, &verbosearg, &scalearg, &fb_arg,
103 &md5arg, &error_concealment, &continuearg,
104 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
105 &outbitdeptharg,
106 #endif
107 NULL
110 #if CONFIG_VP8_DECODER
111 static const arg_def_t addnoise_level = ARG_DEF(NULL, "noise-level", 1,
112 "Enable VP8 postproc add noise");
113 static const arg_def_t deblock = ARG_DEF(NULL, "deblock", 0,
114 "Enable VP8 deblocking");
115 static const arg_def_t demacroblock_level = ARG_DEF(NULL, "demacroblock-level", 1,
116 "Enable VP8 demacroblocking, w/ level");
117 static const arg_def_t pp_debug_info = ARG_DEF(NULL, "pp-debug-info", 1,
118 "Enable VP8 visible debug info");
119 static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL, "pp-dbg-ref-frame", 1,
120 "Display only selected reference frame per macro block");
121 static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL, "pp-dbg-mb-modes", 1,
122 "Display only selected macro block modes");
123 static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL, "pp-dbg-b-modes", 1,
124 "Display only selected block modes");
125 static const arg_def_t pp_disp_mvs = ARG_DEF(NULL, "pp-dbg-mvs", 1,
126 "Draw only selected motion vectors");
127 static const arg_def_t mfqe = ARG_DEF(NULL, "mfqe", 0,
128 "Enable multiframe quality enhancement");
130 static const arg_def_t *vp8_pp_args[] = {
131 &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info,
132 &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe,
133 NULL
135 #endif
137 #if CONFIG_LIBYUV
138 static INLINE int vpx_image_scale(vpx_image_t *src, vpx_image_t *dst,
139 FilterModeEnum mode) {
140 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
141 if (src->fmt == VPX_IMG_FMT_I42016) {
142 assert(dst->fmt == VPX_IMG_FMT_I42016);
143 return I420Scale_16((uint16_t*)src->planes[VPX_PLANE_Y],
144 src->stride[VPX_PLANE_Y]/2,
145 (uint16_t*)src->planes[VPX_PLANE_U],
146 src->stride[VPX_PLANE_U]/2,
147 (uint16_t*)src->planes[VPX_PLANE_V],
148 src->stride[VPX_PLANE_V]/2,
149 src->d_w, src->d_h,
150 (uint16_t*)dst->planes[VPX_PLANE_Y],
151 dst->stride[VPX_PLANE_Y]/2,
152 (uint16_t*)dst->planes[VPX_PLANE_U],
153 dst->stride[VPX_PLANE_U]/2,
154 (uint16_t*)dst->planes[VPX_PLANE_V],
155 dst->stride[VPX_PLANE_V]/2,
156 dst->d_w, dst->d_h,
157 mode);
159 #endif
160 assert(src->fmt == VPX_IMG_FMT_I420);
161 assert(dst->fmt == VPX_IMG_FMT_I420);
162 return I420Scale(src->planes[VPX_PLANE_Y], src->stride[VPX_PLANE_Y],
163 src->planes[VPX_PLANE_U], src->stride[VPX_PLANE_U],
164 src->planes[VPX_PLANE_V], src->stride[VPX_PLANE_V],
165 src->d_w, src->d_h,
166 dst->planes[VPX_PLANE_Y], dst->stride[VPX_PLANE_Y],
167 dst->planes[VPX_PLANE_U], dst->stride[VPX_PLANE_U],
168 dst->planes[VPX_PLANE_V], dst->stride[VPX_PLANE_V],
169 dst->d_w, dst->d_h,
170 mode);
172 #endif
174 void usage_exit() {
175 int i;
177 fprintf(stderr, "Usage: %s <options> filename\n\n"
178 "Options:\n", exec_name);
179 arg_show_usage(stderr, all_args);
180 #if CONFIG_VP8_DECODER
181 fprintf(stderr, "\nVP8 Postprocessing Options:\n");
182 arg_show_usage(stderr, vp8_pp_args);
183 #endif
184 fprintf(stderr,
185 "\nOutput File Patterns:\n\n"
186 " The -o argument specifies the name of the file(s) to "
187 "write to. If the\n argument does not include any escape "
188 "characters, the output will be\n written to a single file. "
189 "Otherwise, the filename will be calculated by\n expanding "
190 "the following escape characters:\n");
191 fprintf(stderr,
192 "\n\t%%w - Frame width"
193 "\n\t%%h - Frame height"
194 "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
195 "\n\n Pattern arguments are only supported in conjunction "
196 "with the --yv12 and\n --i420 options. If the -o option is "
197 "not specified, the output will be\n directed to stdout.\n"
199 fprintf(stderr, "\nIncluded decoders:\n\n");
201 for (i = 0; i < get_vpx_decoder_count(); ++i) {
202 const VpxInterface *const decoder = get_vpx_decoder_by_index(i);
203 fprintf(stderr, " %-6s - %s\n",
204 decoder->name, vpx_codec_iface_name(decoder->codec_interface()));
207 exit(EXIT_FAILURE);
210 static int raw_read_frame(FILE *infile, uint8_t **buffer,
211 size_t *bytes_read, size_t *buffer_size) {
212 char raw_hdr[RAW_FRAME_HDR_SZ];
213 size_t frame_size = 0;
215 if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) {
216 if (!feof(infile))
217 warn("Failed to read RAW frame size\n");
218 } else {
219 const size_t kCorruptFrameThreshold = 256 * 1024 * 1024;
220 const size_t kFrameTooSmallThreshold = 256 * 1024;
221 frame_size = mem_get_le32(raw_hdr);
223 if (frame_size > kCorruptFrameThreshold) {
224 warn("Read invalid frame size (%u)\n", (unsigned int)frame_size);
225 frame_size = 0;
228 if (frame_size < kFrameTooSmallThreshold) {
229 warn("Warning: Read invalid frame size (%u) - not a raw file?\n",
230 (unsigned int)frame_size);
233 if (frame_size > *buffer_size) {
234 uint8_t *new_buf = realloc(*buffer, 2 * frame_size);
235 if (new_buf) {
236 *buffer = new_buf;
237 *buffer_size = 2 * frame_size;
238 } else {
239 warn("Failed to allocate compressed data buffer\n");
240 frame_size = 0;
245 if (!feof(infile)) {
246 if (fread(*buffer, 1, frame_size, infile) != frame_size) {
247 warn("Failed to read full frame\n");
248 return 1;
250 *bytes_read = frame_size;
253 return 0;
256 static int read_frame(struct VpxDecInputContext *input, uint8_t **buf,
257 size_t *bytes_in_buffer, size_t *buffer_size) {
258 switch (input->vpx_input_ctx->file_type) {
259 #if CONFIG_WEBM_IO
260 case FILE_TYPE_WEBM:
261 return webm_read_frame(input->webm_ctx,
262 buf, bytes_in_buffer, buffer_size);
263 #endif
264 case FILE_TYPE_RAW:
265 return raw_read_frame(input->vpx_input_ctx->file,
266 buf, bytes_in_buffer, buffer_size);
267 case FILE_TYPE_IVF:
268 return ivf_read_frame(input->vpx_input_ctx->file,
269 buf, bytes_in_buffer, buffer_size);
270 default:
271 return 1;
275 static void update_image_md5(const vpx_image_t *img, const int planes[3],
276 MD5Context *md5) {
277 int i, y;
279 for (i = 0; i < 3; ++i) {
280 const int plane = planes[i];
281 const unsigned char *buf = img->planes[plane];
282 const int stride = img->stride[plane];
283 const int w = vpx_img_plane_width(img, plane);
284 const int h = vpx_img_plane_height(img, plane);
286 for (y = 0; y < h; ++y) {
287 MD5Update(md5, buf, w);
288 buf += stride;
293 static void write_image_file(const vpx_image_t *img, const int planes[3],
294 FILE *file) {
295 int i, y;
296 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
297 const int bytes_per_sample = ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1);
298 #else
299 const int bytes_per_sample = 1;
300 #endif
302 for (i = 0; i < 3; ++i) {
303 const int plane = planes[i];
304 const unsigned char *buf = img->planes[plane];
305 const int stride = img->stride[plane];
306 const int w = vpx_img_plane_width(img, plane);
307 const int h = vpx_img_plane_height(img, plane);
309 for (y = 0; y < h; ++y) {
310 fwrite(buf, bytes_per_sample, w, file);
311 buf += stride;
316 int file_is_raw(struct VpxInputContext *input) {
317 uint8_t buf[32];
318 int is_raw = 0;
319 vpx_codec_stream_info_t si;
321 si.sz = sizeof(si);
323 if (fread(buf, 1, 32, input->file) == 32) {
324 int i;
326 if (mem_get_le32(buf) < 256 * 1024 * 1024) {
327 for (i = 0; i < get_vpx_decoder_count(); ++i) {
328 const VpxInterface *const decoder = get_vpx_decoder_by_index(i);
329 if (!vpx_codec_peek_stream_info(decoder->codec_interface(),
330 buf + 4, 32 - 4, &si)) {
331 is_raw = 1;
332 input->fourcc = decoder->fourcc;
333 input->width = si.w;
334 input->height = si.h;
335 input->framerate.numerator = 30;
336 input->framerate.denominator = 1;
337 break;
343 rewind(input->file);
344 return is_raw;
347 void show_progress(int frame_in, int frame_out, uint64_t dx_time) {
348 fprintf(stderr,
349 "%d decoded frames/%d showed frames in %"PRId64" us (%.2f fps)\r",
350 frame_in, frame_out, dx_time,
351 (double)frame_out * 1000000.0 / (double)dx_time);
354 struct ExternalFrameBuffer {
355 uint8_t* data;
356 size_t size;
357 int in_use;
360 struct ExternalFrameBufferList {
361 int num_external_frame_buffers;
362 struct ExternalFrameBuffer *ext_fb;
365 // Callback used by libvpx to request an external frame buffer. |cb_priv|
366 // Application private data passed into the set function. |min_size| is the
367 // minimum size in bytes needed to decode the next frame. |fb| pointer to the
368 // frame buffer.
369 int get_vp9_frame_buffer(void *cb_priv, size_t min_size,
370 vpx_codec_frame_buffer_t *fb) {
371 int i;
372 struct ExternalFrameBufferList *const ext_fb_list =
373 (struct ExternalFrameBufferList *)cb_priv;
374 if (ext_fb_list == NULL)
375 return -1;
377 // Find a free frame buffer.
378 for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) {
379 if (!ext_fb_list->ext_fb[i].in_use)
380 break;
383 if (i == ext_fb_list->num_external_frame_buffers)
384 return -1;
386 if (ext_fb_list->ext_fb[i].size < min_size) {
387 free(ext_fb_list->ext_fb[i].data);
388 ext_fb_list->ext_fb[i].data = (uint8_t *)malloc(min_size);
389 if (!ext_fb_list->ext_fb[i].data)
390 return -1;
392 ext_fb_list->ext_fb[i].size = min_size;
395 fb->data = ext_fb_list->ext_fb[i].data;
396 fb->size = ext_fb_list->ext_fb[i].size;
397 ext_fb_list->ext_fb[i].in_use = 1;
399 // Set the frame buffer's private data to point at the external frame buffer.
400 fb->priv = &ext_fb_list->ext_fb[i];
401 return 0;
404 // Callback used by libvpx when there are no references to the frame buffer.
405 // |cb_priv| user private data passed into the set function. |fb| pointer
406 // to the frame buffer.
407 int release_vp9_frame_buffer(void *cb_priv,
408 vpx_codec_frame_buffer_t *fb) {
409 struct ExternalFrameBuffer *const ext_fb =
410 (struct ExternalFrameBuffer *)fb->priv;
411 (void)cb_priv;
412 ext_fb->in_use = 0;
413 return 0;
416 void generate_filename(const char *pattern, char *out, size_t q_len,
417 unsigned int d_w, unsigned int d_h,
418 unsigned int frame_in) {
419 const char *p = pattern;
420 char *q = out;
422 do {
423 char *next_pat = strchr(p, '%');
425 if (p == next_pat) {
426 size_t pat_len;
428 /* parse the pattern */
429 q[q_len - 1] = '\0';
430 switch (p[1]) {
431 case 'w':
432 snprintf(q, q_len - 1, "%d", d_w);
433 break;
434 case 'h':
435 snprintf(q, q_len - 1, "%d", d_h);
436 break;
437 case '1':
438 snprintf(q, q_len - 1, "%d", frame_in);
439 break;
440 case '2':
441 snprintf(q, q_len - 1, "%02d", frame_in);
442 break;
443 case '3':
444 snprintf(q, q_len - 1, "%03d", frame_in);
445 break;
446 case '4':
447 snprintf(q, q_len - 1, "%04d", frame_in);
448 break;
449 case '5':
450 snprintf(q, q_len - 1, "%05d", frame_in);
451 break;
452 case '6':
453 snprintf(q, q_len - 1, "%06d", frame_in);
454 break;
455 case '7':
456 snprintf(q, q_len - 1, "%07d", frame_in);
457 break;
458 case '8':
459 snprintf(q, q_len - 1, "%08d", frame_in);
460 break;
461 case '9':
462 snprintf(q, q_len - 1, "%09d", frame_in);
463 break;
464 default:
465 die("Unrecognized pattern %%%c\n", p[1]);
466 break;
469 pat_len = strlen(q);
470 if (pat_len >= q_len - 1)
471 die("Output filename too long.\n");
472 q += pat_len;
473 p += 2;
474 q_len -= pat_len;
475 } else {
476 size_t copy_len;
478 /* copy the next segment */
479 if (!next_pat)
480 copy_len = strlen(p);
481 else
482 copy_len = next_pat - p;
484 if (copy_len >= q_len - 1)
485 die("Output filename too long.\n");
487 memcpy(q, p, copy_len);
488 q[copy_len] = '\0';
489 q += copy_len;
490 p += copy_len;
491 q_len -= copy_len;
493 } while (*p);
496 static int is_single_file(const char *outfile_pattern) {
497 const char *p = outfile_pattern;
499 do {
500 p = strchr(p, '%');
501 if (p && p[1] >= '1' && p[1] <= '9')
502 return 0; // pattern contains sequence number, so it's not unique
503 if (p)
504 p++;
505 } while (p);
507 return 1;
510 static void print_md5(unsigned char digest[16], const char *filename) {
511 int i;
513 for (i = 0; i < 16; ++i)
514 printf("%02x", digest[i]);
515 printf(" %s\n", filename);
518 static FILE *open_outfile(const char *name) {
519 if (strcmp("-", name) == 0) {
520 set_binary_mode(stdout);
521 return stdout;
522 } else {
523 FILE *file = fopen(name, "wb");
524 if (!file)
525 fatal("Failed to output file %s", name);
526 return file;
530 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
531 static void high_img_upshift(vpx_image_t *dst, vpx_image_t *src,
532 int input_shift) {
533 const int offset = input_shift > 0 ? (1 << (input_shift - 1)) : 0;
534 int plane;
535 if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
536 dst->x_chroma_shift != src->x_chroma_shift ||
537 dst->y_chroma_shift != src->y_chroma_shift ||
538 dst->fmt != src->fmt || input_shift < 0) {
539 fatal("Unsupported image conversion");
541 switch (src->fmt) {
542 case VPX_IMG_FMT_I42016:
543 case VPX_IMG_FMT_I42216:
544 case VPX_IMG_FMT_I44416:
545 break;
546 default:
547 fatal("Unsupported image conversion");
548 break;
550 for (plane = 0; plane < 3; plane++) {
551 int w = src->d_w;
552 int h = src->d_h;
553 int x, y;
554 if (plane) {
555 w >>= src->x_chroma_shift;
556 h >>= src->y_chroma_shift;
558 for (y = 0; y < h; y++) {
559 uint16_t *p_src = (uint16_t *)(src->planes[plane] +
560 y * src->stride[plane]);
561 uint16_t *p_dst = (uint16_t *)(dst->planes[plane] +
562 y * dst->stride[plane]);
563 for (x = 0; x < w; x++)
564 *p_dst++ = (*p_src++ << input_shift) + offset;
569 static void low_img_upshift(vpx_image_t *dst, vpx_image_t *src,
570 int input_shift) {
571 const int offset = input_shift > 0 ? (1 << (input_shift - 1)) : 0;
572 int plane;
573 if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
574 dst->x_chroma_shift != src->x_chroma_shift ||
575 dst->y_chroma_shift != src->y_chroma_shift ||
576 dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
577 input_shift < 0) {
578 fatal("Unsupported image conversion");
580 switch (src->fmt) {
581 case VPX_IMG_FMT_I420:
582 case VPX_IMG_FMT_I422:
583 case VPX_IMG_FMT_I444:
584 break;
585 default:
586 fatal("Unsupported image conversion");
587 break;
589 for (plane = 0; plane < 3; plane++) {
590 int w = src->d_w;
591 int h = src->d_h;
592 int x, y;
593 if (plane) {
594 w >>= src->x_chroma_shift;
595 h >>= src->y_chroma_shift;
597 for (y = 0; y < h; y++) {
598 uint8_t *p_src = src->planes[plane] + y * src->stride[plane];
599 uint16_t *p_dst = (uint16_t *)(dst->planes[plane] +
600 y * dst->stride[plane]);
601 for (x = 0; x < w; x++) {
602 *p_dst++ = (*p_src++ << input_shift) + offset;
608 static void img_upshift(vpx_image_t *dst, vpx_image_t *src,
609 int input_shift) {
610 if (src->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
611 high_img_upshift(dst, src, input_shift);
612 } else {
613 low_img_upshift(dst, src, input_shift);
617 static void high_img_downshift(vpx_image_t *dst, vpx_image_t *src,
618 int down_shift) {
619 int plane;
620 if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
621 dst->x_chroma_shift != src->x_chroma_shift ||
622 dst->y_chroma_shift != src->y_chroma_shift ||
623 dst->fmt != src->fmt || down_shift < 0) {
624 fatal("Unsupported image conversion");
626 switch (src->fmt) {
627 case VPX_IMG_FMT_I42016:
628 case VPX_IMG_FMT_I42216:
629 case VPX_IMG_FMT_I44416:
630 break;
631 default:
632 fatal("Unsupported image conversion");
633 break;
635 for (plane = 0; plane < 3; plane++) {
636 int w = src->d_w;
637 int h = src->d_h;
638 int x, y;
639 if (plane) {
640 w >>= src->x_chroma_shift;
641 h >>= src->y_chroma_shift;
643 for (y = 0; y < h; y++) {
644 uint16_t *p_src = (uint16_t *)(src->planes[plane] +
645 y * src->stride[plane]);
646 uint16_t *p_dst = (uint16_t *)(dst->planes[plane] +
647 y * dst->stride[plane]);
648 for (x = 0; x < w; x++)
649 *p_dst++ = *p_src++ >> down_shift;
654 static void low_img_downshift(vpx_image_t *dst, vpx_image_t *src,
655 int down_shift) {
656 int plane;
657 if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
658 dst->x_chroma_shift != src->x_chroma_shift ||
659 dst->y_chroma_shift != src->y_chroma_shift ||
660 src->fmt != dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
661 down_shift < 0) {
662 fatal("Unsupported image conversion");
664 switch (dst->fmt) {
665 case VPX_IMG_FMT_I420:
666 case VPX_IMG_FMT_I422:
667 case VPX_IMG_FMT_I444:
668 break;
669 default:
670 fatal("Unsupported image conversion");
671 break;
673 for (plane = 0; plane < 3; plane++) {
674 int w = src->d_w;
675 int h = src->d_h;
676 int x, y;
677 if (plane) {
678 w >>= src->x_chroma_shift;
679 h >>= src->y_chroma_shift;
681 for (y = 0; y < h; y++) {
682 uint16_t *p_src = (uint16_t *)(src->planes[plane] +
683 y * src->stride[plane]);
684 uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane];
685 for (x = 0; x < w; x++) {
686 *p_dst++ = *p_src++ >> down_shift;
692 static void img_downshift(vpx_image_t *dst, vpx_image_t *src,
693 int down_shift) {
694 if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
695 high_img_downshift(dst, src, down_shift);
696 } else {
697 low_img_downshift(dst, src, down_shift);
700 #endif
702 int main_loop(int argc, const char **argv_) {
703 vpx_codec_ctx_t decoder;
704 char *fn = NULL;
705 int i;
706 uint8_t *buf = NULL;
707 size_t bytes_in_buffer = 0, buffer_size = 0;
708 FILE *infile;
709 int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0;
710 int do_md5 = 0, progress = 0;
711 int stop_after = 0, postproc = 0, summary = 0, quiet = 1;
712 int arg_skip = 0;
713 int ec_enabled = 0;
714 int keep_going = 0;
715 const VpxInterface *interface = NULL;
716 const VpxInterface *fourcc_interface = NULL;
717 uint64_t dx_time = 0;
718 struct arg arg;
719 char **argv, **argi, **argj;
721 int single_file;
722 int use_y4m = 1;
723 int opt_yv12 = 0;
724 int opt_i420 = 0;
725 vpx_codec_dec_cfg_t cfg = {0, 0, 0};
726 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
727 int output_bit_depth = 0;
728 #endif
729 #if CONFIG_VP8_DECODER
730 vp8_postproc_cfg_t vp8_pp_cfg = {0};
731 int vp8_dbg_color_ref_frame = 0;
732 int vp8_dbg_color_mb_modes = 0;
733 int vp8_dbg_color_b_modes = 0;
734 int vp8_dbg_display_mv = 0;
735 #endif
736 int frames_corrupted = 0;
737 int dec_flags = 0;
738 int do_scale = 0;
739 vpx_image_t *scaled_img = NULL;
740 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
741 vpx_image_t *img_shifted = NULL;
742 #endif
743 int frame_avail, got_data;
744 int num_external_frame_buffers = 0;
745 struct ExternalFrameBufferList ext_fb_list = {0, NULL};
747 const char *outfile_pattern = NULL;
748 char outfile_name[PATH_MAX] = {0};
749 FILE *outfile = NULL;
751 MD5Context md5_ctx;
752 unsigned char md5_digest[16];
754 struct VpxDecInputContext input = {NULL, NULL};
755 struct VpxInputContext vpx_input_ctx;
756 #if CONFIG_WEBM_IO
757 struct WebmInputContext webm_ctx;
758 memset(&(webm_ctx), 0, sizeof(webm_ctx));
759 input.webm_ctx = &webm_ctx;
760 #endif
761 input.vpx_input_ctx = &vpx_input_ctx;
763 /* Parse command line */
764 exec_name = argv_[0];
765 argv = argv_dup(argc - 1, argv_ + 1);
767 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
768 memset(&arg, 0, sizeof(arg));
769 arg.argv_step = 1;
771 if (arg_match(&arg, &codecarg, argi)) {
772 interface = get_vpx_decoder_by_name(arg.val);
773 if (!interface)
774 die("Error: Unrecognized argument (%s) to --codec\n", arg.val);
775 } else if (arg_match(&arg, &looparg, argi)) {
776 // no-op
777 } else if (arg_match(&arg, &outputfile, argi))
778 outfile_pattern = arg.val;
779 else if (arg_match(&arg, &use_yv12, argi)) {
780 use_y4m = 0;
781 flipuv = 1;
782 opt_yv12 = 1;
783 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
784 output_bit_depth = 8; // For yv12 8-bit depth output is assumed
785 #endif
786 } else if (arg_match(&arg, &use_i420, argi)) {
787 use_y4m = 0;
788 flipuv = 0;
789 opt_i420 = 1;
790 } else if (arg_match(&arg, &rawvideo, argi)) {
791 use_y4m = 0;
792 } else if (arg_match(&arg, &flipuvarg, argi))
793 flipuv = 1;
794 else if (arg_match(&arg, &noblitarg, argi))
795 noblit = 1;
796 else if (arg_match(&arg, &progressarg, argi))
797 progress = 1;
798 else if (arg_match(&arg, &limitarg, argi))
799 stop_after = arg_parse_uint(&arg);
800 else if (arg_match(&arg, &skiparg, argi))
801 arg_skip = arg_parse_uint(&arg);
802 else if (arg_match(&arg, &postprocarg, argi))
803 postproc = 1;
804 else if (arg_match(&arg, &md5arg, argi))
805 do_md5 = 1;
806 else if (arg_match(&arg, &summaryarg, argi))
807 summary = 1;
808 else if (arg_match(&arg, &threadsarg, argi))
809 cfg.threads = arg_parse_uint(&arg);
810 else if (arg_match(&arg, &verbosearg, argi))
811 quiet = 0;
812 else if (arg_match(&arg, &scalearg, argi))
813 do_scale = 1;
814 else if (arg_match(&arg, &fb_arg, argi))
815 num_external_frame_buffers = arg_parse_uint(&arg);
816 else if (arg_match(&arg, &continuearg, argi))
817 keep_going = 1;
818 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
819 else if (arg_match(&arg, &outbitdeptharg, argi)) {
820 output_bit_depth = arg_parse_uint(&arg);
822 #endif
823 #if CONFIG_VP8_DECODER
824 else if (arg_match(&arg, &addnoise_level, argi)) {
825 postproc = 1;
826 vp8_pp_cfg.post_proc_flag |= VP8_ADDNOISE;
827 vp8_pp_cfg.noise_level = arg_parse_uint(&arg);
828 } else if (arg_match(&arg, &demacroblock_level, argi)) {
829 postproc = 1;
830 vp8_pp_cfg.post_proc_flag |= VP8_DEMACROBLOCK;
831 vp8_pp_cfg.deblocking_level = arg_parse_uint(&arg);
832 } else if (arg_match(&arg, &deblock, argi)) {
833 postproc = 1;
834 vp8_pp_cfg.post_proc_flag |= VP8_DEBLOCK;
835 } else if (arg_match(&arg, &mfqe, argi)) {
836 postproc = 1;
837 vp8_pp_cfg.post_proc_flag |= VP8_MFQE;
838 } else if (arg_match(&arg, &pp_debug_info, argi)) {
839 unsigned int level = arg_parse_uint(&arg);
841 postproc = 1;
842 vp8_pp_cfg.post_proc_flag &= ~0x7;
844 if (level)
845 vp8_pp_cfg.post_proc_flag |= level;
846 } else if (arg_match(&arg, &pp_disp_ref_frame, argi)) {
847 unsigned int flags = arg_parse_int(&arg);
848 if (flags) {
849 postproc = 1;
850 vp8_dbg_color_ref_frame = flags;
852 } else if (arg_match(&arg, &pp_disp_mb_modes, argi)) {
853 unsigned int flags = arg_parse_int(&arg);
854 if (flags) {
855 postproc = 1;
856 vp8_dbg_color_mb_modes = flags;
858 } else if (arg_match(&arg, &pp_disp_b_modes, argi)) {
859 unsigned int flags = arg_parse_int(&arg);
860 if (flags) {
861 postproc = 1;
862 vp8_dbg_color_b_modes = flags;
864 } else if (arg_match(&arg, &pp_disp_mvs, argi)) {
865 unsigned int flags = arg_parse_int(&arg);
866 if (flags) {
867 postproc = 1;
868 vp8_dbg_display_mv = flags;
870 } else if (arg_match(&arg, &error_concealment, argi)) {
871 ec_enabled = 1;
873 #endif // CONFIG_VP8_DECODER
874 else
875 argj++;
878 /* Check for unrecognized options */
879 for (argi = argv; *argi; argi++)
880 if (argi[0][0] == '-' && strlen(argi[0]) > 1)
881 die("Error: Unrecognized option %s\n", *argi);
883 /* Handle non-option arguments */
884 fn = argv[0];
886 if (!fn)
887 usage_exit();
889 /* Open file */
890 infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin);
892 if (!infile) {
893 fprintf(stderr, "Failed to open file '%s'", strcmp(fn, "-") ? fn : "stdin");
894 return EXIT_FAILURE;
896 #if CONFIG_OS_SUPPORT
897 /* Make sure we don't dump to the terminal, unless forced to with -o - */
898 if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) {
899 fprintf(stderr,
900 "Not dumping raw video to your terminal. Use '-o -' to "
901 "override.\n");
902 return EXIT_FAILURE;
904 #endif
905 input.vpx_input_ctx->file = infile;
906 if (file_is_ivf(input.vpx_input_ctx))
907 input.vpx_input_ctx->file_type = FILE_TYPE_IVF;
908 #if CONFIG_WEBM_IO
909 else if (file_is_webm(input.webm_ctx, input.vpx_input_ctx))
910 input.vpx_input_ctx->file_type = FILE_TYPE_WEBM;
911 #endif
912 else if (file_is_raw(input.vpx_input_ctx))
913 input.vpx_input_ctx->file_type = FILE_TYPE_RAW;
914 else {
915 fprintf(stderr, "Unrecognized input file type.\n");
916 #if !CONFIG_WEBM_IO
917 fprintf(stderr, "vpxdec was built without WebM container support.\n");
918 #endif
919 return EXIT_FAILURE;
922 outfile_pattern = outfile_pattern ? outfile_pattern : "-";
923 single_file = is_single_file(outfile_pattern);
925 if (!noblit && single_file) {
926 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
927 vpx_input_ctx.width, vpx_input_ctx.height, 0);
928 if (do_md5)
929 MD5Init(&md5_ctx);
930 else
931 outfile = open_outfile(outfile_name);
934 if (use_y4m && !noblit) {
935 if (!single_file) {
936 fprintf(stderr, "YUV4MPEG2 not supported with output patterns,"
937 " try --i420 or --yv12.\n");
938 return EXIT_FAILURE;
941 #if CONFIG_WEBM_IO
942 if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) {
943 if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) {
944 fprintf(stderr, "Failed to guess framerate -- error parsing "
945 "webm file?\n");
946 return EXIT_FAILURE;
949 #endif
952 fourcc_interface = get_vpx_decoder_by_fourcc(vpx_input_ctx.fourcc);
953 if (interface && fourcc_interface && interface != fourcc_interface)
954 warn("Header indicates codec: %s\n", fourcc_interface->name);
955 else
956 interface = fourcc_interface;
958 if (!interface)
959 interface = get_vpx_decoder_by_index(0);
961 dec_flags = (postproc ? VPX_CODEC_USE_POSTPROC : 0) |
962 (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0);
963 if (vpx_codec_dec_init(&decoder, interface->codec_interface(),
964 &cfg, dec_flags)) {
965 fprintf(stderr, "Failed to initialize decoder: %s\n",
966 vpx_codec_error(&decoder));
967 return EXIT_FAILURE;
970 if (!quiet)
971 fprintf(stderr, "%s\n", decoder.name);
973 #if CONFIG_VP8_DECODER
975 if (vp8_pp_cfg.post_proc_flag
976 && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) {
977 fprintf(stderr, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder));
978 return EXIT_FAILURE;
981 if (vp8_dbg_color_ref_frame
982 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, vp8_dbg_color_ref_frame)) {
983 fprintf(stderr, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder));
984 return EXIT_FAILURE;
987 if (vp8_dbg_color_mb_modes
988 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, vp8_dbg_color_mb_modes)) {
989 fprintf(stderr, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder));
990 return EXIT_FAILURE;
993 if (vp8_dbg_color_b_modes
994 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, vp8_dbg_color_b_modes)) {
995 fprintf(stderr, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder));
996 return EXIT_FAILURE;
999 if (vp8_dbg_display_mv
1000 && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, vp8_dbg_display_mv)) {
1001 fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder));
1002 return EXIT_FAILURE;
1004 #endif
1007 if (arg_skip)
1008 fprintf(stderr, "Skipping first %d frames.\n", arg_skip);
1009 while (arg_skip) {
1010 if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size))
1011 break;
1012 arg_skip--;
1015 if (num_external_frame_buffers > 0) {
1016 ext_fb_list.num_external_frame_buffers = num_external_frame_buffers;
1017 ext_fb_list.ext_fb = (struct ExternalFrameBuffer *)calloc(
1018 num_external_frame_buffers, sizeof(*ext_fb_list.ext_fb));
1019 if (vpx_codec_set_frame_buffer_functions(
1020 &decoder, get_vp9_frame_buffer, release_vp9_frame_buffer,
1021 &ext_fb_list)) {
1022 fprintf(stderr, "Failed to configure external frame buffers: %s\n",
1023 vpx_codec_error(&decoder));
1024 return EXIT_FAILURE;
1028 frame_avail = 1;
1029 got_data = 0;
1031 /* Decode file */
1032 while (frame_avail || got_data) {
1033 vpx_codec_iter_t iter = NULL;
1034 vpx_image_t *img;
1035 struct vpx_usec_timer timer;
1036 int corrupted;
1038 frame_avail = 0;
1039 if (!stop_after || frame_in < stop_after) {
1040 if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) {
1041 frame_avail = 1;
1042 frame_in++;
1044 vpx_usec_timer_start(&timer);
1046 if (vpx_codec_decode(&decoder, buf, (unsigned int)bytes_in_buffer,
1047 NULL, 0)) {
1048 const char *detail = vpx_codec_error_detail(&decoder);
1049 warn("Failed to decode frame %d: %s",
1050 frame_in, vpx_codec_error(&decoder));
1052 if (detail)
1053 warn("Additional information: %s", detail);
1054 if (!keep_going)
1055 goto fail;
1058 vpx_usec_timer_mark(&timer);
1059 dx_time += vpx_usec_timer_elapsed(&timer);
1063 vpx_usec_timer_start(&timer);
1065 got_data = 0;
1066 if ((img = vpx_codec_get_frame(&decoder, &iter))) {
1067 ++frame_out;
1068 got_data = 1;
1071 vpx_usec_timer_mark(&timer);
1072 dx_time += (unsigned int)vpx_usec_timer_elapsed(&timer);
1074 if (vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) {
1075 warn("Failed VP8_GET_FRAME_CORRUPTED: %s", vpx_codec_error(&decoder));
1076 goto fail;
1078 frames_corrupted += corrupted;
1080 if (progress)
1081 show_progress(frame_in, frame_out, dx_time);
1083 if (!noblit && img) {
1084 const int PLANES_YUV[] = {VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V};
1085 const int PLANES_YVU[] = {VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U};
1086 const int *planes = flipuv ? PLANES_YVU : PLANES_YUV;
1088 if (do_scale) {
1089 if (frame_out == 1) {
1090 // If the output frames are to be scaled to a fixed display size then
1091 // use the width and height specified in the container. If either of
1092 // these is set to 0, use the display size set in the first frame
1093 // header. If that is unavailable, use the raw decoded size of the
1094 // first decoded frame.
1095 int display_width = vpx_input_ctx.width;
1096 int display_height = vpx_input_ctx.height;
1097 if (!display_width || !display_height) {
1098 int display_size[2];
1099 if (vpx_codec_control(&decoder, VP9D_GET_DISPLAY_SIZE,
1100 display_size)) {
1101 // As last resort use size of first frame as display size.
1102 display_width = img->d_w;
1103 display_height = img->d_h;
1104 } else {
1105 display_width = display_size[0];
1106 display_height = display_size[1];
1109 scaled_img = vpx_img_alloc(NULL, img->fmt, display_width,
1110 display_height, 16);
1111 scaled_img->bit_depth = img->bit_depth;
1114 if (img->d_w != scaled_img->d_w || img->d_h != scaled_img->d_h) {
1115 #if CONFIG_LIBYUV
1116 vpx_image_scale(img, scaled_img, kFilterBox);
1117 img = scaled_img;
1118 #else
1119 fprintf(stderr, "Failed to scale output frame: %s.\n"
1120 "Scaling is disabled in this configuration. "
1121 "To enable scaling, configure with --enable-libyuv\n",
1122 vpx_codec_error(&decoder));
1123 return EXIT_FAILURE;
1124 #endif
1127 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
1128 // Default to codec bit depth if output bit depth not set
1129 if (!output_bit_depth) {
1130 output_bit_depth = img->bit_depth;
1132 // Shift up or down if necessary
1133 if (output_bit_depth != img->bit_depth) {
1134 if (!img_shifted) {
1135 if (output_bit_depth == 8) {
1136 img_shifted = vpx_img_alloc(
1137 NULL, img->fmt - VPX_IMG_FMT_HIGHBITDEPTH,
1138 img->d_w, img->d_h, 16);
1139 } else {
1140 img_shifted = vpx_img_alloc(
1141 NULL, img->fmt | VPX_IMG_FMT_HIGHBITDEPTH,
1142 img->d_w, img->d_h, 16);
1144 img_shifted->bit_depth = output_bit_depth;
1146 if (output_bit_depth > img->bit_depth) {
1147 img_upshift(img_shifted, img, output_bit_depth - img->bit_depth);
1148 } else {
1149 img_downshift(img_shifted, img, img->bit_depth - output_bit_depth);
1151 img = img_shifted;
1153 #endif
1155 if (single_file) {
1156 if (use_y4m) {
1157 char buf[Y4M_BUFFER_SIZE] = {0};
1158 size_t len = 0;
1159 if (frame_out == 1) {
1160 // Y4M file header
1161 len = y4m_write_file_header(buf, sizeof(buf),
1162 vpx_input_ctx.width,
1163 vpx_input_ctx.height,
1164 &vpx_input_ctx.framerate,
1165 img->fmt, img->bit_depth);
1166 if (do_md5) {
1167 MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len);
1168 } else {
1169 fputs(buf, outfile);
1173 // Y4M frame header
1174 len = y4m_write_frame_header(buf, sizeof(buf));
1175 if (do_md5) {
1176 MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len);
1177 } else {
1178 fputs(buf, outfile);
1180 } else {
1181 if (frame_out == 1) {
1182 // Check if --yv12 or --i420 options are consistent with the
1183 // bit-stream decoded
1184 if (opt_i420) {
1185 if (img->fmt != VPX_IMG_FMT_I420 &&
1186 img->fmt != VPX_IMG_FMT_I42016) {
1187 fprintf(stderr, "Cannot produce i420 output for bit-stream.\n");
1188 goto fail;
1191 if (opt_yv12) {
1192 if ((img->fmt != VPX_IMG_FMT_I420 &&
1193 img->fmt != VPX_IMG_FMT_YV12) || img->bit_depth != 8) {
1194 fprintf(stderr, "Cannot produce yv12 output for bit-stream.\n");
1195 goto fail;
1201 if (do_md5) {
1202 update_image_md5(img, planes, &md5_ctx);
1203 } else {
1204 write_image_file(img, planes, outfile);
1206 } else {
1207 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
1208 img->d_w, img->d_h, frame_in);
1209 if (do_md5) {
1210 MD5Init(&md5_ctx);
1211 update_image_md5(img, planes, &md5_ctx);
1212 MD5Final(md5_digest, &md5_ctx);
1213 print_md5(md5_digest, outfile_name);
1214 } else {
1215 outfile = open_outfile(outfile_name);
1216 write_image_file(img, planes, outfile);
1217 fclose(outfile);
1222 if (stop_after && frame_in >= stop_after)
1223 break;
1226 if (summary || progress) {
1227 show_progress(frame_in, frame_out, dx_time);
1228 fprintf(stderr, "\n");
1231 if (frames_corrupted)
1232 fprintf(stderr, "WARNING: %d frames corrupted.\n", frames_corrupted);
1234 fail:
1236 if (vpx_codec_destroy(&decoder)) {
1237 fprintf(stderr, "Failed to destroy decoder: %s\n",
1238 vpx_codec_error(&decoder));
1239 return EXIT_FAILURE;
1242 if (!noblit && single_file) {
1243 if (do_md5) {
1244 MD5Final(md5_digest, &md5_ctx);
1245 print_md5(md5_digest, outfile_name);
1246 } else {
1247 fclose(outfile);
1251 #if CONFIG_WEBM_IO
1252 if (input.vpx_input_ctx->file_type == FILE_TYPE_WEBM)
1253 webm_free(input.webm_ctx);
1254 #endif
1256 if (input.vpx_input_ctx->file_type != FILE_TYPE_WEBM)
1257 free(buf);
1259 if (scaled_img) vpx_img_free(scaled_img);
1260 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
1261 if (img_shifted) vpx_img_free(img_shifted);
1262 #endif
1264 for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) {
1265 free(ext_fb_list.ext_fb[i].data);
1267 free(ext_fb_list.ext_fb);
1269 fclose(infile);
1270 free(argv);
1272 return frames_corrupted ? EXIT_FAILURE : EXIT_SUCCESS;
1275 int main(int argc, const char **argv_) {
1276 unsigned int loops = 1, i;
1277 char **argv, **argi, **argj;
1278 struct arg arg;
1279 int error = 0;
1281 argv = argv_dup(argc - 1, argv_ + 1);
1282 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
1283 memset(&arg, 0, sizeof(arg));
1284 arg.argv_step = 1;
1286 if (arg_match(&arg, &looparg, argi)) {
1287 loops = arg_parse_uint(&arg);
1288 break;
1291 free(argv);
1292 for (i = 0; !error && i < loops; i++)
1293 error = main_loop(argc, argv_);
1294 return error;