rv34.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * RV30/40 decoder common data declarations
  3. * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * RV30 and RV40 decoder common data declarations
  24. */
  25. #ifndef AVCODEC_RV34_H
  26. #define AVCODEC_RV34_H
  27. #include "avcodec.h"
  28. #include "mpegvideo.h"
  29. #include "h264pred.h"
  30. #include "rv34dsp.h"
  31. #define MB_TYPE_SEPARATE_DC 0x01000000
  32. #define IS_SEPARATE_DC(a) ((a) & MB_TYPE_SEPARATE_DC)
  33. /**
  34. * RV30 and RV40 Macroblock types
  35. */
  36. enum RV40BlockTypes{
  37. RV34_MB_TYPE_INTRA, ///< Intra macroblock
  38. RV34_MB_TYPE_INTRA16x16, ///< Intra macroblock with DCs in a separate 4x4 block
  39. RV34_MB_P_16x16, ///< P-frame macroblock, one motion frame
  40. RV34_MB_P_8x8, ///< P-frame macroblock, 8x8 motion compensation partitions
  41. RV34_MB_B_FORWARD, ///< B-frame macroblock, forward prediction
  42. RV34_MB_B_BACKWARD, ///< B-frame macroblock, backward prediction
  43. RV34_MB_SKIP, ///< Skipped block
  44. RV34_MB_B_DIRECT, ///< Bidirectionally predicted B-frame macroblock, no motion vectors
  45. RV34_MB_P_16x8, ///< P-frame macroblock, 16x8 motion compensation partitions
  46. RV34_MB_P_8x16, ///< P-frame macroblock, 8x16 motion compensation partitions
  47. RV34_MB_B_BIDIR, ///< Bidirectionally predicted B-frame macroblock, two motion vectors
  48. RV34_MB_P_MIX16x16, ///< P-frame macroblock with DCs in a separate 4x4 block, one motion vector
  49. RV34_MB_TYPES
  50. };
  51. /**
  52. * VLC tables used by the decoder
  53. *
  54. * Intra frame VLC sets do not contain some of those tables.
  55. */
  56. typedef struct RV34VLC{
  57. VLC cbppattern[2]; ///< VLCs used for pattern of coded block patterns decoding
  58. VLC cbp[2][4]; ///< VLCs used for coded block patterns decoding
  59. VLC first_pattern[4]; ///< VLCs used for decoding coefficients in the first subblock
  60. VLC second_pattern[2]; ///< VLCs used for decoding coefficients in the subblocks 2 and 3
  61. VLC third_pattern[2]; ///< VLCs used for decoding coefficients in the last subblock
  62. VLC coefficient; ///< VLCs used for decoding big coefficients
  63. }RV34VLC;
  64. /** essential slice information */
  65. typedef struct SliceInfo{
  66. int type; ///< slice type (intra, inter)
  67. int quant; ///< quantizer used for this slice
  68. int vlc_set; ///< VLCs used for this slice
  69. int start, end; ///< start and end macroblocks of the slice
  70. int width; ///< coded width
  71. int height; ///< coded height
  72. int pts; ///< frame timestamp
  73. }SliceInfo;
  74. /** decoder context */
  75. typedef struct RV34DecContext{
  76. MpegEncContext s;
  77. RV34DSPContext rdsp;
  78. int8_t *intra_types_hist;///< old block types, used for prediction
  79. int8_t *intra_types; ///< block types
  80. int intra_types_stride;///< block types array stride
  81. const uint8_t *luma_dc_quant_i;///< luma subblock DC quantizer for intraframes
  82. const uint8_t *luma_dc_quant_p;///< luma subblock DC quantizer for interframes
  83. RV34VLC *cur_vlcs; ///< VLC set used for current frame decoding
  84. H264PredContext h; ///< functions for 4x4 and 16x16 intra block prediction
  85. SliceInfo si; ///< current slice information
  86. int *mb_type; ///< internal macroblock types
  87. int block_type; ///< current block type
  88. int luma_vlc; ///< which VLC set will be used for decoding of luma blocks
  89. int chroma_vlc; ///< which VLC set will be used for decoding of chroma blocks
  90. int is16; ///< current block has additional 16x16 specific features or not
  91. int dmv[4][2]; ///< differential motion vectors for the current macroblock
  92. int rv30; ///< indicates which RV variant is currently decoded
  93. int max_rpr;
  94. int cur_pts, last_pts, next_pts;
  95. int scaled_weight;
  96. int weight1, weight2; ///< B-frame distance fractions (0.14) used in motion compensation
  97. int mv_weight1, mv_weight2;
  98. int orig_width, orig_height;
  99. uint16_t *cbp_luma; ///< CBP values for luma subblocks
  100. uint8_t *cbp_chroma; ///< CBP values for chroma subblocks
  101. uint16_t *deblock_coefs; ///< deblock coefficients for each macroblock
  102. /** 8x8 block available flags (for MV prediction) */
  103. DECLARE_ALIGNED(8, uint32_t, avail_cache)[3*4];
  104. /** temporary blocks for RV4 weighted MC */
  105. uint8_t *tmp_b_block_y[2];
  106. uint8_t *tmp_b_block_uv[4];
  107. uint8_t *tmp_b_block_base;
  108. int (*parse_slice_header)(struct RV34DecContext *r, GetBitContext *gb, SliceInfo *si);
  109. int (*decode_mb_info)(struct RV34DecContext *r);
  110. int (*decode_intra_types)(struct RV34DecContext *r, GetBitContext *gb, int8_t *dst);
  111. void (*loop_filter)(struct RV34DecContext *r, int row);
  112. }RV34DecContext;
  113. /**
  114. * common decoding functions
  115. */
  116. int ff_rv34_get_start_offset(GetBitContext *gb, int blocks);
  117. int ff_rv34_decode_init(AVCodecContext *avctx);
  118. int ff_rv34_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt);
  119. int ff_rv34_decode_end(AVCodecContext *avctx);
  120. int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
  121. #endif /* AVCODEC_RV34_H */