[FFmpeg-devel] [RFC] libavfilter audio - af_resample
Michael Niedermayer
michaelni
Wed Jul 14 16:30:35 CEST 2010
On Wed, Jul 14, 2010 at 03:33:27AM -0700, S.N. Hemanth Meenakshisundaram wrote:
> Michael Niedermayer wrote:
>> On Tue, Jul 13, 2010 at 03:14:31AM -0700, S.N. Hemanth Meenakshisundaram
>> wrote:
>>
>>> Michael Niedermayer wrote:
>>>
>>>> On Sat, Jul 10, 2010 at 11:37:54PM +0100, M?ns Rullg?rd wrote:
>>>>
>>>>> Michael Niedermayer <michaelni at gmx.at> writes:
>>>>>
>>>>>
>>> Of course, vf_scale internally calls libswscale while af_resample is
>>> currently duplicating a lot of lavc's resample & audioconvert.c code
>>> internally so I could make changes if necessary.
>>>
>>> Should I instead wrap audioconvert for sample format conversion (use
>>> av_audio_convert) and wrap resample.c for channel mixing. Also, perhaps
>>> af_resample should be renamed to reformat to avoid confusing with the
>>> downsampling/upsampling in lavc resample2.c
>>>
>>
>> code should be efficient, not doing unneeded operations or copying.
>> It would also be a plus if the individual parts could be used without
>> avfilter.
>>
>>
>> [...]
>>
> Hi All,
>
> Attached is a patch for af_resample.c to avoid double free and so it works
> with the common Pix Formats/Sample Formats enum. This only shows
> differences from the previous version sent.
>
> If no conversions are required, it just passes on the buffer to the next
> filter.
>
> I'll update libavfilter.texi with usage info. Since individual parts need
> to be used externally, I will rewrite this to wrap available lavc code
> wherever possible.
>
> Regards,
> Hemanth
>
> af_resample.c | 31 ++++++++++++++++++++++++-------
> 1 file changed, 24 insertions(+), 7 deletions(-)
> 3f6958a9d58e84b84f6b399c94af27264f8c9774 resample_new.diff
> diff --git a/libavfilter/af_resample.c b/libavfilter/af_resample.c
> index a7ddd70..d0f157b 100644
> --- a/libavfilter/af_resample.c
> +++ b/libavfilter/af_resample.c
> @@ -38,6 +38,7 @@ typedef struct {
> int64_t out_channel_layout; ///< output channel layout
>
> int in_samples_nb; ///< stores number of samples in previous incoming buffer
> + AVFilterSamplesRef *prev_samples; ///< stores previous incoming buffer
> AVFilterSamplesRef *s16_samples; ///< stores temporary audio data in s16 sample format for channel layout conversions
> AVFilterSamplesRef *temp_samples; ///< stores temporary audio data in s16 sample format after channel layout conversions
> AVFilterSamplesRef *out_samples; ///< stores audio data after required sample format and channel layout conversions
> @@ -193,12 +194,17 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
> static av_cold void uninit(AVFilterContext *ctx)
> {
> ResampleContext *resample = ctx->priv;
> - if (resample->s16_samples)
> + if (resample->s16_samples && resample->s16_samples != resample->prev_samples)
> avfilter_unref_samples(resample->s16_samples);
> - if (resample->temp_samples)
> + if (resample->temp_samples && (resample->temp_samples != resample->prev_samples) &&
> + (resample->temp_samples != resample->s16_samples))
> avfilter_unref_samples(resample->temp_samples);
> - if (resample->out_samples)
> + if (resample->out_samples && (resample->out_samples != resample->prev_samples) &&
> + (resample->out_samples != resample->s16_samples) &&
> + (resample->out_samples != resample->temp_samples))
> avfilter_unref_samples(resample->out_samples);
> + if (resample->prev_samples)
> + avfilter_unref_samples(resample->prev_samples);
> }
>
> static int query_formats(AVFilterContext *ctx)
i think you should seperate variables that hold "primary" pointers
and ones that contain copies of them
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- 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/20100714/d3135d07/attachment.pgp>
More information about the ffmpeg-devel
mailing list