Libav
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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "h264.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(H264Context *h, int n, int square,
38  int height, int delta,
39  uint8_t *dest_y, uint8_t *dest_cb,
40  uint8_t *dest_cr,
41  int x_offset, int y_offset,
42  qpel_mc_func *qpix_put,
43  h264_chroma_mc_func chroma_put,
44  qpel_mc_func *qpix_avg,
45  h264_chroma_mc_func chroma_avg,
46  h264_weight_func *weight_op,
47  h264_biweight_func *weight_avg,
48  int list0, int list1)
49 {
50  if ((h->use_weight == 2 && list0 && list1 &&
51  (h->implicit_weight[h->ref_cache[0][scan8[n]]][h->ref_cache[1][scan8[n]]][h->mb_y & 1] != 32)) ||
52  h->use_weight == 1)
53  mc_part_weighted(h, n, square, height, delta, dest_y, dest_cb, dest_cr,
54  x_offset, y_offset, qpix_put, chroma_put,
55  weight_op[0], weight_op[1], weight_avg[0],
56  weight_avg[1], list0, list1, PIXEL_SHIFT, CHROMA_IDC);
57  else
58  mc_part_std(h, n, square, height, delta, dest_y, dest_cb, dest_cr,
59  x_offset, y_offset, qpix_put, chroma_put, qpix_avg,
60  chroma_avg, list0, list1, PIXEL_SHIFT, CHROMA_IDC);
61 }
62 
63 static void MCFUNC(hl_motion)(H264Context *h, uint8_t *dest_y,
64  uint8_t *dest_cb, uint8_t *dest_cr,
65  qpel_mc_func(*qpix_put)[16],
66  h264_chroma_mc_func(*chroma_put),
67  qpel_mc_func(*qpix_avg)[16],
68  h264_chroma_mc_func(*chroma_avg),
69  h264_weight_func *weight_op,
70  h264_biweight_func *weight_avg)
71 {
72  const int mb_xy = h->mb_xy;
73  const int mb_type = h->cur_pic.mb_type[mb_xy];
74 
75  assert(IS_INTER(mb_type));
76 
77  if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME))
80 
81  if (IS_16X16(mb_type)) {
82  mc_part(h, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,
83  qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],
84  weight_op, weight_avg,
85  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
86  } else if (IS_16X8(mb_type)) {
87  mc_part(h, 0, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 0,
88  qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
89  weight_op, weight_avg,
90  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
91  mc_part(h, 8, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 4,
92  qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
93  weight_op, weight_avg,
94  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
95  } else if (IS_8X16(mb_type)) {
96  mc_part(h, 0, 0, 16, 8 * h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,
97  qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
98  &weight_op[1], &weight_avg[1],
99  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
100  mc_part(h, 4, 0, 16, 8 * h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
101  qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
102  &weight_op[1], &weight_avg[1],
103  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
104  } else {
105  int i;
106 
107  assert(IS_8X8(mb_type));
108 
109  for (i = 0; i < 4; i++) {
110  const int sub_mb_type = h->sub_mb_type[i];
111  const int n = 4 * i;
112  int x_offset = (i & 1) << 2;
113  int y_offset = (i & 2) << 1;
114 
115  if (IS_SUB_8X8(sub_mb_type)) {
116  mc_part(h, n, 1, 8, 0, dest_y, dest_cb, dest_cr,
117  x_offset, y_offset,
118  qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
119  &weight_op[1], &weight_avg[1],
120  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
121  } else if (IS_SUB_8X4(sub_mb_type)) {
122  mc_part(h, n, 0, 4, 4 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr,
123  x_offset, y_offset,
124  qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
125  &weight_op[1], &weight_avg[1],
126  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
127  mc_part(h, n + 2, 0, 4, 4 << PIXEL_SHIFT,
128  dest_y, dest_cb, dest_cr, x_offset, y_offset + 2,
129  qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
130  &weight_op[1], &weight_avg[1],
131  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
132  } else if (IS_SUB_4X8(sub_mb_type)) {
133  mc_part(h, n, 0, 8, 4 * h->mb_linesize,
134  dest_y, dest_cb, dest_cr, x_offset, y_offset,
135  qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
136  &weight_op[2], &weight_avg[2],
137  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
138  mc_part(h, n + 1, 0, 8, 4 * h->mb_linesize,
139  dest_y, dest_cb, dest_cr, x_offset + 2, y_offset,
140  qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
141  &weight_op[2], &weight_avg[2],
142  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
143  } else {
144  int j;
145  assert(IS_SUB_4X4(sub_mb_type));
146  for (j = 0; j < 4; j++) {
147  int sub_x_offset = x_offset + 2 * (j & 1);
148  int sub_y_offset = y_offset + (j & 2);
149  mc_part(h, n + j, 1, 4, 0,
150  dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
151  qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
152  &weight_op[2], &weight_avg[2],
153  IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
154  }
155  }
156  }
157  }
158 
160 }
161 
#define IS_SUB_4X4(a)
Definition: mpegutils.h:89
int mb_y
Definition: h264.h:498
#define IS_SUB_8X8(a)
Definition: mpegutils.h:86
H264Context.
Definition: h264.h:303
#define mc_part
uint8_t
int use_weight
Definition: h264.h:425
float delta
int mb_xy
Definition: h264.h:505
#define IS_DIR(a, part, list)
Definition: mpegutils.h:92
H.264 / AVC / MPEG4 part10 codec.
void(* qpel_mc_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
Definition: qpeldsp.h:65
static int square(int x)
Definition: roqvideoenc.c:112
static void await_references(H264Context *h)
Wait until all reference frames are available for MC operations.
Definition: h264_mb.c:95
static const uint8_t scan8[16 *3+3]
Definition: h264.h:868
#define IS_16X8(a)
Definition: mpegutils.h:83
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:2567
#define IS_SUB_4X8(a)
Definition: mpegutils.h:88
void(* h264_chroma_mc_func)(uint8_t *dst, uint8_t *src, int srcStride, int h, int x, int y)
Definition: h264chroma.h:24
#define HAVE_THREADS
Definition: config.h:302
#define IS_SUB_8X4(a)
Definition: mpegutils.h:87
int implicit_weight[48][48][2]
Definition: h264.h:432
#define CHROMA_IDC
static void MCFUNC() hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, qpel_mc_func(*qpix_put)[16], h264_chroma_mc_func(*chroma_put), qpel_mc_func(*qpix_avg)[16], h264_chroma_mc_func(*chroma_avg), h264_weight_func *weight_op, h264_biweight_func *weight_avg)
#define IS_16X16(a)
Definition: mpegutils.h:82
#define IS_8X16(a)
Definition: mpegutils.h:84
static av_always_inline void prefetch_motion(H264Context *h, int list, int pixel_shift, int chroma_idc)
Definition: h264_mb.c:472
#define IS_INTER(a)
Definition: mpegutils.h:75
int height
Definition: gxfenc.c:72
static av_always_inline void mc_part_weighted(H264Context *h, 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, 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:365
uint16_t sub_mb_type[4]
Definition: h264.h:422
void(* h264_weight_func)(uint8_t *block, int stride, int height, int log2_denom, int weight, int offset)
Definition: h264dsp.h:32
#define IS_8X8(a)
Definition: mpegutils.h:85
void(* h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int height, int log2_denom, int weightd, int weights, int offset)
Definition: h264dsp.h:34
#define PIXEL_SHIFT
int8_t ref_cache[2][5 *8]
Definition: h264.h:379
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:447