* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <ctype.h>
#include <string.h>
+#include "libavutil/avassert.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/common.h"
+#include "libavutil/log.h"
#include "avfilter.h"
#include "avfiltergraph.h"
#include "formats.h"
#include "internal.h"
-#include "libavutil/audioconvert.h"
-#include "libavutil/avassert.h"
-#include "libavutil/log.h"
-
static const AVClass filtergraph_class = {
.class_name = "AVFilterGraph",
.item_name = av_default_item_name,
AVFilterGraph *avfilter_graph_alloc(void)
{
- AVFilterGraph *ret = av_mallocz(sizeof(AVFilterGraph));
+ AVFilterGraph *ret = av_mallocz(sizeof(*ret));
if (!ret)
return NULL;
ret->av_class = &filtergraph_class;
{
if (!*graph)
return;
- for (; (*graph)->filter_count > 0; (*graph)->filter_count--)
- avfilter_free((*graph)->filters[(*graph)->filter_count - 1]);
+ for (; (*graph)->nb_filters > 0; (*graph)->nb_filters--)
+ avfilter_free((*graph)->filters[(*graph)->nb_filters - 1]);
av_freep(&(*graph)->scale_sws_opts);
+ av_freep(&(*graph)->resample_lavr_opts);
av_freep(&(*graph)->filters);
av_freep(graph);
}
int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter)
{
AVFilterContext **filters = av_realloc(graph->filters,
- sizeof(AVFilterContext*) * (graph->filter_count+1));
+ sizeof(*filters) * (graph->nb_filters + 1));
if (!filters)
return AVERROR(ENOMEM);
graph->filters = filters;
- graph->filters[graph->filter_count++] = filter;
+ graph->filters[graph->nb_filters++] = filter;
return 0;
}
AVFilterContext *filt;
int i, j;
- for (i = 0; i < graph->filter_count; i++) {
+ for (i = 0; i < graph->nb_filters; i++) {
filt = graph->filters[i];
for (j = 0; j < filt->nb_inputs; j++) {
AVFilterContext *filt;
int i, ret;
- for (i=0; i < graph->filter_count; i++) {
+ for (i = 0; i < graph->nb_filters; i++) {
filt = graph->filters[i];
if (!filt->nb_outputs) {
{
int i;
- for (i = 0; i < graph->filter_count; i++)
+ for (i = 0; i < graph->nb_filters; i++)
if (graph->filters[i]->name && !strcmp(name, graph->filters[i]->name))
return graph->filters[i];
int scaler_count = 0, resampler_count = 0;
/* ask all the sub-filters for their supported media formats */
- for (i = 0; i < graph->filter_count; i++) {
+ for (i = 0; i < graph->nb_filters; i++) {
if (graph->filters[i]->filter->query_formats)
graph->filters[i]->filter->query_formats(graph->filters[i]);
else
}
/* go through and merge as many format lists as possible */
- for (i = 0; i < graph->filter_count; i++) {
+ for (i = 0; i < graph->nb_filters; i++) {
AVFilterContext *filter = graph->filters[i];
for (j = 0; j < filter->nb_inputs; j++) {
snprintf(inst_name, sizeof(inst_name), "auto-inserted resampler %d",
resampler_count++);
+ scale_args[0] = '\0';
+ if (graph->resample_lavr_opts)
+ snprintf(scale_args, sizeof(scale_args), "%s",
+ graph->resample_lavr_opts);
if ((ret = avfilter_graph_create_filter(&convert, filter,
- inst_name, NULL, NULL, graph)) < 0)
+ inst_name, scale_args,
+ NULL, graph)) < 0)
return ret;
break;
default:
do {
reduced = 0;
- for (i = 0; i < graph->filter_count; i++)
+ for (i = 0; i < graph->nb_filters; i++)
reduced |= reduce_formats_on_filter(graph->filters[i]);
} while (reduced);
}
{
int i;
- for (i = 0; i < graph->filter_count; i++)
+ for (i = 0; i < graph->nb_filters; i++)
swap_samplerates_on_filter(graph->filters[i]);
}
for (i = 0; i < filter->nb_outputs; i++) {
AVFilterLink *outlink = filter->outputs[i];
- int best_idx, best_score = INT_MIN, best_count_diff = INT_MAX;
+ int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
if (outlink->type != AVMEDIA_TYPE_AUDIO ||
outlink->in_channel_layouts->nb_channel_layouts < 2)
best_count_diff = count_diff;
}
}
+ av_assert0(best_idx >= 0);
FFSWAP(uint64_t, outlink->in_channel_layouts->channel_layouts[0],
outlink->in_channel_layouts->channel_layouts[best_idx]);
}
{
int i;
- for (i = 0; i < graph->filter_count; i++)
+ for (i = 0; i < graph->nb_filters; i++)
swap_channel_layouts_on_filter(graph->filters[i]);
}
{
int i;
- for (i = 0; i < graph->filter_count; i++)
+ for (i = 0; i < graph->nb_filters; i++)
swap_sample_fmts_on_filter(graph->filters[i]);
}
{
int i, j, ret;
- for (i = 0; i < graph->filter_count; i++) {
+ for (i = 0; i < graph->nb_filters; i++) {
AVFilterContext *filter = graph->filters[i];
for (j = 0; j < filter->nb_inputs; j++)
int i, j, ret;
int fifo_count = 0;
- for (i = 0; i < graph->filter_count; i++) {
+ for (i = 0; i < graph->nb_filters; i++) {
f = graph->filters[i];
for (j = 0; j < f->nb_inputs; j++) {