[FFmpeg-devel] [RFC] libavfilter audio framework - split patches
Michael Niedermayer
michaelni
Sun Jul 11 16:36:20 CEST 2010
On Sun, Jul 11, 2010 at 07:06:09AM -0700, S.N. Hemanth Meenakshisundaram wrote:
> S.N. Hemanth Meenakshisundaram wrote:
>>
>> I am sending out the working lavfi audio patches in the order Stefano
>> requested for easy committing.
>
> formats.c changes. Same as before but now goes on top of the first refactor
> patch for merge_formats.
> formats.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 60 insertions(+), 2 deletions(-)
> 67a1be17c32e264d8afcd95084c207b003b34dd7 formats.c.diff
> diff --git a/libavfilter/formats.c b/libavfilter/formats.c
> index adc716a..afa4733 100644
> --- a/libavfilter/formats.c
> +++ b/libavfilter/formats.c
> @@ -36,6 +36,7 @@ static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
>
> av_free(a->refs);
> av_free(a->formats);
> + av_free(a->aformats);
> av_free(a);
> }
>
> @@ -54,9 +55,17 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
> ret = av_mallocz(sizeof(AVFilterFormats));
>
> /* merge list of formats */
> - ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count,
> + if (a->type == AVMEDIA_TYPE_VIDEO) {
> + ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count,
> b->format_count));
> - CMP_AND_ADD(a->format_count, b->format_count, a->formats, b->formats, ret->formats);
> + ret->type = AVMEDIA_TYPE_VIDEO;
> + CMP_AND_ADD(a->format_count, b->format_count, a->formats, b->formats, ret->formats);
> + } else if (a->type == AVMEDIA_TYPE_AUDIO) {
> + ret->aformats = av_malloc(sizeof(*ret->aformats) * FFMIN(a->format_count,
> + b->format_count));
> + CMP_AND_ADD(a->format_count, b->format_count, a->aformats, b->aformats, ret->aformats);
> + ret->type = AVMEDIA_TYPE_AUDIO;
> + }
>
> ret->format_count = k;
> /* check that there was at least one common format */
> @@ -85,6 +94,7 @@ AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts)
> formats = av_mallocz(sizeof(AVFilterFormats));
> formats->formats = av_malloc(sizeof(*formats->formats) * count);
> formats->format_count = count;
> + formats->type = AVMEDIA_TYPE_VIDEO;
> memcpy(formats->formats, pix_fmts, sizeof(*formats->formats) * count);
>
> return formats;
> @@ -119,6 +129,53 @@ AVFilterFormats *avfilter_all_colorspaces(void)
> return ret;
> }
>
> +AVFilterFormats *avfilter_make_aformat_list(const enum SampleFormat *sample_fmts)
> +{
> + AVFilterFormats *formats;
> + int count;
> +
> + for (count = 0; sample_fmts[count] != SAMPLE_FMT_NONE; count++)
> + ;
> +
> + formats = av_mallocz(sizeof(AVFilterFormats));
> + formats->aformats = av_malloc(sizeof(*formats->aformats) * count);
> + formats->format_count = count;
> + formats->type = AVMEDIA_TYPE_AUDIO;
> + memcpy(formats->aformats, sample_fmts, sizeof(*formats->aformats) * count);
> +
> + return formats;
> +}
> +
> +int avfilter_add_sampleformat(AVFilterFormats **avff, enum SampleFormat sample_fmt)
> +{
> + enum SampleFormat *sample_fmts;
> +
> + if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats))))
> + return AVERROR(ENOMEM);
> +
> + sample_fmts = av_realloc((*avff)->aformats,
> + sizeof((*avff)->aformats) * ((*avff)->format_count+1));
> + if (!sample_fmts)
> + return AVERROR(ENOMEM);
> +
> + (*avff)->aformats = sample_fmts;
> + (*avff)->aformats[(*avff)->format_count++] = sample_fmt;
> + return 0;
> +}
this code looks duplicated
i think (a)formats could maybe be a union or just int and code could be shared
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100711/a0b165c7/attachment.pgp>
More information about the ffmpeg-devel
mailing list