You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +02:00 
			
		
		
		
	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
This commit is contained in:
		
				
					committed by
					
						 Stefano Sabatini
						Stefano Sabatini
					
				
			
			
				
	
			
			
			
						parent
						
							98137a1a5b
						
					
				
				
					commit
					bdab614be8
				
			| @@ -98,7 +98,9 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, | ||||
|     link->dst     = dst; | ||||
|     link->srcpad  = srcpad; | ||||
|     link->dstpad  = dstpad; | ||||
|     link->format  = PIX_FMT_NONE; | ||||
|     link->type    = src->output_pads[srcpad].type; | ||||
|     assert(PIX_FMT_NONE == -1 && SAMPLE_FMT_NONE == -1); | ||||
|     link->format  = -1; | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
| @@ -122,7 +124,7 @@ int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, | ||||
|     link->dstpad = in; | ||||
|     filt->inputs[in] = link; | ||||
|  | ||||
|     /* if any information on supported colorspaces already exists on the | ||||
|     /* if any information on supported media formats already exists on the | ||||
|      * link, we need to preserve that */ | ||||
|     if(link->out_formats) | ||||
|         avfilter_formats_changeref(&link->out_formats, | ||||
|   | ||||
| @@ -25,7 +25,7 @@ | ||||
| #include "libavutil/avutil.h" | ||||
|  | ||||
| #define LIBAVFILTER_VERSION_MAJOR  1 | ||||
| #define LIBAVFILTER_VERSION_MINOR 25 | ||||
| #define LIBAVFILTER_VERSION_MINOR 26 | ||||
| #define LIBAVFILTER_VERSION_MICRO  1 | ||||
|  | ||||
| #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ | ||||
| @@ -68,7 +68,7 @@ typedef struct AVFilterBuffer | ||||
| { | ||||
|     uint8_t *data[4];           ///< buffer data for each plane | ||||
|     int linesize[4];            ///< number of bytes per line | ||||
|     enum PixelFormat format;    ///< colorspace | ||||
|     int format;                 ///< media format | ||||
|  | ||||
|     unsigned refcount;          ///< number of references to this buffer | ||||
|  | ||||
| @@ -190,7 +190,7 @@ typedef struct AVFilterFormats AVFilterFormats; | ||||
| struct AVFilterFormats | ||||
| { | ||||
|     unsigned format_count;      ///< number of formats | ||||
|     enum PixelFormat *formats;  ///< list of pixel formats | ||||
|     int *formats;               ///< list of media formats | ||||
|  | ||||
|     unsigned refcount;          ///< number of references to this list | ||||
|     AVFilterFormats ***refs;    ///< references to this list | ||||
| @@ -199,25 +199,25 @@ struct AVFilterFormats | ||||
| /** | ||||
|  * Create a list of supported formats. This is intended for use in | ||||
|  * AVFilter->query_formats(). | ||||
|  * @param pix_fmts list of pixel formats, terminated by PIX_FMT_NONE | ||||
|  * @param fmts list of media formats, terminated by -1 | ||||
|  * @return the format list, with no existing references | ||||
|  */ | ||||
| AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts); | ||||
| AVFilterFormats *avfilter_make_format_list(const int *fmts); | ||||
|  | ||||
| /** | ||||
|  * Add pix_fmt to the list of pixel formats contained in *avff. | ||||
|  * Add fmt to the list of media formats contained in *avff. | ||||
|  * If *avff is NULL the function allocates the filter formats struct | ||||
|  * and puts its pointer in *avff. | ||||
|  * | ||||
|  * @return a non negative value in case of success, or a negative | ||||
|  * value corresponding to an AVERROR code in case of error | ||||
|  */ | ||||
| int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt); | ||||
| int avfilter_add_format(AVFilterFormats **avff, int fmt); | ||||
|  | ||||
| /** | ||||
|  * Return a list of all colorspaces supported by FFmpeg. | ||||
|  * Return a list of all formats supported by FFmpeg for the given media type. | ||||
|  */ | ||||
| AVFilterFormats *avfilter_all_colorspaces(void); | ||||
| AVFilterFormats *avfilter_all_formats(enum AVMediaType type); | ||||
|  | ||||
| /** | ||||
|  * Return a format list which contains the intersection of the formats of | ||||
| @@ -507,9 +507,11 @@ struct AVFilterLink | ||||
|         AVLINK_INIT             ///< complete | ||||
|     } init_state; | ||||
|  | ||||
|     enum AVMediaType type;      ///< filter media type | ||||
|  | ||||
|     int w;                      ///< agreed upon image width | ||||
|     int h;                      ///< agreed upon image height | ||||
|     enum PixelFormat format;    ///< agreed upon image colorspace | ||||
|     int format;                 ///< agreed upon media format | ||||
|  | ||||
|     /** | ||||
|      * Lists of formats supported by the input and output filters respectively. | ||||
| @@ -544,7 +546,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, | ||||
|                   AVFilterContext *dst, unsigned dstpad); | ||||
|  | ||||
| /** | ||||
|  * Negotiate the colorspace, dimensions, etc of all inputs to a filter. | ||||
|  * Negotiate the media format, dimensions, etc of all inputs to a filter. | ||||
|  * @param filter the filter to negotiate the properties for its inputs | ||||
|  * @return       zero on successful negotiation | ||||
|  */ | ||||
|   | ||||
| @@ -111,7 +111,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) | ||||
|     int scaler_count = 0; | ||||
|     char inst_name[30]; | ||||
|  | ||||
|     /* ask all the sub-filters for their supported colorspaces */ | ||||
|     /* ask all the sub-filters for their supported media formats */ | ||||
|     for(i = 0; i < graph->filter_count; i ++) { | ||||
|         if(graph->filters[i]->filter->query_formats) | ||||
|             graph->filters[i]->filter->query_formats(graph->filters[i]); | ||||
| @@ -197,7 +197,7 @@ int avfilter_graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx) | ||||
|         return -1; | ||||
|  | ||||
|     /* Once everything is merged, it's possible that we'll still have | ||||
|      * multiple valid colorspace choices. We pick the first one. */ | ||||
|      * multiple valid media format choices. We pick the first one. */ | ||||
|     pick_formats(graph); | ||||
|  | ||||
|     return 0; | ||||
|   | ||||
| @@ -160,7 +160,11 @@ void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) | ||||
|  | ||||
| int avfilter_default_query_formats(AVFilterContext *ctx) | ||||
| { | ||||
|     avfilter_set_common_formats(ctx, avfilter_all_colorspaces()); | ||||
|     enum AVMediaType type = ctx->inputs [0] ? ctx->inputs [0]->type : | ||||
|                             ctx->outputs[0] ? ctx->outputs[0]->type : | ||||
|                             AVMEDIA_TYPE_VIDEO; | ||||
|  | ||||
|     avfilter_set_common_formats(ctx, avfilter_all_formats(type)); | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -70,47 +70,49 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b) | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts) | ||||
| AVFilterFormats *avfilter_make_format_list(const int *fmts) | ||||
| { | ||||
|     AVFilterFormats *formats; | ||||
|     int count; | ||||
|  | ||||
|     for (count = 0; pix_fmts[count] != PIX_FMT_NONE; count++) | ||||
|     for (count = 0; fmts[count] != -1; count++) | ||||
|         ; | ||||
|  | ||||
|     formats               = av_mallocz(sizeof(AVFilterFormats)); | ||||
|     formats->formats      = av_malloc(sizeof(*formats->formats) * count); | ||||
|     formats->format_count = count; | ||||
|     memcpy(formats->formats, pix_fmts, sizeof(*formats->formats) * count); | ||||
|     memcpy(formats->formats, fmts, sizeof(*formats->formats) * count); | ||||
|  | ||||
|     return formats; | ||||
| } | ||||
|  | ||||
| int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt) | ||||
| int avfilter_add_format(AVFilterFormats **avff, int fmt) | ||||
| { | ||||
|     enum PixelFormat *pix_fmts; | ||||
|     int *fmts; | ||||
|  | ||||
|     if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats)))) | ||||
|         return AVERROR(ENOMEM); | ||||
|  | ||||
|     pix_fmts = av_realloc((*avff)->formats, | ||||
|                           sizeof((*avff)->formats) * ((*avff)->format_count+1)); | ||||
|     if (!pix_fmts) | ||||
|     fmts = av_realloc((*avff)->formats, | ||||
|                       sizeof((*avff)->formats) * ((*avff)->format_count+1)); | ||||
|     if (!fmts) | ||||
|         return AVERROR(ENOMEM); | ||||
|  | ||||
|     (*avff)->formats = pix_fmts; | ||||
|     (*avff)->formats[(*avff)->format_count++] = pix_fmt; | ||||
|     (*avff)->formats = fmts; | ||||
|     (*avff)->formats[(*avff)->format_count++] = fmt; | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
| AVFilterFormats *avfilter_all_colorspaces(void) | ||||
| AVFilterFormats *avfilter_all_formats(enum AVMediaType type) | ||||
| { | ||||
|     AVFilterFormats *ret = NULL; | ||||
|     enum PixelFormat pix_fmt; | ||||
|     int fmt; | ||||
|     int num_formats = type == AVMEDIA_TYPE_VIDEO ? PIX_FMT_NB : 0; | ||||
|  | ||||
|     for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) | ||||
|         if (!(av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL)) | ||||
|             avfilter_add_colorspace(&ret, pix_fmt); | ||||
|     for (fmt = 0; fmt < num_formats; fmt++) | ||||
|         if ((type != AVMEDIA_TYPE_VIDEO) || | ||||
|             (type == AVMEDIA_TYPE_VIDEO && !(av_pix_fmt_descriptors[fmt].flags & PIX_FMT_HWACCEL))) | ||||
|             avfilter_add_format(&ret, fmt); | ||||
|  | ||||
|     return ret; | ||||
| } | ||||
|   | ||||
| @@ -83,7 +83,7 @@ static int query_formats(AVFilterContext *ctx) | ||||
|         formats = NULL; | ||||
|         for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) | ||||
|             if (   sws_isSupportedInput(pix_fmt) | ||||
|                 && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0) { | ||||
|                 && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) { | ||||
|                 avfilter_formats_unref(&formats); | ||||
|                 return ret; | ||||
|             } | ||||
| @@ -93,7 +93,7 @@ static int query_formats(AVFilterContext *ctx) | ||||
|         formats = NULL; | ||||
|         for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) | ||||
|             if (    sws_isSupportedOutput(pix_fmt) | ||||
|                 && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0) { | ||||
|                 && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) { | ||||
|                 avfilter_formats_unref(&formats); | ||||
|                 return ret; | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user