2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
11 #ifndef TOOLS_COMMON_H_
12 #define TOOLS_COMMON_H_
16 #include "./aom_config.h"
17 #include "aom/aom_codec.h"
18 #include "aom/aom_image.h"
19 #include "aom/aom_integer.h"
20 #include "aom_ports/msvc.h"
22 #if CONFIG_AV1_ENCODER
23 #include "./y4minput.h"
27 /* MSVS uses _f{seek,tell}i64. */
28 #define fseeko _fseeki64
29 #define ftello _ftelli64
30 typedef int64_t FileOffset
;
32 #include <sys/types.h> /* NOLINT*/
33 /* MinGW uses f{seek,tell}o64 for large files. */
34 #define fseeko fseeko64
35 #define ftello ftello64
36 typedef off64_t FileOffset
;
37 #elif CONFIG_OS_SUPPORT
38 #include <sys/types.h> /* NOLINT*/
39 typedef off_t FileOffset
;
40 /* Use 32-bit file operations in WebM file format when building ARM
41 * executables (.axf) with RVCT. */
45 typedef long FileOffset
; /* NOLINT */
46 #endif /* CONFIG_OS_SUPPORT */
50 #include <io.h> /* NOLINT */
51 #define isatty _isatty
52 #define fileno _fileno
54 #include <unistd.h> /* NOLINT */
56 #endif /* CONFIG_OS_SUPPORT */
58 #define LITERALU64(hi, lo) ((((uint64_t)hi) << 32) | lo)
64 #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */
65 #define IVF_FILE_HDR_SZ 32
67 #define RAW_FRAME_HDR_SZ sizeof(uint32_t)
69 #define AV1_FOURCC 0x31305641
81 struct FileTypeDetectionBuffer
{
92 struct AvxInputContext
{
96 struct FileTypeDetectionBuffer detect
;
97 enum VideoFileType file_type
;
100 struct AvxRational pixel_aspect_ratio
;
102 aom_bit_depth_t bit_depth
;
105 struct AvxRational framerate
;
106 #if CONFIG_AV1_ENCODER
115 #if defined(__GNUC__)
116 #define AOM_NO_RETURN __attribute__((noreturn))
118 #define AOM_NO_RETURN
121 /* Sets a stdio stream into binary mode */
122 FILE *set_binary_mode(FILE *stream
);
124 void die(const char *fmt
, ...) AOM_NO_RETURN
;
125 void fatal(const char *fmt
, ...) AOM_NO_RETURN
;
126 void warn(const char *fmt
, ...);
128 void die_codec(aom_codec_ctx_t
*ctx
, const char *s
) AOM_NO_RETURN
;
130 /* The tool including this file must define usage_exit() */
131 void usage_exit(void) AOM_NO_RETURN
;
135 int read_yuv_frame(struct AvxInputContext
*input_ctx
, aom_image_t
*yuv_frame
);
137 typedef struct AvxInterface
{
138 const char *const name
;
139 const uint32_t fourcc
;
140 aom_codec_iface_t
*(*const codec_interface
)();
143 int get_aom_encoder_count(void);
144 const AvxInterface
*get_aom_encoder_by_index(int i
);
145 const AvxInterface
*get_aom_encoder_by_name(const char *name
);
147 int get_aom_decoder_count(void);
148 const AvxInterface
*get_aom_decoder_by_index(int i
);
149 const AvxInterface
*get_aom_decoder_by_name(const char *name
);
150 const AvxInterface
*get_aom_decoder_by_fourcc(uint32_t fourcc
);
152 void aom_img_write(const aom_image_t
*img
, FILE *file
);
153 int aom_img_read(aom_image_t
*img
, FILE *file
);
155 double sse_to_psnr(double samples
, double peak
, double mse
);
156 void aom_img_upshift(aom_image_t
*dst
, aom_image_t
*src
, int input_shift
);
157 void aom_img_downshift(aom_image_t
*dst
, aom_image_t
*src
, int down_shift
);
158 void aom_img_truncate_16_to_8(aom_image_t
*dst
, aom_image_t
*src
);
164 #endif // TOOLS_COMMON_H_