tools_common.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  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. */
  10. #ifndef VPX_TOOLS_COMMON_H_
  11. #define VPX_TOOLS_COMMON_H_
  12. #include <stdio.h>
  13. #include "./vpx_config.h"
  14. #include "vpx/vpx_codec.h"
  15. #include "vpx/vpx_image.h"
  16. #include "vpx/vpx_integer.h"
  17. #include "vpx_ports/msvc.h"
  18. #if CONFIG_ENCODERS
  19. #include "./y4minput.h"
  20. #endif
  21. #if defined(_MSC_VER)
  22. /* MSVS uses _f{seek,tell}i64. */
  23. #define fseeko _fseeki64
  24. #define ftello _ftelli64
  25. typedef int64_t FileOffset;
  26. #elif defined(_WIN32)
  27. /* MinGW uses f{seek,tell}o64 for large files. */
  28. #define fseeko fseeko64
  29. #define ftello ftello64
  30. typedef off64_t FileOffset;
  31. #elif CONFIG_OS_SUPPORT
  32. #include <sys/types.h> /* NOLINT */
  33. typedef off_t FileOffset;
  34. /* Use 32-bit file operations in WebM file format when building ARM
  35. * executables (.axf) with RVCT. */
  36. #else
  37. #define fseeko fseek
  38. #define ftello ftell
  39. typedef long FileOffset; /* NOLINT */
  40. #endif /* CONFIG_OS_SUPPORT */
  41. #if CONFIG_OS_SUPPORT
  42. #if defined(_MSC_VER)
  43. #include <io.h> /* NOLINT */
  44. #define isatty _isatty
  45. #define fileno _fileno
  46. #else
  47. #include <unistd.h> /* NOLINT */
  48. #endif /* _MSC_VER */
  49. #endif /* CONFIG_OS_SUPPORT */
  50. #define LITERALU64(hi, lo) ((((uint64_t)hi) << 32) | lo)
  51. #ifndef PATH_MAX
  52. #define PATH_MAX 512
  53. #endif
  54. #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */
  55. #define IVF_FILE_HDR_SZ 32
  56. #define RAW_FRAME_HDR_SZ sizeof(uint32_t)
  57. #define VP8_FOURCC 0x30385056
  58. #define VP9_FOURCC 0x30395056
  59. enum VideoFileType {
  60. FILE_TYPE_RAW,
  61. FILE_TYPE_IVF,
  62. FILE_TYPE_Y4M,
  63. FILE_TYPE_WEBM
  64. };
  65. struct FileTypeDetectionBuffer {
  66. char buf[4];
  67. size_t buf_read;
  68. size_t position;
  69. };
  70. struct VpxRational {
  71. int numerator;
  72. int denominator;
  73. };
  74. struct VpxInputContext {
  75. const char *filename;
  76. FILE *file;
  77. int64_t length;
  78. struct FileTypeDetectionBuffer detect;
  79. enum VideoFileType file_type;
  80. uint32_t width;
  81. uint32_t height;
  82. struct VpxRational pixel_aspect_ratio;
  83. vpx_img_fmt_t fmt;
  84. vpx_bit_depth_t bit_depth;
  85. int only_i420;
  86. uint32_t fourcc;
  87. struct VpxRational framerate;
  88. #if CONFIG_ENCODERS
  89. y4m_input y4m;
  90. #endif
  91. };
  92. #ifdef __cplusplus
  93. extern "C" {
  94. #endif
  95. #if defined(__GNUC__)
  96. #define VPX_NO_RETURN __attribute__((noreturn))
  97. #else
  98. #define VPX_NO_RETURN
  99. #endif
  100. /* Sets a stdio stream into binary mode */
  101. FILE *set_binary_mode(FILE *stream);
  102. void die(const char *fmt, ...) VPX_NO_RETURN;
  103. void fatal(const char *fmt, ...) VPX_NO_RETURN;
  104. void warn(const char *fmt, ...);
  105. void die_codec(vpx_codec_ctx_t *ctx, const char *s) VPX_NO_RETURN;
  106. /* The tool including this file must define usage_exit() */
  107. void usage_exit(void) VPX_NO_RETURN;
  108. #undef VPX_NO_RETURN
  109. int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame);
  110. typedef struct VpxInterface {
  111. const char *const name;
  112. const uint32_t fourcc;
  113. vpx_codec_iface_t *(*const codec_interface)();
  114. } VpxInterface;
  115. int get_vpx_encoder_count(void);
  116. const VpxInterface *get_vpx_encoder_by_index(int i);
  117. const VpxInterface *get_vpx_encoder_by_name(const char *name);
  118. int get_vpx_decoder_count(void);
  119. const VpxInterface *get_vpx_decoder_by_index(int i);
  120. const VpxInterface *get_vpx_decoder_by_name(const char *name);
  121. const VpxInterface *get_vpx_decoder_by_fourcc(uint32_t fourcc);
  122. int vpx_img_plane_width(const vpx_image_t *img, int plane);
  123. int vpx_img_plane_height(const vpx_image_t *img, int plane);
  124. void vpx_img_write(const vpx_image_t *img, FILE *file);
  125. int vpx_img_read(vpx_image_t *img, FILE *file);
  126. double sse_to_psnr(double samples, double peak, double mse);
  127. #if CONFIG_ENCODERS
  128. int read_frame(struct VpxInputContext *input_ctx, vpx_image_t *img);
  129. int file_is_y4m(const char detect[4]);
  130. int fourcc_is_ivf(const char detect[4]);
  131. void open_input_file(struct VpxInputContext *input);
  132. void close_input_file(struct VpxInputContext *input);
  133. #endif
  134. #if CONFIG_VP9_HIGHBITDEPTH
  135. void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src, int input_shift);
  136. void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src, int down_shift);
  137. void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src);
  138. #endif
  139. int compare_img(const vpx_image_t *const img1, const vpx_image_t *const img2);
  140. #if CONFIG_VP9_HIGHBITDEPTH
  141. void find_mismatch_high(const vpx_image_t *const img1,
  142. const vpx_image_t *const img2, int yloc[4], int uloc[4],
  143. int vloc[4]);
  144. #endif
  145. void find_mismatch(const vpx_image_t *const img1, const vpx_image_t *const img2,
  146. int yloc[4], int uloc[4], int vloc[4]);
  147. #ifdef __cplusplus
  148. } /* extern "C" */
  149. #endif
  150. #endif // VPX_TOOLS_COMMON_H_