That is a more appropriate place for this, and will also be useful in future commits.
Unified · Split
| @@ -154,6 +154,7 @@ int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, · 153 unmodified lines | |||
| 154 | static av_cold int common_init(AVFilterContext *ctx) | 154 | static av_cold int common_init(AVFilterContext *ctx) |
| 155 | { | 155 | { |
| 156 | BufferSinkContext *buf = ctx->priv; | 156 | BufferSinkContext *buf = ctx->priv; |
| 157 | int ret = 0; | ||
| 157 | 158 | ||
| 158 | #if FF_API_BUFFERSINK_OPTS | 159 | #if FF_API_BUFFERSINK_OPTS |
| 159 | 160 | ||
| @@ -184,6 +185,44 @@ static av_cold int common_init(AVFilterContext *ctx) · 24 unmodified lines | |||
| 184 | 185 | ||
| 185 | CHECK_LIST_SIZE(sample_fmts) | 186 | CHECK_LIST_SIZE(sample_fmts) |
| 186 | CHECK_LIST_SIZE(sample_rates) | 187 | CHECK_LIST_SIZE(sample_rates) |
| 188 | |||
| 189 | if (buf->channel_layouts_str) { | ||
| 190 | const char *cur = buf->channel_layouts_str; | ||
| 191 | |||
| 192 | if (buf->all_channel_counts) | ||
| 193 | av_log(ctx, AV_LOG_WARNING, | ||
| 194 | "Conflicting all_channel_counts and list in options\n"); | ||
| 195 | |||
| 196 | while (cur) { | ||
| 197 | void *tmp; | ||
| 198 | char *next = strchr(cur, '|'); | ||
| 199 | if (next) | ||
| 200 | *next++ = 0; | ||
| 201 | |||
| 202 | // +2 for the new element and terminator | ||
| 203 | tmp = av_realloc_array(buf->channel_layouts, buf->nb_channel_layouts + 2, | ||
| 204 | sizeof(*buf->channel_layouts)); | ||
| 205 | if (!tmp) | ||
| 206 | return AVERROR(ENOMEM); | ||
| 207 | |||
| 208 | memset(&buf->channel_layouts[buf->nb_channel_layouts], 0, | ||
| 209 | sizeof(*buf->channel_layouts)); | ||
| 210 | buf->nb_channel_layouts++; | ||
| 211 | |||
| 212 | ret = av_channel_layout_from_string(&buf->channel_layouts[buf->nb_channel_layouts - 1], cur); | ||
| 213 | if (ret < 0) { | ||
| 214 | av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur); | ||
| 215 | return ret; | ||
| 216 | } | ||
| 217 | if (ret < 0) | ||
| 218 | return ret; | ||
| 219 | |||
| 220 | cur = next; | ||
| 221 | } | ||
| 222 | |||
| 223 | if (buf->nb_channel_layouts) | ||
| 224 | buf->channel_layouts[buf->nb_channel_layouts] = (AVChannelLayout){ 0 }; | ||
| 225 | } | ||
| 187 | } | 226 | } |
| 188 | 227 | ||
| 189 | #undef CHECK_LIST_SIZE | 228 | #undef CHECK_LIST_SIZE |
| @@ -412,8 +451,6 @@ static int asink_query_formats(AVFilterContext *ctx) · 222 unmodified lines | |||
| 412 | #if FF_API_BUFFERSINK_OPTS | 451 | #if FF_API_BUFFERSINK_OPTS |
| 413 | } else { | 452 | } else { |
| 414 | AVFilterFormats *formats = NULL; | 453 | AVFilterFormats *formats = NULL; |
| 415 | AVChannelLayout layout = { 0 }; | ||
| 416 | AVFilterChannelLayouts *layouts = NULL; | ||
| 417 | unsigned i; | 454 | unsigned i; |
| 418 | 455 | ||
| 419 | if (buf->sample_fmts_size) { | 456 | if (buf->sample_fmts_size) { |
| @@ -424,37 +461,9 @@ static int asink_query_formats(AVFilterContext *ctx) · 4 unmodified lines | |||
| 424 | return ret; | 461 | return ret; |
| 425 | } | 462 | } |
| 426 | 463 | ||
| 427 | if (buf->channel_layouts_str || buf->all_channel_counts) { | 464 | if (buf->nb_channel_layouts) { |
| 428 | if (buf->channel_layouts_str) { | 465 | ret = ff_set_common_channel_layouts_from_list(ctx, buf->channel_layouts); |
| 429 | const char *cur = buf->channel_layouts_str; | 466 | if (ret < 0) |
| 430 | |||
| 431 | while (cur) { | ||
| 432 | char *next = strchr(cur, '|'); | ||
| 433 | if (next) | ||
| 434 | *next++ = 0; | ||
| 435 | |||
| 436 | ret = av_channel_layout_from_string(&layout, cur); | ||
| 437 | if (ret < 0) { | ||
| 438 | av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur); | ||
| 439 | return ret; | ||
| 440 | } | ||
| 441 | ret = ff_add_channel_layout(&layouts, &layout); | ||
| 442 | av_channel_layout_uninit(&layout); | ||
| 443 | if (ret < 0) | ||
| 444 | return ret; | ||
| 445 | |||
| 446 | cur = next; | ||
| 447 | } | ||
| 448 | } | ||
| 449 | |||
| 450 | if (buf->all_channel_counts) { | ||
| 451 | if (layouts) | ||
| 452 | av_log(ctx, AV_LOG_WARNING, | ||
| 453 | "Conflicting all_channel_counts and list in options\n"); | ||
| 454 | else if (!(layouts = ff_all_channel_counts())) | ||
| 455 | return AVERROR(ENOMEM); | ||
| 456 | } | ||
| 457 | if ((ret = ff_set_common_channel_layouts(ctx, layouts)) < 0) | ||
| 458 | return ret; | 467 | return ret; |
| 459 | } | 468 | } |
| 460 | 469 | ||