FFmpeg
mpegvideo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Mans Rullgard
3  * Copyright (c) 2014 James Yu <james.yu@linaro.org>
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 <arm_neon.h>
23 
24 #include "config.h"
25 
26 #include "libavutil/attributes.h"
27 #include "libavutil/cpu.h"
28 #if ARCH_AARCH64
29 # include "libavutil/aarch64/cpu.h"
30 #elif ARCH_ARM
31 # include "libavutil/arm/cpu.h"
32 #endif
33 
34 #include "libavcodec/mpegvideo.h"
36 
37 static void inline ff_dct_unquantize_h263_neon(int qscale, int qadd, int nCoeffs,
38  int16_t *block)
39 {
40  int16x8_t q0s16, q2s16, q3s16, q8s16, q10s16, q11s16, q13s16;
41  int16x8_t q14s16, q15s16, qzs16;
42  int16x4_t d0s16, d2s16, d3s16, dzs16;
43  uint16x8_t q1u16, q9u16;
44  uint16x4_t d1u16;
45 
46  dzs16 = vdup_n_s16(0);
47  qzs16 = vdupq_n_s16(0);
48 
49  q15s16 = vdupq_n_s16(qscale << 1);
50  q14s16 = vdupq_n_s16(qadd);
51  q13s16 = vnegq_s16(q14s16);
52 
53  if (nCoeffs > 4) {
54  for (; nCoeffs > 8; nCoeffs -= 16, block += 16) {
55  q0s16 = vld1q_s16(block);
56  q3s16 = vreinterpretq_s16_u16(vcltq_s16(q0s16, qzs16));
57  q8s16 = vld1q_s16(block + 8);
58  q1u16 = vceqq_s16(q0s16, qzs16);
59  q2s16 = vmulq_s16(q0s16, q15s16);
60  q11s16 = vreinterpretq_s16_u16(vcltq_s16(q8s16, qzs16));
61  q10s16 = vmulq_s16(q8s16, q15s16);
62  q3s16 = vbslq_s16(vreinterpretq_u16_s16(q3s16), q13s16, q14s16);
63  q11s16 = vbslq_s16(vreinterpretq_u16_s16(q11s16), q13s16, q14s16);
64  q2s16 = vaddq_s16(q2s16, q3s16);
65  q9u16 = vceqq_s16(q8s16, qzs16);
66  q10s16 = vaddq_s16(q10s16, q11s16);
67  q0s16 = vbslq_s16(q1u16, q0s16, q2s16);
68  q8s16 = vbslq_s16(q9u16, q8s16, q10s16);
69  vst1q_s16(block, q0s16);
70  vst1q_s16(block + 8, q8s16);
71  }
72  }
73  if (nCoeffs <= 0)
74  return;
75 
76  d0s16 = vld1_s16(block);
77  d3s16 = vreinterpret_s16_u16(vclt_s16(d0s16, dzs16));
78  d1u16 = vceq_s16(d0s16, dzs16);
79  d2s16 = vmul_s16(d0s16, vget_high_s16(q15s16));
80  d3s16 = vbsl_s16(vreinterpret_u16_s16(d3s16),
81  vget_high_s16(q13s16), vget_high_s16(q14s16));
82  d2s16 = vadd_s16(d2s16, d3s16);
83  d0s16 = vbsl_s16(d1u16, d0s16, d2s16);
84  vst1_s16(block, d0s16);
85 }
86 
88  int n, int qscale)
89 {
90  int nCoeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
91  int qadd = (qscale - 1) | 1;
92 
93  ff_dct_unquantize_h263_neon(qscale, qadd, nCoeffs + 1, block);
94 }
95 
97  int n, int qscale)
98 {
99  int qadd;
100  int nCoeffs, blk0;
101 
102  if (!s->h263_aic) {
103  if (n < 4)
104  block[0] *= s->y_dc_scale;
105  else
106  block[0] *= s->c_dc_scale;
107  qadd = (qscale - 1) | 1;
108  } else {
109  qadd = 0;
110  }
111 
112  if (s->ac_pred) {
113  nCoeffs = 63;
114  } else {
115  nCoeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
116  if (nCoeffs <= 0)
117  return;
118  }
119 
120  blk0 = block[0];
121 
122  ff_dct_unquantize_h263_neon(qscale, qadd, nCoeffs + 1, block);
123 
124  block[0] = blk0;
125 }
126 
127 
129 {
130  int cpu_flags = av_get_cpu_flags();
131 
132  if (have_neon(cpu_flags)) {
133  s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_neon;
134  s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_neon;
135  }
136 }
mpegvideo_unquantize.h
dct_unquantize_h263_inter_neon
static void dct_unquantize_h263_inter_neon(MpegEncContext *s, int16_t *block, int n, int qscale)
Definition: mpegvideo.c:87
mpegvideo.h
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:56
ff_mpv_unquantize_init_neon
av_cold void ff_mpv_unquantize_init_neon(MPVUnquantDSPContext *s, int bitexact)
Definition: mpegvideo.c:128
av_cold
#define av_cold
Definition: attributes.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:198
cpu.h
cpu.h
have_neon
#define have_neon(flags)
Definition: cpu.h:26
attributes.h
dct_unquantize_h263_intra_neon
static void dct_unquantize_h263_intra_neon(MpegEncContext *s, int16_t *block, int n, int qscale)
Definition: mpegvideo.c:96
blk0
#define blk0(i)
Definition: sha.c:54
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
MPVUnquantDSPContext
Definition: mpegvideo_unquantize.h:34
ff_dct_unquantize_h263_neon
static void ff_dct_unquantize_h263_neon(int qscale, int qadd, int nCoeffs, int16_t *block)
Definition: mpegvideo.c:37
cpu.h
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:64