John Koleszar | c377bf0 | 2010-11-02 09:11:57 -0400 | [diff] [blame] | 1 | /* |
Adrian Grange | ee9843d | 2016-03-24 12:08:51 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | c377bf0 | 2010-11-02 09:11:57 -0400 | [diff] [blame] | 3 | * |
Adrian Grange | ee9843d | 2016-03-24 12:08:51 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
John Koleszar | c377bf0 | 2010-11-02 09:11:57 -0400 | [diff] [blame] | 10 | */ |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 11 | #ifndef TOOLS_COMMON_H_ |
| 12 | #define TOOLS_COMMON_H_ |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | |
Adrian Grange | cebe6f0 | 2016-03-25 12:11:05 -0700 | [diff] [blame] | 16 | #include "./aom_config.h" |
| 17 | #include "aom/aom_codec.h" |
| 18 | #include "aom/aom_image.h" |
| 19 | #include "aom/aom_integer.h" |
Yaowu Xu | bf4202e | 2016-03-21 15:15:19 -0700 | [diff] [blame] | 20 | #include "aom_ports/msvc.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 21 | |
| 22 | #if CONFIG_ENCODERS |
| 23 | #include "./y4minput.h" |
| 24 | #endif |
Tom Finegan | e657919 | 2013-11-11 06:48:18 -0800 | [diff] [blame] | 25 | |
| 26 | #if defined(_MSC_VER) |
James Zern | dae4cfc | 2014-04-02 20:06:07 -0700 | [diff] [blame] | 27 | /* MSVS uses _f{seek,tell}i64. */ |
Tom Finegan | e657919 | 2013-11-11 06:48:18 -0800 | [diff] [blame] | 28 | #define fseeko _fseeki64 |
| 29 | #define ftello _ftelli64 |
| 30 | #elif defined(_WIN32) |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 31 | /* MinGW uses f{seek,tell}o64 for large files. */ |
Tom Finegan | e657919 | 2013-11-11 06:48:18 -0800 | [diff] [blame] | 32 | #define fseeko fseeko64 |
| 33 | #define ftello ftello64 |
clang-format | 99e28b8 | 2016-01-27 12:42:45 -0800 | [diff] [blame] | 34 | #endif /* _WIN32 */ |
Tom Finegan | e657919 | 2013-11-11 06:48:18 -0800 | [diff] [blame] | 35 | |
| 36 | #if CONFIG_OS_SUPPORT |
| 37 | #if defined(_MSC_VER) |
clang-format | 99e28b8 | 2016-01-27 12:42:45 -0800 | [diff] [blame] | 38 | #include <io.h> /* NOLINT */ |
| 39 | #define isatty _isatty |
| 40 | #define fileno _fileno |
Tom Finegan | e657919 | 2013-11-11 06:48:18 -0800 | [diff] [blame] | 41 | #else |
clang-format | 99e28b8 | 2016-01-27 12:42:45 -0800 | [diff] [blame] | 42 | #include <unistd.h> /* NOLINT */ |
| 43 | #endif /* _MSC_VER */ |
| 44 | #endif /* CONFIG_OS_SUPPORT */ |
Tom Finegan | e657919 | 2013-11-11 06:48:18 -0800 | [diff] [blame] | 45 | |
| 46 | /* Use 32-bit file operations in WebM file format when building ARM |
| 47 | * executables (.axf) with RVCT. */ |
| 48 | #if !CONFIG_OS_SUPPORT |
Tom Finegan | e657919 | 2013-11-11 06:48:18 -0800 | [diff] [blame] | 49 | #define fseeko fseek |
| 50 | #define ftello ftell |
clang-format | 99e28b8 | 2016-01-27 12:42:45 -0800 | [diff] [blame] | 51 | #endif /* CONFIG_OS_SUPPORT */ |
Tom Finegan | e657919 | 2013-11-11 06:48:18 -0800 | [diff] [blame] | 52 | |
| 53 | #define LITERALU64(hi, lo) ((((uint64_t)hi) << 32) | lo) |
| 54 | |
| 55 | #ifndef PATH_MAX |
| 56 | #define PATH_MAX 512 |
| 57 | #endif |
| 58 | |
clang-format | 99e28b8 | 2016-01-27 12:42:45 -0800 | [diff] [blame] | 59 | #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */ |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 60 | #define IVF_FILE_HDR_SZ 32 |
| 61 | |
| 62 | #define RAW_FRAME_HDR_SZ sizeof(uint32_t) |
| 63 | |
Adrian Grange | 80edfa0 | 2016-03-28 10:04:30 -0700 | [diff] [blame] | 64 | #define AV1_FOURCC 0x31305641 |
John Koleszar | c377bf0 | 2010-11-02 09:11:57 -0400 | [diff] [blame] | 65 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 66 | enum VideoFileType { |
| 67 | FILE_TYPE_RAW, |
| 68 | FILE_TYPE_IVF, |
| 69 | FILE_TYPE_Y4M, |
| 70 | FILE_TYPE_WEBM |
| 71 | }; |
| 72 | |
| 73 | struct FileTypeDetectionBuffer { |
| 74 | char buf[4]; |
| 75 | size_t buf_read; |
| 76 | size_t position; |
| 77 | }; |
| 78 | |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 79 | struct AvxRational { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 80 | int numerator; |
| 81 | int denominator; |
| 82 | }; |
| 83 | |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 84 | struct AvxInputContext { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 85 | const char *filename; |
| 86 | FILE *file; |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 87 | int64_t length; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 88 | struct FileTypeDetectionBuffer detect; |
| 89 | enum VideoFileType file_type; |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 90 | uint32_t width; |
| 91 | uint32_t height; |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 92 | struct AvxRational pixel_aspect_ratio; |
Adrian Grange | cebe6f0 | 2016-03-25 12:11:05 -0700 | [diff] [blame] | 93 | aom_img_fmt_t fmt; |
| 94 | aom_bit_depth_t bit_depth; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 95 | int only_i420; |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 96 | uint32_t fourcc; |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 97 | struct AvxRational framerate; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 98 | #if CONFIG_ENCODERS |
| 99 | y4m_input y4m; |
| 100 | #endif |
| 101 | }; |
| 102 | |
| 103 | #ifdef __cplusplus |
| 104 | extern "C" { |
| 105 | #endif |
| 106 | |
Jim Bankoski | e9b878c | 2014-08-21 11:43:36 -0700 | [diff] [blame] | 107 | #if defined(__GNUC__) |
Adrian Grange | ff00fc0 | 2016-03-25 12:57:08 -0700 | [diff] [blame] | 108 | #define AOM_NO_RETURN __attribute__((noreturn)) |
Jim Bankoski | e9b878c | 2014-08-21 11:43:36 -0700 | [diff] [blame] | 109 | #else |
Adrian Grange | ff00fc0 | 2016-03-25 12:57:08 -0700 | [diff] [blame] | 110 | #define AOM_NO_RETURN |
Jim Bankoski | e9b878c | 2014-08-21 11:43:36 -0700 | [diff] [blame] | 111 | #endif |
| 112 | |
John Koleszar | c377bf0 | 2010-11-02 09:11:57 -0400 | [diff] [blame] | 113 | /* Sets a stdio stream into binary mode */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 114 | FILE *set_binary_mode(FILE *stream); |
John Koleszar | c377bf0 | 2010-11-02 09:11:57 -0400 | [diff] [blame] | 115 | |
Adrian Grange | ff00fc0 | 2016-03-25 12:57:08 -0700 | [diff] [blame] | 116 | void die(const char *fmt, ...) AOM_NO_RETURN; |
| 117 | void fatal(const char *fmt, ...) AOM_NO_RETURN; |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 118 | void warn(const char *fmt, ...); |
| 119 | |
Adrian Grange | ff00fc0 | 2016-03-25 12:57:08 -0700 | [diff] [blame] | 120 | void die_codec(aom_codec_ctx_t *ctx, const char *s) AOM_NO_RETURN; |
Dmitry Kovalev | 7ec2769 | 2014-01-27 13:40:29 -0800 | [diff] [blame] | 121 | |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 122 | /* The tool including this file must define usage_exit() */ |
Adrian Grange | ff00fc0 | 2016-03-25 12:57:08 -0700 | [diff] [blame] | 123 | void usage_exit(void) AOM_NO_RETURN; |
Jim Bankoski | e9b878c | 2014-08-21 11:43:36 -0700 | [diff] [blame] | 124 | |
Adrian Grange | ff00fc0 | 2016-03-25 12:57:08 -0700 | [diff] [blame] | 125 | #undef AOM_NO_RETURN |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 126 | |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 127 | int read_yuv_frame(struct AvxInputContext *input_ctx, aom_image_t *yuv_frame); |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 128 | |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 129 | typedef struct AvxInterface { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 130 | const char *const name; |
| 131 | const uint32_t fourcc; |
Adrian Grange | cebe6f0 | 2016-03-25 12:11:05 -0700 | [diff] [blame] | 132 | aom_codec_iface_t *(*const codec_interface)(); |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 133 | } AvxInterface; |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 134 | |
Adrian Grange | cebe6f0 | 2016-03-25 12:11:05 -0700 | [diff] [blame] | 135 | int get_aom_encoder_count(void); |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 136 | const AvxInterface *get_aom_encoder_by_index(int i); |
| 137 | const AvxInterface *get_aom_encoder_by_name(const char *name); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 138 | |
Adrian Grange | cebe6f0 | 2016-03-25 12:11:05 -0700 | [diff] [blame] | 139 | int get_aom_decoder_count(void); |
Adrian Grange | 5082a36 | 2016-03-29 14:27:56 -0700 | [diff] [blame] | 140 | const AvxInterface *get_aom_decoder_by_index(int i); |
| 141 | const AvxInterface *get_aom_decoder_by_name(const char *name); |
| 142 | const AvxInterface *get_aom_decoder_by_fourcc(uint32_t fourcc); |
Dmitry Kovalev | 7ec2769 | 2014-01-27 13:40:29 -0800 | [diff] [blame] | 143 | |
Adrian Grange | cebe6f0 | 2016-03-25 12:11:05 -0700 | [diff] [blame] | 144 | // TODO(dkovalev): move this function to aom_image.{c, h}, so it will be part |
| 145 | // of aom_image_t support |
| 146 | int aom_img_plane_width(const aom_image_t *img, int plane); |
| 147 | int aom_img_plane_height(const aom_image_t *img, int plane); |
| 148 | void aom_img_write(const aom_image_t *img, FILE *file); |
| 149 | int aom_img_read(aom_image_t *img, FILE *file); |
Dmitry Kovalev | 592936b | 2014-02-07 11:37:39 -0800 | [diff] [blame] | 150 | |
Dmitry Kovalev | 2dad0e1 | 2014-02-27 14:00:41 -0800 | [diff] [blame] | 151 | double sse_to_psnr(double samples, double peak, double mse); |
| 152 | |
Yaowu Xu | 01dee0b | 2016-03-25 12:43:01 -0700 | [diff] [blame] | 153 | #if CONFIG_AOM_HIGHBITDEPTH |
Adrian Grange | cebe6f0 | 2016-03-25 12:11:05 -0700 | [diff] [blame] | 154 | void aom_img_upshift(aom_image_t *dst, aom_image_t *src, int input_shift); |
| 155 | void aom_img_downshift(aom_image_t *dst, aom_image_t *src, int down_shift); |
| 156 | void aom_img_truncate_16_to_8(aom_image_t *dst, aom_image_t *src); |
Deb Mukherjee | 7a2a611 | 2014-10-06 20:46:11 -0700 | [diff] [blame] | 157 | #endif |
| 158 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 159 | #ifdef __cplusplus |
clang-format | 99e28b8 | 2016-01-27 12:42:45 -0800 | [diff] [blame] | 160 | } /* extern "C" */ |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 161 | #endif |
| 162 | |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 163 | #endif // TOOLS_COMMON_H_ |