tools_common.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 TOOLS_COMMON_H_
  11. #define 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. typedef off_t FileOffset;
  33. /* Use 32-bit file operations in WebM file format when building ARM
  34. * executables (.axf) with RVCT. */
  35. #else
  36. #define fseeko fseek
  37. #define ftello ftell
  38. typedef long FileOffset; /* NOLINT */
  39. #endif /* CONFIG_OS_SUPPORT */
  40. #if CONFIG_OS_SUPPORT
  41. #if defined(_MSC_VER)
  42. #include <io.h> /* NOLINT */
  43. #define isatty _isatty
  44. #define fileno _fileno
  45. #else
  46. #include <unistd.h> /* NOLINT */
  47. #endif /* _MSC_VER */
  48. #endif /* CONFIG_OS_SUPPORT */
  49. #define LITERALU64(hi, lo) ((((uint64_t)hi) << 32) | lo)
  50. #ifndef PATH_MAX
  51. #define PATH_MAX 512
  52. #endif
  53. #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */
  54. #define IVF_FILE_HDR_SZ 32
  55. #define RAW_FRAME_HDR_SZ sizeof(uint32_t)
  56. #define VP8_FOURCC 0x30385056
  57. #define VP9_FOURCC 0x30395056
  58. enum VideoFileType {
  59. FILE_TYPE_RAW,
  60. FILE_TYPE_IVF,
  61. FILE_TYPE_Y4M,
  62. FILE_TYPE_WEBM
  63. };
  64. struct FileTypeDetectionBuffer {
  65. char buf[4];
  66. size_t buf_read;
  67. size_t position;
  68. };
  69. struct VpxRational {
  70. int numerator;
  71. int denominator;
  72. };
  73. struct VpxInputContext {
  74. const char *filename;
  75. FILE *file;
  76. int64_t length;
  77. struct FileTypeDetectionBuffer detect;
  78. enum VideoFileType file_type;
  79. uint32_t width;
  80. uint32_t height;
  81. struct VpxRational pixel_aspect_ratio;
  82. vpx_img_fmt_t fmt;
  83. vpx_bit_depth_t bit_depth;
  84. int only_i420;
  85. uint32_t fourcc;
  86. struct VpxRational framerate;
  87. #if CONFIG_ENCODERS
  88. y4m_input y4m;
  89. #endif
  90. };
  91. #ifdef __cplusplus
  92. extern "C" {
  93. #endif
  94. #if defined(__GNUC__)
  95. #define VPX_NO_RETURN __attribute__((noreturn))
  96. #else
  97. #define VPX_NO_RETURN
  98. #endif
  99. /* Sets a stdio stream into binary mode */
  100. FILE *set_binary_mode(FILE *stream);
  101. void die(const char *fmt, ...) VPX_NO_RETURN;
  102. void fatal(const char *fmt, ...) VPX_NO_RETURN;
  103. void warn(const char *fmt, ...);
  104. void die_codec(vpx_codec_ctx_t *ctx, const char *s) VPX_NO_RETURN;
  105. /* The tool including this file must define usage_exit() */
  106. void usage_exit(void) VPX_NO_RETURN;
  107. #undef VPX_NO_RETURN
  108. int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame);
  109. typedef struct VpxInterface {
  110. const char *const name;
  111. const uint32_t fourcc;
  112. vpx_codec_iface_t *(*const codec_interface)();
  113. } VpxInterface;
  114. int get_vpx_encoder_count(void);
  115. const VpxInterface *get_vpx_encoder_by_index(int i);
  116. const VpxInterface *get_vpx_encoder_by_name(const char *name);
  117. int get_vpx_decoder_count(void);
  118. const VpxInterface *get_vpx_decoder_by_index(int i);
  119. const VpxInterface *get_vpx_decoder_by_name(const char *name);
  120. const VpxInterface *get_vpx_decoder_by_fourcc(uint32_t fourcc);
  121. // TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part
  122. // of vpx_image_t support
  123. int vpx_img_plane_width(const vpx_image_t *img, int plane);
  124. int vpx_img_plane_height(const vpx_image_t *img, int plane);
  125. void vpx_img_write(const vpx_image_t *img, FILE *file);
  126. int vpx_img_read(vpx_image_t *img, FILE *file);
  127. double sse_to_psnr(double samples, double peak, double mse);
  128. #if CONFIG_VP9_HIGHBITDEPTH
  129. void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src, int input_shift);
  130. void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src, int down_shift);
  131. void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src);
  132. #endif
  133. #ifdef __cplusplus
  134. } /* extern "C" */
  135. #endif
  136. #endif // TOOLS_COMMON_H_