mpegutils.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Mpeg video formats-related defines and utility functions
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_MPEGUTILS_H
  21. #define AVCODEC_MPEGUTILS_H
  22. #include <stdint.h>
  23. #include "libavutil/frame.h"
  24. #include "avcodec.h"
  25. #include "version.h"
  26. /**
  27. * Return value for header parsers if frame is not coded.
  28. * */
  29. #define FRAME_SKIPPED 100
  30. /* picture type */
  31. #define PICT_TOP_FIELD 1
  32. #define PICT_BOTTOM_FIELD 2
  33. #define PICT_FRAME 3
  34. /**
  35. * Value of Picture.reference when Picture is not a reference picture, but
  36. * is held for delayed output.
  37. */
  38. #define DELAYED_PIC_REF 4
  39. #define MAX_MB_BYTES (30 * 16 * 16 * 3 / 8 + 120)
  40. #define MAX_FCODE 7
  41. /* MB types */
  42. #define MB_TYPE_INTRA4x4 (1 << 0)
  43. #define MB_TYPE_INTRA16x16 (1 << 1) // FIXME H.264-specific
  44. #define MB_TYPE_INTRA_PCM (1 << 2) // FIXME H.264-specific
  45. #define MB_TYPE_16x16 (1 << 3)
  46. #define MB_TYPE_16x8 (1 << 4)
  47. #define MB_TYPE_8x16 (1 << 5)
  48. #define MB_TYPE_8x8 (1 << 6)
  49. #define MB_TYPE_INTERLACED (1 << 7)
  50. #define MB_TYPE_DIRECT2 (1 << 8) // FIXME
  51. #define MB_TYPE_ACPRED (1 << 9)
  52. #define MB_TYPE_GMC (1 << 10)
  53. #define MB_TYPE_SKIP (1 << 11)
  54. #define MB_TYPE_P0L0 (1 << 12)
  55. #define MB_TYPE_P1L0 (1 << 13)
  56. #define MB_TYPE_P0L1 (1 << 14)
  57. #define MB_TYPE_P1L1 (1 << 15)
  58. #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
  59. #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
  60. #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
  61. #define MB_TYPE_QUANT (1 << 16)
  62. #define MB_TYPE_CBP (1 << 17)
  63. #define MB_TYPE_INTRA MB_TYPE_INTRA4x4 // default mb_type if there is just one type
  64. #define IS_INTRA4x4(a) ((a) & MB_TYPE_INTRA4x4)
  65. #define IS_INTRA16x16(a) ((a) & MB_TYPE_INTRA16x16)
  66. #define IS_PCM(a) ((a) & MB_TYPE_INTRA_PCM)
  67. #define IS_INTRA(a) ((a) & 7)
  68. #define IS_INTER(a) ((a) & (MB_TYPE_16x16 | MB_TYPE_16x8 | \
  69. MB_TYPE_8x16 | MB_TYPE_8x8))
  70. #define IS_SKIP(a) ((a) & MB_TYPE_SKIP)
  71. #define IS_INTRA_PCM(a) ((a) & MB_TYPE_INTRA_PCM)
  72. #define IS_INTERLACED(a) ((a) & MB_TYPE_INTERLACED)
  73. #define IS_DIRECT(a) ((a) & MB_TYPE_DIRECT2)
  74. #define IS_GMC(a) ((a) & MB_TYPE_GMC)
  75. #define IS_16X16(a) ((a) & MB_TYPE_16x16)
  76. #define IS_16X8(a) ((a) & MB_TYPE_16x8)
  77. #define IS_8X16(a) ((a) & MB_TYPE_8x16)
  78. #define IS_8X8(a) ((a) & MB_TYPE_8x8)
  79. #define IS_SUB_8X8(a) ((a) & MB_TYPE_16x16) // note reused
  80. #define IS_SUB_8X4(a) ((a) & MB_TYPE_16x8) // note reused
  81. #define IS_SUB_4X8(a) ((a) & MB_TYPE_8x16) // note reused
  82. #define IS_SUB_4X4(a) ((a) & MB_TYPE_8x8) // note reused
  83. #define IS_ACPRED(a) ((a) & MB_TYPE_ACPRED)
  84. #define IS_QUANT(a) ((a) & MB_TYPE_QUANT)
  85. #define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0 << ((part) + 2 * (list))))
  86. // does this mb use listX, note does not work if subMBs
  87. #define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0 | MB_TYPE_P1L0) << (2 * (list))))
  88. #define HAS_CBP(a) ((a) & MB_TYPE_CBP)
  89. /* MB types for encoding */
  90. #define CANDIDATE_MB_TYPE_INTRA (1 << 0)
  91. #define CANDIDATE_MB_TYPE_INTER (1 << 1)
  92. #define CANDIDATE_MB_TYPE_INTER4V (1 << 2)
  93. #define CANDIDATE_MB_TYPE_SKIPPED (1 << 3)
  94. #define CANDIDATE_MB_TYPE_DIRECT (1 << 4)
  95. #define CANDIDATE_MB_TYPE_FORWARD (1 << 5)
  96. #define CANDIDATE_MB_TYPE_BACKWARD (1 << 6)
  97. #define CANDIDATE_MB_TYPE_BIDIR (1 << 7)
  98. #define CANDIDATE_MB_TYPE_INTER_I (1 << 8)
  99. #define CANDIDATE_MB_TYPE_FORWARD_I (1 << 9)
  100. #define CANDIDATE_MB_TYPE_BACKWARD_I (1 << 10)
  101. #define CANDIDATE_MB_TYPE_BIDIR_I (1 << 11)
  102. #define CANDIDATE_MB_TYPE_DIRECT0 (1 << 12)
  103. #define INPLACE_OFFSET 16
  104. enum OutputFormat {
  105. FMT_MPEG1,
  106. FMT_H261,
  107. FMT_H263,
  108. FMT_MJPEG,
  109. };
  110. /**
  111. * Draw a horizontal band if supported.
  112. *
  113. * @param h is the normal height, this will be reduced automatically if needed
  114. */
  115. void ff_draw_horiz_band(AVCodecContext *avctx, AVFrame *cur, AVFrame *last,
  116. int y, int h, int picture_structure, int first_field,
  117. int low_delay);
  118. /**
  119. * Print debugging info for the given picture.
  120. */
  121. void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table,
  122. uint32_t *mbtype_table, int8_t *qscale_table, int16_t (*motion_val[2])[2],
  123. int *low_delay,
  124. int mb_width, int mb_height, int mb_stride, int quarter_sample);
  125. #endif /* AVCODEC_MPEGUTILS_H */