00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <string.h>
00023
00024 #include "libavutil/bprint.h"
00025 #include "libavutil/pixdesc.h"
00026 #include "avfilter.h"
00027 #include "avfiltergraph.h"
00028
00029 static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
00030 {
00031 char *format;
00032 char layout[64];
00033
00034 if (!buf)
00035 buf = &(AVBPrint){ 0 };
00036 switch (link->type) {
00037 case AVMEDIA_TYPE_VIDEO:
00038 format = av_x_if_null(av_get_pix_fmt_name(link->format), "?");
00039 av_bprintf(buf, "[%dx%d %d:%d %s]", link->w, link->h,
00040 link->sample_aspect_ratio.num,
00041 link->sample_aspect_ratio.den,
00042 format);
00043 break;
00044
00045 case AVMEDIA_TYPE_AUDIO:
00046 av_get_channel_layout_string(layout, sizeof(layout),
00047 -1, link->channel_layout);
00048 format = av_x_if_null(av_get_sample_fmt_name(link->format), "?");
00049 av_bprintf(buf, "[%dHz %s:%s]",
00050 (int)link->sample_rate, format, layout);
00051 break;
00052
00053 default:
00054 av_bprintf(buf, "?");
00055 break;
00056 }
00057 return buf->len;
00058 }
00059
00060 static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph)
00061 {
00062 unsigned i, j, x, e;
00063
00064 for (i = 0; i < graph->filter_count; i++) {
00065 AVFilterContext *filter = graph->filters[i];
00066 unsigned max_src_name = 0, max_dst_name = 0;
00067 unsigned max_in_name = 0, max_out_name = 0;
00068 unsigned max_in_fmt = 0, max_out_fmt = 0;
00069 unsigned width, height, in_indent;
00070 unsigned lname = strlen(filter->name);
00071 unsigned ltype = strlen(filter->filter->name);
00072
00073 for (j = 0; j < filter->input_count; j++) {
00074 AVFilterLink *l = filter->inputs[j];
00075 unsigned ln = strlen(l->src->name) + 1 + strlen(l->srcpad->name);
00076 max_src_name = FFMAX(max_src_name, ln);
00077 max_in_name = FFMAX(max_in_name, strlen(l->dstpad->name));
00078 max_in_fmt = FFMAX(max_in_fmt, print_link_prop(NULL, l));
00079 }
00080 for (j = 0; j < filter->output_count; j++) {
00081 AVFilterLink *l = filter->outputs[j];
00082 unsigned ln = strlen(l->dst->name) + 1 + strlen(l->dstpad->name);
00083 max_dst_name = FFMAX(max_dst_name, ln);
00084 max_out_name = FFMAX(max_out_name, strlen(l->srcpad->name));
00085 max_out_fmt = FFMAX(max_out_fmt, print_link_prop(NULL, l));
00086 }
00087 in_indent = max_src_name + max_in_name + max_in_fmt;
00088 in_indent += in_indent ? 4 : 0;
00089 width = FFMAX(lname + 2, ltype + 4);
00090 height = FFMAX3(2, filter->input_count, filter->output_count);
00091 av_bprint_chars(buf, ' ', in_indent);
00092 av_bprintf(buf, "+");
00093 av_bprint_chars(buf, '-', width);
00094 av_bprintf(buf, "+\n");
00095 for (j = 0; j < height; j++) {
00096 unsigned in_no = j - (height - filter->input_count ) / 2;
00097 unsigned out_no = j - (height - filter->output_count) / 2;
00098
00099
00100 if (in_no < filter->input_count) {
00101 AVFilterLink *l = filter->inputs[in_no];
00102 e = buf->len + max_src_name + 2;
00103 av_bprintf(buf, "%s:%s", l->src->name, l->srcpad->name);
00104 av_bprint_chars(buf, '-', e - buf->len);
00105 e = buf->len + max_in_fmt + 2 +
00106 max_in_name - strlen(l->dstpad->name);
00107 print_link_prop(buf, l);
00108 av_bprint_chars(buf, '-', e - buf->len);
00109 av_bprintf(buf, "%s", l->dstpad->name);
00110 } else {
00111 av_bprint_chars(buf, ' ', in_indent);
00112 }
00113
00114
00115 av_bprintf(buf, "|");
00116 if (j == (height - 2) / 2) {
00117 x = (width - lname) / 2;
00118 av_bprintf(buf, "%*s%-*s", x, "", width - x, filter->name);
00119 } else if (j == (height - 2) / 2 + 1) {
00120 x = (width - ltype - 2) / 2;
00121 av_bprintf(buf, "%*s(%s)%*s", x, "", filter->filter->name,
00122 width - ltype - 2 - x, "");
00123 } else {
00124 av_bprint_chars(buf, ' ', width);
00125 }
00126 av_bprintf(buf, "|");
00127
00128
00129 if (out_no < filter->output_count) {
00130 AVFilterLink *l = filter->outputs[out_no];
00131 unsigned ln = strlen(l->dst->name) + 1 +
00132 strlen(l->dstpad->name);
00133 e = buf->len + max_out_name + 2;
00134 av_bprintf(buf, "%s", l->srcpad->name);
00135 av_bprint_chars(buf, '-', e - buf->len);
00136 e = buf->len + max_out_fmt + 2 +
00137 max_dst_name - ln;
00138 print_link_prop(buf, l);
00139 av_bprint_chars(buf, '-', e - buf->len);
00140 av_bprintf(buf, "%s:%s", l->dst->name, l->dstpad->name);
00141 }
00142 av_bprintf(buf, "\n");
00143 }
00144 av_bprint_chars(buf, ' ', in_indent);
00145 av_bprintf(buf, "+");
00146 av_bprint_chars(buf, '-', width);
00147 av_bprintf(buf, "+\n");
00148 av_bprintf(buf, "\n");
00149 }
00150 }
00151
00152 char *avfilter_graph_dump(AVFilterGraph *graph, const char *options)
00153 {
00154 AVBPrint buf;
00155 char *dump;
00156
00157 av_bprint_init(&buf, 0, 0);
00158 avfilter_graph_dump_to_buf(&buf, graph);
00159 av_bprint_init(&buf, buf.len + 1, buf.len + 1);
00160 avfilter_graph_dump_to_buf(&buf, graph);
00161 av_bprint_finalize(&buf, &dump);
00162 return dump;
00163 }