History

Generalize pixel format enum fields to int formats.

This is needed to make the libavfilter framework work with audio filters. In particular add a type field to AVFilterLink, change the field types: enum PixelFormat format -> int format in AVFilterBuffer enum PixelFormat *formats -> int *formats in AVFilterFormats enum PixelFormat *format -> int format in AVFilterLink and change the function signatures: AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts); -> AVFilterFormats *avfilter_make_format_list(const int *fmts); int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt); -> int avfilter_add_format(AVFilterFormats **avff, int fmt); AVFilterFormats *avfilter_all_colorspaces(void); -> AVFilterFormats *avfilter_all_formats(enum AVMediaType type); This change breaks libavfilter API/ABI. Patch by S.N. Hemanth Meenakshisundaram |smeenaks|ucsd|edu|. Originally committed as revision 24424 to svn://svn.ffmpeg.org/ffmpeg/trunk

S.N. Hemanth Meenakshisundaram committed 16 years ago

Commit bdab6141 parent 98137a16 files · +43 −33Browse files

Unified · Split

6 files
  1. libavfilter/avfilter.c +4 −2
  2. libavfilter/avfilter.h +13 −11
  3. libavfilter/avfiltergraph.c +2 −2
  4. libavfilter/defaults.c +5 −1
  5. libavfilter/formats.c +17 −15
  6. libavfilter/vf_scale.c +2 −2
libavfilter/avfilter.c+4−2
@@ -98,7 +98,9 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 97 unmodified lines
9898 link->dst = dst;
9999 link->srcpad = srcpad;
100100 link->dstpad = dstpad;
101− link->format = PIX_FMT_NONE;
101+ link->type = src->output_pads[srcpad].type;
102+ assert(PIX_FMT_NONE == -1 && SAMPLE_FMT_NONE == -1);
103+ link->format = -1;
102104
103105 return 0;
104106 }
@@ -122,7 +124,7 @@ int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, · 17 unmodified lines
122124 link->dstpad = in;
123125 filt->inputs[in] = link;
124126
125− /* if any information on supported colorspaces already exists on the
127+ /* if any information on supported media formats already exists on the
126128 * link, we need to preserve that */
127129 if(link->out_formats)
128130 avfilter_formats_changeref(&link->out_formats,
libavfilter/avfilter.h+13−11
@@ -25,7 +25,7 @@ · 24 unmodified lines
2525 #include "libavutil/avutil.h"
2626
2727 #define LIBAVFILTER_VERSION_MAJOR 1
28−#define LIBAVFILTER_VERSION_MINOR 25
28+#define LIBAVFILTER_VERSION_MINOR 26
2929 #define LIBAVFILTER_VERSION_MICRO 1
3030
3131 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
@@ -68,7 +68,7 @@ typedef struct AVFilterBuffer · 36 unmodified lines
6868 {
6969 uint8_t *data[4]; ///< buffer data for each plane
7070 int linesize[4]; ///< number of bytes per line
71− enum PixelFormat format; ///< colorspace
71+ int format; ///< media format
7272
7373 unsigned refcount; ///< number of references to this buffer
7474
@@ -190,7 +190,7 @@ typedef struct AVFilterFormats AVFilterFormats; · 115 unmodified lines
190190 struct AVFilterFormats
191191 {
192192 unsigned format_count; ///< number of formats
193− enum PixelFormat *formats; ///< list of pixel formats
193+ int *formats; ///< list of media formats
194194
195195 unsigned refcount; ///< number of references to this list
196196 AVFilterFormats ***refs; ///< references to this list
@@ -199,25 +199,25 @@ struct AVFilterFormats · 2 unmodified lines
199199 /**
200200 * Create a list of supported formats. This is intended for use in
201201 * AVFilter->query_formats().
202− * @param pix_fmts list of pixel formats, terminated by PIX_FMT_NONE
202+ * @param fmts list of media formats, terminated by -1
203203 * @return the format list, with no existing references
204204 */
205−AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts);
205+AVFilterFormats *avfilter_make_format_list(const int *fmts);
206206
207207 /**
208− * Add pix_fmt to the list of pixel formats contained in *avff.
208+ * Add fmt to the list of media formats contained in *avff.
209209 * If *avff is NULL the function allocates the filter formats struct
210210 * and puts its pointer in *avff.
211211 *
212212 * @return a non negative value in case of success, or a negative
213213 * value corresponding to an AVERROR code in case of error
214214 */
215−int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt);
215+int avfilter_add_format(AVFilterFormats **avff, int fmt);
216216
217217 /**
218− * Return a list of all colorspaces supported by FFmpeg.
218+ * Return a list of all formats supported by FFmpeg for the given media type.
219219 */
220−AVFilterFormats *avfilter_all_colorspaces(void);
220+AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
221221
222222 /**
223223 * Return a format list which contains the intersection of the formats of
@@ -507,9 +507,11 @@ struct AVFilterLink · 283 unmodified lines
507507 AVLINK_INIT ///< complete
508508 } init_state;
509509
510+ enum AVMediaType type; ///< filter media type
511+
510512 int w; ///< agreed upon image width
511513 int h; ///< agreed upon image height
512− enum PixelFormat format; ///< agreed upon image colorspace
514+ int format; ///< agreed upon media format
513515
514516 /**
515517 * Lists of formats supported by the input and output filters respectively.
@@ -544,7 +546,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 28 unmodified lines
544546 AVFilterContext *dst, unsigned dstpad);
545547
546548 /**
547− * Negotiate the colorspace, dimensions, etc of all inputs to a filter.
549+ * Negotiate the media format, dimensions, etc of all inputs to a filter.
548550 * @param filter the filter to negotiate the properties for its inputs
549551 * @return zero on successful negotiation
550552 */
libavfilter/avfiltergraph.c+2−2
@@ -111,7 +111,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) · 110 unmodified lines
111111 int scaler_count = 0;
112112 char inst_name[30];
113113
114− /* ask all the sub-filters for their supported colorspaces */
114+ /* ask all the sub-filters for their supported media formats */
115115 for(i = 0; i < graph->filter_count; i ++) {
116116 if(graph->filters[i]->filter->query_formats)
117117 graph->filters[i]->filter->query_formats(graph->filters[i]);
@@ -197,7 +197,7 @@ int avfilter_graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx) · 79 unmodified lines
197197 return -1;
198198
199199 /* Once everything is merged, it's possible that we'll still have
200− * multiple valid colorspace choices. We pick the first one. */
200+ * multiple valid media format choices. We pick the first one. */
201201 pick_formats(graph);
202202
203203 return 0;
libavfilter/defaults.c+5−1
@@ -160,7 +160,11 @@ void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) · 159 unmodified lines
160160
161161 int avfilter_default_query_formats(AVFilterContext *ctx)
162162 {
163− avfilter_set_common_formats(ctx, avfilter_all_colorspaces());
163+ enum AVMediaType type = ctx->inputs [0] ? ctx->inputs [0]->type :
164+ ctx->outputs[0] ? ctx->outputs[0]->type :
165+ AVMEDIA_TYPE_VIDEO;
166+
167+ avfilter_set_common_formats(ctx, avfilter_all_formats(type));
164168 return 0;
165169 }
166170
libavfilter/formats.c+17−15
@@ -70,47 +70,49 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b) · 69 unmodified lines
7070 return ret;
7171 }
7272
73−AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts)
73+AVFilterFormats *avfilter_make_format_list(const int *fmts)
7474 {
7575 AVFilterFormats *formats;
7676 int count;
7777
78− for (count = 0; pix_fmts[count] != PIX_FMT_NONE; count++)
78+ for (count = 0; fmts[count] != -1; count++)
7979 ;
8080
8181 formats = av_mallocz(sizeof(AVFilterFormats));
8282 formats->formats = av_malloc(sizeof(*formats->formats) * count);
8383 formats->format_count = count;
84− memcpy(formats->formats, pix_fmts, sizeof(*formats->formats) * count);
84+ memcpy(formats->formats, fmts, sizeof(*formats->formats) * count);
8585
8686 return formats;
8787 }
8888
89−int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt)
89+int avfilter_add_format(AVFilterFormats **avff, int fmt)
9090 {
91− enum PixelFormat *pix_fmts;
91+ int *fmts;
9292
9393 if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats))))
9494 return AVERROR(ENOMEM);
9595
96− pix_fmts = av_realloc((*avff)->formats,
97− sizeof((*avff)->formats) * ((*avff)->format_count+1));
98− if (!pix_fmts)
96+ fmts = av_realloc((*avff)->formats,
97+ sizeof((*avff)->formats) * ((*avff)->format_count+1));
98+ if (!fmts)
9999 return AVERROR(ENOMEM);
100100
101− (*avff)->formats = pix_fmts;
102− (*avff)->formats[(*avff)->format_count++] = pix_fmt;
101+ (*avff)->formats = fmts;
102+ (*avff)->formats[(*avff)->format_count++] = fmt;
103103 return 0;
104104 }
105105
106−AVFilterFormats *avfilter_all_colorspaces(void)
106+AVFilterFormats *avfilter_all_formats(enum AVMediaType type)
107107 {
108108 AVFilterFormats *ret = NULL;
109− enum PixelFormat pix_fmt;
109+ int fmt;
110+ int num_formats = type == AVMEDIA_TYPE_VIDEO ? PIX_FMT_NB : 0;
110111
111− for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
112− if (!(av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL))
113− avfilter_add_colorspace(&ret, pix_fmt);
112+ for (fmt = 0; fmt < num_formats; fmt++)
113+ if ((type != AVMEDIA_TYPE_VIDEO) ||
114+ (type == AVMEDIA_TYPE_VIDEO && !(av_pix_fmt_descriptors[fmt].flags & PIX_FMT_HWACCEL)))
115+ avfilter_add_format(&ret, fmt);
114116
115117 return ret;
116118 }
libavfilter/vf_scale.c+2−2
@@ -83,7 +83,7 @@ static int query_formats(AVFilterContext *ctx) · 82 unmodified lines
8383 formats = NULL;
8484 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
8585 if ( sws_isSupportedInput(pix_fmt)
86− && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0) {
86+ && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) {
8787 avfilter_formats_unref(&formats);
8888 return ret;
8989 }
@@ -93,7 +93,7 @@ static int query_formats(AVFilterContext *ctx) · 3 unmodified lines
9393 formats = NULL;
9494 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
9595 if ( sws_isSupportedOutput(pix_fmt)
96− && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0) {
96+ && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) {
9797 avfilter_formats_unref(&formats);
9898 return ret;
9999 }

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