| 1010 | } |
| 1011 | |
| 1012 | static int write_parameter_block(const IAMFContext *iamf, AVIOContext *pb, |
| 1013 | const AVIAMFParamDefinition *param, void *log_ctx) |
| 1014 | { |
| 1015 | uint8_t header[MAX_IAMF_OBU_HEADER_SIZE]; |
| 1016 | const IAMFParamDefinition *param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id); |
| 1017 | PutBitContext pbc; |
| 1018 | AVIOContext *dyn_bc; |
| 1019 | uint8_t *dyn_buf = NULL; |
| 1020 | int dyn_size, ret; |
| 1021 | |
| 1022 | if (param->type > AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN) { |
| 1023 | av_log(log_ctx, AV_LOG_DEBUG, "Ignoring side data with unknown type %u\n", |
| 1024 | param->type); |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | if (!param_definition) { |
| 1029 | av_log(log_ctx, AV_LOG_ERROR, "Non-existent Parameter Definition with ID %u referenced by a packet\n", |
| 1030 | param->parameter_id); |
| 1031 | return AVERROR(EINVAL); |
| 1032 | } |
| 1033 | |
| 1034 | if (param->type != param_definition->param->type) { |
| 1035 | av_log(log_ctx, AV_LOG_ERROR, "Inconsistent values for Parameter Definition " |
| 1036 | "with ID %u in a packet\n", |
| 1037 | param->parameter_id); |
| 1038 | return AVERROR(EINVAL); |
| 1039 | } |
| 1040 | |
| 1041 | ret = avio_open_dyn_buf(&dyn_bc); |
| 1042 | if (ret < 0) |
| 1043 | return ret; |
| 1044 | |
| 1045 | // Sequence Header |
| 1046 | init_put_bits(&pbc, header, sizeof(header)); |
| 1047 | put_bits(&pbc, 5, IAMF_OBU_IA_PARAMETER_BLOCK); |
| 1048 | put_bits(&pbc, 3, 0); |
| 1049 | flush_put_bits(&pbc); |
| 1050 | avio_write(pb, header, put_bytes_count(&pbc, 1)); |
| 1051 | |
| 1052 | ffio_write_leb(dyn_bc, param->parameter_id); |
| 1053 | if (!param_definition->mode) { |
| 1054 | ffio_write_leb(dyn_bc, param->duration); |
| 1055 | ffio_write_leb(dyn_bc, param->constant_subblock_duration); |
| 1056 | if (param->constant_subblock_duration == 0) |
| 1057 | ffio_write_leb(dyn_bc, param->nb_subblocks); |
| 1058 | } |
| 1059 | |
| 1060 | for (int i = 0; i < param->nb_subblocks; i++) { |
| 1061 | const void *subblock = av_iamf_param_definition_get_subblock(param, i); |
| 1062 | |
| 1063 | switch (param->type) { |
| 1064 | case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: { |
| 1065 | const AVIAMFMixGain *mix = subblock; |
| 1066 | if (!param_definition->mode && param->constant_subblock_duration == 0) |
| 1067 | ffio_write_leb(dyn_bc, mix->subblock_duration); |
| 1068 | |
| 1069 | ffio_write_leb(dyn_bc, mix->animation_type); |
no test coverage detected