FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h264_mc_template.c
Go to the documentation of this file.
1 /*
2  * H.26L/H.264/AVC/JVT/14496-10/... decoder
3  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
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 #include "h264dec.h"
23 
24 #undef MCFUNC
25 
26 #if CHROMA_IDC == 1
27 # define MCFUNC(n) FUNC(n ## _420)
28 #elif CHROMA_IDC == 2
29 # define MCFUNC(n) FUNC(n ## _422)
30 #elif CHROMA_IDC == 3
31 # define MCFUNC(n) FUNC(n ## _444)
32 #endif
33 
34 #undef mc_part
35 #define mc_part MCFUNC(mc_part)
36 
37 static void mc_part(const H264Context *h, H264SliceContext *sl,
38  int n, int square,
39  int height, int delta,
40  uint8_t *dest_y, uint8_t *dest_cb,
41  uint8_t *dest_cr,
42  int x_offset, int y_offset,
43  const qpel_mc_func *qpix_put,
44  h264_chroma_mc_func chroma_put,
45  const qpel_mc_func *qpix_avg,
46  h264_chroma_mc_func chroma_avg,
47  const h264_weight_func *weight_op,
48  const h264_biweight_func *weight_avg,
49  int list0, int list1)
50 {
51  if ((sl->pwt.use_weight == 2 && list0 && list1 &&
52  (sl->pwt.implicit_weight[sl->ref_cache[0][scan8[n]]][sl->ref_cache[1][scan8[n]]][sl->mb_y & 1] != 32)) ||
53  sl->pwt.use_weight == 1)
54  mc_part_weighted(h, sl, n, square, height, delta, dest_y, dest_cb, dest_cr,
55  x_offset, y_offset, qpix_put, chroma_put,
56  weight_op[0], weight_op[1], weight_avg[0],
57  weight_avg[1], list0, list1, PIXEL_SHIFT, CHROMA_IDC);
58  else
59  mc_part_std(h, sl, n, square, height, delta, dest_y, dest_cb, dest_cr,
60  x_offset, y_offset, qpix_put, chroma_put, qpix_avg,
61  chroma_avg, list0, list1, PIXEL_SHIFT, CHROMA_IDC);
62 }
63 
64 static void MCFUNC(hl_motion)(const H264Context *h, H264SliceContext *sl,
65  uint8_t *dest_y,
66  uint8_t *dest_cb, uint8_t *dest_cr,
67  const qpel_mc_func(*qpix_put)[16],
68  const h264_chroma_mc_func(*chroma_put),
69  const qpel_mc_func(*qpix_avg)[16],
70  const h264_chroma_mc_func(*chroma_avg),
71  const h264_weight_func *weight_op,
72  const h264_biweight_func *weight_avg)
73 {
74  const int mb_xy = sl->mb_xy;
75  const int mb_type = h->cur_pic.mb_type[mb_xy];
76 
77  av_assert2(IS_INTER(mb_type));
78 
79  if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME))
80  await_references(h, sl);
82 
83  if (IS_16X16(mb_type)) {
84  mc_part(h, sl, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,
85  qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],
86  weight_op, weight_avg,
87  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
88  } else if (IS_16X8(mb_type)) {
89  mc_part(h, sl, 0, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 0,
90  qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
91  weight_op, weight_avg,
92  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
93  mc_part(h, sl, 8, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 4,
94  qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
95  weight_op, weight_avg,
96  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
97  } else if (IS_8X16(mb_type)) {
98  mc_part(h, sl, 0, 0, 16, 8 * sl->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,
99  qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
100  &weight_op[1], &weight_avg[1],
101  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
102  mc_part(h, sl, 4, 0, 16, 8 * sl->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
103  qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
104  &weight_op[1], &weight_avg[1],
105  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
106  } else {
107  int i;
108 
109  av_assert2(IS_8X8(mb_type));
110 
111  for (i = 0; i < 4; i++) {
112  const int sub_mb_type = sl->sub_mb_type[i];
113  const int n = 4 * i;
114  int x_offset = (i & 1) << 2;
115  int y_offset = (i & 2) << 1;
116 
117  if (IS_SUB_8X8(sub_mb_type)) {
118  mc_part(h, sl, n, 1, 8, 0, dest_y, dest_cb, dest_cr,
119  x_offset, y_offset,
120  qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
121  &weight_op[1], &weight_avg[1],
122  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
123  } else if (IS_SUB_8X4(sub_mb_type)) {
124  mc_part(h, sl, n, 0, 4, 4 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr,
125  x_offset, y_offset,
126  qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
127  &weight_op[1], &weight_avg[1],
128  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
129  mc_part(h, sl, n + 2, 0, 4, 4 << PIXEL_SHIFT,
130  dest_y, dest_cb, dest_cr, x_offset, y_offset + 2,
131  qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
132  &weight_op[1], &weight_avg[1],
133  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
134  } else if (IS_SUB_4X8(sub_mb_type)) {
135  mc_part(h, sl, n, 0, 8, 4 * sl->mb_linesize,
136  dest_y, dest_cb, dest_cr, x_offset, y_offset,
137  qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
138  &weight_op[2], &weight_avg[2],
139  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
140  mc_part(h, sl, n + 1, 0, 8, 4 * sl->mb_linesize,
141  dest_y, dest_cb, dest_cr, x_offset + 2, y_offset,
142  qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
143  &weight_op[2], &weight_avg[2],
144  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
145  } else {
146  int j;
147  av_assert2(IS_SUB_4X4(sub_mb_type));
148  for (j = 0; j < 4; j++) {
149  int sub_x_offset = x_offset + 2 * (j & 1);
150  int sub_y_offset = y_offset + (j & 2);
151  mc_part(h, sl, n + j, 1, 4, 0,
152  dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
153  qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
154  &weight_op[2], &weight_avg[2],
155  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
156  }
157  }
158  }
159  }
160 
161  if (USES_LIST(mb_type, 1))
163 }
164 
static void await_references(const H264Context *h, H264SliceContext *sl)
Wait until all reference frames are available for MC operations.
Definition: h264_mb.c:96
#define IS_SUB_4X4(a)
Definition: mpegutils.h:95
static av_always_inline void prefetch_motion(const H264Context *h, H264SliceContext *sl, int list, int pixel_shift, int chroma_idc)
Definition: h264_mb.c:483
void(* h264_chroma_mc_func)(uint8_t *dst, uint8_t *src, ptrdiff_t srcStride, int h, int x, int y)
Definition: h264chroma.h:25
#define IS_SUB_8X8(a)
Definition: mpegutils.h:92
void(* qpel_mc_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
Definition: qpeldsp.h:65
H264Context.
Definition: h264dec.h:341
#define USES_LIST(a, list)
Definition: mpegutils.h:101
#define mc_part
uint8_t
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
float delta
#define IS_DIR(a, part, list)
Definition: mpegutils.h:98
#define height
static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceContext *sl, int n, int square, int height, int delta, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int x_offset, int y_offset, const qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op, h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg, int list0, int list1, int pixel_shift, int chroma_idc)
Definition: h264_mb.c:369
static void MCFUNC() hl_motion(const H264Context *h, H264SliceContext *sl, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, const qpel_mc_func(*qpix_put)[16], const h264_chroma_mc_func(*chroma_put), const qpel_mc_func(*qpix_avg)[16], const h264_chroma_mc_func(*chroma_avg), const h264_weight_func *weight_op, const h264_biweight_func *weight_avg)
static int square(int x)
Definition: roqvideoenc.c:113
#define IS_16X8(a)
Definition: mpegutils.h:89
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:3172
#define IS_SUB_4X8(a)
Definition: mpegutils.h:94
H264PredWeightTable pwt
Definition: h264dec.h:201
H.264 / AVC / MPEG-4 part10 codec.
int n
Definition: avisynth_c.h:684
#define IS_SUB_8X4(a)
Definition: mpegutils.h:93
void(* h264_weight_func)(uint8_t *block, ptrdiff_t stride, int height, int log2_denom, int weight, int offset)
Definition: h264dsp.h:33
#define CHROMA_IDC
int implicit_weight[48][48][2]
Definition: h264_parse.h:40
static const uint8_t scan8[16 *3+3]
Definition: h264dec.h:638
#define IS_16X16(a)
Definition: mpegutils.h:88
#define IS_8X16(a)
Definition: mpegutils.h:90
#define IS_INTER(a)
Definition: mpegutils.h:81
int8_t ref_cache[2][5 *8]
Definition: h264dec.h:304
#define IS_8X8(a)
Definition: mpegutils.h:91
#define PIXEL_SHIFT
static void mc_part_std(AVSContext *h, int chroma_height, int delta, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int x_offset, int y_offset, qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, cavs_vector *mv)
Definition: cavs.c:456
void(* h264_biweight_func)(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int height, int log2_denom, int weightd, int weights, int offset)
Definition: h264dsp.h:35