bluez5: aac: work around devices setting multiple bits in caps

Airpods don't follow the specification and set multiple bits in AAC
object type, including the ELD bit, but actually want AAC-LC.  So check
the AOT in the right order.
This commit is contained in:
Pauli Virtanen 2024-12-06 18:53:07 +02:00
parent 1f5c31dbc4
commit c5e57a062d

View file

@ -364,7 +364,15 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags,
if (res != AACENC_OK)
goto error;
if (conf->object_type & AAC_OBJECT_TYPE_MPEG4_AAC_ELD) {
/* If object type has multiple bits set (invalid per spec, see above),
* assume the device usually means AAC-LC.
*/
if (conf->object_type & (AAC_OBJECT_TYPE_MPEG2_AAC_LC |
AAC_OBJECT_TYPE_MPEG4_AAC_LC)) {
res = aacEncoder_SetParam(this->aacenc, AACENC_AOT, AOT_AAC_LC);
if (res != AACENC_OK)
goto error;
} else if (conf->object_type & AAC_OBJECT_TYPE_MPEG4_AAC_ELD) {
res = aacEncoder_SetParam(this->aacenc, AACENC_AOT, AOT_ER_AAC_ELD);
if (res != AACENC_OK)
goto error;
@ -372,11 +380,6 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags,
res = aacEncoder_SetParam(this->aacenc, AACENC_SBR_MODE, 1);
if (res != AACENC_OK)
goto error;
} else if (conf->object_type & (AAC_OBJECT_TYPE_MPEG2_AAC_LC |
AAC_OBJECT_TYPE_MPEG4_AAC_LC)) {
res = aacEncoder_SetParam(this->aacenc, AACENC_AOT, AOT_AAC_LC);
if (res != AACENC_OK)
goto error;
} else {
res = -EINVAL;
goto error;