Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AV2 support #1361

Merged
merged 25 commits into from May 4, 2023
Merged

Add AV2 support #1361

merged 25 commits into from May 4, 2023

Conversation

y-guyon
Copy link
Collaborator

@y-guyon y-guyon commented Apr 20, 2023

Experimental. The AV2 specification is not finalized.

Handle av02 image item type and av2C configuration property.
Handle av02 track sample format.
Add avifavmtest.
Disable AV1 tests when all AV1 codecs are disabled.
Add presubmit ci-unix-static-av2.yml.

libavif can only generate AV2 files if it is built with AVIF_CODEC_AVM set to ON.
The avifEncoder API can only output AV2 files if codecChoice is explicitly set to AVIF_CODEC_CHOICE_AVM to avoid mistakes.
avifenc can only output AV2 files if --codec=avm is specified to avoid mistakes.
aom and avm conflict and cannot be used together in the same libavif binary. Other AV1 codecs can be enabled alongside aom.
libavif will decode any AV1 or AV2 file by default as long as the relevant codecs are enabled. The main behavior change for libavif with only AV1 codecs enabled is that before this change, items or tracks of type av02 were ignored. After this change, conformant AV1-AVIF files with extra av02 items will fail to decode unless avm is enabled.

This change allows decoding files with mixed AV1 and AV2 items or tracks (untested because no encoding tool for that). This decision can be changed in the future.

Note: The first commit exists just to reduce diffs. Please review the second and third commits.

Copy link
Collaborator

@jzern jzern left a comment

Choose a reason for hiding this comment

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

This looks ok, but I'm wondering if this should have an EXPERIMENTAL define to avoid adding av2 support to the common code unnecessarily. Others might have some thoughts.

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
@y-guyon
Copy link
Collaborator Author

y-guyon commented Apr 24, 2023

I'm wondering if this should have an EXPERIMENTAL define to avoid adding av2 support to the common code unnecessarily.

codec_avm.c is only compiled if AVIF_CODEC_AVM is ON.
At encoding, AV2 container code paths can only be successful with AVIF_CODEC_AVM=ON and explicitly specifying avm as the codec.
So I guess you are talking about the av02 and av2C boxes that are accepted during parsing, even if AVIF_CODEC_AVM=OFF. I do not think it adds any computational complexity, and leads to AVIF_RESULT_NO_CODEC_AVAILABLE anyway if the user proceeds with decoding without AVIF_CODEC_AVM=ON.
In my opinion it is rather safe to leave it as is and would avoid #defines cluttering the code, but I would be fine with a few #ifdef EXPERIMENTAL guards. If we go with the latter, should we also put all experiment-tagged features behind that define too (incremental, layers etc.)?

@vigneshvg
Copy link
Collaborator

So I guess you are talking about the av02 and av2C boxes that are accepted during parsing, even if AVIF_CODEC_AVM=OFF. I do not think it adds any computational complexity, and leads to AVIF_RESULT_NO_CODEC_AVAILABLE anyway if the user proceeds with decoding without AVIF_CODEC_AVM=ON.

I didn't look at the code too closely. I have a question about the behavior of avifDecoderParse. Would avifDecoderParse return true for AV2 streams even when AVIF_CODEC_AVM is not set? If so, that would be a potentially not-okay thing to do since some API users rely on avifDecoderParse returning true to conclude if an image is valid AVIF or not.

@jzern
Copy link
Collaborator

jzern commented Apr 26, 2023

So I guess you are talking about the av02 and av2C boxes that are accepted during parsing, even if AVIF_CODEC_AVM=OFF.

Yes, that's what I was referring to. Anything in the common code.

I do not think it adds any computational complexity, and leads to AVIF_RESULT_NO_CODEC_AVAILABLE anyway if the user proceeds with decoding without AVIF_CODEC_AVM=ON.
In my opinion it is rather safe to leave it as is and would avoid #defines cluttering the code, but I would be fine with a few #ifdef EXPERIMENTAL guards. If we go with the latter, should we also put all experiment-tagged features behind that define too (incremental, layers etc.)?

Making it explicit provides some documentation for the user and does avoid some code in production builds. It's not common right now, so we can get the group's opinion later.

src/codec_avm.c Outdated Show resolved Hide resolved
src/obu.c Outdated Show resolved Hide resolved
@y-guyon
Copy link
Collaborator Author

y-guyon commented Apr 26, 2023

I didn't look at the code too closely. I have a question about the behavior of avifDecoderParse. Would avifDecoderParse return true for AV2 streams even when AVIF_CODEC_AVM is not set?

That was the intent, yes.

If so, that would be a potentially not-okay thing to do since some API users rely on avifDecoderParse returning true to conclude if an image is valid AVIF or not.

Good point. I guarded a few places with #if defined(AVIF_CODEC_AVM) in read.c so that av02 image items or tracks are ignored by default. av2C parsing can no longer be reached without defining AVIF_CODEC_AVM.

Making it explicit provides some documentation for the user and does avoid some code in production builds. It's not common right now, so we can get the group's opinion later.

The code for av02/av2C parsing is so similar to av01/av1C that the production build binary increase is barely noticeable. libavif.so is 198192 bytes at a446c05, 198600 bytes with this change (+0.2%).

Copy link
Collaborator

@vigneshvg vigneshvg left a comment

Choose a reason for hiding this comment

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

i took a first pass at reviewing the code.

src/obu.c Outdated Show resolved Hide resolved
src/write.c Outdated Show resolved Hide resolved
src/write.c Outdated Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/read.c Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
@y-guyon y-guyon requested a review from vigneshvg April 27, 2023 14:13
Copy link
Collaborator

@vigneshvg vigneshvg left a comment

Choose a reason for hiding this comment

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

mostly okay. just a few minor comments.

CHANGELOG.md Outdated Show resolved Hide resolved
include/avif/internal.h Outdated Show resolved Hide resolved
src/avif.c Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/read.c Outdated Show resolved Hide resolved
src/write.c Outdated Show resolved Hide resolved
@y-guyon y-guyon requested a review from vigneshvg April 28, 2023 10:44
Copy link
Collaborator

@vigneshvg vigneshvg left a comment

Choose a reason for hiding this comment

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

The changes in read.c, write.c and obu.c look fine now. I still haven't looked at codec_avm.c. I will look into it sometime today. Sorry for the delay and thanks for the patience in working through this.

For easier diff of later changes.
Experimental. The AV2 specification is not finalized.

Handle av02 image item type and av2C configuration property.
Handle av02 track sample format.
Add avifavmtest.
Disable AV1 tests when all AV1 codecs are disabled.
Add presubmit ci-unix-static-av2.yml.

libavif can only generate AV2 files if it is built with AVIF_CODEC_AVM
set to ON.
The avifEncoder API can only output AV2 files if codecChoice is
explicitly set to AVIF_CODEC_CHOICE_AVM to avoid mistakes.
avifenc can only output AV2 files if --codec=avm is specified to avoid
mistakes.
aom and avm conflict and cannot be used together in the same libavif
binary. Other AV1 codecs can be enabled alongside aom.
libavif will decode any AV1 or AV2 file by default as long as the
relevant codecs are enabled. The main behavior change for libavif with
only AV1 codecs enabled is that before this change, items or tracks of
type 'av02' were ignored. After this change, conformant AV1-AVIF files
with extra 'av02' items will fail to decode unless avm is enabled.

This change allows decoding files with mixed AV1 and AV2 items or
tracks (untested because no encoding tool for that). This decision can
be changed in the future.
@y-guyon
Copy link
Collaborator Author

y-guyon commented Apr 28, 2023

I rebased this PR.

The changes in read.c, write.c and obu.c look fine now. I still haven't looked at codec_avm.c. I will look into it sometime today. Sorry for the delay and thanks for the patience in working through this.

No worries, it is not urgent. Thanks for your time.

src/codec_avm.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@vigneshvg vigneshvg left a comment

Choose a reason for hiding this comment

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

lgtm. thank you.

src/codec_avm.c Outdated Show resolved Hide resolved
src/codec_avm.c Outdated Show resolved Hide resolved
// We prefer to simply set the aomImage.planes[] pointers to the plane buffers in 'image'. When
// doing this, we set aomImage.w equal to aomImage.d_w and aomImage.h equal to aomImage.d_h and
// do not "align" aomImage.w and aomImage.h. Unfortunately this exposes a bug in libaom
// (https://crbug.com/aomedia/3113) if chroma is subsampled and image->width or image->height is
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if this was carried over to avm

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@wantehchang wantehchang left a comment

Choose a reason for hiding this comment

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

Yannis: My review is supplemental because I only checked avif.h, internal.h, and the top-level CMakelists.txt. You can merge this pull request with James and Vignesh's approval.

src/obu.c Outdated Show resolved Hide resolved
include/avif/avif.h Show resolved Hide resolved
include/avif/internal.h Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
@y-guyon y-guyon merged commit a900b0c into AOMediaCodec:main May 4, 2023
15 checks passed
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.

None yet

4 participants