Skip to content

Commit 8fa8017

Browse files
authored
AVM: be compatible with profiles when -DCONFIG_AV2_PROFILES=1 (AOMediaCodec#3044)
1 parent 4f927e8 commit 8fa8017

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/codec_avm.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,34 @@ static avifResult avmCodecEncodeImage(avifCodec * codec,
509509
// Profile 2. 8-bit and 10-bit 4:2:2
510510
// 12-bit 4:0:0, 4:2:0, 4:2:2 and 4:4:4
511511
uint8_t seqProfile = 0;
512+
#if defined(CONFIG_AV2_PROFILES) && CONFIG_AV2_PROFILES
513+
// Only 8-bit and 10-bit are supported.
514+
AVIF_ASSERT_OR_RETURN(image->depth == 8 || image->depth == 10)
515+
516+
// Based on https://gitlab.com/AOMediaCodec/avm/-/blob/main/av2/common/enums.h?ref_type=fcab0163f471b38fe593672fcbd24a6beb0be82e#L272
517+
if (alpha) {
518+
seqProfile = 3; // Main_420_10
519+
} else {
520+
switch (image->yuvFormat) {
521+
case AVIF_PIXEL_FORMAT_YUV444:
522+
seqProfile = 5; // Main_444_10
523+
break;
524+
case AVIF_PIXEL_FORMAT_YUV422:
525+
seqProfile = 4; // Main_422_10
526+
break;
527+
case AVIF_PIXEL_FORMAT_YUV420:
528+
seqProfile = 3; // Main_420_10
529+
break;
530+
case AVIF_PIXEL_FORMAT_YUV400:
531+
seqProfile = 3; // Main_420_10
532+
break;
533+
case AVIF_PIXEL_FORMAT_NONE:
534+
case AVIF_PIXEL_FORMAT_COUNT:
535+
default:
536+
break;
537+
}
538+
}
539+
#else
512540
if (image->depth == 12) {
513541
// Only seqProfile 2 can handle 12 bit
514542
seqProfile = 2;
@@ -538,6 +566,7 @@ static avifResult avmCodecEncodeImage(avifCodec * codec,
538566
}
539567
}
540568
}
569+
#endif
541570

542571
cfg->g_profile = seqProfile;
543572
cfg->g_bit_depth = image->depth;

src/obu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ static uint32_t avifBitsReadRG(avifBits * const bits, const uint32_t n)
155155
static avifBool parseSequenceHeaderProfile(avifBits * bits, uint32_t numBits, avifSequenceHeader * header)
156156
{
157157
uint32_t seq_profile = avifBitsRead(bits, numBits);
158+
#if defined(CONFIG_AV2_PROFILES) && CONFIG_AV2_PROFILES
159+
if (seq_profile > 5) {
160+
#else
158161
if (seq_profile > 2) {
162+
#endif
159163
return AVIF_FALSE;
160164
}
161165
header->av1C.seqProfile = (uint8_t)seq_profile;

0 commit comments

Comments
 (0)