Skip to content

Error handling in encoder for width setting#69

Merged
cpncf merged 9 commits intomainfrom
handle_error_width_option
May 6, 2025
Merged

Error handling in encoder for width setting#69
cpncf merged 9 commits intomainfrom
handle_error_width_option

Conversation

@subhrajitm20
Copy link
Collaborator

This PR fixes the error handling in APV encoder for the case of --input-csp 2 (422 subsampling) and width not multiple of 2.

In the existing code, the encoder proceeds with encoding the given file to generate an incorrect bitstream. Example command:
./build/bin/oapv_app_enc -i ./video.yuv -o encoded.oapv -w 1919 -h 1080 -z 60 --input-csp 2
The encoder produces .oapv file. When it is fed to the decoder with command:
./build/bin/oapv_app_dec -i encoded.oapv -o decoded.yuv
the decoder declares error and exits since the decoder already has the correct error handling code on line 702 in oapv_vlc.c.

* For --input-csp 2, -w should be a multiple of 2
@subhrajitm20 subhrajitm20 requested a review from kpchoi May 2, 2025 15:16
Comment on lines 555 to 559
// ensure frame width multiple of 2 in case of 422 format
if ((param->csp == 2) && (param->w & 0x1)) {
logerr("width should be a multiple of 2 for '--input-csp 2'\n");
return -1;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this code to 'check_conf()' function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpchoi
I have moved the changes to the check_conf() function.

* invalid configuration check of --input-csp 2 and -w non-multiple of 2
moved to the check_conf() function
@subhrajitm20 subhrajitm20 requested a review from kpchoi May 5, 2025 05:30
kpchoi and others added 4 commits May 5, 2025 15:55
* updated imhex screenshot compatible with version 4

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>

* updated README

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>

* fixed invalid operation incase of y4m input

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>

---------

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>
Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>
* For --input-csp 2, -w should be a multiple of 2

Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>
* invalid configuration check of --input-csp 2 and -w non-multiple of 2
moved to the check_conf() function

Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>
Comment on lines 327 to 331
// ensure frame width multiple of 2 in case of 422 format
if ((vars->input_csp == 2) && (cdesc->param[FRM_IDX].w & 0x1)) {
logerr("width should be a multiple of 2 for '--input-csp 2'\n");
return -1;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch is correct, but I'd like to recommend to use for loop with cdesc.max_num_frms.
Even though the cdesc.max_num_frms value is alwasy 1, the loop with cdesc.max_num_frms value would be much more flexible when we start to support multiple frames encoding in near future.

like this;

for (i < cdesc.max_num_frms) {
if ((vars->input_csp == 2) && (cdesc->param[i].w & 0x1)) {
logerr("%d-th frame's width should be a multiple of 2 for '--input-csp 2'\n", i);
return -1;
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the changes inside for loop to support multiple frames encoding

* This will allow flexible implementation of multiple frames encoding in
near future

Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>
Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>
int i;
for(i = 0; i < cdesc->max_num_frms; i++) {
// ensure frame width multiple of 2 in case of 422 format
if ((vars->input_csp == 2) && (cdesc->param[FRM_IDX].w & 0x1)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think FRM_IDX should be replaced with 'i'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes

Signed-off-by: Subhrajit Mishra <84323996+subhrajitm20@users.noreply.github.com>
Copy link
Collaborator

@kpchoi kpchoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kpchoi
Copy link
Collaborator

kpchoi commented May 6, 2025

@subhrajitm20
There was DCO checking error. '-s' option could remove the DCO warning message when you commit code.
Anyway, this PR will be merged.

@cpncf cpncf self-requested a review May 6, 2025 04:28
Copy link
Collaborator

@cpncf cpncf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpncf cpncf merged commit 8321887 into main May 6, 2025
5 checks passed
alejandro-arango-epicgames pushed a commit to alejandro-arango-epicgames/openapv that referenced this pull request Sep 29, 2025
…n#69)

* Error handling in encoder for width setting
* For --input-csp 2, -w should be a multiple of 2

* move width check in encoder to check_conf() function
* invalid configuration check of --input-csp 2 and -w non-multiple of 2
moved to the check_conf() function

* Update readme (AcademySoftwareFoundation#67)

* updated imhex screenshot compatible with version 4

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>

* updated README

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>

* fixed invalid operation incase of y4m input

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>

---------

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>
Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>

* Error handling in encoder for width setting
* For --input-csp 2, -w should be a multiple of 2

Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>

* move width check in encoder to check_conf() function
* invalid configuration check of --input-csp 2 and -w non-multiple of 2
moved to the check_conf() function

Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>

* Enclosing check code in for loop of max_num_frms
* This will allow flexible implementation of multiple frames encoding in
near future

Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>

* Using existing for loop for handling invalid width

Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>

* Bug fix: updating FRM_IDX to loop parameter

Signed-off-by: Subhrajit Mishra <84323996+subhrajitm20@users.noreply.github.com>

---------

Signed-off-by: kp5.choi@samsung.com <kp5.choi@samsung.com>
Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com>
Signed-off-by: Subhrajit Mishra <84323996+subhrajitm20@users.noreply.github.com>
Co-authored-by: kpchoi <kp5.choi@samsung.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants