blob: dd1796380a77dfdc4f3c68a7d2b6152acd6db5c3 [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
John Koleszarc2140b82010-09-09 08:16:39 -04002 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
John Koleszar94c52e42010-06-18 12:39:21 -04004 * Use of this source code is governed by a BSD-style license
John Koleszar09202d82010-06-04 16:19:40 -04005 * 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 Koleszar94c52e42010-06-18 12:39:21 -04007 * in the file PATENTS. All contributing project authors may
John Koleszar09202d82010-06-04 16:19:40 -04008 * be found in the AUTHORS file in the root of the source tree.
John Koleszar0ea50ce2010-05-18 11:58:33 -04009 */
10
11
12/* This is a simple program that reads ivf files and decodes them
13 * using the new interface. Decoded frames are output as YV12 raw.
14 */
15#include <stdio.h>
16#include <stdlib.h>
17#include <stdarg.h>
18#include <string.h>
John Koleszar933d44b2010-10-21 20:40:42 -070019#include <limits.h>
20#if defined(_WIN32)
21#include <io.h>
22#define snprintf _snprintf
23#define isatty _isatty
24#define fileno _fileno
25#else
26#include <unistd.h>
27#endif
John Koleszar0ea50ce2010-05-18 11:58:33 -040028#define VPX_CODEC_DISABLE_COMPAT 1
29#include "vpx_config.h"
John Koleszarb7492342010-05-24 11:39:59 -040030#include "vpx/vpx_decoder.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040031#include "vpx_ports/vpx_timer.h"
32#if CONFIG_VP8_DECODER
John Koleszarb7492342010-05-24 11:39:59 -040033#include "vpx/vp8dx.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040034#endif
35#if CONFIG_MD5
36#include "md5_utils.h"
37#endif
John Koleszarc377bf02010-11-02 09:11:57 -040038#include "tools_common.h"
John Koleszarad252da2010-10-19 17:20:17 -040039#include "nestegg/include/nestegg/nestegg.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040040
John Koleszar933d44b2010-10-21 20:40:42 -070041#ifndef PATH_MAX
42#define PATH_MAX 256
43#endif
44
John Koleszar0ea50ce2010-05-18 11:58:33 -040045static const char *exec_name;
46
John Koleszarad252da2010-10-19 17:20:17 -040047#define VP8_FOURCC (0x00385056)
John Koleszar0ea50ce2010-05-18 11:58:33 -040048static const struct
49{
50 char const *name;
51 const vpx_codec_iface_t *iface;
52 unsigned int fourcc;
53 unsigned int fourcc_mask;
54} ifaces[] =
55{
56#if CONFIG_VP8_DECODER
John Koleszarad252da2010-10-19 17:20:17 -040057 {"vp8", &vpx_codec_vp8_dx_algo, VP8_FOURCC, 0x00FFFFFF},
John Koleszar0ea50ce2010-05-18 11:58:33 -040058#endif
59};
60
61#include "args.h"
62static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1,
63 "Codec to use");
John Koleszar0ea50ce2010-05-18 11:58:33 -040064static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0,
John Koleszar933d44b2010-10-21 20:40:42 -070065 "Output raw YV12 frames");
John Koleszar0ea50ce2010-05-18 11:58:33 -040066static const arg_def_t use_i420 = ARG_DEF(NULL, "i420", 0,
John Koleszar933d44b2010-10-21 20:40:42 -070067 "Output raw I420 frames");
John Koleszar0ea50ce2010-05-18 11:58:33 -040068static const arg_def_t flipuvarg = ARG_DEF(NULL, "flipuv", 0,
John Koleszar933d44b2010-10-21 20:40:42 -070069 "Flip the chroma planes in the output");
John Koleszar0ea50ce2010-05-18 11:58:33 -040070static const arg_def_t noblitarg = ARG_DEF(NULL, "noblit", 0,
71 "Don't process the decoded frames");
72static const arg_def_t progressarg = ARG_DEF(NULL, "progress", 0,
73 "Show progress after each frame decodes");
74static const arg_def_t limitarg = ARG_DEF(NULL, "limit", 1,
75 "Stop decoding after n frames");
76static const arg_def_t postprocarg = ARG_DEF(NULL, "postproc", 0,
77 "Postprocess decoded frames");
78static const arg_def_t summaryarg = ARG_DEF(NULL, "summary", 0,
79 "Show timing summary");
Timothy B. Terriberry7f9db412010-05-26 19:36:20 -040080static const arg_def_t outputfile = ARG_DEF("o", "output", 1,
John Koleszar933d44b2010-10-21 20:40:42 -070081 "Output file name pattern (see below)");
John Koleszar0ea50ce2010-05-18 11:58:33 -040082static const arg_def_t threadsarg = ARG_DEF("t", "threads", 1,
83 "Max threads to use");
John Koleszar4b578ea2010-10-21 20:35:12 -070084static const arg_def_t verbosearg = ARG_DEF("v", "verbose", 0,
85 "Show version string");
John Koleszar0ea50ce2010-05-18 11:58:33 -040086
87#if CONFIG_MD5
88static const arg_def_t md5arg = ARG_DEF(NULL, "md5", 0,
89 "Compute the MD5 sum of the decoded frame");
90#endif
91static const arg_def_t *all_args[] =
92{
John Koleszar933d44b2010-10-21 20:40:42 -070093 &codecarg, &use_yv12, &use_i420, &flipuvarg, &noblitarg,
John Koleszar0ea50ce2010-05-18 11:58:33 -040094 &progressarg, &limitarg, &postprocarg, &summaryarg, &outputfile,
John Koleszar933d44b2010-10-21 20:40:42 -070095 &threadsarg, &verbosearg,
John Koleszar0ea50ce2010-05-18 11:58:33 -040096#if CONFIG_MD5
97 &md5arg,
98#endif
99 NULL
100};
101
102#if CONFIG_VP8_DECODER
103static const arg_def_t addnoise_level = ARG_DEF(NULL, "noise-level", 1,
104 "Enable VP8 postproc add noise");
105static const arg_def_t deblock = ARG_DEF(NULL, "deblock", 0,
106 "Enable VP8 deblocking");
107static const arg_def_t demacroblock_level = ARG_DEF(NULL, "demacroblock-level", 1,
108 "Enable VP8 demacroblocking, w/ level");
109static const arg_def_t pp_debug_info = ARG_DEF(NULL, "pp-debug-info", 1,
110 "Enable VP8 visible debug info");
Fritz Koenig647df002010-11-04 16:03:36 -0700111static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL, "pp-dbg-ref-frame", 1,
112 "Display only selected reference frame per macro block");
113static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL, "pp-dbg-mb-modes", 1,
114 "Display only selected macro block modes");
115static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL, "pp-dbg-b-modes", 1,
116 "Display only selected block modes");
117static const arg_def_t pp_disp_mvs = ARG_DEF(NULL, "pp-dbg-mvs", 1,
118 "Draw only selected motion vectors");
John Koleszar0ea50ce2010-05-18 11:58:33 -0400119
120static const arg_def_t *vp8_pp_args[] =
121{
122 &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info,
Fritz Koenig647df002010-11-04 16:03:36 -0700123 &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs,
John Koleszar0ea50ce2010-05-18 11:58:33 -0400124 NULL
125};
126#endif
127
128static void usage_exit()
129{
130 int i;
131
132 fprintf(stderr, "Usage: %s <options> filename\n\n"
133 "Options:\n", exec_name);
134 arg_show_usage(stderr, all_args);
135#if CONFIG_VP8_DECODER
John Koleszar78f2d3e2010-10-11 09:41:14 -0400136 fprintf(stderr, "\nVP8 Postprocessing Options:\n");
John Koleszar0ea50ce2010-05-18 11:58:33 -0400137 arg_show_usage(stderr, vp8_pp_args);
138#endif
John Koleszar933d44b2010-10-21 20:40:42 -0700139 fprintf(stderr,
140 "\nOutput File Patterns:\n\n"
141 " The -o argument specifies the name of the file(s) to "
142 "write to. If the\n argument does not include any escape "
143 "characters, the output will be\n written to a single file. "
144 "Otherwise, the filename will be calculated by\n expanding "
145 "the following escape characters:\n"
146 "\n\t%%w - Frame width"
147 "\n\t%%h - Frame height"
148 "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
149 "\n\n Pattern arguments are only supported in conjunction "
150 "with the --yv12 and\n --i420 options. If the -o option is "
151 "not specified, the output will be\n directed to stdout.\n"
152 );
John Koleszar0ea50ce2010-05-18 11:58:33 -0400153 fprintf(stderr, "\nIncluded decoders:\n\n");
154
155 for (i = 0; i < sizeof(ifaces) / sizeof(ifaces[0]); i++)
156 fprintf(stderr, " %-6s - %s\n",
157 ifaces[i].name,
158 vpx_codec_iface_name(ifaces[i].iface));
159
160 exit(EXIT_FAILURE);
161}
162
163void die(const char *fmt, ...)
164{
165 va_list ap;
166 va_start(ap, fmt);
167 vfprintf(stderr, fmt, ap);
168 fprintf(stderr, "\n");
169 usage_exit();
170}
171
172static unsigned int mem_get_le16(const void *vmem)
173{
174 unsigned int val;
175 const unsigned char *mem = (const unsigned char *)vmem;
176
177 val = mem[1] << 8;
178 val |= mem[0];
179 return val;
180}
181
182static unsigned int mem_get_le32(const void *vmem)
183{
184 unsigned int val;
185 const unsigned char *mem = (const unsigned char *)vmem;
186
187 val = mem[3] << 24;
188 val |= mem[2] << 16;
189 val |= mem[1] << 8;
190 val |= mem[0];
191 return val;
192}
193
John Koleszarad252da2010-10-19 17:20:17 -0400194enum file_kind
195{
196 RAW_FILE,
197 IVF_FILE,
198 WEBM_FILE
199};
200
201struct input_ctx
202{
203 enum file_kind kind;
204 FILE *infile;
205 nestegg *nestegg_ctx;
206 nestegg_packet *pkt;
207 unsigned int chunk;
208 unsigned int chunks;
209 unsigned int video_track;
210};
211
John Koleszar0ea50ce2010-05-18 11:58:33 -0400212#define IVF_FRAME_HDR_SZ (sizeof(uint32_t) + sizeof(uint64_t))
213#define RAW_FRAME_HDR_SZ (sizeof(uint32_t))
John Koleszarad252da2010-10-19 17:20:17 -0400214static int read_frame(struct input_ctx *input,
John Koleszar0ea50ce2010-05-18 11:58:33 -0400215 uint8_t **buf,
John Koleszarad252da2010-10-19 17:20:17 -0400216 size_t *buf_sz,
217 size_t *buf_alloc_sz)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400218{
John Koleszarad252da2010-10-19 17:20:17 -0400219 char raw_hdr[IVF_FRAME_HDR_SZ];
220 size_t new_buf_sz;
221 FILE *infile = input->infile;
222 enum file_kind kind = input->kind;
223 if(kind == WEBM_FILE)
224 {
225 if(input->chunk >= input->chunks)
226 {
227 unsigned int track;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400228
John Koleszarad252da2010-10-19 17:20:17 -0400229 do
230 {
231 /* End of this packet, get another. */
232 if(input->pkt)
233 nestegg_free_packet(input->pkt);
234
235 if(nestegg_read_packet(input->nestegg_ctx, &input->pkt) <= 0
236 || nestegg_packet_track(input->pkt, &track))
237 return 1;
238
239 } while(track != input->video_track);
240
241 if(nestegg_packet_count(input->pkt, &input->chunks))
242 return 1;
243 input->chunk = 0;
244 }
245
246 if(nestegg_packet_data(input->pkt, input->chunk, buf, buf_sz))
247 return 1;
248 input->chunk++;
249
250 return 0;
251 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400252 /* For both the raw and ivf formats, the frame size is the first 4 bytes
253 * of the frame header. We just need to special case on the header
254 * size.
255 */
John Koleszarad252da2010-10-19 17:20:17 -0400256 else if (fread(raw_hdr, kind==IVF_FILE
257 ? IVF_FRAME_HDR_SZ : RAW_FRAME_HDR_SZ, 1, infile) != 1)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400258 {
259 if (!feof(infile))
260 fprintf(stderr, "Failed to read frame size\n");
261
262 new_buf_sz = 0;
263 }
264 else
265 {
266 new_buf_sz = mem_get_le32(raw_hdr);
267
268 if (new_buf_sz > 256 * 1024 * 1024)
269 {
270 fprintf(stderr, "Error: Read invalid frame size (%u)\n",
John Koleszarad252da2010-10-19 17:20:17 -0400271 (unsigned int)new_buf_sz);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400272 new_buf_sz = 0;
273 }
274
John Koleszarad252da2010-10-19 17:20:17 -0400275 if (kind == RAW_FILE && new_buf_sz > 256 * 1024)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400276 fprintf(stderr, "Warning: Read invalid frame size (%u)"
John Koleszarad252da2010-10-19 17:20:17 -0400277 " - not a raw file?\n", (unsigned int)new_buf_sz);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400278
279 if (new_buf_sz > *buf_alloc_sz)
280 {
281 uint8_t *new_buf = realloc(*buf, 2 * new_buf_sz);
282
283 if (new_buf)
284 {
285 *buf = new_buf;
286 *buf_alloc_sz = 2 * new_buf_sz;
287 }
288 else
289 {
290 fprintf(stderr, "Failed to allocate compressed data buffer\n");
291 new_buf_sz = 0;
292 }
293 }
294 }
295
296 *buf_sz = new_buf_sz;
297
298 if (*buf_sz)
299 {
300 if (fread(*buf, 1, *buf_sz, infile) != *buf_sz)
301 {
302 fprintf(stderr, "Failed to read full frame\n");
303 return 1;
304 }
305
306 return 0;
307 }
308
309 return 1;
310}
311
312void *out_open(const char *out_fn, int do_md5)
313{
314 void *out = NULL;
315
316 if (do_md5)
317 {
318#if CONFIG_MD5
Andres Mejia1856f222010-06-14 01:27:33 -0400319 MD5Context *md5_ctx = out = malloc(sizeof(MD5Context));
John Koleszar0ea50ce2010-05-18 11:58:33 -0400320 (void)out_fn;
Andres Mejia1856f222010-06-14 01:27:33 -0400321 MD5Init(md5_ctx);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400322#endif
323 }
324 else
325 {
John Koleszarc377bf02010-11-02 09:11:57 -0400326 FILE *outfile = out = strcmp("-", out_fn) ? fopen(out_fn, "wb")
327 : set_binary_mode(stdout);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400328
329 if (!outfile)
330 {
331 fprintf(stderr, "Failed to output file");
332 exit(EXIT_FAILURE);
333 }
334 }
335
336 return out;
337}
338
339void out_put(void *out, const uint8_t *buf, unsigned int len, int do_md5)
340{
341 if (do_md5)
342 {
343#if CONFIG_MD5
Andres Mejia1856f222010-06-14 01:27:33 -0400344 MD5Update(out, buf, len);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400345#endif
346 }
347 else
348 {
Timothy B. Terriberryc4d7e5e2010-10-27 16:04:02 -0700349 if(fwrite(buf, 1, len, out));
John Koleszar0ea50ce2010-05-18 11:58:33 -0400350 }
351}
352
353void out_close(void *out, const char *out_fn, int do_md5)
354{
355 if (do_md5)
356 {
357#if CONFIG_MD5
358 uint8_t md5[16];
359 int i;
360
Andres Mejia1856f222010-06-14 01:27:33 -0400361 MD5Final(md5, out);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400362 free(out);
363
364 for (i = 0; i < 16; i++)
365 printf("%02x", md5[i]);
366
367 printf(" %s\n", out_fn);
368#endif
369 }
370 else
371 {
372 fclose(out);
373 }
374}
375
Timothy B. Terriberry7f9db412010-05-26 19:36:20 -0400376unsigned int file_is_ivf(FILE *infile,
377 unsigned int *fourcc,
378 unsigned int *width,
379 unsigned int *height,
John Koleszarad252da2010-10-19 17:20:17 -0400380 unsigned int *fps_den,
381 unsigned int *fps_num)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400382{
383 char raw_hdr[32];
384 int is_ivf = 0;
385
386 if (fread(raw_hdr, 1, 32, infile) == 32)
387 {
388 if (raw_hdr[0] == 'D' && raw_hdr[1] == 'K'
389 && raw_hdr[2] == 'I' && raw_hdr[3] == 'F')
390 {
391 is_ivf = 1;
392
393 if (mem_get_le16(raw_hdr + 4) != 0)
394 fprintf(stderr, "Error: Unrecognized IVF version! This file may not"
395 " decode properly.");
396
397 *fourcc = mem_get_le32(raw_hdr + 8);
Timothy B. Terriberry7f9db412010-05-26 19:36:20 -0400398 *width = mem_get_le16(raw_hdr + 12);
399 *height = mem_get_le16(raw_hdr + 14);
John Koleszarad252da2010-10-19 17:20:17 -0400400 *fps_num = mem_get_le32(raw_hdr + 16);
401 *fps_den = mem_get_le32(raw_hdr + 20);
402
John Koleszarea68ee02010-10-21 15:02:10 -0400403 /* Some versions of vpxenc used 1/(2*fps) for the timebase, so
John Koleszarad252da2010-10-19 17:20:17 -0400404 * we can guess the framerate using only the timebase in this
405 * case. Other files would require reading ahead to guess the
406 * timebase, like we do for webm.
407 */
408 if(*fps_num < 1000)
409 {
410 /* Correct for the factor of 2 applied to the timebase in the
411 * encoder.
412 */
413 if(*fps_num&1)*fps_den<<=1;
414 else *fps_num>>=1;
415 }
416 else
417 {
418 /* Don't know FPS for sure, and don't have readahead code
419 * (yet?), so just default to 30fps.
420 */
421 *fps_num = 30;
422 *fps_den = 1;
423 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400424 }
425 }
426
427 if (!is_ivf)
428 rewind(infile);
429
430 return is_ivf;
431}
432
John Koleszarad252da2010-10-19 17:20:17 -0400433
John Koleszarcfe3f912010-10-20 10:49:12 -0400434unsigned int file_is_raw(FILE *infile,
435 unsigned int *fourcc,
436 unsigned int *width,
437 unsigned int *height,
438 unsigned int *fps_den,
439 unsigned int *fps_num)
440{
441 unsigned char buf[32];
442 int is_raw = 0;
443 vpx_codec_stream_info_t si;
444
John Koleszar19255b82010-11-23 13:40:31 -0500445 si.sz = sizeof(si);
446
John Koleszarcfe3f912010-10-20 10:49:12 -0400447 if (fread(buf, 1, 32, infile) == 32)
448 {
449 int i;
450
451 if(mem_get_le32(buf) < 256 * 1024 * 1024)
452 for (i = 0; i < sizeof(ifaces) / sizeof(ifaces[0]); i++)
453 if(!vpx_codec_peek_stream_info(ifaces[i].iface,
454 buf + 4, 32 - 4, &si))
455 {
456 is_raw = 1;
457 *fourcc = ifaces[i].fourcc;
458 *width = si.w;
459 *height = si.h;
460 *fps_num = 30;
461 *fps_den = 1;
462 break;
463 }
464 }
465
466 rewind(infile);
467 return is_raw;
468}
469
470
John Koleszarad252da2010-10-19 17:20:17 -0400471static int
472nestegg_read_cb(void *buffer, size_t length, void *userdata)
473{
474 FILE *f = userdata;
475
Timothy B. Terriberryc4d7e5e2010-10-27 16:04:02 -0700476 if(fread(buffer, 1, length, f) < length)
477 {
478 if (ferror(f))
479 return -1;
480 if (feof(f))
481 return 0;
482 }
John Koleszarad252da2010-10-19 17:20:17 -0400483 return 1;
484}
485
486
487static int
488nestegg_seek_cb(int64_t offset, int whence, void * userdata)
489{
490 switch(whence) {
491 case NESTEGG_SEEK_SET: whence = SEEK_SET; break;
492 case NESTEGG_SEEK_CUR: whence = SEEK_CUR; break;
493 case NESTEGG_SEEK_END: whence = SEEK_END; break;
494 };
495 return fseek(userdata, offset, whence)? -1 : 0;
496}
497
498
499static int64_t
500nestegg_tell_cb(void * userdata)
501{
502 return ftell(userdata);
503}
504
505
506static void
507nestegg_log_cb(nestegg * context, unsigned int severity, char const * format,
508 ...)
509{
510 va_list ap;
511
512 va_start(ap, format);
513 vfprintf(stderr, format, ap);
514 fprintf(stderr, "\n");
515 va_end(ap);
516}
517
518
519static int
520webm_guess_framerate(struct input_ctx *input,
521 unsigned int *fps_den,
522 unsigned int *fps_num)
523{
524 unsigned int i;
525 uint64_t tstamp=0;
526
527 /* Guess the framerate. Read up to 1 second, or 50 video packets,
528 * whichever comes first.
529 */
530 for(i=0; tstamp < 1000000000 && i < 50;)
531 {
532 nestegg_packet * pkt;
533 unsigned int track;
534
535 if(nestegg_read_packet(input->nestegg_ctx, &pkt) <= 0)
536 break;
537
538 nestegg_packet_track(pkt, &track);
539 if(track == input->video_track)
540 {
541 nestegg_packet_tstamp(pkt, &tstamp);
542 i++;
543 }
544
545 nestegg_free_packet(pkt);
546 }
547
548 if(nestegg_track_seek(input->nestegg_ctx, input->video_track, 0))
549 goto fail;
550
551 *fps_num = (i - 1) * 1000000;
552 *fps_den = tstamp / 1000;
553 return 0;
554fail:
John Koleszarbd05d9e2010-11-04 14:54:51 -0400555 nestegg_destroy(input->nestegg_ctx);
John Koleszarad252da2010-10-19 17:20:17 -0400556 input->nestegg_ctx = NULL;
557 rewind(input->infile);
558 return 1;
559}
560
561
562static int
563file_is_webm(struct input_ctx *input,
564 unsigned int *fourcc,
565 unsigned int *width,
566 unsigned int *height,
567 unsigned int *fps_den,
568 unsigned int *fps_num)
569{
570 unsigned int i, n;
571 int track_type = -1;
572 uint64_t tstamp=0;
573
574 nestegg_io io = {nestegg_read_cb, nestegg_seek_cb, nestegg_tell_cb,
575 input->infile};
576 nestegg_video_params params;
577 nestegg_packet * pkt;
578
579 if(nestegg_init(&input->nestegg_ctx, io, NULL))
580 goto fail;
581
582 if(nestegg_track_count(input->nestegg_ctx, &n))
583 goto fail;
584
585 for(i=0; i<n; i++)
586 {
587 track_type = nestegg_track_type(input->nestegg_ctx, i);
588
589 if(track_type == NESTEGG_TRACK_VIDEO)
590 break;
591 else if(track_type < 0)
592 goto fail;
593 }
594
595 if(nestegg_track_codec_id(input->nestegg_ctx, i) != NESTEGG_CODEC_VP8)
596 {
597 fprintf(stderr, "Not VP8 video, quitting.\n");
598 exit(1);
599 }
600
601 input->video_track = i;
602
603 if(nestegg_track_video_params(input->nestegg_ctx, i, &params))
604 goto fail;
605
606 *fps_den = 0;
607 *fps_num = 0;
608 *fourcc = VP8_FOURCC;
609 *width = params.width;
610 *height = params.height;
611 return 1;
612fail:
613 input->nestegg_ctx = NULL;
614 rewind(input->infile);
615 return 0;
616}
617
John Koleszar5d12e042010-10-21 17:28:34 -0400618
619void show_progress(int frame_in, int frame_out, unsigned long dx_time)
620{
621 fprintf(stderr, "%d decoded frames/%d showed frames in %lu us (%.2f fps)\r",
622 frame_in, frame_out, dx_time,
623 (float)frame_out * 1000000.0 / (float)dx_time);
624}
625
626
John Koleszar933d44b2010-10-21 20:40:42 -0700627void generate_filename(const char *pattern, char *out, size_t q_len,
628 unsigned int d_w, unsigned int d_h,
629 unsigned int frame_in)
630{
631 const char *p = pattern;
632 char *q = out;
633
634 do
635 {
636 char *next_pat = strchr(p, '%');
637
638 if(p == next_pat)
639 {
640 size_t pat_len;
641
642 // parse the pattern
643 q[q_len - 1] = '\0';
644 switch(p[1])
645 {
646 case 'w': snprintf(q, q_len - 1, "%d", d_w); break;
647 case 'h': snprintf(q, q_len - 1, "%d", d_h); break;
648 case '1': snprintf(q, q_len - 1, "%d", frame_in); break;
649 case '2': snprintf(q, q_len - 1, "%02d", frame_in); break;
650 case '3': snprintf(q, q_len - 1, "%03d", frame_in); break;
651 case '4': snprintf(q, q_len - 1, "%04d", frame_in); break;
652 case '5': snprintf(q, q_len - 1, "%05d", frame_in); break;
653 case '6': snprintf(q, q_len - 1, "%06d", frame_in); break;
654 case '7': snprintf(q, q_len - 1, "%07d", frame_in); break;
655 case '8': snprintf(q, q_len - 1, "%08d", frame_in); break;
656 case '9': snprintf(q, q_len - 1, "%09d", frame_in); break;
657 default:
658 die("Unrecognized pattern %%%c\n", p[1]);
659 }
660
661 pat_len = strlen(q);
662 if(pat_len >= q_len - 1)
663 die("Output filename too long.\n");
664 q += pat_len;
665 p += 2;
666 q_len -= pat_len;
667 }
668 else
669 {
670 size_t copy_len;
671
672 // copy the next segment
673 if(!next_pat)
674 copy_len = strlen(p);
675 else
676 copy_len = next_pat - p;
677
678 if(copy_len >= q_len - 1)
679 die("Output filename too long.\n");
680
681 memcpy(q, p, copy_len);
682 q[copy_len] = '\0';
683 q += copy_len;
684 p += copy_len;
685 q_len -= copy_len;
686 }
687 } while(*p);
688}
689
690
John Koleszar0ea50ce2010-05-18 11:58:33 -0400691int main(int argc, const char **argv_)
692{
693 vpx_codec_ctx_t decoder;
John Koleszar933d44b2010-10-21 20:40:42 -0700694 char *fn = NULL;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400695 int i;
696 uint8_t *buf = NULL;
John Koleszarad252da2010-10-19 17:20:17 -0400697 size_t buf_sz = 0, buf_alloc_sz = 0;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400698 FILE *infile;
699 int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0, do_md5 = 0, progress = 0;
John Koleszar4b578ea2010-10-21 20:35:12 -0700700 int stop_after = 0, postproc = 0, summary = 0, quiet = 1;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400701 vpx_codec_iface_t *iface = NULL;
John Koleszarad252da2010-10-19 17:20:17 -0400702 unsigned int fourcc;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400703 unsigned long dx_time = 0;
704 struct arg arg;
705 char **argv, **argi, **argj;
John Koleszar933d44b2010-10-21 20:40:42 -0700706 const char *outfile_pattern = 0;
707 char outfile[PATH_MAX];
708 int single_file;
709 int use_y4m = 1;
Timothy B. Terriberry7f9db412010-05-26 19:36:20 -0400710 unsigned int width;
711 unsigned int height;
John Koleszarad252da2010-10-19 17:20:17 -0400712 unsigned int fps_den;
713 unsigned int fps_num;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400714 void *out = NULL;
715 vpx_codec_dec_cfg_t cfg = {0};
716#if CONFIG_VP8_DECODER
717 vp8_postproc_cfg_t vp8_pp_cfg = {0};
Fritz Koenig647df002010-11-04 16:03:36 -0700718 int vp8_dbg_color_ref_frame = 0;
719 int vp8_dbg_color_mb_modes = 0;
720 int vp8_dbg_color_b_modes = 0;
721 int vp8_dbg_display_mv = 0;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400722#endif
John Koleszarad252da2010-10-19 17:20:17 -0400723 struct input_ctx input = {0};
John Koleszar0ea50ce2010-05-18 11:58:33 -0400724
725 /* Parse command line */
726 exec_name = argv_[0];
727 argv = argv_dup(argc - 1, argv_ + 1);
728
729 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step)
730 {
731 memset(&arg, 0, sizeof(arg));
732 arg.argv_step = 1;
733
734 if (arg_match(&arg, &codecarg, argi))
735 {
736 int j, k = -1;
737
738 for (j = 0; j < sizeof(ifaces) / sizeof(ifaces[0]); j++)
739 if (!strcmp(ifaces[j].name, arg.val))
740 k = j;
741
742 if (k >= 0)
743 iface = ifaces[k].iface;
744 else
745 die("Error: Unrecognized argument (%s) to --codec\n",
746 arg.val);
747 }
748 else if (arg_match(&arg, &outputfile, argi))
John Koleszar933d44b2010-10-21 20:40:42 -0700749 outfile_pattern = arg.val;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400750 else if (arg_match(&arg, &use_yv12, argi))
John Koleszar933d44b2010-10-21 20:40:42 -0700751 {
752 use_y4m = 0;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400753 flipuv = 1;
John Koleszar933d44b2010-10-21 20:40:42 -0700754 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400755 else if (arg_match(&arg, &use_i420, argi))
John Koleszar933d44b2010-10-21 20:40:42 -0700756 {
757 use_y4m = 0;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400758 flipuv = 0;
John Koleszar933d44b2010-10-21 20:40:42 -0700759 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400760 else if (arg_match(&arg, &flipuvarg, argi))
761 flipuv = 1;
762 else if (arg_match(&arg, &noblitarg, argi))
763 noblit = 1;
764 else if (arg_match(&arg, &progressarg, argi))
765 progress = 1;
766 else if (arg_match(&arg, &limitarg, argi))
767 stop_after = arg_parse_uint(&arg);
768 else if (arg_match(&arg, &postprocarg, argi))
769 postproc = 1;
770 else if (arg_match(&arg, &md5arg, argi))
771 do_md5 = 1;
772 else if (arg_match(&arg, &summaryarg, argi))
773 summary = 1;
774 else if (arg_match(&arg, &threadsarg, argi))
775 cfg.threads = arg_parse_uint(&arg);
John Koleszar4b578ea2010-10-21 20:35:12 -0700776 else if (arg_match(&arg, &verbosearg, argi))
777 quiet = 0;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400778
779#if CONFIG_VP8_DECODER
780 else if (arg_match(&arg, &addnoise_level, argi))
781 {
782 postproc = 1;
783 vp8_pp_cfg.post_proc_flag |= VP8_ADDNOISE;
784 vp8_pp_cfg.noise_level = arg_parse_uint(&arg);
785 }
786 else if (arg_match(&arg, &demacroblock_level, argi))
787 {
788 postproc = 1;
789 vp8_pp_cfg.post_proc_flag |= VP8_DEMACROBLOCK;
790 vp8_pp_cfg.deblocking_level = arg_parse_uint(&arg);
791 }
792 else if (arg_match(&arg, &deblock, argi))
793 {
794 postproc = 1;
795 vp8_pp_cfg.post_proc_flag |= VP8_DEBLOCK;
796 }
797 else if (arg_match(&arg, &pp_debug_info, argi))
798 {
799 unsigned int level = arg_parse_uint(&arg);
800
801 postproc = 1;
802 vp8_pp_cfg.post_proc_flag &= ~0x7;
803
804 if (level)
Fritz Koenigcf127472010-10-26 13:26:17 -0700805 vp8_pp_cfg.post_proc_flag |= level;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400806 }
Fritz Koenig647df002010-11-04 16:03:36 -0700807 else if (arg_match(&arg, &pp_disp_ref_frame, argi))
808 {
809 unsigned int flags = arg_parse_int(&arg);
810 if (flags)
811 {
812 postproc = 1;
813 vp8_dbg_color_ref_frame = flags;
814 }
815 }
816 else if (arg_match(&arg, &pp_disp_mb_modes, argi))
817 {
818 unsigned int flags = arg_parse_int(&arg);
819 if (flags)
820 {
821 postproc = 1;
822 vp8_dbg_color_mb_modes = flags;
823 }
824 }
825 else if (arg_match(&arg, &pp_disp_b_modes, argi))
826 {
827 unsigned int flags = arg_parse_int(&arg);
828 if (flags)
829 {
830 postproc = 1;
831 vp8_dbg_color_b_modes = flags;
832 }
833 }
834 else if (arg_match(&arg, &pp_disp_mvs, argi))
835 {
836 unsigned int flags = arg_parse_int(&arg);
837 if (flags)
838 {
839 postproc = 1;
840 vp8_dbg_display_mv = flags;
841 }
842 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400843
844#endif
845 else
846 argj++;
847 }
848
849 /* Check for unrecognized options */
850 for (argi = argv; *argi; argi++)
851 if (argi[0][0] == '-' && strlen(argi[0]) > 1)
852 die("Error: Unrecognized option %s\n", *argi);
853
854 /* Handle non-option arguments */
855 fn = argv[0];
856
857 if (!fn)
858 usage_exit();
859
John Koleszar0ea50ce2010-05-18 11:58:33 -0400860 /* Open file */
John Koleszarc377bf02010-11-02 09:11:57 -0400861 infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400862
863 if (!infile)
864 {
John Koleszar933d44b2010-10-21 20:40:42 -0700865 fprintf(stderr, "Failed to open file '%s'",
866 strcmp(fn, "-") ? fn : "stdin");
John Koleszar0ea50ce2010-05-18 11:58:33 -0400867 return EXIT_FAILURE;
868 }
869
John Koleszar933d44b2010-10-21 20:40:42 -0700870 /* Make sure we don't dump to the terminal, unless forced to with -o - */
John Koleszar24c86052010-10-27 10:08:17 -0400871 if(!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit)
John Koleszar933d44b2010-10-21 20:40:42 -0700872 {
873 fprintf(stderr,
874 "Not dumping raw video to your terminal. Use '-o -' to "
875 "override.\n");
876 return EXIT_FAILURE;
877 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400878
John Koleszarad252da2010-10-19 17:20:17 -0400879 input.infile = infile;
880 if(file_is_ivf(infile, &fourcc, &width, &height, &fps_den,
881 &fps_num))
882 input.kind = IVF_FILE;
John Koleszarcfe3f912010-10-20 10:49:12 -0400883 else if(file_is_webm(&input, &fourcc, &width, &height, &fps_den, &fps_num))
John Koleszarad252da2010-10-19 17:20:17 -0400884 input.kind = WEBM_FILE;
John Koleszarcfe3f912010-10-20 10:49:12 -0400885 else if(file_is_raw(infile, &fourcc, &width, &height, &fps_den, &fps_num))
John Koleszarad252da2010-10-19 17:20:17 -0400886 input.kind = RAW_FILE;
John Koleszarcfe3f912010-10-20 10:49:12 -0400887 else
John Koleszar0ea50ce2010-05-18 11:58:33 -0400888 {
John Koleszarcfe3f912010-10-20 10:49:12 -0400889 fprintf(stderr, "Unrecognized input file type.\n");
Timothy B. Terriberry7f9db412010-05-26 19:36:20 -0400890 return EXIT_FAILURE;
891 }
John Koleszar0ea50ce2010-05-18 11:58:33 -0400892
John Koleszar933d44b2010-10-21 20:40:42 -0700893 /* If the output file is not set or doesn't have a sequence number in
894 * it, then we only open it once.
895 */
896 outfile_pattern = outfile_pattern ? outfile_pattern : "-";
897 single_file = 1;
898 {
899 const char *p = outfile_pattern;
900 do
901 {
902 p = strchr(p, '%');
903 if(p && p[1] >= '1' && p[1] <= '9')
904 {
905 // pattern contains sequence number, so it's not unique.
906 single_file = 0;
907 break;
908 }
909 if(p)
910 p++;
911 } while(p);
912 }
913
914 if(single_file && !noblit)
915 {
916 generate_filename(outfile_pattern, outfile, sizeof(outfile)-1,
917 width, height, 0);
918 out = out_open(outfile, do_md5);
919 }
920
921 if (use_y4m && !noblit)
John Koleszarcfe3f912010-10-20 10:49:12 -0400922 {
923 char buffer[128];
John Koleszar933d44b2010-10-21 20:40:42 -0700924 if (!single_file)
John Koleszarcfe3f912010-10-20 10:49:12 -0400925 {
John Koleszar933d44b2010-10-21 20:40:42 -0700926 fprintf(stderr, "YUV4MPEG2 not supported with output patterns,"
927 " try --i420 or --yv12.\n");
John Koleszarcfe3f912010-10-20 10:49:12 -0400928 return EXIT_FAILURE;
929 }
930
931 if(input.kind == WEBM_FILE)
John Koleszarbd05d9e2010-11-04 14:54:51 -0400932 if(webm_guess_framerate(&input, &fps_den, &fps_num))
933 {
934 fprintf(stderr, "Failed to guess framerate -- error parsing "
935 "webm file?\n");
936 return EXIT_FAILURE;
937 }
938
John Koleszarcfe3f912010-10-20 10:49:12 -0400939
940 /*Note: We can't output an aspect ratio here because IVF doesn't
941 store one, and neither does VP8.
942 That will have to wait until these tools support WebM natively.*/
943 sprintf(buffer, "YUV4MPEG2 C%s W%u H%u F%u:%u I%c\n",
944 "420jpeg", width, height, fps_num, fps_den, 'p');
945 out_put(out, (unsigned char *)buffer, strlen(buffer), do_md5);
946 }
947
948 /* Try to determine the codec from the fourcc. */
949 for (i = 0; i < sizeof(ifaces) / sizeof(ifaces[0]); i++)
950 if ((fourcc & ifaces[i].fourcc_mask) == ifaces[i].fourcc)
951 {
952 vpx_codec_iface_t *ivf_iface = ifaces[i].iface;
953
954 if (iface && iface != ivf_iface)
955 fprintf(stderr, "Notice -- IVF header indicates codec: %s\n",
956 ifaces[i].name);
957 else
958 iface = ivf_iface;
959
960 break;
961 }
962
John Koleszar0ea50ce2010-05-18 11:58:33 -0400963 if (vpx_codec_dec_init(&decoder, iface ? iface : ifaces[0].iface, &cfg,
964 postproc ? VPX_CODEC_USE_POSTPROC : 0))
965 {
966 fprintf(stderr, "Failed to initialize decoder: %s\n", vpx_codec_error(&decoder));
967 return EXIT_FAILURE;
968 }
969
970 if (!quiet)
971 fprintf(stderr, "%s\n", decoder.name);
972
973#if CONFIG_VP8_DECODER
974
975 if (vp8_pp_cfg.post_proc_flag
976 && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg))
977 {
978 fprintf(stderr, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder));
979 return EXIT_FAILURE;
980 }
981
Fritz Koenig647df002010-11-04 16:03:36 -0700982 if (vp8_dbg_color_ref_frame
983 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, vp8_dbg_color_ref_frame))
984 {
985 fprintf(stderr, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder));
986 return EXIT_FAILURE;
987 }
988
989 if (vp8_dbg_color_mb_modes
990 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, vp8_dbg_color_mb_modes))
991 {
992 fprintf(stderr, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder));
993 return EXIT_FAILURE;
994 }
995
996 if (vp8_dbg_color_b_modes
997 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, vp8_dbg_color_b_modes))
998 {
999 fprintf(stderr, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder));
1000 return EXIT_FAILURE;
1001 }
1002
1003 if (vp8_dbg_display_mv
1004 && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, vp8_dbg_display_mv))
1005 {
1006 fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder));
1007 return EXIT_FAILURE;
1008 }
John Koleszar0ea50ce2010-05-18 11:58:33 -04001009#endif
1010
1011 /* Decode file */
John Koleszarad252da2010-10-19 17:20:17 -04001012 while (!read_frame(&input, &buf, &buf_sz, &buf_alloc_sz))
John Koleszar0ea50ce2010-05-18 11:58:33 -04001013 {
1014 vpx_codec_iter_t iter = NULL;
1015 vpx_image_t *img;
1016 struct vpx_usec_timer timer;
1017
1018 vpx_usec_timer_start(&timer);
1019
1020 if (vpx_codec_decode(&decoder, buf, buf_sz, NULL, 0))
1021 {
1022 const char *detail = vpx_codec_error_detail(&decoder);
1023 fprintf(stderr, "Failed to decode frame: %s\n", vpx_codec_error(&decoder));
1024
1025 if (detail)
1026 fprintf(stderr, " Additional information: %s\n", detail);
1027
1028 goto fail;
1029 }
1030
1031 vpx_usec_timer_mark(&timer);
1032 dx_time += vpx_usec_timer_elapsed(&timer);
1033
1034 ++frame_in;
1035
John Koleszar0ea50ce2010-05-18 11:58:33 -04001036 if ((img = vpx_codec_get_frame(&decoder, &iter)))
1037 ++frame_out;
1038
John Koleszar5d12e042010-10-21 17:28:34 -04001039 if (progress)
1040 show_progress(frame_in, frame_out, dx_time);
1041
John Koleszar0ea50ce2010-05-18 11:58:33 -04001042 if (!noblit)
1043 {
1044 if (img)
1045 {
1046 unsigned int y;
John Koleszar933d44b2010-10-21 20:40:42 -07001047 char out_fn[PATH_MAX];
John Koleszar0ea50ce2010-05-18 11:58:33 -04001048 uint8_t *buf;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001049
John Koleszar933d44b2010-10-21 20:40:42 -07001050 if (!single_file)
John Koleszar0ea50ce2010-05-18 11:58:33 -04001051 {
John Koleszar933d44b2010-10-21 20:40:42 -07001052 size_t len = sizeof(out_fn)-1;
1053
1054 out_fn[len] = '\0';
1055 generate_filename(outfile_pattern, out_fn, len-1,
1056 img->d_w, img->d_h, frame_in);
John Koleszar0ea50ce2010-05-18 11:58:33 -04001057 out = out_open(out_fn, do_md5);
1058 }
Timothy B. Terriberry7f9db412010-05-26 19:36:20 -04001059 else if(use_y4m)
1060 out_put(out, (unsigned char *)"FRAME\n", 6, do_md5);
John Koleszar0ea50ce2010-05-18 11:58:33 -04001061
John Koleszarb6c71912010-05-24 21:45:05 -04001062 buf = img->planes[VPX_PLANE_Y];
John Koleszar0ea50ce2010-05-18 11:58:33 -04001063
1064 for (y = 0; y < img->d_h; y++)
1065 {
1066 out_put(out, buf, img->d_w, do_md5);
John Koleszarb6c71912010-05-24 21:45:05 -04001067 buf += img->stride[VPX_PLANE_Y];
John Koleszar0ea50ce2010-05-18 11:58:33 -04001068 }
1069
John Koleszarb6c71912010-05-24 21:45:05 -04001070 buf = img->planes[flipuv?VPX_PLANE_V:VPX_PLANE_U];
John Koleszar0ea50ce2010-05-18 11:58:33 -04001071
1072 for (y = 0; y < (1 + img->d_h) / 2; y++)
1073 {
1074 out_put(out, buf, (1 + img->d_w) / 2, do_md5);
John Koleszarb6c71912010-05-24 21:45:05 -04001075 buf += img->stride[VPX_PLANE_U];
John Koleszar0ea50ce2010-05-18 11:58:33 -04001076 }
1077
John Koleszarb6c71912010-05-24 21:45:05 -04001078 buf = img->planes[flipuv?VPX_PLANE_U:VPX_PLANE_V];
John Koleszar0ea50ce2010-05-18 11:58:33 -04001079
1080 for (y = 0; y < (1 + img->d_h) / 2; y++)
1081 {
1082 out_put(out, buf, (1 + img->d_w) / 2, do_md5);
John Koleszarb6c71912010-05-24 21:45:05 -04001083 buf += img->stride[VPX_PLANE_V];
John Koleszar0ea50ce2010-05-18 11:58:33 -04001084 }
1085
John Koleszar933d44b2010-10-21 20:40:42 -07001086 if (!single_file)
John Koleszar0ea50ce2010-05-18 11:58:33 -04001087 out_close(out, out_fn, do_md5);
1088 }
1089 }
1090
1091 if (stop_after && frame_in >= stop_after)
1092 break;
1093 }
1094
John Koleszar5d12e042010-10-21 17:28:34 -04001095 if (summary || progress)
John Koleszar0ea50ce2010-05-18 11:58:33 -04001096 {
John Koleszar5d12e042010-10-21 17:28:34 -04001097 show_progress(frame_in, frame_out, dx_time);
1098 fprintf(stderr, "\n");
John Koleszar0ea50ce2010-05-18 11:58:33 -04001099 }
1100
1101fail:
1102
1103 if (vpx_codec_destroy(&decoder))
1104 {
1105 fprintf(stderr, "Failed to destroy decoder: %s\n", vpx_codec_error(&decoder));
1106 return EXIT_FAILURE;
1107 }
1108
John Koleszar933d44b2010-10-21 20:40:42 -07001109 if (single_file && !noblit)
1110 out_close(out, outfile, do_md5);
John Koleszar0ea50ce2010-05-18 11:58:33 -04001111
John Koleszarad252da2010-10-19 17:20:17 -04001112 if(input.nestegg_ctx)
1113 nestegg_destroy(input.nestegg_ctx);
1114 if(input.kind != WEBM_FILE)
1115 free(buf);
John Koleszar0ea50ce2010-05-18 11:58:33 -04001116 fclose(infile);
John Koleszar0ea50ce2010-05-18 11:58:33 -04001117 free(argv);
1118
1119 return EXIT_SUCCESS;
1120}