Unified · Split
| @@ -248,6 +248,11 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void · 247 unmodified lines | ||
| 248 | 248 | } else { |
| 249 | 249 | AVBPrint bp; |
| 250 | 250 | |
| 251 | + if (iamf_audio_element->nb_layers < 1) { | |
| 252 | + av_log(log_ctx, AV_LOG_ERROR, "Invalid amount of layers for CHANNEL_BASED audio element. Must be >= 1\n"); | |
| 253 | + return AVERROR(EINVAL); | |
| 254 | + } | |
| 255 | + | |
| 251 | 256 | for (int j, i = 0; i < iamf_audio_element->nb_layers; i++) { |
| 252 | 257 | const AVIAMFLayer *layer = iamf_audio_element->layers[i]; |
| 253 | 258 | |
| @@ -741,13 +746,40 @@ static int iamf_write_audio_element(const IAMFContext *iamf, · 487 unmodified lines | ||
| 741 | 746 | for (int i = 0; i < audio_element->nb_substreams; i++) |
| 742 | 747 | ffio_write_leb(dyn_bc, audio_element->substreams[i].audio_substream_id); |
| 743 | 748 | |
| 744 | − if (element->nb_layers == 1) | |
| 749 | + /* When audio_element_type = 1, num_parameters SHALL be set to 0 */ | |
| 750 | + if (element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE) | |
| 751 | + param_definition_types = 0; | |
| 752 | + else { | |
| 753 | + int layout = 0, expanded_layout = 0; | |
| 754 | + get_loudspeaker_layout(element->layers[0], &layout, &expanded_layout); | |
| 755 | + /* When the loudspeaker_layout = 15, the type PARAMETER_DEFINITION_DEMIXING SHALL NOT be present. */ | |
| 756 | + if (layout == 15) | |
| 757 | + param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING; | |
| 758 | + /* When the loudspeaker_layout of the (non-)scalable channel audio (i.e., num_layers = 1) is less than or equal to 3.1.2ch, | |
| 759 | + * (i.e., Mono, Stereo, or 3.1.2ch), the type PARAMETER_DEFINITION_DEMIXING SHALL NOT be present. */ | |
| 760 | + else if (element->nb_layers == 1 && (layout == 0 || layout == 1 || layout == 8)) | |
| 745 | 761 | param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING; |
| 762 | + /* When num_layers > 1, the type PARAMETER_DEFINITION_RECON_GAIN SHALL be present */ | |
| 746 | 763 | if (element->nb_layers > 1) |
| 747 | 764 | param_definition_types |= AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN; |
| 765 | + /* When codec_id = fLaC or ipcm, the type PARAMETER_DEFINITION_RECON_GAIN SHALL NOT be present. */ | |
| 748 | 766 | if (codec_config->codec_tag == MKTAG('f','L','a','C') || |
| 749 | 767 | codec_config->codec_tag == MKTAG('i','p','c','m')) |
| 750 | 768 | param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN; |
| 769 | + if ((param_definition_types & AV_IAMF_PARAMETER_DEFINITION_DEMIXING) && !element->demixing_info) { | |
| 770 | + if (element->nb_layers > 1) { | |
| 771 | + get_loudspeaker_layout(element->layers[element->nb_layers-1], &layout, &expanded_layout); | |
| 772 | + /* When the highest loudspeaker_layout of the scalable channel audio (i.e., num_layers > 1) is greater than 3.1.2ch, | |
| 773 | + * (i.e., 5.1.2ch, 5.1.4ch, 7.1.2ch, or 7.1.4ch), type PARAMETER_DEFINITION_DEMIXING SHALL be present. */ | |
| 774 | + if (layout == 3 && layout == 4 && layout == 6 && layout == 7) { | |
| 775 | + av_log(log_ctx, AV_LOG_ERROR, "demixing_info needed but not set in Stream Group #%u\n", | |
| 776 | + audio_element->audio_element_id); | |
| 777 | + return AVERROR(EINVAL); | |
| 778 | + } | |
| 779 | + } | |
| 780 | + param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING; | |
| 781 | + } | |
| 782 | + } | |
| 751 | 783 | |
| 752 | 784 | ffio_write_leb(dyn_bc, av_popcount(param_definition_types)); // num_parameters |
| 753 | 785 | |
| @@ -756,12 +788,6 @@ static int iamf_write_audio_element(const IAMFContext *iamf, · 2 unmodified lines | ||
| 756 | 788 | const IAMFParamDefinition *param_def; |
| 757 | 789 | const AVIAMFDemixingInfo *demix; |
| 758 | 790 | |
| 759 | − if (!param) { | |
| 760 | − av_log(log_ctx, AV_LOG_ERROR, "demixing_info needed but not set in Stream Group #%u\n", | |
| 761 | − audio_element->audio_element_id); | |
| 762 | − return AVERROR(EINVAL); | |
| 763 | − } | |
| 764 | − | |
| 765 | 791 | demix = av_iamf_param_definition_get_subblock(param, 0); |
| 766 | 792 | ffio_write_leb(dyn_bc, AV_IAMF_PARAMETER_DEFINITION_DEMIXING); // type |
| 767 | 793 | |