2008-02-10 20:02:11 +02:00
|
|
|
/*
|
|
|
|
* Filter layer - format negotiation
|
|
|
|
* copyright (c) 2007 Bobby Bingham
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avfilter.h"
|
|
|
|
|
2008-02-22 00:10:11 +02:00
|
|
|
/**
|
|
|
|
* Add all refs from a to ret and destroy a.
|
|
|
|
*/
|
2008-02-10 20:04:52 +02:00
|
|
|
static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
|
|
|
|
{
|
|
|
|
int i;
|
2008-02-10 20:04:55 +02:00
|
|
|
|
2008-02-10 20:04:52 +02:00
|
|
|
for(i = 0; i < a->refcount; i ++) {
|
|
|
|
ret->refs[ret->refcount] = a->refs[i];
|
|
|
|
*ret->refs[ret->refcount++] = ret;
|
|
|
|
}
|
2008-02-10 20:04:55 +02:00
|
|
|
|
|
|
|
av_free(a->refs);
|
|
|
|
av_free(a->formats);
|
|
|
|
av_free(a);
|
2008-02-10 20:04:52 +02:00
|
|
|
}
|
|
|
|
|
2008-02-10 20:02:11 +02:00
|
|
|
AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
|
|
|
|
{
|
|
|
|
AVFilterFormats *ret;
|
|
|
|
unsigned i, j, k = 0;
|
|
|
|
|
|
|
|
ret = av_mallocz(sizeof(AVFilterFormats));
|
|
|
|
|
|
|
|
/* merge list of formats */
|
2008-02-10 20:04:43 +02:00
|
|
|
ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count,
|
|
|
|
b->format_count));
|
2008-02-10 20:02:11 +02:00
|
|
|
for(i = 0; i < a->format_count; i ++)
|
|
|
|
for(j = 0; j < b->format_count; j ++)
|
|
|
|
if(a->formats[i] == b->formats[j])
|
|
|
|
ret->formats[k++] = a->formats[i];
|
|
|
|
|
2008-02-10 20:05:02 +02:00
|
|
|
ret->format_count = k;
|
2008-02-10 20:02:11 +02:00
|
|
|
/* check that there was at least one common format */
|
2008-02-10 20:05:02 +02:00
|
|
|
if(!ret->format_count) {
|
2008-02-10 20:02:11 +02:00
|
|
|
av_free(ret->formats);
|
|
|
|
av_free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
|
2008-02-10 20:04:52 +02:00
|
|
|
|
|
|
|
merge_ref(ret, a);
|
|
|
|
merge_ref(ret, b);
|
2008-02-10 20:02:11 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-21 23:43:43 +03:00
|
|
|
AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts)
|
2009-10-19 02:06:52 +03:00
|
|
|
{
|
|
|
|
AVFilterFormats *formats;
|
|
|
|
int count;
|
|
|
|
|
2009-10-21 23:43:43 +03:00
|
|
|
for (count = 0; pix_fmts[count] != PIX_FMT_NONE; count++)
|
2009-10-19 02:06:52 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
formats = av_mallocz(sizeof(AVFilterFormats));
|
|
|
|
formats->formats = av_malloc(sizeof(*formats->formats) * count);
|
|
|
|
formats->format_count = count;
|
2009-10-21 23:43:43 +03:00
|
|
|
memcpy(formats->formats, pix_fmts, sizeof(*formats->formats) * count);
|
2009-10-19 02:06:52 +03:00
|
|
|
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
2010-01-04 00:26:59 +02:00
|
|
|
int avfilter_add_colorspace(AVFilterFormats *avff, enum PixelFormat pix_fmt)
|
|
|
|
{
|
|
|
|
enum PixelFormat *pix_fmts =
|
|
|
|
av_realloc(avff->formats, sizeof(avff->formats) * (avff->format_count+1));
|
|
|
|
|
|
|
|
if (!pix_fmts)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
avff->formats = pix_fmts;
|
|
|
|
avff->formats[avff->format_count++] = pix_fmt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-10 20:02:11 +02:00
|
|
|
AVFilterFormats *avfilter_all_colorspaces(void)
|
|
|
|
{
|
2008-02-10 20:04:49 +02:00
|
|
|
AVFilterFormats *ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ret = av_mallocz(sizeof(AVFilterFormats));
|
|
|
|
ret->formats = av_malloc(sizeof(*ret->formats) * PIX_FMT_NB);
|
|
|
|
ret->format_count = PIX_FMT_NB;
|
|
|
|
|
|
|
|
for(i = 0; i < PIX_FMT_NB; i ++)
|
|
|
|
ret->formats[i] = i;
|
|
|
|
|
|
|
|
return ret;
|
2008-02-10 20:02:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
|
|
|
|
{
|
|
|
|
*ref = f;
|
|
|
|
f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount);
|
|
|
|
f->refs[f->refcount-1] = ref;
|
|
|
|
}
|
|
|
|
|
2008-02-10 20:04:27 +02:00
|
|
|
static int find_ref_index(AVFilterFormats **ref)
|
2008-02-10 20:03:18 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < (*ref)->refcount; i ++)
|
|
|
|
if((*ref)->refs[i] == ref)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-02-10 20:02:11 +02:00
|
|
|
void avfilter_formats_unref(AVFilterFormats **ref)
|
|
|
|
{
|
2008-02-10 20:05:02 +02:00
|
|
|
int idx = find_ref_index(ref);
|
2008-02-10 20:03:18 +02:00
|
|
|
|
2008-02-10 20:05:02 +02:00
|
|
|
if(idx >= 0)
|
2008-02-10 20:03:18 +02:00
|
|
|
memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
|
|
|
|
sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
|
|
|
|
|
2008-02-10 20:02:11 +02:00
|
|
|
if(!--(*ref)->refcount) {
|
|
|
|
av_free((*ref)->formats);
|
|
|
|
av_free((*ref)->refs);
|
|
|
|
av_free(*ref);
|
|
|
|
}
|
|
|
|
*ref = NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-10 20:04:32 +02:00
|
|
|
void avfilter_formats_changeref(AVFilterFormats **oldref,
|
|
|
|
AVFilterFormats **newref)
|
|
|
|
{
|
2008-02-10 20:05:02 +02:00
|
|
|
int idx = find_ref_index(oldref);
|
2008-02-10 20:04:32 +02:00
|
|
|
|
2008-02-10 20:05:02 +02:00
|
|
|
if(idx >= 0) {
|
2008-02-10 20:04:32 +02:00
|
|
|
(*oldref)->refs[idx] = newref;
|
|
|
|
*newref = *oldref;
|
|
|
|
*oldref = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|