Skip to content

Commit f5cbde2

Browse files
kpchoimss-park
andauthored
Add signature syntax (#60)
* modification of default number of threads in decoder Signed-off-by: Minsoo Park <[email protected]> * modification Signed-off-by: Minsoo Park <[email protected]> * refactoring for parameter parser Signed-off-by: [email protected] <[email protected]> * add signature write/read Signed-off-by: [email protected] <[email protected]> * normalize LF Signed-off-by: [email protected] <[email protected]> * missed header file Signed-off-by: [email protected] <[email protected]> * fixed oapv_get_num_cpu_cores function for android Signed-off-by: [email protected] <[email protected]> * refactoring Signed-off-by: [email protected] <[email protected]> * update test bitstream and modification of input param Signed-off-by: Minsoo Park <[email protected]> --------- Signed-off-by: Minsoo Park <[email protected]> Signed-off-by: [email protected] <[email protected]> Co-authored-by: Minsoo Park <[email protected]>
1 parent e4fed4d commit f5cbde2

File tree

20 files changed

+134
-79
lines changed

20 files changed

+134
-79
lines changed

app/oapv_app_enc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ static const args_opt_t enc_args_opts[] = {
133133
"number of skipped access units before encoding"
134134
},
135135
{
136-
ARGS_NO_KEY, "qp-offset-c1", ARGS_VAL_TYPE_INTEGER, 0, NULL,
136+
ARGS_NO_KEY, "qp-offset-c1", ARGS_VAL_TYPE_STRING, 0, NULL,
137137
"QP offset value for Component 1 (Cb)"
138138
},
139139
{
140-
ARGS_NO_KEY, "qp-offset-c2", ARGS_VAL_TYPE_INTEGER, 0, NULL,
140+
ARGS_NO_KEY, "qp-offset-c2", ARGS_VAL_TYPE_STRING, 0, NULL,
141141
"QP offset value for Component 2 (Cr)"
142142
},
143143
{
144-
ARGS_NO_KEY, "qp-offset-c3", ARGS_VAL_TYPE_INTEGER, 0, NULL,
144+
ARGS_NO_KEY, "qp-offset-c3", ARGS_VAL_TYPE_STRING, 0, NULL,
145145
"QP offset value for Component 3"
146146
},
147147
{
@@ -549,7 +549,7 @@ static int update_param(args_var_t *vars, oapve_param_t *param)
549549

550550

551551
UPDATE_A_PARAM_W_KEY_VAL(param, "tile-w", vars->tile_w);
552-
UPDATE_A_PARAM_W_KEY_VAL(param, "tile-w", vars->tile_h);
552+
UPDATE_A_PARAM_W_KEY_VAL(param, "tile-h", vars->tile_h);
553553

554554
param->csp = vars->input_csp;
555555
return 0;

inc/oapv.h

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,18 @@ struct oapv_frm_info {
363363
int chroma_format_idc;
364364
int bit_depth;
365365
int capture_time_distance;
366-
/* custom quantization matrix */
366+
// flag for custom quantization matrix
367367
int use_q_matrix;
368-
unsigned char q_matrix[OAPV_MAX_CC][OAPV_BLK_D]; // only meaningful if use_q_matrix is true
369-
/* color description values */
368+
// q_matrix is meaningful if use_q_matrix is true
369+
unsigned char q_matrix[OAPV_MAX_CC][OAPV_BLK_D];
370+
// flag for color_description_present_flag */
370371
int color_description_present_flag;
371-
unsigned char color_primaries; // only meaningful if color_description_present_flag is true
372-
unsigned char transfer_characteristics; // only meaningful if color_description_present_flag is true
373-
unsigned char matrix_coefficients; // only meaningful if color_description_present_flag is true
374-
int full_range_flag; // only meaningful if color_description_present_flag is true
372+
// color_primaries, transfer_characteristics, matrix_coefficients, and
373+
// full_range_flag are meaningful if color_description_present_flag is true
374+
unsigned char color_primaries;
375+
unsigned char transfer_characteristics;
376+
unsigned char matrix_coefficients;
377+
int full_range_flag;
375378
};
376379

377380
typedef struct oapv_au_info oapv_au_info_t;
@@ -528,43 +531,59 @@ struct oapve_param {
528531
};
529532

530533
#define OAPV_CDESC_THREADS_AUTO 0
534+
/*****************************************************************************
535+
* automatic assignment of number of threads in creation of encoder & decoder
536+
*****************************************************************************/
537+
#define OAPV_CDESC_THREADS_AUTO 0
538+
531539
/*****************************************************************************
532540
* description for encoder creation
533541
*****************************************************************************/
534542
typedef struct oapve_cdesc oapve_cdesc_t;
535543
struct oapve_cdesc {
536-
int max_bs_buf_size; // max bitstream buffer size
537-
int max_num_frms; // max number of frames to be encoded
538-
int threads; // number of threads
539-
oapve_param_t param[OAPV_MAX_NUM_FRAMES]; // encoding parameters
544+
// max bitstream buffer size
545+
int max_bs_buf_size;
546+
// max number of frames to be encoded
547+
int max_num_frms;
548+
// max number of threads (or OAPV_CDESC_THREADS_AUTO for auto-assignment)
549+
int threads;
550+
// encoding parameters
551+
oapve_param_t param[OAPV_MAX_NUM_FRAMES];
540552
};
541553

542554
/*****************************************************************************
543555
* encoding status
544556
*****************************************************************************/
545557
typedef struct oapve_stat oapve_stat_t;
546558
struct oapve_stat {
547-
int write; // byte size of encoded bitstream
548-
oapv_au_info_t aui; // information of encoded frames
549-
int frm_size[OAPV_MAX_NUM_FRAMES]; // bitstream byte size of each frame
559+
// byte size of encoded bitstream
560+
int write;
561+
// information of encoded frames
562+
oapv_au_info_t aui;
563+
// bitstream byte size of each frame
564+
int frm_size[OAPV_MAX_NUM_FRAMES];
550565
};
551566

552567
/*****************************************************************************
553568
* description for decoder creation
554569
*****************************************************************************/
555570
typedef struct oapvd_cdesc oapvd_cdesc_t;
556571
struct oapvd_cdesc {
557-
int threads; // number of threads
572+
// max number of threads (or OAPV_CDESC_THREADS_AUTO for auto-assignment)
573+
int threads;
558574
};
559575

560576
/*****************************************************************************
561577
* decoding status
562578
*****************************************************************************/
563579
typedef struct oapvd_stat oapvd_stat_t;
564580
struct oapvd_stat {
565-
int read; // byte size of decoded bitstream (read size)
566-
oapv_au_info_t aui; // information of decoded frames
567-
int frm_size[OAPV_MAX_NUM_FRAMES]; // bitstream byte size of each frame
581+
// byte size of decoded bitstream (read size)
582+
int read;
583+
// information of decoded frames
584+
oapv_au_info_t aui;
585+
// bitstream byte size of each frame
586+
int frm_size[OAPV_MAX_NUM_FRAMES];
568587
};
569588

570589
/*****************************************************************************
@@ -582,7 +601,7 @@ struct oapvm_payload {
582601
/*****************************************************************************
583602
* interface for metadata container
584603
*****************************************************************************/
585-
typedef void *oapvm_t; /* instance identifier for OAPV metadata container */
604+
typedef void *oapvm_t; // instance identifier for OAPV metadata container
586605

587606
oapvm_t OAPV_EXPORT oapvm_create(int *err);
588607
void OAPV_EXPORT oapvm_delete(oapvm_t mid);

src/oapv.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,9 @@ int oapve_encode(oapve_t eid, oapv_frms_t *ifrms, oapvm_t mid, oapv_bitb_t *bitb
13061306
u8 *bs_pos_au_beg = oapv_bsw_sink(bs); // address syntax of au size
13071307
u8 *bs_pos_pbu_beg;
13081308
oapv_bs_t bs_pbu_beg;
1309-
oapv_bsw_write(bs, 0, 32);
1309+
oapv_bsw_write(bs, 0, 32); // raw bitstream byte size (skip)
1310+
1311+
oapv_bsw_write(bs, 0x61507631, 32); // signature ('aPv1')
13101312

13111313
for(i = 0; i < ifrms->num_frms; i++) {
13121314
frm = &ifrms->frm[i];
@@ -1380,7 +1382,7 @@ int oapve_encode(oapve_t eid, oapv_frms_t *ifrms, oapvm_t mid, oapv_bitb_t *bitb
13801382
}
13811383
}
13821384

1383-
u32 au_size = (u32)((u8 *)oapv_bsw_sink(bs) - bs_pos_au_beg) - 4;
1385+
u32 au_size = (u32)((u8 *)oapv_bsw_sink(bs) - bs_pos_au_beg) - 4 /* au_size */;
13841386
oapv_bsw_write_direct(bs_pos_au_beg, au_size, 32); /* u(32) */
13851387

13861388
oapv_bsw_deinit(&ctx->bs); /* de-init BSW */
@@ -1936,7 +1938,6 @@ void oapvd_delete(oapvd_t did)
19361938
int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid, oapvd_stat_t *stat)
19371939
{
19381940
oapvd_ctx_t *ctx;
1939-
oapv_bs_t *bs;
19401941
oapv_pbuh_t pbuh;
19411942
int ret = OAPV_OK;
19421943
u32 pbu_size;
@@ -1946,7 +1947,16 @@ int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid
19461947
ctx = dec_id_to_ctx(did);
19471948
oapv_assert_rv(ctx, OAPV_ERR_INVALID_ARGUMENT);
19481949

1950+
// read signature ('aPv1')
1951+
oapv_assert_rv(bitb->ssize > 4, OAPV_ERR_MALFORMED_BITSTREAM);
1952+
u32 signature = oapv_bsr_read_direct(bitb->addr, 32);
1953+
oapv_assert_rv(signature == 0x61507631, OAPV_ERR_MALFORMED_BITSTREAM);
1954+
cur_read_size += 4;
1955+
stat->read += 4;
1956+
1957+
// decode PBUs
19491958
do {
1959+
oapv_bs_t *bs;
19501960
u32 remain = bitb->ssize - cur_read_size;
19511961
oapv_assert_gv((remain >= 8), ret, OAPV_ERR_MALFORMED_BITSTREAM, ERR);
19521962
oapv_bsr_init(&ctx->bs, (u8 *)bitb->addr + cur_read_size, remain, NULL);
@@ -2009,7 +2019,7 @@ int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid
20092019

20102020
ofrms->frm[frame_cnt].pbu_type = pbuh.pbu_type;
20112021
ofrms->frm[frame_cnt].group_id = pbuh.group_id;
2012-
stat->frm_size[frame_cnt] = pbu_size + 4 /* PUB size length*/;
2022+
stat->frm_size[frame_cnt] = pbu_size + 4 /* byte size of 'pbu_size' syntax */;
20132023
frame_cnt++;
20142024
}
20152025
else if(pbuh.pbu_type == OAPV_PBU_TYPE_METADATA) {
@@ -2022,7 +2032,7 @@ int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid
20222032
ret = oapvd_vlc_filler(bs, (pbu_size - 4));
20232033
oapv_assert_g(OAPV_SUCCEEDED(ret), ERR);
20242034
}
2025-
cur_read_size += pbu_size + 4;
2035+
cur_read_size += pbu_size + 4 /* byte size of 'pbu_size' syntax */;
20262036
} while(cur_read_size < bitb->ssize);
20272037
stat->aui.num_frms = frame_cnt;
20282038
oapv_assert_gv(ofrms->num_frms == frame_cnt, ret, OAPV_ERR_MALFORMED_BITSTREAM, ERR);
@@ -2055,15 +2065,22 @@ int oapvd_info(void *au, int au_size, oapv_au_info_t *aui)
20552065
{
20562066
int ret, frm_count = 0;
20572067
u32 cur_read_size = 0;
2068+
int pbu_count = 0;
2069+
oapv_bs_t bs;
20582070

20592071
DUMP_SET(0);
20602072

2061-
/* 'au' address contains series of PBU */
2073+
// read signature ('aPv1')
2074+
oapv_assert_rv(au_size > 4, OAPV_ERR_MALFORMED_BITSTREAM);
2075+
u32 signature = oapv_bsr_read_direct(au, 32);
2076+
oapv_assert_rv(signature == 0x61507631, OAPV_ERR_MALFORMED_BITSTREAM);
2077+
cur_read_size += 4;
2078+
2079+
// parse PBUs
20622080
do {
2063-
oapv_bs_t bs;
20642081
u32 pbu_size = 0;
20652082
u32 remain = au_size - cur_read_size;
2066-
oapv_assert_rv((remain >= 8), OAPV_ERR_MALFORMED_BITSTREAM);
2083+
oapv_assert_rv(remain >= 8, OAPV_ERR_MALFORMED_BITSTREAM);
20672084
oapv_bsr_init(&bs, (u8 *)au + cur_read_size, remain, NULL);
20682085

20692086
ret = oapvd_vlc_pbu_size(&bs, &pbu_size); // read pbu_size (4 byte)
@@ -2105,6 +2122,7 @@ int oapvd_info(void *au, int au_size, oapv_au_info_t *aui)
21052122
}
21062123
aui->num_frms = frm_count;
21072124
cur_read_size += pbu_size + 4; /* 4byte is for pbu_size syntax itself */
2125+
pbu_count++;
21082126
} while(cur_read_size < au_size);
21092127
DUMP_SET(1);
21102128
return OAPV_OK;

src/oapv_bs.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ void *oapv_bsw_sink(oapv_bs_t *bs)
8080
return (void *)bs->cur;
8181
}
8282

83-
int oapv_bsw_write_direct(void *bits, u32 val, int len)
83+
int oapv_bsw_write_direct(void *addr, u32 val, int len)
8484
{
8585
int i;
86-
unsigned char *p = (unsigned char *)bits;
86+
unsigned char *p = (unsigned char *)addr;
8787

8888
oapv_assert_rv((len & 0x7) == 0, -1); // len should be byte-aligned
8989

@@ -370,6 +370,26 @@ int oapv_bsr_read1(oapv_bs_t *bs)
370370
return code;
371371
}
372372

373+
u32 oapv_bsr_read_direct(void *addr, int len)
374+
{
375+
u32 code = 0;
376+
int shift = 24;
377+
u8 *p = (u8 *)addr;
378+
int byte = (len + 7) >> 3;
379+
380+
oapv_assert(len <= 32);
381+
382+
while(byte) {
383+
code |= *(p) << shift;
384+
shift -= 8;
385+
byte--;
386+
p++;
387+
}
388+
code = code >> (32 - len);
389+
return code;
390+
}
391+
392+
373393
///////////////////////////////////////////////////////////////////////////////
374394
// end of decoder code
375395
#endif // ENABLE_DECODER

src/oapv_bs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static inline int bsw_get_write_byte(oapv_bs_t *bs)
6969
void oapv_bsw_init(oapv_bs_t *bs, u8 *buf, int size, oapv_bs_fn_flush_t fn_flush);
7070
void oapv_bsw_deinit(oapv_bs_t *bs);
7171
void *oapv_bsw_sink(oapv_bs_t *bs);
72-
int oapv_bsw_write_direct(void *bits, u32 val, int len);
72+
int oapv_bsw_write_direct(void *addr, u32 val, int len);
7373
int oapv_bsw_write1(oapv_bs_t *bs, int val);
7474
int oapv_bsw_write(oapv_bs_t *bs, u32 val, int len);
7575
///////////////////////////////////////////////////////////////////////////////
@@ -139,6 +139,7 @@ void *oapv_bsr_sink(oapv_bs_t *bs);
139139
void oapv_bsr_move(oapv_bs_t *bs, u8 *pos);
140140
u32 oapv_bsr_read(oapv_bs_t *bs, int size);
141141
int oapv_bsr_read1(oapv_bs_t *bs);
142+
u32 oapv_bsr_read_direct(void *addr, int len);
142143

143144
///////////////////////////////////////////////////////////////////////////////
144145
// end of decoder code

src/oapv_param.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131

3232
#ifndef __OAPV_PARAM_H__32943289478329438247238643278463728473829__
33-
#define ifndef __OAPV_PARAM_H__32943289478329438247238643278463728473829__
33+
#define __OAPV_PARAM_H__32943289478329438247238643278463728473829__
3434

3535
#include "oapv.h"
3636

test/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
| No. | Bitstream Name | Description | Profile&nbsp;&nbsp; | Level | Band | Frame Rate | Resolution | # of Frame | MD5 sum of bitstream |
77
|-----|----------------|--------------------------------------------------------------|---------------------|-------|------|------------|------------|------------|----------------------------------|
8-
| 1 | tile_A | one-tile per one-picture | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 74c5c0ca1bd2cfb28c6e2e0673e965f9 |
9-
| 2 | tile_B | Tile size = min size tile (256x128) | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 666ec80235a1e8f59db044d77a89a495 |
10-
| 3 | tile_C | # of Tiles: max num tile (20x20) | 422-10 | 5 | 0 | 30 fps | 7680x4320 | 3 | 75363d036965a9dccc90a9ce8d0ae652 |
11-
| 4 | tile_D | tile dummy data test | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | dd492519c90409a9ca5710746f45c125 |
12-
| 5 | tile_E | tile_size_present_in_fh_flag=on | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 134c4aa46cec9ab0299824682a89eecd |
13-
| 6 | qp_A | QP matrix enabled | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 5ca6d4ea0f65add261b44ed3532a0a73 |
14-
| 7 | qp_B | Tile QP variation in a frame | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 85bfa477911447d994c17dea9703a9c7 |
15-
| 8 | qp_C | Set all the QPs in a frame equal to min. QP (=0) | 422-10 | 6 | 2 | 60 fps | 3840x2160 | 3 | 8c2928ec05eb06d42d6a8bda0ceb7e8d |
16-
| 9 | qp_D | Set all the QPs in a frame equal to max. QP (=51) | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 9c98e376fb59100f5a5585482fb33746 |
17-
| 10 | qp_E | Set different QP betwee luma and chroma | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 6d1a1bc982d412758f353c8d041979d1 |
18-
| 11 | syn_A | Exercise a synthetic image with QP = 0 and QP = 51 | 422-10 | 4.1 | 2 | 60 fps | 1920x1080 | 2 | db9f8f7ce57871481e5b257b79149b1e |
19-
| 12 | syn_B | Exercise a synthetic image with Tile QP variation in Frame | 422-10 | 4.1 | 2 | 60 fps | 1920x1080 | 2 | 5f6c57f0bfe7ceb2f97a56a3bec7fb7a |
8+
| 1 | tile_A | one-tile per one-picture | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | c5b2f4c4ec9804f0292b2f12bd558dc5 |
9+
| 2 | tile_B | Tile size = min size tile (256x128) | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 7d626cea95f8d7a4b3f1f6e3d10e923c |
10+
| 3 | tile_C | # of Tiles: max num tile (20x20) | 422-10 | 5 | 0 | 30 fps | 7680x4320 | 3 | 758377994717d15999f53341eb5d6038 |
11+
| 4 | tile_D | tile dummy data test | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | e124625d4ad310e2e60e366a63f669c9 |
12+
| 5 | tile_E | tile_size_present_in_fh_flag=on | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 77cd01a8821cd17c2188fca033edc726 |
13+
| 6 | qp_A | QP matrix enabled | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 1ade0aed96ddf0aab286a082c17701d7 |
14+
| 7 | qp_B | Tile QP variation in a frame | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | c7cac366f29dc6571bc814923cadeb4b |
15+
| 8 | qp_C | Set all the QPs in a frame equal to min. QP (=0) | 422-10 | 6 | 2 | 60 fps | 3840x2160 | 3 | 6e2928f315e1670b6842955b0e7b4ad8 |
16+
| 9 | qp_D | Set all the QPs in a frame equal to max. QP (=51) | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | c7a3e5d7f1c987a064a7bdb08944901f |
17+
| 10 | qp_E | Set different QP betwee luma and chroma | 422-10 | 4.1 | 2 | 60 fps | 3840x2160 | 3 | 7d626cea95f8d7a4b3f1f6e3d10e923c |
18+
| 11 | syn_A | Exercise a synthetic image with QP = 0 and QP = 51 | 422-10 | 4.1 | 2 | 60 fps | 1920x1080 | 2 | 7b0cc8fdffdfca860dcee9b69b051053 |
19+
| 12 | syn_B | Exercise a synthetic image with Tile QP variation in Frame | 422-10 | 4.1 | 2 | 60 fps | 1920x1080 | 2 | b87a59443b009e9241393e6e1a927d61 |
2020

2121
## Test sequence
2222
"sequence" folder has the uncompressed video sequence for encoder testing.

test/bitstream/qp_A.apv

12 Bytes
Binary file not shown.

test/bitstream/qp_B.apv

12 Bytes
Binary file not shown.

test/bitstream/qp_C.apv

12 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)