| 125 | |
| 126 | |
| 127 | int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args, |
| 128 | const AVTextFormatSection *sections, int nb_sections, AVTextFormatOptions options, char *show_data_hash) |
| 129 | { |
| 130 | AVTextFormatContext *tctx; |
| 131 | int ret = 0; |
| 132 | |
| 133 | av_assert0(ptctx && formatter); |
| 134 | |
| 135 | if (!(tctx = av_mallocz(sizeof(AVTextFormatContext)))) { |
| 136 | ret = AVERROR(ENOMEM); |
| 137 | goto fail; |
| 138 | } |
| 139 | |
| 140 | for (int i = 0; i < SECTION_MAX_NB_LEVELS; i++) |
| 141 | av_bprint_init(&tctx->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED); |
| 142 | |
| 143 | tctx->class = &textcontext_class; |
| 144 | av_opt_set_defaults(tctx); |
| 145 | |
| 146 | if (!(tctx->priv = av_mallocz(formatter->priv_size))) { |
| 147 | ret = AVERROR(ENOMEM); |
| 148 | goto fail; |
| 149 | } |
| 150 | |
| 151 | tctx->opts = options; |
| 152 | |
| 153 | if (nb_sections > SECTION_MAX_NB_SECTIONS) { |
| 154 | av_log(tctx, AV_LOG_ERROR, "The number of section definitions (%d) is larger than the maximum allowed (%d)\n", nb_sections, SECTION_MAX_NB_SECTIONS); |
| 155 | ret = AVERROR(EINVAL); |
| 156 | goto fail; |
| 157 | } |
| 158 | |
| 159 | tctx->formatter = formatter; |
| 160 | tctx->level = -1; |
| 161 | tctx->sections = sections; |
| 162 | tctx->nb_sections = nb_sections; |
| 163 | tctx->writer = writer_context; |
| 164 | |
| 165 | if (formatter->priv_class) { |
| 166 | void *priv_ctx = tctx->priv; |
| 167 | *(const AVClass **)priv_ctx = formatter->priv_class; |
| 168 | av_opt_set_defaults(priv_ctx); |
| 169 | } |
| 170 | |
| 171 | /* convert options to dictionary */ |
| 172 | if (args) { |
| 173 | AVDictionary *opts = NULL; |
| 174 | const AVDictionaryEntry *opt = NULL; |
| 175 | |
| 176 | if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) { |
| 177 | av_log(tctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to textformat context\n", args); |
| 178 | av_dict_free(&opts); |
| 179 | goto fail; |
| 180 | } |
| 181 | |
| 182 | while ((opt = av_dict_iterate(opts, opt))) { |
| 183 | if ((ret = av_opt_set(tctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) { |
| 184 | av_log(tctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to textformat context\n", |
no test coverage detected