• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavfilter/formats.c

Go to the documentation of this file.
00001 /*
00002  * Filter layer - format negotiation
00003  * copyright (c) 2007 Bobby Bingham
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avfilter.h"
00023 
00027 static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
00028 {
00029     int i;
00030 
00031     for(i = 0; i < a->refcount; i ++) {
00032         ret->refs[ret->refcount] = a->refs[i];
00033         *ret->refs[ret->refcount++] = ret;
00034     }
00035 
00036     av_free(a->refs);
00037     av_free(a->formats);
00038     av_free(a);
00039 }
00040 
00041 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
00042 {
00043     AVFilterFormats *ret;
00044     unsigned i, j, k = 0;
00045 
00046     if (a == b)
00047         return a;
00048 
00049     if (a == b)
00050         return a;
00051 
00052     ret = av_mallocz(sizeof(AVFilterFormats));
00053 
00054     /* merge list of formats */
00055     ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count,
00056                                                            b->format_count));
00057     for(i = 0; i < a->format_count; i ++)
00058         for(j = 0; j < b->format_count; j ++)
00059             if(a->formats[i] == b->formats[j])
00060                 ret->formats[k++] = a->formats[i];
00061 
00062     ret->format_count = k;
00063     /* check that there was at least one common format */
00064     if(!ret->format_count) {
00065         av_free(ret->formats);
00066         av_free(ret);
00067         return NULL;
00068     }
00069 
00070     ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
00071 
00072     merge_ref(ret, a);
00073     merge_ref(ret, b);
00074 
00075     return ret;
00076 }
00077 
00078 AVFilterFormats *avfilter_make_format_list(int len, ...)
00079 {
00080     AVFilterFormats *ret;
00081     int i;
00082     va_list vl;
00083 
00084     ret = av_mallocz(sizeof(AVFilterFormats));
00085     ret->formats = av_malloc(sizeof(*ret->formats) * len);
00086     ret->format_count = len;
00087 
00088     va_start(vl, len);
00089     for(i = 0; i < len; i ++)
00090         ret->formats[i] = va_arg(vl, int);
00091     va_end(vl);
00092 
00093     return ret;
00094 }
00095 
00096 AVFilterFormats *avfilter_all_colorspaces(void)
00097 {
00098     AVFilterFormats *ret;
00099     int i;
00100 
00101     ret = av_mallocz(sizeof(AVFilterFormats));
00102     ret->formats = av_malloc(sizeof(*ret->formats) * PIX_FMT_NB);
00103     ret->format_count = PIX_FMT_NB;
00104 
00105     for(i = 0; i < PIX_FMT_NB; i ++)
00106         ret->formats[i] = i;
00107 
00108     return ret;
00109 }
00110 
00111 void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
00112 {
00113     *ref = f;
00114     f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount);
00115     f->refs[f->refcount-1] = ref;
00116 }
00117 
00118 static int find_ref_index(AVFilterFormats **ref)
00119 {
00120     int i;
00121     for(i = 0; i < (*ref)->refcount; i ++)
00122         if((*ref)->refs[i] == ref)
00123             return i;
00124     return -1;
00125 }
00126 
00127 void avfilter_formats_unref(AVFilterFormats **ref)
00128 {
00129     int idx = find_ref_index(ref);
00130 
00131     if(idx >= 0)
00132         memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
00133             sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
00134 
00135     if(!--(*ref)->refcount) {
00136         av_free((*ref)->formats);
00137         av_free((*ref)->refs);
00138         av_free(*ref);
00139     }
00140     *ref = NULL;
00141 }
00142 
00143 void avfilter_formats_changeref(AVFilterFormats **oldref,
00144                                 AVFilterFormats **newref)
00145 {
00146     int idx = find_ref_index(oldref);
00147 
00148     if(idx >= 0) {
00149         (*oldref)->refs[idx] = newref;
00150         *newref = *oldref;
00151         *oldref = NULL;
00152     }
00153 }
00154 

Generated on Sat Feb 16 2013 09:23:14 for ffmpeg by  doxygen 1.7.1