Skip to content

Commit 17608f8

Browse files
author
openapv
authored
Merge pull request #11 from openapv/refactor_code_and_compilable_arm32_x86_32
Refactoring code and compilable for ARM 32bit and x86 32bit
2 parents 17bb846 + 48983ed commit 17608f8

34 files changed

+1027
-1010
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ elseif( UNIX OR MINGW )
8181
set(OPT_DBG "-DNDEBUG") # disable assert
8282
endif()
8383

84-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_DBG} -${OPT_LV} -fomit-frame-pointer -Wall -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-attributes -Werror -Wno-strict-overflow -Wno-unknown-pragmas -Wno-stringop-overflow -std=c99")
85-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pointer-sign -pthread -Wno-pointer-to-int-cast -Wno-maybe-uninitialized")
84+
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_DBG} -${OPT_LV} -fomit-frame-pointer -Wall -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-attributes -Werror -Wno-strict-overflow -Wno-unknown-pragmas -Wno-stringop-overflow -std=c99")
85+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_DBG} -${OPT_LV} -fomit-frame-pointer -Wall -Wno-unused-function -std=c99")
86+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pointer-sign -pthread -Wno-pointer-to-int-cast")
8687
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lm")
8788
endif()
8889

app/oapv_app_dec.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static void print_stat_frm(oapvd_stat_t* stat, oapv_frms_t* frms, oapvm_t mid, A
322322
int main(int argc, const char** argv)
323323
{
324324
ARGS_PARSER* args;
325-
ARGS_VAR* args_var;
325+
ARGS_VAR* args_var = NULL;
326326
unsigned char* bs_buf = NULL;
327327
oapvd_t did = NULL;
328328
oapvm_t mid = NULL;
@@ -334,11 +334,10 @@ int main(int argc, const char** argv)
334334
oapv_frm_t* frm = NULL;
335335
oapv_au_info_t aui;
336336
oapvd_stat_t stat;
337-
int ret = 0;
337+
int i, ret = 0;
338338
oapv_clk_t clk_beg, clk_tot;
339339
int au_cnt, frm_cnt[OAPV_MAX_NUM_FRAMES];
340340
int read_size, bs_buf_size = 0;
341-
int i, w, h;
342341
FILE* fp_bs = NULL;
343342
int is_y4m = 0;
344343
char* errstr = NULL;
@@ -555,9 +554,6 @@ int main(int argc, const char** argv)
555554
imgb_o = frm->imgb;
556555
}
557556

558-
w = imgb_o->w[0];
559-
h = imgb_o->h[0];
560-
561557
if(strlen(args_var->fname_out)) {
562558
if(frm_cnt[i] == 0 && is_y4m) {
563559
if(write_y4m_header(args_var->fname_out, imgb_o)) {

app/oapv_app_enc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static int update_param(ARGS_VAR* vars, oapve_param_t* param)
420420
char* tmp = vars->q_matrix_y;
421421
int cnt = 0;
422422
int len_cnt = 0;
423-
while(len_cnt < len_y && cnt < OAPV_BLOCK_D) {
423+
while(len_cnt < len_y && cnt < OAPV_BLK_D) {
424424
sscanf(tmp, "%d", &param->q_matrix_y[cnt]);
425425
if(param->q_matrix_y[cnt] < 1 || param->q_matrix_y[cnt] > 256) {
426426
logerr("input value of q_matrix_y is invalid\n");
@@ -430,7 +430,7 @@ static int update_param(ARGS_VAR* vars, oapve_param_t* param)
430430
tmp = vars->q_matrix_y + len_cnt;
431431
cnt++;
432432
}
433-
if(cnt < OAPV_BLOCK_D) {
433+
if(cnt < OAPV_BLK_D) {
434434
logerr("input number of q_matrix_y is not enough\n");
435435
return -1;
436436
}
@@ -442,7 +442,7 @@ static int update_param(ARGS_VAR* vars, oapve_param_t* param)
442442
char* tmp = vars->q_matrix_u;
443443
int cnt = 0;
444444
int len_cnt = 0;
445-
while(len_cnt < len_u && cnt < OAPV_BLOCK_D) {
445+
while(len_cnt < len_u && cnt < OAPV_BLK_D) {
446446
sscanf(tmp, "%d", &param->q_matrix_u[cnt]);
447447
if(param->q_matrix_u[cnt] < 1 || param->q_matrix_u[cnt] > 256) {
448448
logerr("input value of q_matrix_u is invalid\n");
@@ -452,7 +452,7 @@ static int update_param(ARGS_VAR* vars, oapve_param_t* param)
452452
tmp = vars->q_matrix_u + len_cnt;
453453
cnt++;
454454
}
455-
if(cnt < OAPV_BLOCK_D) {
455+
if(cnt < OAPV_BLK_D) {
456456
logerr("input number of q_matrix_u is not enough\n");
457457
return -1;
458458
}
@@ -464,7 +464,7 @@ static int update_param(ARGS_VAR* vars, oapve_param_t* param)
464464
char* tmp = vars->q_matrix_v;
465465
int cnt = 0;
466466
int len_cnt = 0;
467-
while(len_cnt < len_v && cnt < OAPV_BLOCK_D) {
467+
while(len_cnt < len_v && cnt < OAPV_BLK_D) {
468468
sscanf(tmp, "%d", &param->q_matrix_v[cnt]);
469469
if(param->q_matrix_v[cnt] < 1 || param->q_matrix_v[cnt] > 256) {
470470
logerr("input value of q_matrix_v is invalid\n");
@@ -474,27 +474,27 @@ static int update_param(ARGS_VAR* vars, oapve_param_t* param)
474474
tmp = vars->q_matrix_v + len_cnt;
475475
cnt++;
476476
}
477-
if(cnt < OAPV_BLOCK_D) {
477+
if(cnt < OAPV_BLK_D) {
478478
logerr("input number of q_matrix_v is not enough\n");
479479
return -1;
480480
}
481481
}
482482

483483
if(param->use_q_matrix) {
484484
if(len_y == 0) {
485-
for(int i = 0; i < OAPV_BLOCK_D; i++) {
485+
for(int i = 0; i < OAPV_BLK_D; i++) {
486486
param->q_matrix_y[i] = 16;
487487
}
488488
}
489489

490490
if(len_u == 0) {
491-
for(int i = 0; i < OAPV_BLOCK_D; i++) {
491+
for(int i = 0; i < OAPV_BLK_D; i++) {
492492
param->q_matrix_u[i] = 16;
493493
}
494494
}
495495

496496
if(len_v == 0) {
497-
for(int i = 0; i < OAPV_BLOCK_D; i++) {
497+
for(int i = 0; i < OAPV_BLK_D; i++) {
498498
param->q_matrix_v[i] = 16;
499499
}
500500
}

app/oapv_app_util.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ oapv_imgb_t * imgb_create(int w, int h, int cs)
290290

291291
for(i = 0; i < imgb->np; i++)
292292
{
293+
// width and height need to be aligned to macroblock size
293294
imgb->aw[i] = ALIGN_VAL(imgb->w[i], OAPV_MB_W);
294295
imgb->s[i] = imgb->aw[i] * bd;
295296
imgb->ah[i] = ALIGN_VAL(imgb->h[i], OAPV_MB_H);
@@ -436,7 +437,6 @@ static int imgb_write(char * fname, oapv_imgb_t * imgb)
436437
{
437438
unsigned char * p8;
438439
int i, j, bd;
439-
int cs_w_off, cs_h_off;
440440
FILE * fp;
441441

442442
int chroma_format = OAPV_CS_GET_FORMAT(imgb->cs);
@@ -452,15 +452,11 @@ static int imgb_write(char * fname, oapv_imgb_t * imgb)
452452
chroma_format == OAPV_CF_YCBCR444 || chroma_format == OAPV_CF_YCBCR4444))
453453
{
454454
bd = 1;
455-
cs_w_off = 2;
456-
cs_h_off = 2;
457455
}
458456
else if(bit_depth >= 10 && bit_depth <= 14 && (chroma_format == OAPV_CF_YCBCR400 || chroma_format == OAPV_CF_YCBCR420 || chroma_format == OAPV_CF_YCBCR422 ||
459457
chroma_format == OAPV_CF_YCBCR444 || chroma_format == OAPV_CF_YCBCR4444))
460458
{
461459
bd = 2;
462-
cs_w_off = 2;
463-
cs_h_off = 2;
464460
}
465461
else if (bit_depth >= 10 && chroma_format == OAPV_CF_PLANAR2)
466462
{

app/oapv_app_y4m.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int y4m_parse_tags(Y4M_INFO * y4m, char * tags)
6464
char *q;
6565
char t_buff[20];
6666
int found_w = 0, found_h = 0, found_cf = 0;
67-
int fps_n, fps_d, pix_ratio_n, pix_ratio_d, interlace;
67+
int fps_n, fps_d, pix_ratio_n, pix_ratio_d;
6868

6969
for (p = tags;; p = q)
7070
{
@@ -104,7 +104,7 @@ static int y4m_parse_tags(Y4M_INFO * y4m, char * tags)
104104
}
105105
case 'I':
106106
{
107-
interlace = p[1];
107+
//interlace = p[1];
108108
break;
109109
}
110110
case 'A':
@@ -301,4 +301,4 @@ static int write_y4m_frame_header(char * fname)
301301

302302
}
303303

304-
#endif /* _OAPV_APP_Y4M_H_ */
304+
#endif /* _OAPV_APP_Y4M_H_ */

inc/oapv.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@ extern "C"
4141

4242
/* size of macroblock */
4343
#define OAPV_LOG2_MB (4)
44-
#define OAPV_MB (1 << OAPV_LOG2_MB)
45-
#define OAPV_MB_W (1 << OAPV_LOG2_MB)
46-
#define OAPV_MB_H (1 << OAPV_LOG2_MB)
44+
#define OAPV_LOG2_MB_W (4)
45+
#define OAPV_LOG2_MB_H (4)
46+
#define OAPV_MB_W (1 << OAPV_LOG2_MB_W)
47+
#define OAPV_MB_H (1 << OAPV_LOG2_MB_H)
4748
#define OAPV_MB_D (OAPV_MB_W * OAPV_MB_H)
4849

4950
/* size of block */
50-
#define OAPV_LOG2_BLOCK (3)
51-
#define OAPV_BLOCK (1 << OAPV_LOG2_BLOCK)
52-
#define OAPV_BLOCK_W (1 << OAPV_LOG2_BLOCK)
53-
#define OAPV_BLOCK_H (1 << OAPV_LOG2_BLOCK)
54-
#define OAPV_BLOCK_D (OAPV_BLOCK_W * OAPV_BLOCK_H)
55-
51+
#define OAPV_LOG2_BLK (3)
52+
#define OAPV_LOG2_BLK_W (3)
53+
#define OAPV_LOG2_BLK_H (3)
54+
#define OAPV_BLK_W (1 << OAPV_LOG2_BLK)
55+
#define OAPV_BLK_H (1 << OAPV_LOG2_BLK)
56+
#define OAPV_BLK_D (OAPV_BLK_W * OAPV_BLK_H)
57+
58+
/* maximum number of thread */
5659
#define OAPV_MAX_THREADS (32)
5760

5861
/*****************************************************************************
@@ -385,9 +388,9 @@ struct oapve_param {
385388
int use_filler;
386389
/* use filler quantization matrix */
387390
int use_q_matrix;
388-
int q_matrix_y[OAPV_BLOCK_D];
389-
int q_matrix_u[OAPV_BLOCK_D];
390-
int q_matrix_v[OAPV_BLOCK_D];
391+
int q_matrix_y[OAPV_BLK_D];
392+
int q_matrix_u[OAPV_BLK_D];
393+
int q_matrix_v[OAPV_BLK_D];
391394
/* color space */
392395
int csp;
393396
int tile_cols;

src/CMakeLists.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ file (GLOB LIB_AVX_INC "../src/avx/oapv_*.h" )
1616
include(GenerateExportHeader)
1717
include_directories("${CMAKE_BINARY_DIR}/include")
1818

19-
if( ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "64" )
20-
add_compile_definitions( _IS64BIT)
21-
endif()
19+
message("SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
2220

23-
if(NOT ARM)
24-
set(ARM "FALSE")
25-
else()
21+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(arm|aarch)")
22+
message(" ARM processor")
23+
# add_definitions (-mfloat-abi=softfp -mfpu=neon)
2624
add_definitions(-DARM=1)
25+
set(ARM "TRUE")
26+
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86|ia64|i386|i686)")
27+
message(" X86 processor")
28+
add_definitions(-DX86=1)
29+
set(X86 "TRUE")
2730
endif()
28-
message("ARM=${ARM}")
2931

32+
if( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "64" )
33+
message(" 64-bit")
34+
add_compile_definitions( _IS64BIT)
35+
endif()
3036

3137
if(ARM)
3238
add_library( ${LIB_NAME_BASE} STATIC ${LIB_API_SRC} ${LIB_INC} ${LIB_BASE_SRC} ${LIB_BASE_INC}

src/avx/oapv_sad_avx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
#include "oapv_sad_avx.h"
3333

3434
#if X86_SSE
35-
const OAPV_FN_SAD oapv_tbl_sad_16b_avx[1] =
35+
const oapv_fn_sad_t oapv_tbl_sad_16b_avx[2] =
3636
{
3737
oapv_sad_16b_sse_8x2n,
38+
NULL
3839
};
3940

4041
#endif

src/avx/oapv_sad_avx.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <immintrin.h>
3737

3838
#if X86_SSE
39-
extern const OAPV_FN_SAD oapv_tbl_sad_16b_avx[1];
39+
extern const oapv_fn_sad_t oapv_tbl_sad_16b_avx[2];
4040
#endif /* X86_SSE */
41+
4142
#endif /* _OAPV_SAD_AVX_H_ */
43+

src/avx/oapv_tq_avx.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ static void oapv_tx_pb8b_avx(s16 *src, s16 *dst, int shift, int line)
9696
_mm_store_si128((__m128i *)(dst + 7 * line), _mm256_extracti128_si256(d1, 1));
9797
}
9898

99-
const oapv_fn_tx_t oapv_tbl_txb_avx[1] =
99+
const oapv_fn_tx_t oapv_tbl_txb_avx[2] =
100100
{
101101
oapv_tx_pb8b_avx,
102+
NULL
102103
};
103104

104105
///////////////////////////////////////////////////////////////////////////////
@@ -281,27 +282,28 @@ static void oapv_itx_pb8b_avx(s16* src, s16* dst, int shift, int line)
281282
}
282283
}
283284

284-
const oapv_fn_itx_t oapv_tbl_fn_itx_avx[1] =
285+
const oapv_fn_itx_t oapv_tbl_fn_itx_avx[2] =
285286
{
286287
oapv_itx_pb8b_avx,
288+
NULL
287289
};
288290

289-
static int oapv_quant_nnz_avx(u8 qp, int q_matrix[OAPV_BLOCK_H * OAPV_BLOCK_W], s16 *coef, int log2_block_w, int log2_block_h,
291+
static int oapv_quant_nnz_avx(u8 qp, int q_matrix[OAPV_BLK_H * OAPV_BLK_W], s16 *coef, int log2_w, int log2_h,
290292
u16 scale, int ch_type, int bit_depth, int deadzone_offset)
291293
{
292294
int nnz = 0;
293295
s32 offset;
294296
int shift;
295297
int tr_shift;
296-
int log2_size = (log2_block_w + log2_block_h) >> 1;
298+
int log2_size = (log2_w + log2_h) >> 1;
297299

298300
tr_shift = MAX_TX_DYNAMIC_RANGE - bit_depth - log2_size;
299301
shift = QUANT_SHIFT + tr_shift + (qp / 6);
300302
offset = deadzone_offset << (shift - 9);
301303

302304
__m256i offset_1 = _mm256_set1_epi32(offset);
303305

304-
int pixels = (1 << (log2_block_w + log2_block_h));
306+
int pixels = (1 << (log2_w + log2_h));
305307
int i;
306308
__m256i shuffle = _mm256_setr_epi8(
307309
0, 1, 4, 5, 8, 9, 12, 13,
@@ -342,13 +344,14 @@ static int oapv_quant_nnz_avx(u8 qp, int q_matrix[OAPV_BLOCK_H * OAPV_BLOCK_W],
342344
return nnz;
343345
}
344346

345-
const oapv_fn_quant_t oapv_tbl_quantb_avx[1] =
347+
const oapv_fn_quant_t oapv_tbl_quantb_avx[2] =
346348
{
347349
oapv_quant_nnz_avx,
350+
NULL
348351
};
349352

350353

351-
static void oapv_dquant_avx(s16 *coef, int q_matrix[OAPV_BLOCK_H * OAPV_BLOCK_W], int log2_w, int log2_h, int scale, s8 shift)
354+
static void oapv_dquant_avx(s16 *coef, int q_matrix[OAPV_BLK_H * OAPV_BLK_W], int log2_w, int log2_h, int scale, s8 shift)
352355
{
353356
int i;
354357
int pixels = (1 << (log2_w + log2_h));
@@ -406,7 +409,8 @@ static void oapv_dquant_avx(s16 *coef, int q_matrix[OAPV_BLOCK_H * OAPV_BLOCK_W]
406409
}
407410
}
408411
}
409-
const oapv_fn_iquant_t oapv_tbl_fn_iquant_avx[1] =
412+
const oapv_fn_iquant_t oapv_tbl_fn_iquant_avx[2] =
410413
{
411414
oapv_dquant_avx,
415+
NULL,
412416
};

0 commit comments

Comments
 (0)