History

lavfi: refactor query_formats and auto-insert audio conversion filters

Behaviour has been changed to fail negotiation if fields have been left empty. Patch was originally based on a patch by Hemanth.

Mina Nagy Zaki committed 15 years ago

Commit 3ee0bed1 parent 37cc4431 file · +73 −28Browse files

Unified · Split

libavfilter/avfiltergraph.c+73−28
@@ -23,6 +23,7 @@ · 22 unmodified lines
23#include <ctype.h>23#include <ctype.h>
24#include <string.h>24#include <string.h>
25 25
26#include "libavutil/audioconvert.h"
26#include "avfilter.h"27#include "avfilter.h"
27#include "avfiltergraph.h"28#include "avfiltergraph.h"
28#include "internal.h"29#include "internal.h"
@@ -135,11 +136,57 @@ AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name) · 106 unmodified lines
135 return NULL;136 return NULL;
136}137}
137 138
139static int insert_conv_filter(AVFilterGraph *graph, AVFilterLink *link,
140 const char *filt_name, const char *filt_args)
141{
142 static int auto_count = 0, ret;
143 char inst_name[32];
144 AVFilterContext *filt_ctx;
145
146 snprintf(inst_name, sizeof(inst_name), "auto-inserted %s %d",
147 filt_name, auto_count++);
148
149 if ((ret = avfilter_graph_create_filter(&filt_ctx,
150 avfilter_get_by_name(filt_name),
151 inst_name, filt_args, NULL, graph)) < 0)
152 return ret;
153 if ((ret = avfilter_insert_filter(link, filt_ctx, 0, 0)) < 0)
154 return ret;
155
156 filt_ctx->filter->query_formats(filt_ctx);
157
158 if ( ((link = filt_ctx-> inputs[0]) &&
159 !avfilter_merge_formats(link->in_formats, link->out_formats)) ||
160 ((link = filt_ctx->outputs[0]) &&
161 !avfilter_merge_formats(link->in_formats, link->out_formats))
162 ) {
163 av_log(NULL, AV_LOG_ERROR,
164 "Impossible to convert between the formats supported by the filter "
165 "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
166 return AVERROR(EINVAL);
167 }
168
169 if (link->type == AVMEDIA_TYPE_AUDIO &&
170 (((link = filt_ctx-> inputs[0]) &&
171 (!avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) ||
172 !avfilter_merge_formats(link->in_packing, link->out_packing))) ||
173 ((link = filt_ctx->outputs[0]) &&
174 (!avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) ||
175 !avfilter_merge_formats(link->in_packing, link->out_packing))))
176 ) {
177 av_log(NULL, AV_LOG_ERROR,
178 "Impossible to convert between the channel layouts/packing formats supported by the filter "
179 "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
180 return AVERROR(EINVAL);
181 }
182
183 return 0;
184}
185
138static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)186static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
139{187{
140 int i, j, ret;188 int i, j, ret;
141 int scaler_count = 0;189 char filt_args[128];
142 char inst_name[30];
143 190
144 /* ask all the sub-filters for their supported media formats */191 /* ask all the sub-filters for their supported media formats */
145 for (i = 0; i < graph->filter_count; i++) {192 for (i = 0; i < graph->filter_count; i++) {
@@ -155,32 +202,30 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) · 9 unmodified lines
155 202
156 for (j = 0; j < filter->input_count; j++) {203 for (j = 0; j < filter->input_count; j++) {
157 AVFilterLink *link = filter->inputs[j];204 AVFilterLink *link = filter->inputs[j];
158 if (link && link->in_formats != link->out_formats) {205 if (!link) continue;
159 if (!avfilter_merge_formats(link->in_formats,206
160 link->out_formats)) {207 if (!link->in_formats || !link->out_formats)
161 AVFilterContext *scale;208 return AVERROR(EINVAL);
162 char scale_args[256];209
163 /* couldn't merge format lists. auto-insert scale filter */210 if (link->type == AVMEDIA_TYPE_VIDEO &&
164 snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d",211 !avfilter_merge_formats(link->in_formats, link->out_formats)) {
165 scaler_count++);212
166 snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts);213 /* couldn't merge format lists, auto-insert scale filter */
167 if ((ret = avfilter_graph_create_filter(&scale, avfilter_get_by_name("scale"),214 snprintf(filt_args, sizeof(filt_args), "0:0:%s",
168 inst_name, scale_args, NULL, graph)) < 0)215 graph->scale_sws_opts);
169 return ret;216 if (ret = insert_conv_filter(graph, link, "scale", filt_args))
170 if ((ret = avfilter_insert_filter(link, scale, 0, 0)) < 0)217 return ret;
171 return ret;218 }
172 219 else if (link->type == AVMEDIA_TYPE_AUDIO) {
173 scale->filter->query_formats(scale);220 if (!link->in_chlayouts || !link->out_chlayouts ||
174 if (((link = scale-> inputs[0]) &&221 !link->in_packing || !link->out_packing)
175 !avfilter_merge_formats(link->in_formats, link->out_formats)) ||222 return AVERROR(EINVAL);
176 ((link = scale->outputs[0]) &&223
177 !avfilter_merge_formats(link->in_formats, link->out_formats))) {224 if (!avfilter_merge_formats(link->in_formats, link->out_formats) ||
178 av_log(log_ctx, AV_LOG_ERROR,225 !avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) ||
179 "Impossible to convert between the formats supported by the filter "226 !avfilter_merge_formats(link->in_packing, link->out_packing))
180 "'%s' and the filter '%s'\n", link->src->name, link->dst->name);227 if (ret = insert_conv_filter(graph, link, "aconvert", NULL))
181 return AVERROR(EINVAL);228 return ret;
182 }
183 }
184 }229 }
185 }230 }
186 }231 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t