• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
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.
10  */
11 #ifndef AOM_COMMON_TOOLS_COMMON_H_
12 #define AOM_COMMON_TOOLS_COMMON_H_
13 
14 #include <stdio.h>
15 
16 #include "config/aom_config.h"
17 
18 #include "aom/aom_codec.h"
19 #include "aom/aom_image.h"
20 #include "aom/aom_integer.h"
21 #include "aom_ports/mem.h"
22 #include "aom_ports/msvc.h"
23 
24 #if CONFIG_AV1_ENCODER
25 #include "common/y4minput.h"
26 #endif
27 
28 #if defined(_MSC_VER)
29 /* MSVS uses _f{seek,tell}i64. */
30 #define fseeko _fseeki64
31 #define ftello _ftelli64
32 typedef int64_t FileOffset;
33 #elif defined(_WIN32)
34 #include <sys/types.h> /* NOLINT*/
35 /* MinGW uses f{seek,tell}o64 for large files. */
36 #define fseeko fseeko64
37 #define ftello ftello64
38 typedef off64_t FileOffset;
39 #elif CONFIG_OS_SUPPORT
40 #include <sys/types.h> /* NOLINT*/
41 typedef off_t FileOffset;
42 /* Use 32-bit file operations in WebM file format when building ARM
43  * executables (.axf) with RVCT. */
44 #else
45 #define fseeko fseek
46 #define ftello ftell
47 typedef long FileOffset; /* NOLINT */
48 #endif /* CONFIG_OS_SUPPORT */
49 
50 #if CONFIG_OS_SUPPORT
51 #if defined(_MSC_VER)
52 #include <io.h> /* NOLINT */
53 #define isatty _isatty
54 #define fileno _fileno
55 #else
56 #include <unistd.h> /* NOLINT */
57 #endif              /* _MSC_VER */
58 #endif              /* CONFIG_OS_SUPPORT */
59 
60 #define LITERALU64(hi, lo) ((((uint64_t)hi) << 32) | lo)
61 
62 #ifndef PATH_MAX
63 #define PATH_MAX 512
64 #endif
65 
66 #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */
67 #define IVF_FILE_HDR_SZ 32
68 
69 #define RAW_FRAME_HDR_SZ sizeof(uint32_t)
70 
71 #define AV1_FOURCC 0x31305641
72 
73 enum VideoFileType {
74   FILE_TYPE_OBU,
75   FILE_TYPE_RAW,
76   FILE_TYPE_IVF,
77   FILE_TYPE_Y4M,
78   FILE_TYPE_WEBM
79 };
80 
81 // Used in lightfield example.
82 enum {
83   YUV1D,  // 1D tile output for conformance test.
84   YUV,    // Tile output in YUV format.
85   NV12,   // Tile output in NV12 format.
86 } UENUM1BYTE(OUTPUT_FORMAT);
87 
88 // The fourcc for large_scale_tile encoding is "LSTC".
89 #define LST_FOURCC 0x4354534c
90 
91 struct FileTypeDetectionBuffer {
92   char buf[4];
93   size_t buf_read;
94   size_t position;
95 };
96 
97 struct AvxRational {
98   int numerator;
99   int denominator;
100 };
101 
102 struct AvxInputContext {
103   const char *filename;
104   FILE *file;
105   int64_t length;
106   struct FileTypeDetectionBuffer detect;
107   enum VideoFileType file_type;
108   uint32_t width;
109   uint32_t height;
110   struct AvxRational pixel_aspect_ratio;
111   aom_img_fmt_t fmt;
112   aom_bit_depth_t bit_depth;
113   int only_i420;
114   uint32_t fourcc;
115   struct AvxRational framerate;
116 #if CONFIG_AV1_ENCODER
117   y4m_input y4m;
118 #endif
119 };
120 
121 #ifdef __cplusplus
122 extern "C" {
123 #endif
124 
125 #if defined(__GNUC__)
126 #define AOM_NO_RETURN __attribute__((noreturn))
127 #else
128 #define AOM_NO_RETURN
129 #endif
130 
131 /* Sets a stdio stream into binary mode */
132 FILE *set_binary_mode(FILE *stream);
133 
134 void die(const char *fmt, ...) AOM_NO_RETURN;
135 void fatal(const char *fmt, ...) AOM_NO_RETURN;
136 void warn(const char *fmt, ...);
137 
138 void die_codec(aom_codec_ctx_t *ctx, const char *s) AOM_NO_RETURN;
139 
140 /* The tool including this file must define usage_exit() */
141 void usage_exit(void) AOM_NO_RETURN;
142 
143 #undef AOM_NO_RETURN
144 
145 int read_yuv_frame(struct AvxInputContext *input_ctx, aom_image_t *yuv_frame);
146 
147 typedef struct AvxInterface {
148   const char *const name;
149   const uint32_t fourcc;
150   aom_codec_iface_t *(*const codec_interface)();
151 } AvxInterface;
152 
153 int get_aom_encoder_count(void);
154 const AvxInterface *get_aom_encoder_by_index(int i);
155 const AvxInterface *get_aom_encoder_by_name(const char *name);
156 const AvxInterface *get_aom_lst_encoder(void);
157 
158 int get_aom_decoder_count(void);
159 const AvxInterface *get_aom_decoder_by_index(int i);
160 const AvxInterface *get_aom_decoder_by_name(const char *name);
161 const AvxInterface *get_aom_decoder_by_fourcc(uint32_t fourcc);
162 
163 void aom_img_write(const aom_image_t *img, FILE *file);
164 int aom_img_read(aom_image_t *img, FILE *file);
165 
166 double sse_to_psnr(double samples, double peak, double mse);
167 void aom_img_upshift(aom_image_t *dst, const aom_image_t *src, int input_shift);
168 void aom_img_downshift(aom_image_t *dst, const aom_image_t *src,
169                        int down_shift);
170 void aom_shift_img(unsigned int output_bit_depth, aom_image_t **img_ptr,
171                    aom_image_t **img_shifted_ptr);
172 void aom_img_truncate_16_to_8(aom_image_t *dst, const aom_image_t *src);
173 
174 // Output in NV12 format.
175 void aom_img_write_nv12(const aom_image_t *img, FILE *file);
176 
177 #ifdef __cplusplus
178 } /* extern "C" */
179 #endif
180 
181 #endif  // AOM_COMMON_TOOLS_COMMON_H_
182