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
Unified · Split
| @@ -98,7 +98,9 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 97 unmodified lines | |||
| 98 | link->dst = dst; | 98 | link->dst = dst; |
| 99 | link->srcpad = srcpad; | 99 | link->srcpad = srcpad; |
| 100 | link->dstpad = dstpad; | 100 | 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; | ||
| 102 | 104 | ||
| 103 | return 0; | 105 | return 0; |
| 104 | } | 106 | } |
| @@ -122,7 +124,7 @@ int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, · 17 unmodified lines | |||
| 122 | link->dstpad = in; | 124 | link->dstpad = in; |
| 123 | filt->inputs[in] = link; | 125 | filt->inputs[in] = link; |
| 124 | 126 | ||
| 125 | /* if any information on supported colorspaces already exists on the | 127 | /* if any information on supported media formats already exists on the |
| 126 | * link, we need to preserve that */ | 128 | * link, we need to preserve that */ |
| 127 | if(link->out_formats) | 129 | if(link->out_formats) |
| 128 | avfilter_formats_changeref(&link->out_formats, | 130 | avfilter_formats_changeref(&link->out_formats, |
| @@ -25,7 +25,7 @@ · 24 unmodified lines | |||
| 25 | #include "libavutil/avutil.h" | 25 | #include "libavutil/avutil.h" |
| 26 | 26 | ||
| 27 | #define LIBAVFILTER_VERSION_MAJOR 1 | 27 | #define LIBAVFILTER_VERSION_MAJOR 1 |
| 28 | #define LIBAVFILTER_VERSION_MINOR 25 | 28 | #define LIBAVFILTER_VERSION_MINOR 26 |
| 29 | #define LIBAVFILTER_VERSION_MICRO 1 | 29 | #define LIBAVFILTER_VERSION_MICRO 1 |
| 30 | 30 | ||
| 31 | #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ | 31 | #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
| @@ -68,7 +68,7 @@ typedef struct AVFilterBuffer · 36 unmodified lines | |||
| 68 | { | 68 | { |
| 69 | uint8_t *data[4]; ///< buffer data for each plane | 69 | uint8_t *data[4]; ///< buffer data for each plane |
| 70 | int linesize[4]; ///< number of bytes per line | 70 | int linesize[4]; ///< number of bytes per line |
| 71 | enum PixelFormat format; ///< colorspace | 71 | int format; ///< media format |
| 72 | 72 | ||
| 73 | unsigned refcount; ///< number of references to this buffer | 73 | unsigned refcount; ///< number of references to this buffer |
| 74 | 74 | ||
| @@ -190,7 +190,7 @@ typedef struct AVFilterFormats AVFilterFormats; · 115 unmodified lines | |||
| 190 | struct AVFilterFormats | 190 | struct AVFilterFormats |
| 191 | { | 191 | { |
| 192 | unsigned format_count; ///< number of formats | 192 | unsigned format_count; ///< number of formats |
| 193 | enum PixelFormat *formats; ///< list of pixel formats | 193 | int *formats; ///< list of media formats |
| 194 | 194 | ||
| 195 | unsigned refcount; ///< number of references to this list | 195 | unsigned refcount; ///< number of references to this list |
| 196 | AVFilterFormats ***refs; ///< references to this list | 196 | AVFilterFormats ***refs; ///< references to this list |
| @@ -199,25 +199,25 @@ struct AVFilterFormats · 2 unmodified lines | |||
| 199 | /** | 199 | /** |
| 200 | * Create a list of supported formats. This is intended for use in | 200 | * Create a list of supported formats. This is intended for use in |
| 201 | * AVFilter->query_formats(). | 201 | * 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 |
| 203 | * @return the format list, with no existing references | 203 | * @return the format list, with no existing references |
| 204 | */ | 204 | */ |
| 205 | AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts); | 205 | AVFilterFormats *avfilter_make_format_list(const int *fmts); |
| 206 | 206 | ||
| 207 | /** | 207 | /** |
| 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. |
| 209 | * If *avff is NULL the function allocates the filter formats struct | 209 | * If *avff is NULL the function allocates the filter formats struct |
| 210 | * and puts its pointer in *avff. | 210 | * and puts its pointer in *avff. |
| 211 | * | 211 | * |
| 212 | * @return a non negative value in case of success, or a negative | 212 | * @return a non negative value in case of success, or a negative |
| 213 | * value corresponding to an AVERROR code in case of error | 213 | * value corresponding to an AVERROR code in case of error |
| 214 | */ | 214 | */ |
| 215 | int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt); | 215 | int avfilter_add_format(AVFilterFormats **avff, int fmt); |
| 216 | 216 | ||
| 217 | /** | 217 | /** |
| 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. |
| 219 | */ | 219 | */ |
| 220 | AVFilterFormats *avfilter_all_colorspaces(void); | 220 | AVFilterFormats *avfilter_all_formats(enum AVMediaType type); |
| 221 | 221 | ||
| 222 | /** | 222 | /** |
| 223 | * Return a format list which contains the intersection of the formats of | 223 | * Return a format list which contains the intersection of the formats of |
| @@ -507,9 +507,11 @@ struct AVFilterLink · 283 unmodified lines | |||
| 507 | AVLINK_INIT ///< complete | 507 | AVLINK_INIT ///< complete |
| 508 | } init_state; | 508 | } init_state; |
| 509 | 509 | ||
| 510 | enum AVMediaType type; ///< filter media type | ||
| 511 | |||
| 510 | int w; ///< agreed upon image width | 512 | int w; ///< agreed upon image width |
| 511 | int h; ///< agreed upon image height | 513 | int h; ///< agreed upon image height |
| 512 | enum PixelFormat format; ///< agreed upon image colorspace | 514 | int format; ///< agreed upon media format |
| 513 | 515 | ||
| 514 | /** | 516 | /** |
| 515 | * Lists of formats supported by the input and output filters respectively. | 517 | * 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 | |||
| 544 | AVFilterContext *dst, unsigned dstpad); | 546 | AVFilterContext *dst, unsigned dstpad); |
| 545 | 547 | ||
| 546 | /** | 548 | /** |
| 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. |
| 548 | * @param filter the filter to negotiate the properties for its inputs | 550 | * @param filter the filter to negotiate the properties for its inputs |
| 549 | * @return zero on successful negotiation | 551 | * @return zero on successful negotiation |
| 550 | */ | 552 | */ |
| @@ -111,7 +111,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) · 110 unmodified lines | |||
| 111 | int scaler_count = 0; | 111 | int scaler_count = 0; |
| 112 | char inst_name[30]; | 112 | char inst_name[30]; |
| 113 | 113 | ||
| 114 | /* ask all the sub-filters for their supported colorspaces */ | 114 | /* ask all the sub-filters for their supported media formats */ |
| 115 | for(i = 0; i < graph->filter_count; i ++) { | 115 | for(i = 0; i < graph->filter_count; i ++) { |
| 116 | if(graph->filters[i]->filter->query_formats) | 116 | if(graph->filters[i]->filter->query_formats) |
| 117 | graph->filters[i]->filter->query_formats(graph->filters[i]); | 117 | 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 | |||
| 197 | return -1; | 197 | return -1; |
| 198 | 198 | ||
| 199 | /* Once everything is merged, it's possible that we'll still have | 199 | /* 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. */ |
| 201 | pick_formats(graph); | 201 | pick_formats(graph); |
| 202 | 202 | ||
| 203 | return 0; | 203 | return 0; |
| @@ -160,7 +160,11 @@ void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) · 159 unmodified lines | |||
| 160 | 160 | ||
| 161 | int avfilter_default_query_formats(AVFilterContext *ctx) | 161 | int avfilter_default_query_formats(AVFilterContext *ctx) |
| 162 | { | 162 | { |
| 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)); | ||
| 164 | return 0; | 168 | return 0; |
| 165 | } | 169 | } |
| 166 | 170 | ||
| @@ -70,47 +70,49 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b) · 69 unmodified lines | |||
| 70 | return ret; | 70 | return ret; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts) | 73 | AVFilterFormats *avfilter_make_format_list(const int *fmts) |
| 74 | { | 74 | { |
| 75 | AVFilterFormats *formats; | 75 | AVFilterFormats *formats; |
| 76 | int count; | 76 | int count; |
| 77 | 77 | ||
| 78 | for (count = 0; pix_fmts[count] != PIX_FMT_NONE; count++) | 78 | for (count = 0; fmts[count] != -1; count++) |
| 79 | ; | 79 | ; |
| 80 | 80 | ||
| 81 | formats = av_mallocz(sizeof(AVFilterFormats)); | 81 | formats = av_mallocz(sizeof(AVFilterFormats)); |
| 82 | formats->formats = av_malloc(sizeof(*formats->formats) * count); | 82 | formats->formats = av_malloc(sizeof(*formats->formats) * count); |
| 83 | formats->format_count = count; | 83 | formats->format_count = count; |
| 84 | memcpy(formats->formats, pix_fmts, sizeof(*formats->formats) * count); | 84 | memcpy(formats->formats, fmts, sizeof(*formats->formats) * count); |
| 85 | 85 | ||
| 86 | return formats; | 86 | return formats; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt) | 89 | int avfilter_add_format(AVFilterFormats **avff, int fmt) |
| 90 | { | 90 | { |
| 91 | enum PixelFormat *pix_fmts; | 91 | int *fmts; |
| 92 | 92 | ||
| 93 | if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats)))) | 93 | if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats)))) |
| 94 | return AVERROR(ENOMEM); | 94 | return AVERROR(ENOMEM); |
| 95 | 95 | ||
| 96 | pix_fmts = av_realloc((*avff)->formats, | 96 | fmts = av_realloc((*avff)->formats, |
| 97 | sizeof((*avff)->formats) * ((*avff)->format_count+1)); | 97 | sizeof((*avff)->formats) * ((*avff)->format_count+1)); |
| 98 | if (!pix_fmts) | 98 | if (!fmts) |
| 99 | return AVERROR(ENOMEM); | 99 | return AVERROR(ENOMEM); |
| 100 | 100 | ||
| 101 | (*avff)->formats = pix_fmts; | 101 | (*avff)->formats = fmts; |
| 102 | (*avff)->formats[(*avff)->format_count++] = pix_fmt; | 102 | (*avff)->formats[(*avff)->format_count++] = fmt; |
| 103 | return 0; | 103 | return 0; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | AVFilterFormats *avfilter_all_colorspaces(void) | 106 | AVFilterFormats *avfilter_all_formats(enum AVMediaType type) |
| 107 | { | 107 | { |
| 108 | AVFilterFormats *ret = NULL; | 108 | AVFilterFormats *ret = NULL; |
| 109 | enum PixelFormat pix_fmt; | 109 | int fmt; |
| 110 | int num_formats = type == AVMEDIA_TYPE_VIDEO ? PIX_FMT_NB : 0; | ||
| 110 | 111 | ||
| 111 | for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) | 112 | for (fmt = 0; fmt < num_formats; fmt++) |
| 112 | if (!(av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL)) | 113 | if ((type != AVMEDIA_TYPE_VIDEO) || |
| 113 | avfilter_add_colorspace(&ret, pix_fmt); | 114 | (type == AVMEDIA_TYPE_VIDEO && !(av_pix_fmt_descriptors[fmt].flags & PIX_FMT_HWACCEL))) |
| 115 | avfilter_add_format(&ret, fmt); | ||
| 114 | 116 | ||
| 115 | return ret; | 117 | return ret; |
| 116 | } | 118 | } |
| @@ -83,7 +83,7 @@ static int query_formats(AVFilterContext *ctx) · 82 unmodified lines | |||
| 83 | formats = NULL; | 83 | formats = NULL; |
| 84 | for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) | 84 | for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) |
| 85 | if ( sws_isSupportedInput(pix_fmt) | 85 | if ( sws_isSupportedInput(pix_fmt) |
| 86 | && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0) { | 86 | && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) { |
| 87 | avfilter_formats_unref(&formats); | 87 | avfilter_formats_unref(&formats); |
| 88 | return ret; | 88 | return ret; |
| 89 | } | 89 | } |
| @@ -93,7 +93,7 @@ static int query_formats(AVFilterContext *ctx) · 3 unmodified lines | |||
| 93 | formats = NULL; | 93 | formats = NULL; |
| 94 | for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) | 94 | for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) |
| 95 | if ( sws_isSupportedOutput(pix_fmt) | 95 | if ( sws_isSupportedOutput(pix_fmt) |
| 96 | && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0) { | 96 | && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) { |
| 97 | avfilter_formats_unref(&formats); | 97 | avfilter_formats_unref(&formats); |
| 98 | return ret; | 98 | return ret; |
| 99 | } | 99 | } |