tools_common.h 4.1 KB

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